; *************************************************************************** ; copyright : (C) 2023 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. * ; *************************************************************************** ; *************************************************************************** ; defines .include "comproto_defs.asm" ; *************************************************************************** ; data .dseg cproDataBegin: cproMode: .byte 1 cproDataEnd: ; *************************************************************************** ; code .cseg CPRO_BEGIN: CPRO_Init: ; preset SRAM data area ldi xh, HIGH(cproDataBegin) ldi xl, LOW(cproDataBegin) clr r16 ldi r17, (cproDataEnd-cproDataBegin) rcall Utils_FillSram #ifdef MODULES_COM_WITH_ADDR_PROTO rcall CPRO_Address_Init #endif sec ret ; --------------------------------------------------------------------------- ; CPRO_OnPacketReceived: ; ; Try to handle the given packet. ; ; IN: ; - X : pointer to received buffer ; OUT: ; - CFLAG: set if handled, cleared otherwise ; USED: depending on called routines CPRO_OnPacketReceived: adiw xh:xl, COM2_MSG_OFFS_CMD ld r16, x sbiw xh:xl, COM2_MSG_OFFS_CMD cpi r16, CPRO_CMD_PING brne CPRO_OnPacketReceived_l1 rjmp cproHandlePing CPRO_OnPacketReceived_l1: #ifdef MODULES_COM_WITH_ADDR_PROTO rjmp CPRO_Address_OnPacketReceived #else clc ret #endif cproHandlePing: adiw xh:xl, COM2_MSG_OFFS_SRCADDR ld r16, x tst r16 ; dont handle src address 0 breq cproHandlePing_notHandled inc r16 breq cproHandlePing_notHandled ; dont handle src address 255 dec r16 ldi xl, LOW(com2SendBuffer) ldi xh, HIGH(com2SendBuffer) rcall CPRO_WritePong rjmp COM2_SendPacket ; use carry flag from this routine cproHandlePing_notHandled: clc ret CPRO_END: .equ MODULE_SIZE_CPRO = CPRO_END-CPRO_BEGIN