From abac650427133ca9d11393c7fab30570b4bf48c2 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 26 Apr 2026 12:47:01 +0200 Subject: [PATCH] avr: removed old modules. --- avr/modules/0BUILD | 6 - avr/modules/com2/0BUILD | 15 - avr/modules/com2/README | 86 ----- avr/modules/com2/buffer.asm | 203 ------------ avr/modules/com2/crc.asm | 106 ------ avr/modules/com2/defs.asm | 48 --- avr/modules/com2/main.asm | 348 -------------------- avr/modules/com2/screen.asm | 166 ---------- avr/modules/comproto/0BUILD | 27 -- avr/modules/comproto/MESSAGES | 317 ------------------ avr/modules/comproto/addr.asm | 434 ------------------------- avr/modules/comproto/addr1.asm | 166 ---------- avr/modules/comproto/addr2.asm | 185 ----------- avr/modules/comproto/defs.asm | 105 ------ avr/modules/comproto/main.asm | 142 -------- avr/modules/comproto/msg_device.asm | 46 --- avr/modules/comproto/msg_memstats.asm | 57 ---- avr/modules/comproto/msg_ping.asm | 33 -- avr/modules/comproto/msg_pong.asm | 33 -- avr/modules/comproto/msg_reboot.asm | 72 ---- avr/modules/comproto/msg_recvstats.asm | 50 --- avr/modules/comproto/msg_result.asm | 47 --- avr/modules/comproto/msg_sendstats.asm | 49 --- avr/modules/comproto/msg_sysstats.asm | 49 --- avr/modules/comproto/msg_twi.asm | 67 ---- avr/modules/comproto/msg_value.asm | 266 --------------- avr/modules/comproto/screen.asm | 101 ------ avr/modules/led_activity/0BUILD | 11 - avr/modules/led_activity/main.asm | 90 ----- avr/modules/led_signal/0BUILD | 11 - avr/modules/led_signal/main.asm | 156 --------- avr/modules/ma_light/0BUILD | 11 - avr/modules/ma_light/main.asm | 352 -------------------- avr/modules/stats/0BUILD | 11 - avr/modules/stats/main.asm | 115 ------- 35 files changed, 3981 deletions(-) delete mode 100644 avr/modules/com2/0BUILD delete mode 100644 avr/modules/com2/README delete mode 100644 avr/modules/com2/buffer.asm delete mode 100644 avr/modules/com2/crc.asm delete mode 100644 avr/modules/com2/defs.asm delete mode 100644 avr/modules/com2/main.asm delete mode 100644 avr/modules/com2/screen.asm delete mode 100644 avr/modules/comproto/0BUILD delete mode 100644 avr/modules/comproto/MESSAGES delete mode 100644 avr/modules/comproto/addr.asm delete mode 100644 avr/modules/comproto/addr1.asm delete mode 100644 avr/modules/comproto/addr2.asm delete mode 100644 avr/modules/comproto/defs.asm delete mode 100644 avr/modules/comproto/main.asm delete mode 100644 avr/modules/comproto/msg_device.asm delete mode 100644 avr/modules/comproto/msg_memstats.asm delete mode 100644 avr/modules/comproto/msg_ping.asm delete mode 100644 avr/modules/comproto/msg_pong.asm delete mode 100644 avr/modules/comproto/msg_reboot.asm delete mode 100644 avr/modules/comproto/msg_recvstats.asm delete mode 100644 avr/modules/comproto/msg_result.asm delete mode 100644 avr/modules/comproto/msg_sendstats.asm delete mode 100644 avr/modules/comproto/msg_sysstats.asm delete mode 100644 avr/modules/comproto/msg_twi.asm delete mode 100644 avr/modules/comproto/msg_value.asm delete mode 100644 avr/modules/comproto/screen.asm delete mode 100644 avr/modules/led_activity/0BUILD delete mode 100644 avr/modules/led_activity/main.asm delete mode 100644 avr/modules/led_signal/0BUILD delete mode 100644 avr/modules/led_signal/main.asm delete mode 100644 avr/modules/ma_light/0BUILD delete mode 100644 avr/modules/ma_light/main.asm delete mode 100644 avr/modules/stats/0BUILD delete mode 100644 avr/modules/stats/main.asm diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index 8fe82d9..2e6a05c 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -8,17 +8,12 @@ ccs811 clock cny70 - com2 - comproto ds18b20 flash lcd lcd2 led - led_activity led_simple - led_signal - ma_light motion owimaster reed @@ -26,7 +21,6 @@ sgp40 si7021 sk6812 - stats tcrt1000 timer twimaster diff --git a/avr/modules/com2/0BUILD b/avr/modules/com2/0BUILD deleted file mode 100644 index cb15b25..0000000 --- a/avr/modules/com2/0BUILD +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - buffer.asm - crc.asm - defs.asm - main.asm - screen.asm - - - - - diff --git a/avr/modules/com2/README b/avr/modules/com2/README deleted file mode 100644 index 9380f3e..0000000 --- a/avr/modules/com2/README +++ /dev/null @@ -1,86 +0,0 @@ -This is the inter-node communication protocol. - -Hardware -======== - -AqHome uses asynchronous serial communication, nodes are connected via 4 lines: -- 5V [red] -- GND [black] -- DATA (0V/3.3V) [green] -- ATTN (0V/3.3V) [blue] - -DATA and ATTN are only pulled low by nodes on the bus, never pulled high, this allows for multi-master -mode. Every node sends data at will (after checking for free line). - - -5V, GND -------- -Power line 5V, mcu nodes use a voltage regulator to locally provide stable 3.3V. - - -DATA ----- -TTL-UART communication line (3.3V, 19200 Baud, 1 startbit, 8 databits, one stopbit, no parity bit->19200N1). - - -ATTN ----- -Whenever a node wants to send data it has to first check whether this line is HIGH. If it is, the sending -node must pull down this line to GND to inform other nodes about the intent to send. This is used by mcu nodes -as an interrupt source thus waking each node as soon as a message is to appear on the bus. -After sending data via the DATA line the sending node has to release this line which is then automatically pulled -HIGH by the logic on the power supply board. - - - -Protocol -======== - -The protocol is simple to reduce overhead and to keep the code size inside the mcu nodes small. -There is no generic request-reply protocol. Messages are not repeated on the lowlevel layer. However, -if a message can't be transmitted it might get retried later by the sending node (e.g. when reporting -sensor data). Also, some operations consist of a request and a reply, but that's on a higher level (e.g. remotely setting a -specific value in a node). The maximum size of a message is 24 bytes (max. 21 bytes payload). - - -Basic Message Format --------------------- - -Nodes communicate via messages. The first byte of every message is the destination node address, so every node can determine -after the first byte whether it is interested in the following message. All nodes but the destination can immediately go back -to sleep after receiving the first byte (they will be awoken again by ATTN going low for the next message). -The next byte is the length of the remainder of the message (if any). The last byte is a CRC8 checksum byte. - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 n payload data ---------------------------------------------------------- - 2+n 1 CRC8 byte - - -Command Messages ----------------- - -Command messages are an extension to the Basic Message Format specifying the first two bytes of the payload. -The first byte of the payload is a command code (e.g. "100" for report of sensor data), followed by the -bus address of the sender. The remainder of the payload is defined by the type of message(i.e. the message code). - - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 n payload data (depending on command code) ---------------------------------------------------------- - 4+n 1 CRC8 byte - - - - diff --git a/avr/modules/com2/buffer.asm b/avr/modules/com2/buffer.asm deleted file mode 100644 index 876f624..0000000 --- a/avr/modules/com2/buffer.asm +++ /dev/null @@ -1,203 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - - -; =========================================================================== -; -; Macros for working with message buffers. -; -; Helpfull defines: -; - COM2_BUFFER_NUM number of buffers to provide -; - COM2_BUFFER_SIZE size of each buffer (CAVE: change COM2_M_BufferPosToX when changing value!) -; -; Variables: -; - buffersUsed: .byte 1 holds number of buffers in use -; - maxBuffersUsed: .byte 1 holds max number of buffers every in use at the same time -; - buffersWritePos: .byte 1 holds current write pos -; - buffersReadPos: .byte 1 holds current read pos -; - buffers: .byte COM2_BUFFER_SIZE*COM2_BUFFER_NUM - - - -; --------------------------------------------------------------------------- -; @macro COM2_M_BufferAlloc -; -; Allocate a message buffer. -; -; COM2_M_BufferAlloc COM2_BUFFER_NUM, com2MaxBuffersUsed, com2RecvBuffersUsed, com2RecvBuffersWritePos -; -; @param %0 max number of buffers -; @param %1 pointer to byte containing max number of buffers ever used -; @param %2 pointer to byte containing number of buffers currently in use -; @param %3 pointer to byte containing the write pointer -; @param %4 pointer to routine to calculate buffer pos (e.g. uartBitbang_BufferPosToX) -; @return CFLAG set if okay, clear otherwise -; @return X pos to allocated buffer -; @clobbers R16, R17, R21 - -.macro COM2_M_BufferAlloc - in r21, SREG ; save global interrupt enable bit from SREG - cli - lds r17, @2 - cpi r17, @0 - brcc l_error ; no buffer available - inc r17 ; increment number of buffers used - sts @2, r17 ; store new value - lds r16, @1 ; calc max buffers used - cp r16, r17 - brcc l0 - sts @1, r17 -l0: - lds r16, @3 ; get current write pos - mov r17, r16 ; increment for next call - inc r17 - cpi r17, @0 ; CF set if COM_BUFFER_NUM > R17 - brcs l1 - clr r17 ; wraparound -l1: - sts @3, r17 ; store new writepos for next caller - rcall @4 ; *_BufferPosToX(R16, R17) - out SREG, r21 ; restore global interrupt enable bit in SREG - sec - rjmp l_end -l_error: - out SREG, r21 - clc -l_end: -.endmacro -; @end - - - -; --------------------------------------------------------------------------- -; @macro COM2_M_BufferDeallocBack -; -; Release a transfer buffer at the end of the list by decreasing the write pos. -; This releases the last allocated buffer! -; -; COM2_M_BufferDeallocBack COM2_BUFFER_NUM, com2RecvBuffersUsed, com2RecvBuffersWritePos -; -; @param %0 maximum number of buffers -; @param %1 pointer to a byte containing number of buffers used -; @param %2 pointer to a byte containing current write pos -; @return CFLAG set if okay, clear otherwise -; @clobbers r16, r17, r21 - -.macro COM2_M_BufferDeallocBack - in r21, SREG ; save global interrupt enable bit from SREG - cli - lds r17, @1 - tst r17 - breq l_error ; no buffer allocated, nothing to release - dec r17 - sts @1, r17 ; store new value - lds r17, @2 - tst r17 ; 0? - brne l1 ; nope go directly decrement r17 - ldi r17, @0 ; wrap-around -l1: - dec r17 - sts @2, r17 - out SREG, r21 - sec - rjmp l_end -l_error: - out SREG, r21 - clc -l_end: -.endmacro -; @end - - - -; --------------------------------------------------------------------------- -; @macro COM2_M_BufferDeallocFront -; -; Release a transfer buffer by increasing the read pos. -; -; COM2_M_BufferDeallocFront COM2_BUFFER_NUM com2RecvBuffersUsed com2RecvBuffersReadPos -; -; @param %0 maximum number of buffers -; @param %1 pointer to a byte containing number of buffers used -; @param %2 pointer to a byte containing current read pos -; @return CFLAG set if okay, clear otherwise -; @clobbers r16, r17, r21 - -.macro COM2_M_BufferDeallocFront - in r21, SREG ; save global interrupt enable bit from SREG - cli - lds r17, @1 - tst r17 - breq l_error ; no buffer allocated, nothing to release - dec r17 - sts @1, r17 ; store new value - lds r17, @2 - inc r17 - cpi r17, @0 - brcs l1 - clr r17 ; wrap-around -l1: - sts @2, r17 - out SREG, r21 - sec - rjmp l_end -l_error: - out SREG, r21 - clc -l_end: -.endmacro -; @end - - - -; --------------------------------------------------------------------------- -; @macro COM2_M_BufferPosToX -; -; Get a pointer to the SRAM position of the given buffer. -; CAVE: Code must correspond to COM2_BUFFER_SIZE!! -; -; COM2_M_BufferPosToX com2RecvBuffers -; -; @param %0 pointer to a 2 byte var containing pointer to buffers -; @param R16 buffer number (starting with 0) -; @return X pointer to buffer in SRAM -; @clobbers R16, R17 - -.macro COM2_M_BufferPosToX - ; calculate offset - clr r17 - mov xl, r16 - clr xh - - lsl xl - rol xh ; *2 - - add xl, r16 - adc xh, r17 ; *3 - - lsl xl - rol xh ; *6 - - lsl xl - rol xh ; *12 - - lsl xl - rol xh ; *24 - - ; add base position of buffers - ldi r16, LOW(@0) - ldi r17, HIGH(@0) - add xl, r16 - adc xh, r17 -.endmacro -; @end - - - diff --git a/avr/modules/com2/crc.asm b/avr/modules/com2/crc.asm deleted file mode 100644 index 9ed4cb4..0000000 --- a/avr/modules/com2/crc.asm +++ /dev/null @@ -1,106 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - - - -; --------------------------------------------------------------------------- -; add checksum byte to buffer -; -; IN: -; - X : pointer to packet buffer (points behind checksum upon return) -; OUT: -; - CFLAG: set if okay, clear otherwise -; - X : points behind checksum byte pos upon return -; MODIFIED REGS: R16, R17, R18, R19, X - -com2CalcAndAddChecksumByte: - rcall com2CalcMsgChecksum - st X+, r16 ; add checksum byte - sec - ret - - - -; --------------------------------------------------------------------------- -; check message in buffer -; -; IN: -; - X : pointer to packet buffer -; OUT: -; - CFLAG: set if okay, clear otherwise -; MODIFIED REGS: R16, R17 (R18, R19, R20, X) - -com2CheckMessageInBuffer: - rcall com2CalcMsgChecksum ; (R16, R17, R18, R19, R20, X) - ld r17, X - cp r16, r17 ; should be equal - brne com2CheckMessageInBuffer_error - sec - ret -com2CheckMessageInBuffer_error: - clc - ret - - - -; --------------------------------------------------------------------------- -; @routine com2CalcMsgChecksum -; -; calc checksum from msg buffer (except crc byte) -; -; @return r16 crc8 checksum -; @return X points to position of checksum byte -; @param X pointer to packet buffer (points to checksum byte upon return) -; @clobbers R16, R18 (R17, R19, R20, X) - -com2CalcMsgChecksum: - adiw xh:xl, COM2_MSG_OFFS_MSGLEN - ld r18, X ; read msg len - sbiw xh:xl, COM2_MSG_OFFS_MSGLEN - inc r18 ; account for dest address - inc r18 ; account for msg len byte - rjmp com2CrcCalc ; (R16, R17, R18, R20, X) -; @end - - - -; --------------------------------------------------------------------------- -; @routine com2CrcCalc @global -; calc checksum using given polynomial -; -; @return r16 calculated checksum -; @return X points directly after last checked byte -; @param X pointer to data to calc crc8 for -; @param r18 number of bytes to calc crc8 for -; @clobbers: R16, R17, R18, R19, R20, X - -com2CrcCalc: - ldi r16, 0xff ; start crc - ldi r19, COM2_CRC8_POLYNOMIAL ; polynomial - -com2CrcCalc_loop1: - ld r17, X+ ; running var - eor r16, r17 - ldi r20, 8 ; counter for loop2 -com2CrcCalc_loop2: - lsl r16 - brcc com2CrcCalc_l1 - eor r16, r19 -com2CrcCalc_l1: - dec r20 - brne com2CrcCalc_loop2 - dec r18 - brne com2CrcCalc_loop1 - ret -; @end - - - - diff --git a/avr/modules/com2/defs.asm b/avr/modules/com2/defs.asm deleted file mode 100644 index a13ea89..0000000 --- a/avr/modules/com2/defs.asm +++ /dev/null @@ -1,48 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - - - - -.equ COM2_BUFFER_SIZE = 24 ; CAVE: must change code in COM2_BufferPosToX when changing this! -.equ COM2_BUFFER_NUM = 4 - -.equ COM2_MAINTENANCE_ADDR = 0xc1 - - -; flags for variable payload enqueue function -.equ COM2_PAYLOAD_FLAGS_SECONDS = 0x01 -.equ COM2_PAYLOAD_FLAGS_UID = 0x02 -.equ COM2_PAYLOAD_FLAGS_RESERVED1 = 0x04 -.equ COM2_PAYLOAD_FLAGS_NUM0 = 0x08 -.equ COM2_PAYLOAD_FLAGS_NUM1 = 0x10 -.equ COM2_PAYLOAD_FLAGS_NUM2 = 0x20 -.equ COM2_PAYLOAD_FLAGS_NUM3 = 0x40 -.equ COM2_PAYLOAD_FLAGS_NUM4 = 0x80 -.equ COM2_PAYLOAD_FLAGS_SHIFT_NUM = 3 - - - -.equ COM2_MSG_OFFS_DESTADDR = 0 -.equ COM2_MSG_OFFS_MSGLEN = 1 -.equ COM2_MSG_OFFS_MSGDATA = 2 -.equ COM2_MSG_OFFS_CMD = 2 ; first at COM2_MSG_OFFS_MSGDATA -.equ COM2_MSG_OFFS_SRCADDR = 3 -.equ COM2_MSG_OFFS_PAYLOAD = 4 ; payload for the cmd follows here - - -.equ COM2_ERROR_NOTFORME = 1 ; receiption errors -.equ COM2_ERROR_IOERROR = 2 -.equ COM2_ERROR_DATAERROR = 3 -.equ COM2_ERROR_BUSY = 4 ; send errors -.equ COM2_ERROR_COLLISION = 5 - - -.equ COM2_CRC8_POLYNOMIAL = 0x97 ; HD=4 up to 119 bytes, e.g. detects all 1 to 3 bit errors diff --git a/avr/modules/com2/main.asm b/avr/modules/com2/main.asm deleted file mode 100644 index f116f84..0000000 --- a/avr/modules/com2/main.asm +++ /dev/null @@ -1,348 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - -.include "modules/com2/buffer.asm" - - - -; *************************************************************************** -; data - -.dseg - - -com2DataBegin: - com2Address: .byte 1 - - com2Interrupts: .byte 2 - com2LastMsgId: .byte 2 - -com2RecvStatsBegin: ; 12 bytes - com2StatsPacketsIn: .byte 2 - com2StatsContentError: .byte 2 - com2StatsIoError: .byte 2 - com2StatsNoBufferError: .byte 2 - com2StatsHandled: .byte 2 - com2StatsMissed: .byte 2 ; currently not used -com2RecvStatsEnd: - -com2SendStatsBegin: ; 6 bytes - com2StatsPacketsOut: .byte 2 - com2StatsCollisions: .byte 2 - com2StatsBusyError: .byte 2 -com2SendStatsEnd: - - com2StatsNotForMe: .byte 2 - com2StatsIgnored: .byte 2 - - com2MaxSendBuffersUsed: .byte 1 - com2MaxRecvBuffersUsed: .byte 1 - - com2SendBuffer: .byte COM2_BUFFER_SIZE -com2DataEnd: - - - -; *************************************************************************** -; code - -.cseg - -COM2_BEGIN: - - - - -; --------------------------------------------------------------------------- -; @routine Com2_Init @global -; -; @return CFLAG set if okay, clear on error -; @clobbers R16, R17, X, Y - -Com2_Init: - ; preset SRAM data area - ldi xh, HIGH(com2DataBegin) - ldi xl, LOW(com2DataBegin) - clr r16 - ldi r17, (com2DataEnd-com2DataBegin) - rcall Utils_FillSram - - ; set address to 0 (will be updated later) - clr r16 - sts com2Address, r16 - - rjmp COMIO_Init -; @end - - - -; --------------------------------------------------------------------------- -; @routine Com2_Run @global -; -; @return CFLAG set if something done, can be called again immediately (otherwise: wait for timer interrupt and retry) -; @clobbers (R1, R3, R16, R17, R18, R19, R22, X) - -COM2_Run: - rcall COMIO_Run - brcs COM2_Run_carrySet - rjmp com2HandleNextPacketInQueue ; return CFLAG from com2HandleNextPacketInQueue -COM2_Run_carrySet: - rcall com2HandleNextPacketInQueue - sec ; return CFLAG set regardless of com2HandleNextPacketInQueue - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine com2HandleNextPacketInQueue -; -; Get next received packet, call onPacketReceived on it and release it -; @return CFLAG set if something done -; @clobbers any - -com2HandleNextPacketInQueue: - rcall COMIO_GetNextReceivedPacket - brcc com2HandleNextPacketInQueue_retNc - push xl - push xh - rcall com2CheckMessageInBuffer - pop xh - pop xl - brcs com2HandleNextPacketInQueue_crcOk - ldi xl, LOW(com2StatsContentError) - ldi xh, HIGH(com2StatsContentError) - rjmp com2HandleNextPacketInQueue_incCounterDeallocBuffer -com2HandleNextPacketInQueue_crcOk: - rcall onPacketReceived - brcs com2HandleNextPacketInQueue_handled - ldi xl, LOW(com2StatsIgnored) - ldi xh, HIGH(com2StatsIgnored) - rjmp com2HandleNextPacketInQueue_incCounterDeallocBuffer -com2HandleNextPacketInQueue_handled: - ldi xl, LOW(com2StatsHandled) - ldi xh, HIGH(com2StatsHandled) -com2HandleNextPacketInQueue_incCounterDeallocBuffer: - rcall Utils_IncrementCounter16 ; (r18, r19, r22) - rcall COMIO_ReleaseReceivedPacket - sec - ret -com2HandleNextPacketInQueue_retNc: - clc - ret -; @end - - - - - -; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -; Preparing messages -; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - - - -; --------------------------------------------------------------------------- -; @routine COM2_WriteMsgWithCmdAndSrcAddr @global -; -; Write a simple packet into the given buffer with payload being only CMD and source address. -; -; IN: -; @param R16 destination address -; @param R18 command (e.g. CPRO_CMD_PING or CPRO_CMD_PONG) -; @param X pointer to buffer to write to -; @return CFLAG set if okay, clear otherwise -; @clobbers R16, R17, X, Y (R3, R4, R15, R16, R17, R18, R19, R20, R21) - -COM2_WriteMsgWithCmdAndSrcAddr: - ldi r17, COM2_PAYLOAD_FLAGS_SECONDS - push xh - push xl - rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X) - pop xl - pop xh - rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X) - sec - ret -COM2_WriteMsgWithCmdAndSrcAddr_error: - clc - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine COM2_BeginMsgWithVariablePayload @global -; -; begin packet with variable payload. -; -; @param R16 destination address -; @param R17 flags -; @param R18 command (e.g. CPRO_CMD_PING) -; @param X pointer to packet buffer -; @return X points to end of packet as it was written so far -; @clobbers R3, R16, R17, R18, R19, R20, R21, X (R4) - -COM2_BeginMsgWithVariablePayload: - ; write header (dest address, msg length) - st X+, r16 ; destination address - mov r16, r17 ; calculate payload size - mov r3, r17 - rcall com2CalcPayloadSize ; (R4, R16, R17) - inc r16 ; add CMD byte - inc r16 ; add source address byte - st X+, r16 - ; write payload - st X+, r18 ; 0: CMD - lds r16, com2Address ; 1: source address - st X+, r16 - lsr r3 ; shift out COM2_PAYLOAD_FLAGS_SECONDS - brcc COM2_BeginMsgWithVariablePayload_l1 - ; write seconds - rcall COM2_AddSecsToBuffer -COM2_BeginMsgWithVariablePayload_l1: - lsr r3 ; shift out COM2_PAYLOAD_FLAGS_UID - brcc COM2_BeginMsgWithVariablePayload_l2 - ; write uid - rcall COM2_AddUidToBuffer -COM2_BeginMsgWithVariablePayload_l2: - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine COM2_AddUidToBuffer @global -; -; Write UID into buffer given by X. -; -; @return X points to behind written uid -; @param X pointer to packet buffer -; @clobbers: r18, r19, r20, r21 (r16) - -COM2_AddUidToBuffer: - push xh - push xl - rcall Utils_ReadUid ; (R16, X) - pop xl - pop xh - st X+, r18 - st X+, r19 - st X+, r20 - st X+, r21 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine COM2_AddSecsToBuffer @global -; -; Write current seconds counter (4 bytes) into buffer given by X, advance X. -; -; @return X points to behind written seconds -; @param X pointer to packet buffer -; @clobbers r16 - -COM2_AddSecsToBuffer: - lds r16, timerModuleCounterSecs ; add current seconds counter - st X+, r16 - lds r16, timerModuleCounterSecs+1 - st X+, r16 - lds r16, timerModuleCounterSecs+2 - st X+, r16 - lds r16, timerModuleCounterSecs+3 - st X+, r16 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine COM2_AddNextMsgIdToBuffer @global -; -; Write next message id (2 bytes) into buffer given by X, advance X. -; -; @return X points to behind written message id -; @param X pointer to packet buffer -; @clobbers: r16, r17, r18 - -COM2_AddNextMsgIdToBuffer: - ldi r18, 1 - lds r16, com2LastMsgId - lds r17, com2LastMsgId+1 - add r16, r18 - dec r18 - adc r17, r18 - sts com2LastMsgId, r16 - sts com2LastMsgId+1, r17 - st X+, r16 - st X+, r17 - ret -; @end - - - -; --------------------------------------------------------------------------- -; com2CalcPayloadSize -; -; Calculate payload size from given flags -; -; @param R16 flags -; @return R16 payload size -; @clobbers R4, R16, R17 - -com2CalcPayloadSize: - clr r4 - ldi r17, 4 - lsr r16 ; shift out COM2_PAYLOAD_FLAGS_SECONDS - brcc com2CalcPayloadSize_l1 - add r4, r17 ; add 4 bytes -com2CalcPayloadSize_l1: - lsr r16 ; shift out COM2_PAYLOAD_FLAGS_UID - brcc com2CalcPayloadSize_l2 - add r4, r17 ; add 4 bytes -com2CalcPayloadSize_l2: - lsr r16 ; shift out reserved1, after this R16 contains COM2_PAYLOAD_FLAGS_NUM0-4 - add r16, r4 ; add previous bytes to R16 - ret -; @end - - - - - - - -; --------------------------------------------------------------------------- -; @routine COM2_SendPacket -; -; send packet from sendBuffer, if line free. -; -; @return CFLAG set if okay (packet sent), cleared on error -; @clobbers any (depending on io implementation) - -COM2_SendPacket: - ldi xl, LOW(com2SendBuffer) - ldi xh, HIGH(com2SendBuffer) - rjmp COMIO_SendPacket -; @end - - - - - -.include "modules/com2/crc.asm" - - - -COM2_END: -.equ MODULE_SIZE_COM2 = COM2_END-COM2_BEGIN - diff --git a/avr/modules/com2/screen.asm b/avr/modules/com2/screen.asm deleted file mode 100644 index c2bd3ce..0000000 --- a/avr/modules/com2/screen.asm +++ /dev/null @@ -1,166 +0,0 @@ -; *************************************************************************** -; 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 - - diff --git a/avr/modules/comproto/0BUILD b/avr/modules/comproto/0BUILD deleted file mode 100644 index ed7af9f..0000000 --- a/avr/modules/comproto/0BUILD +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - addr.asm - addr1.asm - addr2.asm - defs.asm - main.asm - msg_device.asm - msg_memstats.asm - msg_ping.asm - msg_pong.asm - msg_reboot.asm - msg_recvstats.asm - msg_sendstats.asm - msg_sysstats.asm - msg_twi.asm - msg_value.asm - screen.asm - - - - - - diff --git a/avr/modules/comproto/MESSAGES b/avr/modules/comproto/MESSAGES deleted file mode 100644 index b0172ae..0000000 --- a/avr/modules/comproto/MESSAGES +++ /dev/null @@ -1,317 +0,0 @@ - -General Message Format -====================== - -Currently messages can maximally use 21 bytes for data because: -- maximum buffer size if 24 bytes -- a message contains a checksum byte - - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 n payload data (depending on command code) ---------------------------------------------------------- - 4+n 1 CRC8 byte - - - -PING Message -============ - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 CRC8 byte - - - -PONG Message -============ - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 CRC8 byte - - - -RESULT Message -============== - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 2 ref msg id - 6 1 result code ---------------------------------------------------------- - 7 1 CRC8 byte - - - -Address Messages -================ - -This includes HAVE_ADDRESS, CLAIM_ADDRESS and DENY_ADDRESS. - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 4 UID of the sending node - 8 1 bus address ---------------------------------------------------------- - 9 1 CRC8 byte - - - -RANGE Message -============= - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 first available address - 5 1 last available address ---------------------------------------------------------- - 6 1 CRC8 byte - - - -VALUE Message -============== - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code (REPORT_VALUE, REQ_SET_VALUE, RSP_SET_VALUE) - 3 1 source address ---------------------------------------------------------- - 4 4 UID of the sending node - 8 2 msg id/ref msg id - 10 1 value id - 11 1 value type - 12 2 value - 14 2 denom ---------------------------------------------------------- - 16 1 CRC8 byte - - - -DEVICE Message -============== - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 4 UID of the sending node - 8 4 manufacturer - 12 2 device type - 14 1 device hw version - 15 1 device hw revision - 16 1 firmware variant (depends on hardware type) - 17 1 firmware version: major - 18 1 firmware version: minor - 19 1 firmware version: patchlevel ---------------------------------------------------------- - 20 1 CRC8 byte - - - -SENDSTATS Message -================= - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 Interface number - 5 4 UID of the sending node - 9 2 packets out - 11 2 collisions - 13 2 line busy errors ---------------------------------------------------------- - 14 1 CRC8 byte - - - -RECVSTATS Message -================= - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 Interface number - 5 4 UID of the sending node - 9 2 packets in - 11 2 content errors (invalid msg length, CRC errors) - 13 2 io errors - 15 2 no buffer errors - 17 2 handled packets - 19 2 missed packets ---------------------------------------------------------- - 21 1 CRC8 byte - - - - - - -FLASHSTART Message -================== - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 4 UID ---------------------------------------------------------- - 8 1 CRC8 byte - - - -FLASHREADY Message -================== - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 4 UID - 8 4 manufacturer - 12 2 device type - 14 1 device hw version - 15 1 device hw revision - 16 1 firmware variant (depends on hardware type) - 17 1 firmware version: major - 18 1 firmware version: minor - 19 1 firmware version: patchlevel - 20 2 page size in bytes ---------------------------------------------------------- - 22 1 CRC8 byte - - - -FLASHDATA Message -================= - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 2 address - 6 n data bytes (max 124 bytes) ---------------------------------------------------------- - 6+n 1 CRC8 byte - - - -FLASHEND Message -================ - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 reason (0 if okay, error code to abort) ---------------------------------------------------------- - 5 1 CRC8 byte - - - -FLASHRESPONSE Message -===================== - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 1 response code ---------------------------------------------------------- - 5 1 CRC8 byte - - - - -DATA Message -============ - -Offset Length Meaning ---------------------------------------------------------- - 0 1 destination address - 1 1 remaining message length ---------------------------------------------------------- - 2 1 command code - 3 1 source address ---------------------------------------------------------- - 4 4 ROM address - 8 n data bytes ---------------------------------------------------------- - 8+n 1 CRC8 byte - - - diff --git a/avr/modules/comproto/addr.asm b/avr/modules/comproto/addr.asm deleted file mode 100644 index 4ec1424..0000000 --- a/avr/modules/comproto/addr.asm +++ /dev/null @@ -1,434 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - - -; *************************************************************************** -; This sub-module contains code for cooperative address management. -; Because the network of nodes doen't have a central control unit the nodes -; need to assign addresses to themselves with help from the community of existing -; nodes. -; -; Protocol A: Full Address Assignment Protocol -; -------------------------------------------- -; This protocol is used when a node has no currently or previously assigned address. -; In this case we need to find a free address which no other node uses. -; -; 1) a node needs an address. It sends the packet "NEED_ADDRESS" -; 2) every node which already has an address sees this message and answers with -; a "HAVE_ADDRESS" packet. The nodes must not answer all at once to avoid -; congestions. Instead, the time it takes for a node to respond depends on -; its own address (e.g. a node with address 10 will wait for 10+3s before answering) -; 3) the initial node collects all "HAVE_ADDRESS" packets and puts the addresses -; received this way into a bitfield in which for every address received a bit is -; set -; 4) after about 130s all nodes in the address range 1-127 should have answered. -; So after this time the initial node looks at the bitfield of received addresses -; and selects the first unused address (corresponding bit cleared in bitfield). -; For this address the initial node sends a "CLAIM_ADDRESS" packet, three times -; with about 30s between the packets. -; 5) if the to-be-claimed address is already in use by another node, that node will -; send a "DENY_ADDRESS" packet. This is the second line of defense against address -; collisions and should very rarely occur. -; 6) after no node denied the to-be-claimed address the initial node finally takes the -; address and sends a "HAVE_ADDRESS" packet. -; 7) this concludes the address assignemt protocol -; -; Protocol B: Shortened Address Assignment Protocol -; ------------------------------------------------- -; This protocol is used upon boot when a node previously got an address assigned to it. -; In this case the address is probably not used by an other node so we can shorten the -; procedure. -; -; 1) a node sends the packet CLAIM_ADDRESS with the previously assigned address -; 2) if any other node objects to this node using that address (e.g. because the other -; node now uses that address) that node will send a DENY_ADDRESS packet. -; 3) if no DENY_ADDRESS has been received within 10s the address can be used. -; 4) Otherwise the node changes into protocol A (see above). - - -#ifdef MODULES_COM_WITH_ADDR_PROTO - - - -; *************************************************************************** -; defs - - - - - -; *************************************************************************** -; data - -.dseg - - -cproAddressDataBegin: - cproAddrRangeBegin: .byte 1 - cproAddrRangeEnd: .byte 1 - cproUsedAddresses: .byte 16 ; one bit per address known to b in use -cproAddressDataEnd: - -cproAddresModeTimer: .byte 2 ; timer must not be zeroed, this is done by the timer module!! - - - -; *************************************************************************** -; code - -.cseg - - - -CPRO_Address_Init: - ldi xh, HIGH(cproAddressDataBegin) - ldi xl, LOW(cproAddressDataBegin) - clr r16 - ldi r17, (cproAddressDataEnd-cproAddressDataBegin) - rcall Utils_FillSram - - ; setup timer for address setup (after 10s) - ldi r16, CPRO_MODE_NOADDRESS - sts cproMode, r16 - ldi r18, 100 - ldi r19, 0 - rcall cproAddressSetTimer - ret - - - -CPRO_StartReclaimAddrProcedure: - ldi xl, LOW(EEPROM_OFFS_COMADDR) - ldi xh, HIGH(EEPROM_OFFS_COMADDR) - in r15, SREG - push r15 - cli - rcall Utils_ReadEepromIncr ; (R16) - tst r16 - breq CPRO_StartReclaimAddrProcedure_l1 - cpi r16, 0xff - breq CPRO_StartReclaimAddrProcedure_l1 - sts cproAddrRangeBegin, r16 ; currently claimed address - ldi r16, CPRO_MODE_SEND_RECLAIM_ADDR - sts cproMode, r16 - rcall cproAddressSetTimer1s ; use singleshot timer, send after 1s - pop r15 - out SREG, r15 - sec - ret -CPRO_StartReclaimAddrProcedure_l1: - rcall CPRO_StartGetAddrProcedure - pop r15 - out SREG, r15 - ret - - - -CPRO_StartGetAddrProcedure: - ; reset bitfield of used addresses - ldi xh, HIGH(cproUsedAddresses) - ldi xl, LOW(cproUsedAddresses) - clr r16 - ldi r17, 16 - rcall Utils_FillSram - ; preset range - ldi r16, 1 - sts cproAddrRangeBegin, r16 - ldi r16, 126 - sts cproAddrRangeEnd, r16 - ; setup singleshot timer to later send "NEED_ADDRESS" packet - ldi r16, CPRO_MODE_SEND_NEED_ADDR - sts cproMode, r16 - rcall cproAddressSetTimer1s - sec - ret - - - - - -; REGS: r18, r19 -; -cproAddressSetTimer1s: - ldi r18, 10 - ldi r19, 0 - rjmp cproAddressSetTimer - - - -; IN: -; - r18: timer value (low) -; - r19: timer value (high) -; REGS: none - -cproAddressSetTimer: - push r15 - in r15, SREG - cli - sts cproAddresModeTimer, r18 - sts cproAddresModeTimer+1, r19 - out SREG, r15 - pop r15 - ret - - - - - -cproGetFirstFreeAddr: - rjmp cproGetFreeAddr - - - -cproGetNextFreeAddr: - lds r16, cproAddrRangeBegin - inc r16 - sts cproAddrRangeBegin, r16 - rjmp cproGetFreeAddr - - - -cproGetFreeAddr: - lds r16, cproAddrRangeBegin - lds r17, cproAddrRangeEnd - cp r16, r17 - brge cproGetFreeAddr_error - rcall cproFindFreeAddr - brcc cproGetFreeAddr_error - sec - ret -cproGetFreeAddr_error: - clc - ret - - - -cproHandleAddrRange: ; not handled for now - ; TODO - clc - ret - - - - - - - -; --------------------------------------------------------------------------- -; cproFindFreeAddr -; -; find a free address in the bitfield cproUsedAddresses -; -; IN: -; - nothing -; OUT: -; - CFLAG: set if handled, cleared otherwise -; - R16: free address (if CFLAG set) -; USED: R16, R17, R18, R19, R20, R21 X, (R1, R2, Z) - -cproFindFreeAddr: - ldi xl, LOW(cproUsedAddresses) - ldi xh, HIGH(cproUsedAddresses) - lds r16, cproAddrRangeBegin - dec r16 - rcall cproGetPosAndMaskInBitField ; r1=bit pos, r2=mask (r1, r2, r17, Z) - clr r17 - add xl, r1 - adc xh, r17 ; X: pointer to byte - mov r17, r2 ; mask - lds r18, cproAddrRangeBegin - dec r18 - lds r19, cproAddrRangeEnd - inc r19 ; to make comparision easier - ldi r20, 8 -cproFindFreeAddr_byteLoop: - ld r16, X+ - cpi r16, 0xff - breq cproFindFreeAddr_nextByte ; byte full, skip -cproFindFreeAddr_bitLoop: - mov r21, r16 - and r21, r17 - brne cproFindFreeAddr_nextBit - ; found a clear bit, return - inc r18 - sts cproAddrRangeBegin, r18 - mov r16, r18 - sec - ret -cproFindFreeAddr_nextBit: - inc r18 ; next address - lsl r17 ; shift mask to the left - brcc cproFindFreeAddr_bitLoop - dec r18 ; take back inc -cproFindFreeAddr_nextByte: - add r18, r20 - andi r18, 0xf8 ; clear lower 3 bits - cp r18, r19 ; compare to end address+1 - brcc cproFindFreeAddr_allFull - ldi r17, 0x01 ; mask - rjmp cproFindFreeAddr_byteLoop -cproFindFreeAddr_allFull: - clc - ret - - - -; --------------------------------------------------------------------------- -; cproSetBitInBitfield -; -; IN: -; - R16 : bit number to set (0-127) -; OUT: -; - nothing -; USED: R16, R17, X (r1, r2, Z) - -cproSetBitInBitfield: - ; set bit corresponding to given address in bitfield of used addresses - rcall cproGetPosAndMaskInBitField ; get offset into R1, mask into R2 (r1, r2, r17, Z) - ldi xl, LOW(cproUsedAddresses) - ldi xh, HIGH(cproUsedAddresses) - clr r17 - add xl, r1 - adc xh, r17 - ld r16, X - or r16, r2 - st X, r16 - ret - - - -; --------------------------------------------------------------------------- -; Get offset and mask for a given bit in a bitfield -; IN: -; - R16: bit to request position for -; OUT: -; - R1: offset into the bitfield to the byte containing the given bit -; - R2: mask for given id (apply to r1) -; USED REGISTERS: r1, r2, r17, Z - -cproGetPosAndMaskInBitField: - mov r1, r16 ; divide by 8 to get the offset to the byte containing the given module id - lsr r1 - lsr r1 - lsr r1 ; r1=offset of the byte holding the given bit - mov r2, r16 ; get bit mask for bit position in table byte - ldi r17, 7 ; keep lower 3 bits - and r2, r17 - ldi zh, HIGH(cproModuleBitNumToMaskMap*2) - ldi zl, LOW(cproModuleBitNumToMaskMap*2) - add zl, r2 - brcc cproGetPosAndMaskInBitField_noOverflow - inc zh -cproGetPosAndMaskInBitField_noOverflow: - lpm r2, z ; r2=mask for bit in byte from bitfield - ret - - -cproModuleBitNumToMaskMap: - .db 1, 2, 4, 8, 16, 32, 64, 128 - - - -; --------------------------------------------------------------------------- -; Send a NEEDADDRESS packet. -; -; IN: -; - nothing -; OUT: -; - CFLAG: set if okay, clear otherwise -; MODIFIED REGS: R18 (R3, R4, R15, R16, R17, R20, R21, X, Y (R18, R19) - -CPRO_SendNeedAddress: - ldi r18, CPRO_CMD_NEED_ADDRESS - rjmp cproSendAddressPacket - - - -; --------------------------------------------------------------------------- -; Send a HAVE_ADDRESS packet. -; -; IN: -; - nothing -; - R19: address to send -; OUT: -; - CFLAG: set if okay, clear otherwise -; MODIFIED REGS: R18 (R3, R4, R15, R16, R17, R18, R19, R20, R21, X, Y) - -CPRO_SendHaveAddress: - ldi r18, CPRO_CMD_HAVE_ADDRESS - rjmp cproSendAddressPacket - - - -; --------------------------------------------------------------------------- -; Send a CLAIM_ADDRESS packet. -; -; IN: -; - R19: claimed address -; OUT: -; - CFLAG: set if okay, clear otherwise -; MODIFIED REGS: R18 (R3, R4, R15, R16, R17, R18, R19, R20, R21, X, Y) - -CPRO_SendClaimAddress: - ldi r18, CPRO_CMD_CLAIM_ADDRESS - rjmp cproSendAddressPacket - - - -; --------------------------------------------------------------------------- -; Send a DENY_ADDRESS packet. -; -; IN: -; - nothing -; OUT: -; - CFLAG: set if okay, clear otherwise -; MODIFIED REGS: R18, R19 (R3, R4, R15, R16, R17, R20, R21, X, Y) - -CPRO_SendDenyAddress: - ldi r18, CPRO_CMD_DENY_ADDRESS - lds r19, com2Address - rjmp cproSendAddressPacket - - - -; --------------------------------------------------------------------------- -; cproSendAddressPacket -; Send a NEED/HAVE/CLAIM ADDRESS packet. -; -; IN: -; - R18: command (either CPRO_CMD_NEED_ADDRESS, CPRO_CMD_HAVE_ADDRESS or CPRO_CMD_CLAIM_ADDRESS) -; - R19: address to send (claim, have) -; OUT: -; - CFLAG: set if okay, clear otherwise -; MODIFIED REGS: R16, R17, R20, R21, X, Y (R3, R4, R15, R16, R17, R18, R19, R21, X) - -cproSendAddressPacket: - ldi xl, LOW(com2SendBuffer) - ldi xh, HIGH(com2SendBuffer) - mov r6, r19 - - ldi r16, 0xff - ldi r17, COM2_PAYLOAD_FLAGS_UID | (1< - - - - - main.asm - - - - - diff --git a/avr/modules/led_activity/main.asm b/avr/modules/led_activity/main.asm deleted file mode 100644 index 091e079..0000000 --- a/avr/modules/led_activity/main.asm +++ /dev/null @@ -1,90 +0,0 @@ -; *************************************************************************** -; copyright : (C) 2025 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. * -; *************************************************************************** - - -.equ LED_ACTIVITY_TIME = 2 - - - -; *************************************************************************** -; data - -.dseg - -ledActivityTimer: .byte 1 - - -; *************************************************************************** -; code - -.cseg - - -LED_ACTIVITY_BEGIN: - - - -; --------------------------------------------------------------------------- -; LedActivity_Init -; -; @return CFLAG: set if okay, clear on error -; USED: R1, R2, R3, R4, R16, R17, X - -LedActivity_Init: - sbi LED_ACTIVITY_DDR, LED_ACTIVITY_PINNUM ; out - ldi r16, 50 - sts ledActivityTimer, r16 ; keep on for 5s at the beginning - sec - ret - - - -; --------------------------------------------------------------------------- -; @routine LedActivity_Every100ms @global -; -; @clobbers r16, r17 - -LedActivity_Every100ms: - lds r16, ledActivityTimer - tst r16 - breq LedActivity_Every100ms_ret - dec r16 - sts ledActivityTimer, r16 - brne LedActivity_Every100ms_ret - sbi LED_ACTIVITY_PORT, LED_ACTIVITY_PINNUM ; turn LED off -LedActivity_Every100ms_ret: - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine LedActivity_Restart @global -; -; @clobbers r16 - -LedActivity_Trigger: - lds r16, ledActivityTimer - tst r16 - brne LedActivity_Trigger_ledIsOn - cbi LED_ACTIVITY_PORT, LED_ACTIVITY_PINNUM ; turn LED on -LedActivity_Trigger_ledIsOn: - ldi r16, LED_ACTIVITY_TIME - sts ledActivityTimer, r16 - ret -; @end - - - - -LED_ACTIVITY_END: -.equ MODULE_SIZE_LED_ACTIVITY = LED_ACTIVITY_END-LED_ACTIVITY_BEGIN - - - diff --git a/avr/modules/led_signal/0BUILD b/avr/modules/led_signal/0BUILD deleted file mode 100644 index febd367..0000000 --- a/avr/modules/led_signal/0BUILD +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - main.asm - - - - - diff --git a/avr/modules/led_signal/main.asm b/avr/modules/led_signal/main.asm deleted file mode 100644 index 8475d01..0000000 --- a/avr/modules/led_signal/main.asm +++ /dev/null @@ -1,156 +0,0 @@ -; *************************************************************************** -; copyright : (C) 2025 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. * -; *************************************************************************** - - - -; *************************************************************************** -; data - -.dseg - -ledSignalTimer: .byte 1 -ledSignalFlags: .byte 1 -ledSignalRunFlags: .byte 1 -ledSignalBitCounter: .byte 1 - - -; *************************************************************************** -; code - -.cseg - - -LED_SIGNAL_BEGIN: - - - -; --------------------------------------------------------------------------- -; LedSignal_Init -; -; @return CFLAG: set if okay, clear on error -; USED: R1, R2, R3, R4, R16, R17, X - -LedSignal_Init: - sbi LED_SIGNAL_DDR, LED_SIGNAL_PINNUM ; out - clr r16 - sts ledSignalFlags, r16 - ldi r16, 100 - sts ledSignalTimer, r16 - sec - ret - - - -; --------------------------------------------------------------------------- -; @routine LedSignal_Every100ms @global -; -; @clobbers r16, r17 - -LedSignal_Every100ms: - lds r16, ledSignalTimer - dec r16 - breq LedSignal_Every100ms_timer0 - sts ledSignalTimer, r16 - cpi r16, 80 - brcs LedSignal_Every100ms_checkBit - brne LedSignal_Every100ms_ret - rcall LedSignal_Restart ; (r16, r17) - rjmp LedSignal_Every100ms_ret -LedSignal_Every100ms_checkBit: - lds r17, ledSignalRunFlags - andi r17, 1 - brne LedSignal_Every100ms_bit1 -LedSignal_Every100ms_bit0: - cpi r16, 8 - breq LedSignal_Every100ms_ledOff - rjmp LedSignal_Every100ms_ret -LedSignal_Every100ms_bit1: - cpi r16, 3 - breq LedSignal_Every100ms_ledOff - rjmp LedSignal_Every100ms_ret -LedSignal_Every100ms_ledOff: - sbi LED_SIGNAL_PORT, LED_SIGNAL_PINNUM ; off - rjmp LedSignal_Every100ms_ret -LedSignal_Every100ms_timer0: - lds r17, ledSignalBitCounter - dec r17 - brne LedSignal_Every100ms_nextBit - ldi r17, 100 - sts ledSignalTimer, r17 - rjmp LedSignal_Every100ms_ret -LedSignal_Every100ms_nextBit: - sts ledSignalBitCounter, r17 - lds r16, ledSignalRunFlags - lsr r16 - sts ledSignalRunFlags, r16 - ldi r16, 10 - sts ledSignalTimer, r16 - cbi LED_SIGNAL_PORT, LED_SIGNAL_PINNUM ; on -LedSignal_Every100ms_ret: - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine LedSignal_Restart @global -; -; @clobbers r16, r17 - -LedSignal_Restart: - ldi r16, 8 - sts ledSignalBitCounter, r16 - ldi r16, 10 - sts ledSignalTimer, r16 - lds r16, ledSignalFlags - sts ledSignalRunFlags, r16 - cbi LED_SIGNAL_PORT, LED_SIGNAL_PINNUM ; on - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine LedSignal_SetFlag @global -; -; @param r16 flag mask -; @clobbers r17 - -LedSignal_SetFlag: - lds r17, ledSignalFlags - or r17, r16 - sts ledSignalFlags, r17 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine LedSignal_ClrFlag @global -; -; @param r16 flag mask -; @clobbers r17 - -LedSignal_ClrFlag: - lds r17, ledSignalFlags - com r16 - and r17, r16 - com r16 - sts ledSignalFlags, r17 - ret -; @end - - - - -LED_SIGNAL_END: -.equ MODULE_SIZE_LED_SIGNAL = LED_SIGNAL_END-LED_SIGNAL_BEGIN - - - diff --git a/avr/modules/ma_light/0BUILD b/avr/modules/ma_light/0BUILD deleted file mode 100644 index febd367..0000000 --- a/avr/modules/ma_light/0BUILD +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - main.asm - - - - - diff --git a/avr/modules/ma_light/main.asm b/avr/modules/ma_light/main.asm deleted file mode 100644 index 04e0a6f..0000000 --- a/avr/modules/ma_light/main.asm +++ /dev/null @@ -1,352 +0,0 @@ -; *************************************************************************** -; 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. * -; *************************************************************************** - - -; *************************************************************************** -; defines - -.equ MOTIONLIGHT_DEFAULT_ONTIME = 3000 ; 5min (in 1/10 secs) - -.equ MOTIONLIGHT_SOURCE_NUM = 2 - -.equ MOTIONLIGHT_SOURCE_OFFS_ADDR = 0 -.equ MOTIONLIGHT_SOURCE_OFFS_VALUEID = 1 -.equ MOTIONLIGHT_SOURCE_SIZE = 2 - - - -; *************************************************************************** -; data - -.dseg - - - -motionLightDataBegin: -motionLightTimer: .byte 2 -motionLightOnTime: .byte 2 -motionLightColor: .byte 4 -motionLightSources: .byte MOTIONLIGHT_SOURCE_NUM*MOTIONLIGHT_SOURCE_SIZE -motionLightDataEnd: - - - -; *************************************************************************** -; code - -.cseg - -MOTIONLIGHT_BEGIN: - - -; --------------------------------------------------------------------------- -; @routine MotionLight_Init @global -; - -MotionLight_Init: - ; preset SRAM data area - ldi xh, HIGH(motionLightDataBegin) - ldi xl, LOW(motionLightDataBegin) - clr r16 - ldi r17, (motionLightDataEnd-motionLightDataBegin) - rcall Utils_FillSram - - ldi xh, HIGH(motionLightColor) - ldi xl, LOW(motionLightColor) - clr r16 - ldi r17, 0x80 - st X+, r16 ; R - st X+, r16 ; G - st X+, r17 ; B - st X+, r16 ; WW - ldi r16, LOW(MOTIONLIGHT_DEFAULT_ONTIME) - sts motionLightOnTime, r16 - ldi r16, HIGH(MOTIONLIGHT_DEFAULT_ONTIME) - sts motionLightOnTime+1, r16 - - rcall motionLightReadConfFromEeprom - - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine MotionLight_Fini @global -; - -MotionLight_Fini: - clr r16 - sts motionLightTimer, r16 ; clear timer - sts motionLightTimer+1, r16 - rjmp motionLightTurnOff -; @end - - - -; --------------------------------------------------------------------------- -; @routine MotionLight_Every100ms @global -; -; @clobbers r16, r24, r26, (r17, r18, r19, r20, r21, r23) - -MotionLight_Every100ms: - lds r24, motionLightTimer - lds r25, motionLightTimer+1 - sbiw r25:r24, 1 - brcs MotionLight_Every100ms_ret - sts motionLightTimer, r24 - sts motionLightTimer+1, r25 - breq MotionLight_Every100ms_off -MotionLight_Every100ms_ret: - ret -MotionLight_Every100ms_off: - rjmp motionLightTurnOff ; (r16, r17, r18, r19, r20, r21, r23) -; @end - - - -; --------------------------------------------------------------------------- -; @routine MotionLight_OnPacketReceived @global -; -; @clobbers any, -X - -MotionLight_OnPacketReceived: - adiw xh:xl, 2 ; command - ld r16, X - sbiw xh:xl, 2 - cpi r16, CPRO_CMD_VALUE_REPORT - breq MotionLight_OnPacketReceived_report - cpi r16, CPRO_CMD_VALUE_SET - breq MotionLight_OnPacketReceived_set -MotionLight_OnPacketReceived_clcRet: - clc ; unexpected msg - ret -MotionLight_OnPacketReceived_report: - rcall CPRO_ReadValue ; (none) - mov r16, r18 - or r16, r19 - breq MotionLight_OnPacketReceived_clcRet ; zero value, ignore - rcall motionLightHasSource ; (r16, r24, Y) - brcs MotionLight_OnPacketReceived_turnOn - ret -MotionLight_OnPacketReceived_turnOn: - lds r16, motionLightTimer - lds r17, motionLightTimer+1 - or r16, r17 - brne MotionLight_OnPacketReceived_startTimer - rcall motionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23) -MotionLight_OnPacketReceived_startTimer: - rcall motionLightStartTimer - ret -MotionLight_OnPacketReceived_set: - rcall CPRO_ReadValue ; (none) - cpi r17, VALUE_ID_MAL_RGBW_VALUE - breq MotionLight_OnPacketReceived_setRGBW - cpi r17, VALUE_ID_MAL_ONTIME - breq MotionLight_OnPacketReceived_setOnTime - cpi r17, VALUE_ID_MAL_SOURCE1 - breq MotionLight_OnPacketReceived_setSource1 - cpi r17, VALUE_ID_MAL_SOURCE2 - breq MotionLight_OnPacketReceived_setSource2 - clc ; unexpected message - ret -MotionLight_OnPacketReceived_setRGBW: - sts motionLightColor, r18 - sts motionLightColor+1, r19 - sts motionLightColor+2, r20 - sts motionLightColor+3, r21 - rcall motionLightStartTimer ; immediately ON with new color - rcall motionLightTurnOn - rjmp MotionLight_OnPacketReceived_sendAck -MotionLight_OnPacketReceived_setOnTime: - sts motionLightOnTime, r18 - sts motionLightOnTime+1, r19 - rjmp MotionLight_OnPacketReceived_sendAck -MotionLight_OnPacketReceived_setSource1: - sts motionLightSources, r18 ; peerAddr - sts motionLightSources+1, r19 ; valueId - rjmp MotionLight_OnPacketReceived_sendAck -MotionLight_OnPacketReceived_setSource2: - sts motionLightSources+MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr - sts motionLightSources+MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId -MotionLight_OnPacketReceived_sendAck: - ldi r16, CPRO_CMD_VALUE_SET_ACK - rcall CPRO_SendSetValueResponse - push xl - push xh - rcall motionLightWriteConfToEeprom - pop xh - pop xl - sec - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine motionLightHasSource -; -; @return CFLAGS set if we have a matching source entry, cleared otherwise -; @param r17 value id -; @param r22 source address -; @clobbers r16, r24, Y - -motionLightHasSource: - ldi yl, LOW(motionLightSources) - ldi yh, HIGH(motionLightSources) - ldi r24, MOTIONLIGHT_SOURCE_NUM -motionLightHasSource_loop: - ldd r16, Y+MOTIONLIGHT_SOURCE_OFFS_ADDR - cp r16, r22 - brne motionLightHasSource_next - ldd r16, Y+MOTIONLIGHT_SOURCE_OFFS_VALUEID - cp r16, r17 - brne motionLightHasSource_next - sec - ret -motionLightHasSource_next: - adiw yh:yl, MOTIONLIGHT_SOURCE_SIZE - dec r24 - brne motionLightHasSource_loop - clc - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine motionLightStartTimer -; -; @clobbers r16 - -motionLightStartTimer: - lds r16, motionLightOnTime - sts motionLightTimer, r16 - lds r16, motionLightOnTime+1 - sts motionLightTimer+1, r16 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine motionLightTurnOn -; -; @clobbers r18, r19, r20, r21 (r16, t17, r23) - -motionLightTurnOn: - lds r18, motionLightColor - lds r19, motionLightColor+1 - lds r20, motionLightColor+2 - lds r21, motionLightColor+3 - rjmp SK6812_SetAllColor ; (r16, r17, r23) -; @end - - - -; --------------------------------------------------------------------------- -; @routine motionLightTurnOff -; -; @clobbers r18, r19, r20, r21 (r16, t17, r23) - -motionLightTurnOff: - clr r18 - clr r19 - clr r20 - clr r21 - rjmp SK6812_SetAllColor ; (r16, r17, r23) -; @end - - - -; --------------------------------------------------------------------------- -; @routine motionLightReadConfFromEeprom -; -; @clobbers - -motionLightReadConfFromEeprom: - push r15 - in r15, SREG - cli - ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME) - ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME) - rcall Utils_ReadEepromIncr ; (R16) - mov r18, r16 - rcall Utils_ReadEepromIncr ; (R16) - mov r19, r16 - and r16, r18 - cpi r16, 0xff - breq motionLightReadConfFromEeprom_end - sts motionLightOnTime, r18 - sts motionLightOnTime+1, r19 - - ; read source 1 - rcall Utils_ReadEepromIncr ; (R16) - mov r18, r16 - rcall Utils_ReadEepromIncr ; (R16) - mov r19, r16 - sts motionLightSources+MOTIONLIGHT_SOURCE_OFFS_ADDR, r18 - sts motionLightSources+MOTIONLIGHT_SOURCE_OFFS_VALUEID, r19 - - ; read source 2 - rcall Utils_ReadEepromIncr ; (R16) - mov r18, r16 - rcall Utils_ReadEepromIncr ; (R16) - mov r19, r16 - sts motionLightSources+MOTIONLIGHT_SOURCE_SIZE+MOTIONLIGHT_SOURCE_OFFS_ADDR, r18 - sts motionLightSources+MOTIONLIGHT_SOURCE_SIZE+MOTIONLIGHT_SOURCE_OFFS_VALUEID, r19 - -motionLightReadConfFromEeprom_end: - out SREG, r15 - pop r15 - ret -; @end - - - -; --------------------------------------------------------------------------- -; @routine motionLightWriteConfToEeprom -; -; @clobbers r15, r16, r17, X - -motionLightWriteConfToEeprom: - push r15 - in r15, SREG - cli - ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME) - ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME) - - lds r16, motionLightOnTime - rcall Utils_WriteEepromIncr ; (R17) - lds r16, motionLightOnTime+1 - rcall Utils_WriteEepromIncr ; (R17) - - ; write source 1 - lds r16, motionLightSources+MOTIONLIGHT_SOURCE_OFFS_ADDR - rcall Utils_WriteEepromIncr ; (R16) - lds r16, motionLightSources+MOTIONLIGHT_SOURCE_OFFS_VALUEID - rcall Utils_WriteEepromIncr ; (R16) - - ; write source 2 - lds r16, motionLightSources+MOTIONLIGHT_SOURCE_SIZE+MOTIONLIGHT_SOURCE_OFFS_ADDR - rcall Utils_WriteEepromIncr ; (R16) - lds r16, motionLightSources+MOTIONLIGHT_SOURCE_SIZE+MOTIONLIGHT_SOURCE_OFFS_VALUEID - rcall Utils_WriteEepromIncr ; (R16) - - out SREG, r15 - pop r15 - ret -; @end - - - -MOTIONLIGHT_END: -.equ MODULE_SIZE_MOTIONLIGHT = MOTIONLIGHT_END-MOTIONLIGHT_BEGIN - - diff --git a/avr/modules/stats/0BUILD b/avr/modules/stats/0BUILD deleted file mode 100644 index febd367..0000000 --- a/avr/modules/stats/0BUILD +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - main.asm - - - - - diff --git a/avr/modules/stats/main.asm b/avr/modules/stats/main.asm deleted file mode 100644 index c319739..0000000 --- a/avr/modules/stats/main.asm +++ /dev/null @@ -1,115 +0,0 @@ -; *************************************************************************** -; 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 - -.equ STATS_POS_MAX = 5 -.equ STATS_POS_DEVICE = 5 -.equ STATS_POS_SEND = 4 -.equ STATS_POS_RECV = 3 -.equ STATS_POS_SYS = 2 -.equ STATS_POS_MEM = 1 - - -; *************************************************************************** -; data - -.dseg - - -statsDataBegin: - statsRemaining: .byte 1 -statsDataEnd: - -statsSendTimer: .byte 2 ; intentionally outside zeroed out are - - -; *************************************************************************** -; code - -.cseg - - - -Stats_Init: - ; preset SRAM data area - ldi xh, HIGH(statsDataBegin) - ldi xl, LOW(statsDataBegin) - clr r16 - ldi r17, (statsDataEnd-statsDataBegin) - rcall Utils_FillSram - sec - ret - - - -Stats_Run: - in r15, SREG - push r15 - cli - - lds r17, statsRemaining - tst r17 ; some left? - breq Stats_Run_done ; nope, jump to end - - ldi xl, LOW(com2SendBuffer) - ldi xh, HIGH(com2SendBuffer) - ldi r16, 0xff ; broadcast - - cpi r17, STATS_POS_RECV - brne Stats_Run_l1 - rcall CPRO_WriteComRecvStats - rjmp Stats_Run_SendPacket -Stats_Run_l1: - cpi r17, STATS_POS_SYS - brne Stats_Run_l2 - rcall CPRO_WriteSysStats - rjmp Stats_Run_SendPacket -Stats_Run_l2: - cpi r17, STATS_POS_MEM - brne Stats_Run_l3 - rcall CPRO_WriteMemStats - rjmp Stats_Run_SendPacket -Stats_Run_l3: - cpi r17, STATS_POS_SEND - brne Stats_Run_l4 - rcall CPRO_WriteComSendStats - rjmp Stats_Run_SendPacket -Stats_Run_l4: - cpi r17, STATS_POS_DEVICE - brne Stats_Run_l5 - rcall CPRO_WriteDevice - rjmp Stats_Run_SendPacket -Stats_Run_l5: - ; add more stats here - rjmp Stats_Run_done -Stats_Run_SendPacket: - rcall COM2_SendPacket - brcc Stats_Run_done ; only decrement counter if message successfully sent - lds r16, statsRemaining - dec r16 - sts statsRemaining, r16 -Stats_Run_done: - pop r15 - out SREG, r15 - clc - ret - - - - -Stats_Timer: - ldi r16, STATS_POS_MAX ; RECV, SYS - sts statsRemaining, r16 - ret - - -