avr: removed old modules.
This commit is contained in:
@@ -8,17 +8,12 @@
|
|||||||
ccs811
|
ccs811
|
||||||
clock
|
clock
|
||||||
cny70
|
cny70
|
||||||
com2
|
|
||||||
comproto
|
|
||||||
ds18b20
|
ds18b20
|
||||||
flash
|
flash
|
||||||
lcd
|
lcd
|
||||||
lcd2
|
lcd2
|
||||||
led
|
led
|
||||||
led_activity
|
|
||||||
led_simple
|
led_simple
|
||||||
led_signal
|
|
||||||
ma_light
|
|
||||||
motion
|
motion
|
||||||
owimaster
|
owimaster
|
||||||
reed
|
reed
|
||||||
@@ -26,7 +21,6 @@
|
|||||||
sgp40
|
sgp40
|
||||||
si7021
|
si7021
|
||||||
sk6812
|
sk6812
|
||||||
stats
|
|
||||||
tcrt1000
|
tcrt1000
|
||||||
timer
|
timer
|
||||||
twimaster
|
twimaster
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<gwbuild>
|
|
||||||
|
|
||||||
<extradist>
|
|
||||||
buffer.asm
|
|
||||||
crc.asm
|
|
||||||
defs.asm
|
|
||||||
main.asm
|
|
||||||
screen.asm
|
|
||||||
</extradist>
|
|
||||||
|
|
||||||
</gwbuild>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<gwbuild>
|
|
||||||
|
|
||||||
<extradist>
|
|
||||||
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
|
|
||||||
</extradist>
|
|
||||||
|
|
||||||
|
|
||||||
</gwbuild>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
|
|
||||||
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
st X+, r6 ; address
|
|
||||||
ldi xl, LOW(com2SendBuffer)
|
|
||||||
ldi xh, HIGH(com2SendBuffer)
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
rjmp COM2_SendPacket
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.include "modules/comproto/addr1.asm"
|
|
||||||
.include "modules/comproto/addr2.asm"
|
|
||||||
|
|
||||||
|
|
||||||
#endif ; MODULES_COM_WITH_ADDR_PROTO
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,166 +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 file contains timer handlers for the address protocol
|
|
||||||
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CPRO_Address_OnTimer:
|
|
||||||
lds r16, cproMode
|
|
||||||
ldi r17, CPRO_MODE_NEXT_FREE
|
|
||||||
ldi zl, LOW(cproAddressOnTimerTable)
|
|
||||||
ldi zh, HIGH(cproAddressOnTimerTable)
|
|
||||||
rjmp Utils_TableJump
|
|
||||||
|
|
||||||
|
|
||||||
cproAddressOnTimerTable:
|
|
||||||
.dw CPRO_StartReclaimAddrProcedure ; CPRO_MODE_NOADDRESS
|
|
||||||
.dw 0 ; CPRO_MODE_NORMAL
|
|
||||||
.dw cproHandle1sNeedAddr ; CPRO_MODE_SEND_NEED_ADDR
|
|
||||||
.dw cproHandle1sGetAddrStarted ; CPRO_MODE_GETADDRSTARTED
|
|
||||||
.dw cproHandle1sSendClaimAddr1 ; CPRO_MODE_SEND_CLAIM_ADDR1
|
|
||||||
.dw cproHandle1sClaimingAddr12 ; CPRO_MODE_CLAIMING_ADDR1
|
|
||||||
.dw cproHandle1sClaimingAddr12 ; CPRO_MODE_CLAIMING_ADDR2
|
|
||||||
.dw cproHandle1sClaimingAddr3 ; CPRO_MODE_CLAIMING_ADDR3
|
|
||||||
.dw cproHandle1sSendingHaveAddress ; CPRO_MODE_SENDING_HAVE_ADDR
|
|
||||||
.dw cproHandle1sSendReclaimAddr ; CPRO_MODE_SEND_RECLAIM_ADDR
|
|
||||||
.dw cproHandle1sReclaimingAddr ; CPRO_MODE_RECLAIMING_ADDR
|
|
||||||
.dw cproHandle1sSendDenyAddr ; CPRO_MODE_SEND_DENY_ADDR
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sSendingHaveAddress:
|
|
||||||
lds r19, com2Address
|
|
||||||
rcall CPRO_SendHaveAddress
|
|
||||||
brcs cproHandle1sSendingHaveAddress_okay
|
|
||||||
rcall cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
ret
|
|
||||||
cproHandle1sSendingHaveAddress_okay:
|
|
||||||
ldi r16, CPRO_MODE_NORMAL
|
|
||||||
sts cproMode, r16
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sNeedAddr:
|
|
||||||
rcall CPRO_SendNeedAddress
|
|
||||||
brcs cproHandle1sNeedAddr_okay
|
|
||||||
rjmp cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
cproHandle1sNeedAddr_okay:
|
|
||||||
ldi r16, CPRO_MODE_GETADDRSTARTED ; wait for incoming messages
|
|
||||||
sts cproMode, r16
|
|
||||||
ldi r18, LOW(CPRO_WAITTIME_GETADDR) ; set timeout
|
|
||||||
ldi r19, HIGH(CPRO_WAITTIME_GETADDR) ; set timeout
|
|
||||||
rjmp cproAddressSetTimer
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sSendDenyAddr:
|
|
||||||
rcall CPRO_SendDenyAddress
|
|
||||||
brcs cproHandle1sSendDenyAddr_okay
|
|
||||||
rjmp cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
cproHandle1sSendDenyAddr_okay:
|
|
||||||
ldi r16, CPRO_MODE_NORMAL ; DENY_ADDR sent, back to normal
|
|
||||||
sts cproMode, r16
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sSendReclaimAddr:
|
|
||||||
lds r19, cproAddrRangeBegin
|
|
||||||
rcall CPRO_SendClaimAddress
|
|
||||||
brcs cproHandle1sSendReclaimAddr_okay
|
|
||||||
rjmp cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
cproHandle1sSendReclaimAddr_okay:
|
|
||||||
ldi r16, CPRO_MODE_RECLAIMING_ADDR
|
|
||||||
sts cproMode, r16
|
|
||||||
ldi r18, LOW(CPRO_WAITTIME_RECLAIMADDR)
|
|
||||||
ldi r19, HIGH(CPRO_WAITTIME_RECLAIMADDR)
|
|
||||||
rjmp cproAddressSetTimer ; prepare time for next stage
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sGetAddrStarted:
|
|
||||||
rcall cproGetFirstFreeAddr
|
|
||||||
brcs cproHandle1sGetAddrStarted_gotAddr
|
|
||||||
; no free address, abort TODO: send an error message to bus ("bus full")
|
|
||||||
ldi r16, CPRO_MODE_NOADDRESS
|
|
||||||
sts cproMode, r16
|
|
||||||
ret
|
|
||||||
cproHandle1sGetAddrStarted_gotAddr:
|
|
||||||
ldi r16, CPRO_MODE_SEND_CLAIM_ADDR1
|
|
||||||
sts cproMode, r16
|
|
||||||
rjmp cproAddressSetTimer1s ; start
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sSendClaimAddr1:
|
|
||||||
lds r19, cproAddrRangeBegin
|
|
||||||
rcall CPRO_SendClaimAddress
|
|
||||||
brcs cproHandle1sClaimSend_okay
|
|
||||||
rjmp cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
cproHandle1sClaimSend_okay: ; goto nex stage
|
|
||||||
ldi r16, CPRO_MODE_CLAIMING_ADDR1
|
|
||||||
sts cproMode, r16
|
|
||||||
ldi r18, LOW(CPRO_WAITTIME_CLAIMADDR)
|
|
||||||
ldi r19, HIGH(CPRO_WAITTIME_CLAIMADDR)
|
|
||||||
rjmp cproAddressSetTimer ; prepare timer for next stage
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sClaimingAddr12:
|
|
||||||
lds r19, cproAddrRangeBegin ; currently claimed address
|
|
||||||
rcall CPRO_SendClaimAddress
|
|
||||||
brcs cproHandle1sClaimingAddr12_okay
|
|
||||||
rjmp cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
cproHandle1sClaimingAddr12_okay:
|
|
||||||
lds r16, cproMode
|
|
||||||
inc r16
|
|
||||||
sts cproMode, r16
|
|
||||||
ldi r18, LOW(CPRO_WAITTIME_CLAIMADDR)
|
|
||||||
ldi r19, HIGH(CPRO_WAITTIME_CLAIMADDR)
|
|
||||||
rjmp cproAddressSetTimer ; prepare time for next stage
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandle1sClaimingAddr3:
|
|
||||||
cproHandle1sReclaimingAddr:
|
|
||||||
; claimed given address 3rd time or addr reclaimed, set address and enter "normal" mode
|
|
||||||
lds r19, cproAddrRangeBegin ; currently claimed address
|
|
||||||
sts com2Address, r19
|
|
||||||
rcall CPRO_SendHaveAddress
|
|
||||||
brcs cproHandle1sClaimingAddr3_okay
|
|
||||||
rjmp cproAddressSetTimer1s ; could not send, restart timer 1s and retry later
|
|
||||||
cproHandle1sClaimingAddr3_okay:
|
|
||||||
in r15, SREG
|
|
||||||
push r15
|
|
||||||
cli
|
|
||||||
lds r16, com2Address ; currently sent address is in cproAddrRangeBegin
|
|
||||||
ldi xl, LOW(EEPROM_OFFS_COMADDR) ; write address into eeprom
|
|
||||||
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
|
|
||||||
rcall Utils_WriteEepromIncr ; write address to EEPROM
|
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
ldi r16, CPRO_MODE_NORMAL ; set mode to "normal"
|
|
||||||
sts cproMode, r16
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,185 +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 file contains packet receiption handlers for the address protocol
|
|
||||||
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; CPRO_Address_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_Address_OnPacketReceived:
|
|
||||||
adiw xh:xl, COM2_MSG_OFFS_CMD
|
|
||||||
ld r16, x
|
|
||||||
sbiw xh:xl, COM2_MSG_OFFS_CMD
|
|
||||||
|
|
||||||
cpi r16, CPRO_CMD_NEED_ADDRESS
|
|
||||||
brcs CPRO_Address_OnPacketReceived_nc ; smaller than 60
|
|
||||||
|
|
||||||
cpi r16, (CPRO_CMD_ADDRESS_RANGE+1)
|
|
||||||
brcc CPRO_Address_OnPacketReceived_nc
|
|
||||||
|
|
||||||
CPRO_Address_OnPacketReceived_debug2:
|
|
||||||
ldi r17, (cproPacketTypeTransTableEnd-cproPacketTypeTransTableBegin)*2
|
|
||||||
ldi zl, LOW(cproPacketTypeTransTableBegin)
|
|
||||||
ldi zh, HIGH(cproPacketTypeTransTableBegin)
|
|
||||||
rcall Utils_FindBytePositionInTable
|
|
||||||
brcc CPRO_Address_OnPacketReceived_nc
|
|
||||||
|
|
||||||
ldi r17, (cproPacketTypeTransTableEnd-cproPacketTypeTransTableBegin)*2
|
|
||||||
ldi zl, LOW(cproPacketTypeHandleTable)
|
|
||||||
ldi zh, HIGH(cproPacketTypeHandleTable)
|
|
||||||
rcall Utils_TableJump
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
CPRO_Address_OnPacketReceived_nc:
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproPacketTypeTransTableBegin:
|
|
||||||
.db CPRO_CMD_NEED_ADDRESS, CPRO_CMD_HAVE_ADDRESS, CPRO_CMD_ADDRESS_RANGE, CPRO_CMD_DENY_ADDRESS, CPRO_CMD_CLAIM_ADDRESS, CPRO_CMD_PING
|
|
||||||
cproPacketTypeTransTableEnd:
|
|
||||||
|
|
||||||
; position within table must be in same order as in table above!
|
|
||||||
cproPacketTypeHandleTable:
|
|
||||||
.dw cproHandleNeedAddr, cproHandleHaveAddr, cproHandleAddrRange, cproHandleDenyAddr, cproHandleClaimAddr, cproHandlePing
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandleNeedAddr:
|
|
||||||
lds r17, cproMode
|
|
||||||
cpi r17, CPRO_MODE_NORMAL
|
|
||||||
brne cproHandleNeedAddr_done
|
|
||||||
; enter CPRO_MODE_SENDING_HAVE_ADDR mode
|
|
||||||
lds r16, com2Address
|
|
||||||
tst r16
|
|
||||||
breq cproHandleNeedAddr_done ; we have no address, don't handle
|
|
||||||
ldi r24, CPRO_MODE_SENDING_HAVE_ADDR ; start singleshot timer for sending HAVE_ADDRESS
|
|
||||||
sts cproMode, r24
|
|
||||||
lds r24, com2Address
|
|
||||||
clr r25
|
|
||||||
lsl r24 ; *2
|
|
||||||
rol r25
|
|
||||||
lsl r24 ; *4
|
|
||||||
rol r25
|
|
||||||
lsl r24 ; *8
|
|
||||||
rol r25
|
|
||||||
adiw r25:r24, 30 ; add 3 secs
|
|
||||||
mov r18, r24
|
|
||||||
mov r19, r25
|
|
||||||
rjmp cproAddressSetTimer
|
|
||||||
cproHandleNeedAddr_done:
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandleHaveAddr:
|
|
||||||
lds r17, cproMode
|
|
||||||
cpi r17, CPRO_MODE_GETADDRSTARTED
|
|
||||||
brne cproHandleHaveAddr_done
|
|
||||||
; validate address
|
|
||||||
adiw xh:xl, CPRO_PACKET_HAVEADDR_OFFS_ADDRESS
|
|
||||||
ld r16, x
|
|
||||||
sbiw xh:xl, CPRO_PACKET_HAVEADDR_OFFS_ADDRESS
|
|
||||||
tst r16
|
|
||||||
breq cproHandleHaveAddr_done ; invalid address, ignore
|
|
||||||
cpi r16, 127
|
|
||||||
brcc cproHandleHaveAddr_done ; invalid address, ignore
|
|
||||||
; set bit corresponding to given address in bitfield of used addresses
|
|
||||||
dec r16
|
|
||||||
rcall cproSetBitInBitfield
|
|
||||||
cproHandleHaveAddr_done:
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandleClaimAddr:
|
|
||||||
adiw xh:xl, CPRO_PACKET_CLAIMADDR_OFFS_ADDRESS
|
|
||||||
ld r16, x
|
|
||||||
sbiw xh:xl, CPRO_PACKET_CLAIMADDR_OFFS_ADDRESS
|
|
||||||
tst r16 ; dont handle claim addr 0
|
|
||||||
breq cproHandleClaimAddr_done
|
|
||||||
cpi r16, 0xff ; dont handle claim addr 0
|
|
||||||
breq cproHandleClaimAddr_done
|
|
||||||
lds r17, com2Address
|
|
||||||
tst r17
|
|
||||||
breq cproHandleClaimAddr_done ; we have no address, yet
|
|
||||||
cp r16, r17
|
|
||||||
brne cproHandleClaimAddr_done ; not our address
|
|
||||||
ldi r16, CPRO_MODE_SEND_DENY_ADDR
|
|
||||||
sts cproMode, r16
|
|
||||||
rcall cproAddressSetTimer1s
|
|
||||||
|
|
||||||
cproHandleClaimAddr_done:
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cproHandleDenyAddr:
|
|
||||||
; check mode
|
|
||||||
lds r17, cproMode
|
|
||||||
cpi r17, CPRO_MODE_CLAIMING_ADDR1
|
|
||||||
brcs cproHandleDenyAddr_notInClaimAddr13Mode
|
|
||||||
cpi r17, CPRO_MODE_CLAIMING_ADDR3+1
|
|
||||||
brcc cproHandleDenyAddr_notInClaimAddr13Mode
|
|
||||||
; we are in one of the three CLAIM_ADDRESS modes and received a DENY_ADDR, check address
|
|
||||||
adiw xh:xl, CPRO_PACKET_DENYADDR_OFFS_ADDRESS
|
|
||||||
ld r16, x
|
|
||||||
sbiw xh:xl, CPRO_PACKET_DENYADDR_OFFS_ADDRESS
|
|
||||||
lds r17, cproAddrRangeBegin
|
|
||||||
cp r16, r17
|
|
||||||
brne cproHandleDenyAddr_done ; not our currently claimed address, ignore
|
|
||||||
; someone denied us our claimed address, try next
|
|
||||||
rcall cproGetNextFreeAddr
|
|
||||||
brcs cproHandleDenyAddr_gotFreeAddr
|
|
||||||
; no free address, abort TODO: send an error message to bus ("bus full")
|
|
||||||
ldi r16, CPRO_MODE_NOADDRESS
|
|
||||||
sts cproMode, r16
|
|
||||||
ret
|
|
||||||
cproHandleDenyAddr_gotFreeAddr: ; claim next address
|
|
||||||
ldi r16, CPRO_MODE_SEND_CLAIM_ADDR1
|
|
||||||
sts cproMode, r16
|
|
||||||
rcall cproAddressSetTimer1s ; start timer
|
|
||||||
rjmp cproHandleDenyAddr_done
|
|
||||||
cproHandleDenyAddr_notInClaimAddr13Mode: ; reclaim mode?
|
|
||||||
lds r17, cproMode
|
|
||||||
cpi r17, CPRO_MODE_RECLAIMING_ADDR
|
|
||||||
brne cproHandleDenyAddr_done
|
|
||||||
; reclaiming went wrong, go through full address assignment protocol
|
|
||||||
rcall CPRO_StartGetAddrProcedure
|
|
||||||
cproHandleDenyAddr_done:
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,105 +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
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; message codes
|
|
||||||
|
|
||||||
.equ CPRO_CMD_PING = 10
|
|
||||||
.equ CPRO_CMD_PONG = 11
|
|
||||||
.equ CPRO_CMD_COMSENDSTATS = 20
|
|
||||||
.equ CPRO_CMD_COMRECVSTATS = 21
|
|
||||||
.equ CPRO_CMD_TWIBUSMEMBER = 30
|
|
||||||
.equ CPRO_CMD_DEBUG = 40
|
|
||||||
|
|
||||||
.equ CPRO_CMD_RESULT = 50
|
|
||||||
|
|
||||||
.equ CPRO_CMD_NEED_ADDRESS = 60
|
|
||||||
.equ CPRO_CMD_HAVE_ADDRESS = 61
|
|
||||||
.equ CPRO_CMD_CLAIM_ADDRESS = 62
|
|
||||||
.equ CPRO_CMD_DENY_ADDRESS = 63
|
|
||||||
.equ CPRO_CMD_ADDRESS_RANGE = 64
|
|
||||||
|
|
||||||
.equ CPRO_CMD_FLASH_START = 70
|
|
||||||
.equ CPRO_CMD_FLASH_END = 71
|
|
||||||
.equ CPRO_CMD_FLASH_READY = 72
|
|
||||||
.equ CPRO_CMD_FLASH_DATA = 73
|
|
||||||
.equ CPRO_CMD_FLASH_RSP = 74
|
|
||||||
|
|
||||||
.equ CPRO_CMD_DEVICE = 80
|
|
||||||
.equ CPRO_CMD_MEMSTATS = 81
|
|
||||||
.equ CPRO_CMD_SYSSTATS = 82
|
|
||||||
|
|
||||||
.equ CPRO_CMD_REBOOT_REQUEST = 90
|
|
||||||
.equ CPRO_CMD_REBOOT_RESPONSE = 91
|
|
||||||
|
|
||||||
.equ CPRO_CMD_VALUE_REPORT = 100
|
|
||||||
.equ CPRO_CMD_VALUE_SET = 101
|
|
||||||
.equ CPRO_CMD_VALUE_SET_ACK = 102
|
|
||||||
.equ CPRO_CMD_VALUE_SET_NACK = 103
|
|
||||||
|
|
||||||
.equ CPRO_CMD_DATA = 110
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; offsets in CPRO_CMD_VALUE_* messages
|
|
||||||
|
|
||||||
.equ CPRO_PACKET_VALUE_OFFS_UID = 4
|
|
||||||
.equ CPRO_PACKET_VALUE_OFFS_MSGID = 8
|
|
||||||
.equ CPRO_PACKET_VALUE_OFFS_VALUEID = 10
|
|
||||||
.equ CPRO_PACKET_VALUE_OFFS_VALUE = 12
|
|
||||||
.equ CPRO_PACKET_VALUE_OFFS_DENOM = 14
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; offsets in CPRO_*_ADDRESS messages
|
|
||||||
|
|
||||||
.equ CPRO_PACKET_HAVEADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
|
||||||
.equ CPRO_PACKET_CLAIMADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
|
||||||
.equ CPRO_PACKET_DENYADDR_OFFS_ADDRESS = COM2_MSG_OFFS_PAYLOAD+4
|
|
||||||
.equ CPRO_PACKET_REBOOTREQ_OFFS_UID = COM2_MSG_OFFS_PAYLOAD+0
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; wait times for address protocol
|
|
||||||
|
|
||||||
.equ CPRO_WAITTIME_INITIAL = 100
|
|
||||||
.equ CPRO_WAITTIME_GETADDR = 1300
|
|
||||||
.equ CPRO_WAITTIME_CLAIMADDR = 170
|
|
||||||
.equ CPRO_WAITTIME_RECLAIMADDR = 100
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; modes of operation
|
|
||||||
|
|
||||||
.equ CPRO_MODE_NOADDRESS = 0x00 ; no address, yet
|
|
||||||
.equ CPRO_MODE_NORMAL = 0x01 ; normal operation
|
|
||||||
.equ CPRO_MODE_SEND_NEED_ADDR = 0x02 ; wait to send need address
|
|
||||||
.equ CPRO_MODE_GETADDRSTARTED = 0x03 ; waiting for HAVE_ADDRESS and ADDRESS_RANGE packets to arrive
|
|
||||||
.equ CPRO_MODE_SEND_CLAIM_ADDR1 = 0x04 ; send CLAIM_ADDRESS as part of reclaiming procedure
|
|
||||||
.equ CPRO_MODE_CLAIMING_ADDR1 = 0x05 ; CLAIM_ADDRESS sent, waiting for HAVE_ADDRESS packet to reject the claim
|
|
||||||
.equ CPRO_MODE_CLAIMING_ADDR2 = 0x06 ; CLAIM_ADDRESS sent, 2nd try
|
|
||||||
.equ CPRO_MODE_CLAIMING_ADDR3 = 0x07 ; CLAIM_ADDRESS sent, 3rd try
|
|
||||||
.equ CPRO_MODE_SENDING_HAVE_ADDR = 0x08 ; waiting for our turn to send HAVE_ADDRESS packet
|
|
||||||
.equ CPRO_MODE_SEND_RECLAIM_ADDR = 0x09 ; send CLAIM_ADDRESS as part of reclaiming procedure
|
|
||||||
.equ CPRO_MODE_RECLAIMING_ADDR = 0x0a ; CLAIM_ADDRESS with the previously used address sent after bootup
|
|
||||||
.equ CPRO_MODE_SEND_DENY_ADDR = 0x0b ; someone claimed our address, send a DENY_ADDR message
|
|
||||||
.equ CPRO_MODE_NEXT_FREE = 0x0c ; next free mode
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,142 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; 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:
|
|
||||||
cpi r16, CPRO_CMD_REBOOT_REQUEST
|
|
||||||
brne CPRO_OnPacketReceived_l2
|
|
||||||
rjmp cproHandleReboot
|
|
||||||
|
|
||||||
CPRO_OnPacketReceived_l2:
|
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Compare the UID from a message against our own UID.
|
|
||||||
;
|
|
||||||
;IN:
|
|
||||||
; - X: pointer to UID in a message to compare against out own uid
|
|
||||||
; OUT:
|
|
||||||
; - CFLAG set if matches, cleared otherwise
|
|
||||||
; REGS: r16, r18, r19, r20, r21, X
|
|
||||||
|
|
||||||
cproCheckUidInMsg:
|
|
||||||
push xl
|
|
||||||
push xh
|
|
||||||
rcall Utils_ReadUid
|
|
||||||
pop xh
|
|
||||||
pop xl
|
|
||||||
ld r16, X+
|
|
||||||
cp r16, r18
|
|
||||||
brne cproCheckUidInMsg_notMe
|
|
||||||
ld r16, X+
|
|
||||||
cp r16, r19
|
|
||||||
brne cproCheckUidInMsg_notMe
|
|
||||||
ld r16, X+
|
|
||||||
cp r16, r20
|
|
||||||
brne cproCheckUidInMsg_notMe
|
|
||||||
ld r16, X+
|
|
||||||
cp r16, r21
|
|
||||||
brne cproCheckUidInMsg_notMe
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
cproCheckUidInMsg_notMe:
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
CPRO_END:
|
|
||||||
.equ MODULE_SIZE_CPRO = CPRO_END-CPRO_BEGIN
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,46 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Enqueue a DEVICE packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteDevice:
|
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | (12<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
|
|
||||||
ldi r18, CPRO_CMD_DEVICE
|
|
||||||
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
push yh
|
|
||||||
push yl
|
|
||||||
ldi zh, HIGH(devInfoBlock*2) ; 6-17: devInfoBlock
|
|
||||||
ldi zl, LOW(devInfoBlock*2)
|
|
||||||
ldi r18, 12
|
|
||||||
rcall Utils_CopyFromFlash ; (R17, R18, X, Y)
|
|
||||||
pop yl
|
|
||||||
pop yh
|
|
||||||
|
|
||||||
sbiw xh:xl, 20 ; go back to beginning of message (1 byte dst addr, 1 byte length, 14 bytes payload)
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, R20, X)
|
|
||||||
sbiw xh:xl, 21 ; go back to beginning of message (1 byte dst addr, 1 byte length, 14 bytes payload, 1 byte crc)
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,57 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Enqueue a MEMSTATS packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteMemStats:
|
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | COM2_PAYLOAD_FLAGS_SECONDS | (6<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
|
|
||||||
ldi r18, CPRO_CMD_MEMSTATS
|
|
||||||
push xh
|
|
||||||
push xl
|
|
||||||
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
; payload
|
|
||||||
ldi r20, LOW(RAMEND)
|
|
||||||
ldi r21, HIGH(RAMEND)
|
|
||||||
in r17, SPL
|
|
||||||
sub r20, r17
|
|
||||||
st X+, r20 ; stack used
|
|
||||||
in r17, SPH
|
|
||||||
sbc r21, r17
|
|
||||||
st X+, r21
|
|
||||||
lds r17, com2MaxSendBuffersUsed
|
|
||||||
st X+, r17 ; used buffers
|
|
||||||
lds r17, com2MaxRecvBuffersUsed
|
|
||||||
st X+, r17 ; max used buffers
|
|
||||||
lds r17, com2StatsNoBufferError
|
|
||||||
st X+, r17 ; recvNoBuffer
|
|
||||||
lds r17, com2StatsNoBufferError+1
|
|
||||||
st X+, r17
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,33 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Write a PING packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - X : buffer to write to
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WritePing:
|
|
||||||
ldi r18, CPRO_CMD_PING
|
|
||||||
rjmp COM2_WriteMsgWithCmdAndSrcAddr
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,33 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Write a PONG packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - X : buffer to write to
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WritePong:
|
|
||||||
ldi r18, CPRO_CMD_PONG
|
|
||||||
rjmp COM2_WriteMsgWithCmdAndSrcAddr
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,72 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Handle reboot request
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - X : buffer containing the received packet
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS:
|
|
||||||
|
|
||||||
cproHandleReboot:
|
|
||||||
adiw xh:xl, CPRO_PACKET_REBOOTREQ_OFFS_UID
|
|
||||||
rcall cproCheckUidInMsg
|
|
||||||
brcc cproHandleReboot_notHandled
|
|
||||||
sbiw xh:xl, CPRO_PACKET_REBOOTREQ_OFFS_UID+4
|
|
||||||
adiw xh:xl, COM2_MSG_OFFS_SRCADDR
|
|
||||||
ld r16, x
|
|
||||||
cpi r16, 0xff
|
|
||||||
breq cproHandleReboot_notHandled ; dont handle src address 255
|
|
||||||
cproHandleReboot_loop1:
|
|
||||||
push r16
|
|
||||||
ldi xl, LOW(com2SendBuffer)
|
|
||||||
ldi xh, HIGH(com2SendBuffer)
|
|
||||||
rcall CPRO_WriteRebootResponse
|
|
||||||
rcall COM2_SendPacket
|
|
||||||
pop r16
|
|
||||||
brcc cproHandleReboot_loop1
|
|
||||||
|
|
||||||
; directly call bootloader
|
|
||||||
cli
|
|
||||||
rcall systemSetBootSpeed ; reset speed if necessary (TODO: let bootloader set its speed)
|
|
||||||
rjmp BOOTLOADER_ADDR
|
|
||||||
cproHandleReboot_notHandled:
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Write a Reboot Response packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - X : buffer to write to
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteRebootResponse:
|
|
||||||
ldi r18, CPRO_CMD_REBOOT_RESPONSE
|
|
||||||
rjmp COM2_WriteMsgWithCmdAndSrcAddr ; R3, R4, R15, R16, R17, R18, R19, R20, R21, X
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,50 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Write a COM reception stats packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - X : buffer to write to
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteComRecvStats:
|
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | ((com2RecvStatsEnd-com2RecvStatsBegin)<<COM2_PAYLOAD_FLAGS_SHIFT_NUM) ; uid + payload
|
|
||||||
ldi r18, CPRO_CMD_COMRECVSTATS
|
|
||||||
push xh
|
|
||||||
push xl
|
|
||||||
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
push yh
|
|
||||||
push yl
|
|
||||||
ldi yh, HIGH(com2RecvStatsBegin)
|
|
||||||
ldi yl, LOW(com2RecvStatsBegin)
|
|
||||||
ldi r18, com2RecvStatsEnd-com2RecvStatsBegin
|
|
||||||
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
|
|
||||||
pop yl
|
|
||||||
pop yh
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,47 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_WriteResult @global
|
|
||||||
; Write a RESULT message.
|
|
||||||
;
|
|
||||||
; @return nothing
|
|
||||||
; @param R16 destination address
|
|
||||||
; @param R17 result
|
|
||||||
; @param R19:R18 ref msg id
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @clobbers R16 (R17, R18, R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteResult:
|
|
||||||
st X+, r16 ; dest address
|
|
||||||
ldi r16, 5 ; msg code+src address+3 payload bytes
|
|
||||||
st X+, r16 ; msg len
|
|
||||||
ldi r16, CPRO_CMD_RESULT
|
|
||||||
st X+, r16 ; msg code
|
|
||||||
lds r16, com2Address
|
|
||||||
st X+, r16 ; src address
|
|
||||||
st X+, r18 ; ref msg id (low)
|
|
||||||
st X+, r19 ; ref msg id (high)
|
|
||||||
st X+, r17 ; result
|
|
||||||
sbiw xh:xl, 7 ; go back to beginning of message
|
|
||||||
|
|
||||||
; calc and add checksum
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
sbiw xh:xl, 8 ; go back to beginning of message
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
@@ -1,49 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Write a ComSendStats packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - X : buffer to write to
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteComSendStats:
|
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | (6<<COM2_PAYLOAD_FLAGS_SHIFT_NUM) ; UID + 6 bytes payload
|
|
||||||
ldi r18, CPRO_CMD_COMSENDSTATS
|
|
||||||
push xh
|
|
||||||
push xl
|
|
||||||
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
push yh
|
|
||||||
push yl
|
|
||||||
ldi yh, HIGH(com2SendStatsBegin)
|
|
||||||
ldi yl, LOW(com2SendStatsBegin)
|
|
||||||
ldi r18, 6
|
|
||||||
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
|
|
||||||
pop yl
|
|
||||||
pop yh
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,49 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Write a SYSSTATS packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - X : buffer to write to
|
|
||||||
; OUT:
|
|
||||||
; - nothing
|
|
||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteSysStats:
|
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | COM2_PAYLOAD_FLAGS_SECONDS | (4<<COM2_PAYLOAD_FLAGS_SHIFT_NUM)
|
|
||||||
ldi r18, CPRO_CMD_SYSSTATS
|
|
||||||
push xh
|
|
||||||
push xl
|
|
||||||
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
; payload
|
|
||||||
lds r17, com2Interrupts
|
|
||||||
st X+, r17 ; com interrupts
|
|
||||||
lds r17, com2Interrupts+1
|
|
||||||
st X+, r17
|
|
||||||
|
|
||||||
clr r17
|
|
||||||
st X+, r17 ; timer interrupts (not used anymore)
|
|
||||||
st X+, r17
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,67 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; Enqueue a TWI Bus Member packet.
|
|
||||||
;
|
|
||||||
; IN:
|
|
||||||
; - R16: destination address
|
|
||||||
; - R1 : Address of the bus member
|
|
||||||
; - R2 : availability (0=not available, 1=available)
|
|
||||||
; OUT:
|
|
||||||
; - CFLAG: set if okay, clear otherwise
|
|
||||||
; MODIFIED REGS: R16, R17, R20, X (R15, Y)
|
|
||||||
|
|
||||||
CPRO_EnqueueTwiBusMember:
|
|
||||||
push r16
|
|
||||||
rcall COM_AllocBufferAndGetXY ; (r16, r17, r21)
|
|
||||||
pop r16
|
|
||||||
brcc CPRO_EnqueueTwiBusMember_error
|
|
||||||
clr r17 ; r17: XOR byte
|
|
||||||
; write header (dest address, msg length)
|
|
||||||
st X+, r16 ; destination address
|
|
||||||
eor r17, r16
|
|
||||||
ldi r16, 4 ; 4 bytes payload
|
|
||||||
st X+, r16
|
|
||||||
eor r17, r16
|
|
||||||
; write payload
|
|
||||||
ldi r16, CPRO_CMD_TWIBUSMEMBER ; send command
|
|
||||||
st X+, r16
|
|
||||||
eor r17, r16
|
|
||||||
lds r16, comAddress ; send source address
|
|
||||||
st X+, r16
|
|
||||||
eor r17, r16
|
|
||||||
mov r16, r1 ; send i2c bus member address
|
|
||||||
st X+, r16
|
|
||||||
eor r17, r16
|
|
||||||
mov r16, r2 ; send i2c bus member availability
|
|
||||||
st X+, r16
|
|
||||||
eor r17, r16
|
|
||||||
; store XOR byte
|
|
||||||
st X+, r17
|
|
||||||
; mark buffer as enqueued with PRIO "info" (limited amount of retries)
|
|
||||||
ldi r20, COM_BUFFER_PRIO_INFO
|
|
||||||
rcall COM_EnqueuePacket ; (R15, R16)
|
|
||||||
brcc CPRO_EnqueueTwiBusMember_error
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
CPRO_EnqueueTwiBusMember_error:
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,266 +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. *
|
|
||||||
; ***************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
|
||||||
; code
|
|
||||||
|
|
||||||
.cseg
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_ReadValue @global
|
|
||||||
; Read a REPORT_VALUE/SET_VALUE message.
|
|
||||||
;
|
|
||||||
; @param X buffer to read from
|
|
||||||
; @return R17 value id
|
|
||||||
; @return R19:R18 value
|
|
||||||
; @return R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
|
||||||
; @return R22 source address
|
|
||||||
; @return R23 command
|
|
||||||
|
|
||||||
CPRO_ReadValue:
|
|
||||||
adiw xh:xl, 2
|
|
||||||
ld r23, X+ ; command
|
|
||||||
ld r22, X+ ; src address
|
|
||||||
adiw xh:xl, 6 ; skip uid, msg id
|
|
||||||
ld r17, X
|
|
||||||
adiw xh:xl, 2 ; skip value id, value type
|
|
||||||
ld r18, X+
|
|
||||||
ld r19, X+
|
|
||||||
ld r20, X+
|
|
||||||
ld r21, X+
|
|
||||||
sbiw xh:xl, 16 ; back to msg begin
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_WriteReportValue @global
|
|
||||||
; Write a REPORT_VALUE packet.
|
|
||||||
;
|
|
||||||
; @return nothing
|
|
||||||
; @param R16 destination address
|
|
||||||
; @param R17 value id
|
|
||||||
; @param R19:R18 value
|
|
||||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
|
||||||
; @param R22 value type
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @clobbers R16 (R17, R18, R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_WriteReportValue:
|
|
||||||
rcall CPRO_PrepareReportValue ; (R16, R17, R18, R19, R20, R21)
|
|
||||||
|
|
||||||
; set msg id
|
|
||||||
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_MSGID
|
|
||||||
rcall COM2_AddNextMsgIdToBuffer ; (r16, r17, r18)
|
|
||||||
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_MSGID+2 ; go back to begin of msg
|
|
||||||
|
|
||||||
; calc and add checksum
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
sbiw xh:xl, 17 ; go back to beginning of message
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_PrepareReportValue @global
|
|
||||||
; Write a REPORT_VALUE packet (except the checksum byte).
|
|
||||||
;
|
|
||||||
; @return nothing
|
|
||||||
; @param R16 destination address
|
|
||||||
; @param R17 value id
|
|
||||||
; @param R19:R18 value
|
|
||||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100)
|
|
||||||
; @param R22 value type
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @clobbers R16 (R17, R18, R19, R20, R21)
|
|
||||||
|
|
||||||
CPRO_PrepareReportValue:
|
|
||||||
st X+, r16 ; dest address
|
|
||||||
ldi r16, 14 ; msg code+src address+12 payload bytes
|
|
||||||
st X+, r16 ; msg len
|
|
||||||
ldi r16, CPRO_CMD_VALUE_REPORT
|
|
||||||
st X+, r16 ; msg code
|
|
||||||
lds r16, com2Address
|
|
||||||
st X+, r16 ; src address
|
|
||||||
adiw xh:xl, 6 ; skip uid (4 bytes), msg/ref id (2 bytes)
|
|
||||||
st X+, r17 ; value id
|
|
||||||
st X+, r22 ; value type
|
|
||||||
st X+, r18 ; value (low)
|
|
||||||
st X+, r19 ; value (high)
|
|
||||||
st X+, r20 ; denom (low)
|
|
||||||
st X+, r21 ; denom (high)
|
|
||||||
|
|
||||||
sbiw xh:xl, 12 ; go back to UID (12=16 back, 4 forward)
|
|
||||||
rcall COM2_AddUidToBuffer ; (r16, r18, r19, r20, r21)
|
|
||||||
clr r16
|
|
||||||
st X+, r16 ; msg id (low)
|
|
||||||
st X+, r16 ; msg id (high)
|
|
||||||
sbiw xh:xl, 10 ; go back to beginning of message
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_WriteSetValueResponse @global
|
|
||||||
; Write response to a SET_VALUE request.
|
|
||||||
;
|
|
||||||
; @return nothing
|
|
||||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @param Y buffer with received setValueRequest message
|
|
||||||
; @clobbers R16, R17, R18, R19, (Y)
|
|
||||||
|
|
||||||
CPRO_WriteSetValueResponse:
|
|
||||||
rcall cproInvertValueMsg ; (R16, R17, R18, R19, Y)
|
|
||||||
|
|
||||||
; add checksum byte
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
sbiw xh:xl, 16 ; go back to beginning of message
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_WriteGetValueResponse @global
|
|
||||||
; Write response to a SET_VALUE request.
|
|
||||||
;
|
|
||||||
; @return nothing
|
|
||||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
|
||||||
; @param R19:R18 value
|
|
||||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100, 0=don't change)
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @param Y buffer with received setValueRequest message
|
|
||||||
; @clobbers R16, R17, R18, R19, (R20, R21, Y)
|
|
||||||
|
|
||||||
CPRO_WriteGetValueResponse:
|
|
||||||
push r18
|
|
||||||
push r19
|
|
||||||
rcall cproInvertValueMsg ; (R16, R17, R18, R19, Y)
|
|
||||||
pop r19
|
|
||||||
pop r18
|
|
||||||
|
|
||||||
; replace values
|
|
||||||
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE
|
|
||||||
st X+, r18 ; value (low)
|
|
||||||
st X+, r19 ; value (high)
|
|
||||||
st X+, r20 ; denom (low)
|
|
||||||
st X+, r21 ; denom (high)
|
|
||||||
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_VALUE+4
|
|
||||||
|
|
||||||
; add checksum byte
|
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
|
||||||
sbiw xh:xl, 13 ; go back to beginning of message
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine cproInvertValueMsg
|
|
||||||
; Write response to a SET_VALUE request.
|
|
||||||
;
|
|
||||||
; @return nothing
|
|
||||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @param Y buffer with received setValueRequest message
|
|
||||||
; @clobbers R16, R17, R18, R19, (Y)
|
|
||||||
|
|
||||||
cproInvertValueMsg:
|
|
||||||
; copy received message into new message
|
|
||||||
mov r19, r16
|
|
||||||
ldi r18, 16 ; message size without checksum byte
|
|
||||||
rcall Utils_Copy_SDRAM ; (R17, R18, X, Y)
|
|
||||||
sbiw xh:xl, 16 ; go back to beginning of message
|
|
||||||
|
|
||||||
; exchange src and dest address
|
|
||||||
adiw xh:xl, 3 ; src address
|
|
||||||
ld r16, X
|
|
||||||
lds r17, com2Address
|
|
||||||
st X, r17 ; set our src address
|
|
||||||
sbiw xh:xl, 3
|
|
||||||
st X, r16 ; set old src address as destination address
|
|
||||||
|
|
||||||
; replace msg code
|
|
||||||
adiw xh:xl, 2 ; msg code
|
|
||||||
st X, r19
|
|
||||||
sbiw xh:xl, 2
|
|
||||||
|
|
||||||
; replace UID
|
|
||||||
adiw xh:xl, CPRO_PACKET_VALUE_OFFS_UID
|
|
||||||
rcall COM2_AddUidToBuffer ; (r16, r18, r19, r20, r21)
|
|
||||||
sbiw xh:xl, CPRO_PACKET_VALUE_OFFS_UID+4 ; go back to beginning of message
|
|
||||||
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_SendSetValueResponse @global
|
|
||||||
; Write response to a SET_VALUE request.
|
|
||||||
;
|
|
||||||
; @return CFLAG set if okay, cleared on error
|
|
||||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @param Y buffer with received setValueRequest message
|
|
||||||
; @clobbers Y, (R16, R17, R18, R19, R22)
|
|
||||||
|
|
||||||
CPRO_SendSetValueResponse:
|
|
||||||
push xh
|
|
||||||
push xl
|
|
||||||
mov yh, xh
|
|
||||||
mov yl, xl
|
|
||||||
ldi xl, LOW(com2SendBuffer)
|
|
||||||
ldi xh, HIGH(com2SendBuffer)
|
|
||||||
rcall CPRO_WriteSetValueResponse ; (R16, R17, R18, R19, Y)
|
|
||||||
rcall COM2_SendPacket ; (r18, r19, r22, X)
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
|
||||||
; @routine CPRO_SendGetValueResponse @global
|
|
||||||
; Write response to a GET_VALUE request.
|
|
||||||
;
|
|
||||||
; @return CFLAG set if okay, cleared on error
|
|
||||||
; @param R16 message code (CPRO_CMD_VALUE_SET_ACK or CPRO_CMD_VALUE_SET_NACK)
|
|
||||||
; @param R19:R18 value
|
|
||||||
; @param R21:R20 denom (e.g. 100, meaning value must be divided by 100, 0=don't change)
|
|
||||||
; @param X buffer to write to
|
|
||||||
; @param Y buffer with received getValueRequest message
|
|
||||||
; @clobbers Y, (R16, R17, R18, R19, R22)
|
|
||||||
|
|
||||||
CPRO_SendGetValueResponse:
|
|
||||||
push xh
|
|
||||||
push xl
|
|
||||||
mov yh, xh
|
|
||||||
mov yl, xl
|
|
||||||
ldi xl, LOW(com2SendBuffer)
|
|
||||||
ldi xh, HIGH(com2SendBuffer)
|
|
||||||
rcall CPRO_WriteGetValueResponse ; (R16, R17, R18, R19, Y)
|
|
||||||
rcall COM2_SendPacket ; (r18, r19, r22, X)
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
ret
|
|
||||||
; @end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,101 +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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CPRO_Screen:
|
|
||||||
in r15, SREG ; debug
|
|
||||||
push r15
|
|
||||||
cli
|
|
||||||
|
|
||||||
ldi r16, 0
|
|
||||||
rcall LCD_Fill
|
|
||||||
|
|
||||||
ldi r18, 0
|
|
||||||
ldi r19, 0
|
|
||||||
rcall LCD_SetCursor
|
|
||||||
ldi zl, LOW(cproScreenText_title)
|
|
||||||
ldi zh, HIGH(cproScreenText_title)
|
|
||||||
rcall LCD_PrintFromFlash
|
|
||||||
|
|
||||||
ldi r18, 0
|
|
||||||
ldi r19, 2
|
|
||||||
rcall LCD_SetCursor
|
|
||||||
ldi zl, LOW(cproScreenText_uid)
|
|
||||||
ldi zh, HIGH(cproScreenText_uid)
|
|
||||||
rcall LCD_PrintFromFlash
|
|
||||||
push xh ; 1-4: UID
|
|
||||||
push xl
|
|
||||||
rcall Utils_ReadUid ; (R16, X)
|
|
||||||
pop xl
|
|
||||||
pop xh
|
|
||||||
push r18
|
|
||||||
push r19
|
|
||||||
mov r18, r20
|
|
||||||
mov r19, r21
|
|
||||||
rcall LCD_PrintHexWord
|
|
||||||
pop r19
|
|
||||||
pop r18
|
|
||||||
rcall LCD_PrintHexWord
|
|
||||||
|
|
||||||
ldi r18, 0
|
|
||||||
ldi r19, 3
|
|
||||||
rcall LCD_SetCursor
|
|
||||||
ldi zl, LOW(cproScreenText_addr)
|
|
||||||
ldi zh, HIGH(cproScreenText_addr)
|
|
||||||
rcall LCD_PrintFromFlash
|
|
||||||
lds r16, com2Address
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
ldi r16, 32
|
|
||||||
rcall LCD_PrintChar
|
|
||||||
lds r16, cproMode
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
ldi r16, 32
|
|
||||||
rcall LCD_PrintChar
|
|
||||||
lds r16, cproAddrRangeBegin
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
|
|
||||||
ldi r18, 0
|
|
||||||
ldi r19, 4
|
|
||||||
rcall LCD_SetCursor
|
|
||||||
ldi zl, LOW(cproScreenText_bitmap)
|
|
||||||
ldi zh, HIGH(cproScreenText_bitmap)
|
|
||||||
rcall LCD_PrintFromFlash
|
|
||||||
lds r16, cproUsedAddresses
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
lds r16, cproUsedAddresses+1
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
lds r16, cproUsedAddresses+2
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
lds r16, cproUsedAddresses+3
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
|
|
||||||
pop r15
|
|
||||||
out SREG, r15
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
cproScreenText_title: .db "CPRO Screen", 0
|
|
||||||
cproScreenText_uid: .db "UID : ", 0
|
|
||||||
cproScreenText_addr: .db "Address: ", 0
|
|
||||||
cproScreenText_bitmap: .db "BITMAP : ", 0
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<gwbuild>
|
|
||||||
|
|
||||||
<extradist>
|
|
||||||
main.asm
|
|
||||||
</extradist>
|
|
||||||
|
|
||||||
</gwbuild>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<gwbuild>
|
|
||||||
|
|
||||||
<extradist>
|
|
||||||
main.asm
|
|
||||||
</extradist>
|
|
||||||
|
|
||||||
</gwbuild>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<gwbuild>
|
|
||||||
|
|
||||||
<extradist>
|
|
||||||
main.asm
|
|
||||||
</extradist>
|
|
||||||
|
|
||||||
</gwbuild>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<?xml?>
|
|
||||||
|
|
||||||
<gwbuild>
|
|
||||||
|
|
||||||
<extradist>
|
|
||||||
main.asm
|
|
||||||
</extradist>
|
|
||||||
|
|
||||||
</gwbuild>
|
|
||||||
|
|
||||||
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user