; ***************************************************************************
; copyright   : (C) 2024 by Martin Preuss
; email       : martin@libchipcard.de
;
; ***************************************************************************
; * This file is part of the project "AqHome".                              *
; * Please see toplevel file COPYING of that project for license details.   *
; ***************************************************************************


; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; This file contains timer handlers for the address protocol
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;


; ***************************************************************************
; code

.cseg



COM2_Screen_RecvStats:
  in r15, SREG
  push r15
    cli

    ldi r16, 0
    rcall LCD_Fill

    ldi r18, 0
    ldi r19, 0
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenRecvText_title)
    ldi zh, HIGH(com2ScreenRecvText_title)
    rcall LCD_PrintFromFlash

    ldi r18, 0
    ldi r19, 2
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenRecvText_packetsIn)
    ldi zh, HIGH(com2ScreenRecvText_packetsIn)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsPacketsIn
    lds r19, com2StatsPacketsIn+1
    rcall LCD_PrintHexWord
    ldi r16, 32
    rcall LCD_PrintChar
    lds r18, com2StatsNotForMe
    lds r19, com2StatsNotForMe+1
    rcall LCD_PrintHexWord

    ldi r18, 0
    ldi r19, 3
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenRecvText_handled)
    ldi zh, HIGH(com2ScreenRecvText_handled)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsHandled
    lds r19, com2StatsHandled+1
    rcall LCD_PrintHexWord

    ldi r18, 0
    ldi r19, 4
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenRecvText_contentErrs)
    ldi zh, HIGH(com2ScreenRecvText_contentErrs)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsContentError
    lds r19, com2StatsContentError+1
    rcall LCD_PrintHexWord

    ldi r18, 0
    ldi r19, 5
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenRecvText_IoErrs)
    ldi zh, HIGH(com2ScreenRecvText_IoErrs)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsIoError
    lds r19, com2StatsIoError+1
    rcall LCD_PrintHexWord

    ldi r18, 0
    ldi r19, 6
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenRecvText_NoBufErrs)
    ldi zh, HIGH(com2ScreenRecvText_NoBufErrs)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsNoBufferError
    lds r19, com2StatsNoBufferError+1
    rcall LCD_PrintHexWord
  
  pop r15
  out SREG, r15
  ret


#if 0
COM2_Screen_SendStats:
  in r15, SREG
  push r15
    cli

    ldi r16, 0
    rcall LCD_Fill

    ldi r18, 0
    ldi r19, 0
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenSendText_title)
    ldi zh, HIGH(com2ScreenSendText_title)
    rcall LCD_PrintFromFlash

    ldi r18, 0
    ldi r19, 2
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenSendText_packetsOut)
    ldi zh, HIGH(com2ScreenSendText_packetsOut)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsPacketsOut
    lds r19, com2StatsPacketsOut+1
    rcall LCD_PrintHexWord

    ldi r18, 0
    ldi r19, 3
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenSendText_collisions)
    ldi zh, HIGH(com2ScreenSendText_collisions)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsCollisions
    lds r19, com2StatsCollisions+1
    rcall LCD_PrintHexWord

    ldi r18, 0
    ldi r19, 4
    rcall LCD_SetCursor
    ldi zl, LOW(com2ScreenSendText_busy)
    ldi zh, HIGH(com2ScreenSendText_busy)
    rcall LCD_PrintFromFlash
    lds r18, com2StatsBusyError
    lds r19, com2StatsBusyError+1
    rcall LCD_PrintHexWord
 
  pop r15
  out SREG, r15
  ret
#endif


com2ScreenRecvText_title:          .db "COM2 Recv Stats", 0
com2ScreenRecvText_packetsIn:      .db "In   : ", 0
com2ScreenRecvText_handled:        .db "Hdl  : ", 0
com2ScreenRecvText_contentErrs:    .db "ECon : ", 0
com2ScreenRecvText_IoErrs:         .db "EIO  : ", 0
com2ScreenRecvText_NoBufErrs:      .db "ENBuf: ", 0


#if 0
com2ScreenSendText_title:          .db "COM2 Send Stats", 0
com2ScreenSendText_packetsOut:     .db "Out      : ", 0
com2ScreenSendText_collisions:     .db "E Coll   : ", 0
com2ScreenSendText_busy:           .db "E Busy   : ", 0
#endif


