avr: added code and messages for device information.

- send firmware information in DEVICE message
- introduced new version of VALUE message (sending UID now instead of
  timestamp)
- make SENDSTATS and RECVSTATS messages also send UID instead of timestamp
This commit is contained in:
Martin Preuss
2023-03-19 23:20:16 +01:00
parent 9b7e72c3ad
commit 0db8a14972
4 changed files with 137 additions and 9 deletions

View File

@@ -40,16 +40,18 @@
; ---------------------------------------------------------------------------
; list of modules to use
; firmware settings including list of modules used
#define FW_TYPE AQHOME_FW_TYPE_ATT84_TEMP1
#define FW_MAIN_VERSION_HIGH 0
#define FW_MAIN_VERSION_LOW 1
#define MODULES_TIMER
#define MODULES_COM
#define MODULES_LED
#define MODULES_TWI_MASTER
#define MODULES_LCD
;#define MODULES_LCD
#define MODULES_SI7021
.set MODULES_MASK = 0
@@ -242,8 +244,6 @@ ledA3Flash: .db DDRA+0x20, PORTA+0x20, PINA+0x20, (1<<PORTA3)
blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 2s pause, restart
;blinkPattern2: .db 10, 20, 0xff, 0xff ; 1 long blink, 2s pause, restart
firmwareHeader: .db FW_MAIN_VERSION_HIGH, FW_MAIN_VERSION_LOW
.dw MODULES_MASK
.include "main.asm"
@@ -292,7 +292,9 @@ onEverySecond:
; Called every 10 seconds. Add your routine calls here. No arguments, no results.
onEvery10s:
#ifdef MODULES_LCD
rcall printSendStats
#endif
ret
@@ -322,15 +324,22 @@ onEveryMinute:
lds r16, comAddress ; do we have an address assigned?
tst r16
breq onEveryMinute_l1 ; no, do nothing
; will later send this only every hour or so
ldi r16, 0xff ; send stats to everybody
rcall CPRO_EnqueueComSendStats
ldi r16, 0xff ; send recv to everybody
rcall CPRO_EnqueueComRecvStats
ldi r16, 0xff ; send device info to everybody
rcall CPRO_EnqueueDevice
onEveryMinute_l1:
#endif
ret
; ---------------------------------------------------------------------------
; Called every 15 minutes. Add your routine calls here. No arguments, no results.

View File

@@ -11,7 +11,7 @@
.equ CPRO_CMD_COMRECVSTATS = 21
.equ CPRO_CMD_TWIBUSMEMBER = 30
.equ CPRO_CMD_DEBUG = 40
.equ CPRO_CMD_VALUE = 50
.equ CPRO_CMD_VALUE = 51 ; was 50 when sending timestamp instead of uid
.equ CPRO_CMD_NEED_ADDRESS = 60
.equ CPRO_CMD_HAVE_ADDRESS = 61
.equ CPRO_CMD_CLAIM_ADDRESS = 62
@@ -24,6 +24,8 @@
.equ CPRO_CMD_FLASH_DATA = 73
.equ CPRO_CMD_FLASH_RSP = 74
.equ CPRO_CMD_DEVICE = 80
; flags for variable payload enqueue function
.equ CPRO_PAYLOAD_FLAGS_SECONDS = 0x01
@@ -250,7 +252,7 @@ CPRO_EnqueueComSendStats:
pop r16
brcc CPRO_EnqueueComSendStats_error
ldi r17, CPRO_PAYLOAD_FLAGS_SECONDS | (6<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM) ; seconds + 6 bytes payload
ldi r17, CPRO_PAYLOAD_FLAGS_UID | (6<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM) ; seconds + 6 bytes payload
ldi r18, CPRO_CMD_COMSENDSTATS
push xh
push xl
@@ -290,6 +292,64 @@ CPRO_EnqueueComSendStats_error:
#ifndef BASE_SYSTEM
; ---------------------------------------------------------------------------
; Enqueue a COM reception stats packet.
;
; IN:
; - R16: destination address
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGS: R16, R17, R20, X (R15, Y)
CPRO_EnqueueComRecvStats:
push r15
in r15, SREG
cli
push r16
rcall COM_AllocBufferAndGetXY ; (r16, r17, r21)
pop r16
brcc CPRO_EnqueueComRecvStats_error
ldi r17, CPRO_PAYLOAD_FLAGS_UID | (6<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM) ; seconds + 6 bytes payload
ldi r18, CPRO_CMD_COMRECVSTATS
push xh
push xl
rcall cproBeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
lds r16, comStatsPacketsIn ; 6: packets in
st X+, r16
lds r16, comStatsPacketsIn+1
st X+, r16
lds r16, comStatsRecvErrs ; 8: errors
st X+, r16
lds r16, comStatsRecvErrs+1
st X+, r16
lds r16, comStatsHandled ; 10: ignored
st X+, r16
lds r16, comStatsHandled+1
st X+, r16
pop xl
pop xh
rcall cproCalcAndAddChecksumByte
; mark buffer as enqueued with PRIO "important" (higher retry count)
ldi r20, COM_BUFFER_PRIO_IMPORTANT
rcall COM_EnqueuePacket ; (R15, R16)
brcc CPRO_EnqueueComRecvStats_error
pop r15
out SREG, r15
sec
ret
CPRO_EnqueueComRecvStats_error:
pop r15
out SREG, r15
clc
ret
#endif
#ifdef WITH_DEBUG
# ifndef BASE_SYSTEM
; ---------------------------------------------------------------------------
; Enqueue a TWI Bus Member packet.
;
; IN:
@@ -336,11 +396,13 @@ CPRO_EnqueueTwiBusMember:
CPRO_EnqueueTwiBusMember_error:
clc
ret
# endif
#endif
#ifndef BASE_SYSTEM
#ifdef WITH_DEBUG
# ifndef BASE_SYSTEM
; ---------------------------------------------------------------------------
; Enqueue a DEBUG packet.
;
@@ -388,9 +450,58 @@ CPRO_EnqueueDebug:
CPRO_EnqueueDebug_error:
clc
ret
# endif
#endif
; ---------------------------------------------------------------------------
; Enqueue a DEVICE packet.
;
; IN:
; - R16: destination address
; OUT:
; - CFLAG: set if okay, clear otherwise
; MODIFIED REGS: R6, R16, R17, R18, R20 (R3, R4, R15, R19, R21, X)
CPRO_EnqueueDevice:
mov r6, r16
rcall COM_AllocBufferAndGetXY ; (r16, r17, r21)
brcc CPRO_EnqueueDevice_error
push xh
push xl
mov r16, r6
ldi r17, CPRO_PAYLOAD_FLAGS_UID | (6<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM)
ldi r18, CPRO_CMD_DEVICE
rcall cproBeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
ldi r17, LOW(FW_TYPE)
st X+, r17 ; 6: firmware type low
ldi r17, HIGH(FW_TYPE)
st X+, r17 ; 7: firmware type high
ldi r17, FW_MAIN_VERSION_LOW
st X+, r17 ; 8: version low
ldi r17, FW_MAIN_VERSION_HIGH
st X+, r17 ; 9: version high
ldi r17, LOW(MODULES_MASK)
st X+, r17 ; 10: modules mask low
ldi r17, HIGH(MODULES_MASK)
st X+, r17 ; 11: modules mask low
pop xl
pop xh
rcall cproCalcAndAddChecksumByte
; mark buffer as enqueued with PRIO "normal" (slightly limited number of retries)
ldi r20, COM_BUFFER_PRIO_NORMAL
rcall COM_EnqueuePacket ; (R15, R16)
brcc CPRO_EnqueueValue_error
sec
ret
CPRO_EnqueueDevice_error:
clc
ret
#ifndef BASE_SYSTEM
; ---------------------------------------------------------------------------
@@ -421,7 +532,7 @@ CPRO_EnqueueValue:
push xh
push xl
mov r16, r6
ldi r17, CPRO_PAYLOAD_FLAGS_SECONDS | (6<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM)
ldi r17, CPRO_PAYLOAD_FLAGS_UID | (6<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM)
ldi r18, CPRO_CMD_VALUE
rcall cproBeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
st X+, r7 ; 6: value id

View File

@@ -13,3 +13,6 @@
.equ AQHOME_FW_MODULE_LCD = 5
.equ AQHOME_FW_MODULE_SI7021 = 6
.equ AQHOME_FW_TYPE_ATT84_TEMP1 = 1

View File

@@ -366,6 +366,8 @@ twiReceiveByteSendAck_error:
#ifdef WITH_DEBUG
TWI_Master_ScanNext:
in r15, SREG
cli
@@ -418,5 +420,8 @@ TWI_Master_ScanNext_finshed:
TWI_Master_ScanNext_end:
out SREG, r15
ret
#endif