avr: new com2 and timer stack basically works again.
This commit is contained in:
@@ -92,6 +92,8 @@ void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch
|
|||||||
GWEN_Buffer_AppendString(dbuf, " LCD");
|
GWEN_Buffer_AppendString(dbuf, " LCD");
|
||||||
if (modules & AQH_MSG_DEVICE_MASK_SI7021)
|
if (modules & AQH_MSG_DEVICE_MASK_SI7021)
|
||||||
GWEN_Buffer_AppendString(dbuf, " SI7021");
|
GWEN_Buffer_AppendString(dbuf, " SI7021");
|
||||||
|
if (modules & AQH_MSG_DEVICE_MASK_STATS)
|
||||||
|
GWEN_Buffer_AppendString(dbuf, " STATS");
|
||||||
GWEN_Buffer_AppendString(dbuf, " ]");
|
GWEN_Buffer_AppendString(dbuf, " ]");
|
||||||
}
|
}
|
||||||
GWEN_Buffer_AppendString(dbuf, ")\n");
|
GWEN_Buffer_AppendString(dbuf, ")\n");
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#define AQH_MSG_DEVICE_MASK_TWIMASTER 0x10
|
#define AQH_MSG_DEVICE_MASK_TWIMASTER 0x10
|
||||||
#define AQH_MSG_DEVICE_MASK_LCD 0x20
|
#define AQH_MSG_DEVICE_MASK_LCD 0x20
|
||||||
#define AQH_MSG_DEVICE_MASK_SI7021 0x40
|
#define AQH_MSG_DEVICE_MASK_SI7021 0x40
|
||||||
|
#define AQH_MSG_DEVICE_MASK_STATS 0x80
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,10 @@
|
|||||||
|
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_SECONDS 0 /* 4 bytes */
|
#define AQH_MSG_OFFS_MEMSTATS_SECONDS 0 /* 4 bytes */
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_UID 4 /* 4 bytes */
|
#define AQH_MSG_OFFS_MEMSTATS_UID 4 /* 4 bytes */
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_STACKPTR 8 /* 2 bytes */
|
#define AQH_MSG_OFFS_MEMSTATS_STACKUSAGE 8 /* 2 bytes */
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED 10 /* 1 byte */
|
#define AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED 10 /* 1 byte */
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED 11 /* 1 byte */
|
#define AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED 11 /* 1 byte */
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_SENDNOBUFFER 12 /* 2 bytes */
|
#define AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER 12 /* 2 bytes */
|
||||||
#define AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER 14 /* 2 bytes */
|
|
||||||
|
|
||||||
#define AQH_MSG_MEMSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER+2)
|
#define AQH_MSG_MEMSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER+2)
|
||||||
|
|
||||||
@@ -44,9 +43,9 @@ uint32_t AQH_MemStatsMsg_GetSeconds(const GWEN_MSG *msg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t AQH_MemStatsMsg_GetStackPtr(const GWEN_MSG *msg)
|
uint16_t AQH_MemStatsMsg_GetStackUsage(const GWEN_MSG *msg)
|
||||||
{
|
{
|
||||||
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_STACKPTR, 0);
|
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_STACKUSAGE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -65,13 +64,6 @@ uint8_t AQH_MemStatsMsg_GetMaxBuffersUsed(const GWEN_MSG *msg)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t AQH_MemStatsMsg_GetSendNoBufferErrors(const GWEN_MSG *msg)
|
|
||||||
{
|
|
||||||
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_SENDNOBUFFER, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint16_t AQH_MemStatsMsg_GetRecvNoBufferErrors(const GWEN_MSG *msg)
|
uint16_t AQH_MemStatsMsg_GetRecvNoBufferErrors(const GWEN_MSG *msg)
|
||||||
{
|
{
|
||||||
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER, 0);
|
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER, 0);
|
||||||
@@ -82,17 +74,15 @@ uint16_t AQH_MemStatsMsg_GetRecvNoBufferErrors(const GWEN_MSG *msg)
|
|||||||
void AQH_MemStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
void AQH_MemStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||||
{
|
{
|
||||||
GWEN_Buffer_AppendArgs(dbuf,
|
GWEN_Buffer_AppendArgs(dbuf,
|
||||||
"0x%02x->0x%02x: MEMSTATS %s (uid=0x%08x, uptime=%d, stackptr=%d[%04x], buffers used=%d(max=%d), no sendbuf errs=%d, no recvbuf=%d)\n",
|
"0x%02x->0x%02x: MEMSTATS %s (uid=0x%08x, uptime=%d, stack used=%d, buffers used=%d(max=%d), no recvbuf=%d)\n",
|
||||||
AQH_NodeMsg_GetSourceAddress(msg),
|
AQH_NodeMsg_GetSourceAddress(msg),
|
||||||
AQH_NodeMsg_GetDestAddress(msg),
|
AQH_NodeMsg_GetDestAddress(msg),
|
||||||
sText,
|
sText,
|
||||||
(unsigned int) AQH_MemStatsMsg_GetUid(msg),
|
(unsigned int) AQH_MemStatsMsg_GetUid(msg),
|
||||||
AQH_MemStatsMsg_GetSeconds(msg),
|
AQH_MemStatsMsg_GetSeconds(msg),
|
||||||
AQH_MemStatsMsg_GetStackPtr(msg),
|
AQH_MemStatsMsg_GetStackUsage(msg),
|
||||||
AQH_MemStatsMsg_GetStackPtr(msg),
|
|
||||||
AQH_MemStatsMsg_GetBuffersUsed(msg),
|
AQH_MemStatsMsg_GetBuffersUsed(msg),
|
||||||
AQH_MemStatsMsg_GetMaxBuffersUsed(msg),
|
AQH_MemStatsMsg_GetMaxBuffersUsed(msg),
|
||||||
AQH_MemStatsMsg_GetSendNoBufferErrors(msg),
|
|
||||||
AQH_MemStatsMsg_GetRecvNoBufferErrors(msg));
|
AQH_MemStatsMsg_GetRecvNoBufferErrors(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
AQHOME_API uint32_t AQH_MemStatsMsg_GetUid(const GWEN_MSG *msg);
|
AQHOME_API uint32_t AQH_MemStatsMsg_GetUid(const GWEN_MSG *msg);
|
||||||
AQHOME_API uint32_t AQH_MemStatsMsg_GetSeconds(const GWEN_MSG *msg);
|
AQHOME_API uint32_t AQH_MemStatsMsg_GetSeconds(const GWEN_MSG *msg);
|
||||||
AQHOME_API uint16_t AQH_MemStatsMsg_GetStackPtr(const GWEN_MSG *msg);
|
AQHOME_API uint16_t AQH_MemStatsMsg_GetStackUsage(const GWEN_MSG *msg);
|
||||||
AQHOME_API uint8_t AQH_MemStatsMsg_GetBuffersUsed(const GWEN_MSG *msg);
|
AQHOME_API uint8_t AQH_MemStatsMsg_GetBuffersUsed(const GWEN_MSG *msg);
|
||||||
AQHOME_API uint8_t AQH_MemStatsMsg_GetMaxBuffersUsed(const GWEN_MSG *msg);
|
AQHOME_API uint8_t AQH_MemStatsMsg_GetMaxBuffersUsed(const GWEN_MSG *msg);
|
||||||
AQHOME_API uint16_t AQH_MemStatsMsg_GetSendNoBufferErrors(const GWEN_MSG *msg);
|
AQHOME_API uint16_t AQH_MemStatsMsg_GetSendNoBufferErrors(const GWEN_MSG *msg);
|
||||||
|
|||||||
@@ -216,6 +216,8 @@ Offset Length Meaning
|
|||||||
10 2 content errors (invalid msg length, CRC errors)
|
10 2 content errors (invalid msg length, CRC errors)
|
||||||
12 2 io errors
|
12 2 io errors
|
||||||
14 2 no buffer errors
|
14 2 no buffer errors
|
||||||
|
16 2 handled packets
|
||||||
|
18 2 missed packets
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,12 +61,12 @@
|
|||||||
|
|
||||||
#define MODULES_TIMER
|
#define MODULES_TIMER
|
||||||
#define MODULES_COM
|
#define MODULES_COM
|
||||||
;#define MODULES_COM_WITH_ADDR_PROTO
|
#define MODULES_COM_WITH_ADDR_PROTO
|
||||||
#define MODULES_LED
|
#define MODULES_LED
|
||||||
#define MODULES_TWI_MASTER
|
#define MODULES_TWI_MASTER
|
||||||
#define MODULES_LCD
|
#define MODULES_LCD
|
||||||
#define MODULES_SI7021
|
#define MODULES_SI7021
|
||||||
|
#define MODULES_STATS
|
||||||
|
|
||||||
|
|
||||||
.set MODULES_MASK = 0
|
.set MODULES_MASK = 0
|
||||||
@@ -88,7 +88,9 @@
|
|||||||
#ifdef MODULES_SI7021
|
#ifdef MODULES_SI7021
|
||||||
.set MODULES_MASK = MODULES_MASK | (1<<AQHOME_FW_MODULE_SI7021)
|
.set MODULES_MASK = MODULES_MASK | (1<<AQHOME_FW_MODULE_SI7021)
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
.set MODULES_MASK = MODULES_MASK | (1<<AQHOME_FW_MODULE_STATS)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
@@ -227,11 +229,14 @@
|
|||||||
.include "comproto.asm"
|
.include "comproto.asm"
|
||||||
.include "comproto_addr.asm"
|
.include "comproto_addr.asm"
|
||||||
.include "comproto_recvstats.asm"
|
.include "comproto_recvstats.asm"
|
||||||
|
.include "comproto_sysstats.asm"
|
||||||
|
.include "comproto_memstats.asm"
|
||||||
.include "comproto_pong.asm"
|
.include "comproto_pong.asm"
|
||||||
;.include "comproto_values.asm"
|
;.include "comproto_values.asm"
|
||||||
.include "twimaster.asm"
|
.include "twimaster.asm"
|
||||||
.include "lcd.asm"
|
.include "lcd.asm"
|
||||||
.include "si7021.asm"
|
.include "si7021.asm"
|
||||||
|
.include "stats.asm"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -242,12 +247,14 @@
|
|||||||
|
|
||||||
|
|
||||||
sramTimerProtocolEverySec: .byte 2
|
sramTimerProtocolEverySec: .byte 2
|
||||||
sramTimerEnqueueComStats: .byte 2
|
sramTimerWriteStats: .byte 2
|
||||||
sramTimerEnqueueMemStats: .byte 2
|
sramTimerEnqueueMemStats: .byte 2
|
||||||
sramTimerEnqueueSysStats: .byte 2
|
sramTimerEnqueueSysStats: .byte 2
|
||||||
sramTimerEnqueueValues: .byte 2
|
sramTimerEnqueueValues: .byte 2
|
||||||
sramTimerSI7021Measure: .byte 2
|
sramTimerSI7021Measure: .byte 2
|
||||||
sramPeriodicalLcdMark: .byte 2
|
#ifdef MODULES_LCD
|
||||||
|
sramPeriodicalLcdMark: .byte 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
@@ -269,10 +276,15 @@ blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 2s pause, restart
|
|||||||
timerList:
|
timerList:
|
||||||
; SRAM variable/counter routine flags secs (0=don't start or restart)
|
; SRAM variable/counter routine flags secs (0=don't start or restart)
|
||||||
#ifdef MODULES_COM_WITH_ADDR_PROTO
|
#ifdef MODULES_COM_WITH_ADDR_PROTO
|
||||||
; .dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
.dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
|
||||||
#endif
|
#endif
|
||||||
.dw sramTimerEnqueueComStats, enqueueComStats, TIMER_FLAGS_IF_ADDR, 10 ; every 30s
|
#ifdef MODULES_STATS
|
||||||
|
.dw statsSendTimer, Stats_Timer, TIMER_FLAGS_IF_ADDR, 30 ; every 30s
|
||||||
|
#endif
|
||||||
|
#ifdef MODULES_LCD
|
||||||
.dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 1 ; every sec
|
.dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 1 ; every sec
|
||||||
|
.dw sramTimerWriteStats, writeStats, 0, 10
|
||||||
|
#endif
|
||||||
; .dw sramTimerSI7021Measure, SI7021_PeriodicMeasurement, 0, 30 ; every 30s
|
; .dw sramTimerSI7021Measure, SI7021_PeriodicMeasurement, 0, 30 ; every 30s
|
||||||
; .dw sramTimerEnqueueValues, Main_SendValueMsg, TIMER_FLAGS_IF_ADDR, 60 ; every 1m
|
; .dw sramTimerEnqueueValues, Main_SendValueMsg, TIMER_FLAGS_IF_ADDR, 60 ; every 1m
|
||||||
.dw 0 ; end of list
|
.dw 0 ; end of list
|
||||||
@@ -306,34 +318,18 @@ onSystemStart:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MODULES_LCD
|
||||||
periodicalLcdMark:
|
periodicalLcdMark:
|
||||||
rcall printTimerMark
|
rcall printTimerMark
|
||||||
ret
|
ret
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
enqueueComStats:
|
|
||||||
|
writeStats:
|
||||||
|
sbi PINA, PORTA2 ; debug (toggle)
|
||||||
rcall printSendStats
|
rcall printSendStats
|
||||||
ldi r16, 0xff ; send to everybody
|
ret
|
||||||
ldi xl, LOW(com2SendBuffer)
|
|
||||||
ldi xh, HIGH(com2SendBuffer)
|
|
||||||
rcall CPRO_WriteComRecvStats
|
|
||||||
rjmp COM2_SendPacket
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
;enqueueMemStats:
|
|
||||||
; ldi r16, 0xff ; send to everybody
|
|
||||||
; rcall CPRO_EnqueueMemStats
|
|
||||||
|
|
||||||
; ldi r16, 0xff ; send to everybody
|
|
||||||
; rjmp CPRO_EnqueueDevice
|
|
||||||
|
|
||||||
|
|
||||||
;enqueueSysStats:
|
|
||||||
; ldi r16, 0xff ; send to everybody
|
|
||||||
; rjmp CPRO_EnqueueSysStats
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -369,7 +365,6 @@ onEvery100ms:
|
|||||||
|
|
||||||
onPacketReceived:
|
onPacketReceived:
|
||||||
; rcall CPRO_OnPacketReceived
|
; rcall CPRO_OnPacketReceived
|
||||||
sbi PINA, PORTA2 ; debug (toggle)
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|||||||
282
avr/com2.asm
282
avr/com2.asm
@@ -12,7 +12,8 @@
|
|||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
; defines
|
; defines
|
||||||
|
|
||||||
.equ COM2_BUFFER_SIZE = 24
|
.equ COM2_BUFFER_SIZE = 24 ; CAVE: must change code in COM2_BufferPosToX when changing this!
|
||||||
|
.equ COM2_BUFFER_NUM = 4
|
||||||
|
|
||||||
.equ COM2_MAXWAIT_US = 100 ; maximum wait time in microseconds when waiting for rising/falling clock
|
.equ COM2_MAXWAIT_US = 100 ; maximum wait time in microseconds when waiting for rising/falling clock
|
||||||
.equ COM2_MAINTENANCE_ADDR = 0xc1
|
.equ COM2_MAINTENANCE_ADDR = 0xc1
|
||||||
@@ -53,16 +54,25 @@ com2DataBegin:
|
|||||||
com2Interrupts: .byte 2
|
com2Interrupts: .byte 2
|
||||||
|
|
||||||
com2StatsPacketsIn: .byte 2
|
com2StatsPacketsIn: .byte 2
|
||||||
com2StatsPacketsOut: .byte 2
|
|
||||||
|
|
||||||
com2StatsIoError: .byte 2
|
com2StatsIoError: .byte 2
|
||||||
com2StatsContentError: .byte 2
|
com2StatsContentError: .byte 2
|
||||||
com2StatsNoBufferError: .byte 2
|
com2StatsNoBufferError: .byte 2
|
||||||
|
com2StatsIgnored: .byte 2
|
||||||
|
com2StatsHandled: .byte 2
|
||||||
|
com2StatsMissed: .byte 2 ; currently not used
|
||||||
|
|
||||||
|
com2StatsPacketsOut: .byte 2
|
||||||
com2StatsBusyError: .byte 2
|
com2StatsBusyError: .byte 2
|
||||||
com2StatsCollisions: .byte 2
|
com2StatsCollisions: .byte 2
|
||||||
|
|
||||||
|
|
||||||
com2RecvBuffer: .byte COM2_BUFFER_SIZE
|
com2RecvBuffersUsed: .byte 1
|
||||||
|
com2MaxBuffersUsed: .byte 1
|
||||||
|
com2RecvBuffersWritePos: .byte 1
|
||||||
|
com2RecvBuffersReadPos: .byte 1
|
||||||
|
|
||||||
|
com2RecvBuffers: .byte COM2_BUFFER_SIZE*COM2_BUFFER_NUM
|
||||||
com2SendBuffer: .byte COM2_BUFFER_SIZE
|
com2SendBuffer: .byte COM2_BUFFER_SIZE
|
||||||
com2DataEnd:
|
com2DataEnd:
|
||||||
|
|
||||||
@@ -134,19 +144,32 @@ Com2_Init:
|
|||||||
; REGS: (R1, R3, R16, R17, R18, R19, R22, X)
|
; REGS: (R1, R3, R16, R17, R18, R19, R22, X)
|
||||||
|
|
||||||
COM2_Run:
|
COM2_Run:
|
||||||
lds r16, com2RecvBuffer
|
rjmp com2HandleNextPacketInQueue
|
||||||
tst r16
|
|
||||||
brne COM2_Run_packetReceived
|
|
||||||
clc
|
|
||||||
ret
|
|
||||||
|
|
||||||
COM2_Run_packetReceived:
|
|
||||||
ldi xl, LOW(com2RecvBuffer)
|
|
||||||
ldi xh, HIGH(com2RecvBuffer)
|
com2HandleNextPacketInQueue:
|
||||||
|
lds r16, com2RecvBuffersUsed
|
||||||
|
tst r16
|
||||||
|
breq com2HandleNextPacketInQueue_retNc ; no buffers in use
|
||||||
|
|
||||||
|
lds r16, com2RecvBuffersReadPos
|
||||||
|
rcall COM2_BufferPosToX ; get current read buffer to X (R16, R17)
|
||||||
rcall onPacketReceived
|
rcall onPacketReceived
|
||||||
clr r16
|
brcs com2HandleNextPacketInQueue_handled
|
||||||
sts com2RecvBuffer, r16 ; unlock buffer
|
ldi xl, LOW(com2StatsIgnored)
|
||||||
sec
|
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 COM2_BufferDeallocFront ; (r16, r17, r21)
|
||||||
|
sec ; always return with set CFLAG
|
||||||
|
ret
|
||||||
|
com2HandleNextPacketInQueue_retNc:
|
||||||
|
clc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
@@ -286,13 +309,9 @@ com2CalcPayloadSize_l2:
|
|||||||
; REGS: r16, r17, x (r18, r19, r20, r21, r22)
|
; REGS: r16, r17, x (r18, r19, r20, r21, r22)
|
||||||
|
|
||||||
com2ReceivePacket:
|
com2ReceivePacket:
|
||||||
ldi xl, LOW(com2RecvBuffer)
|
rcall COM2_BufferAlloc ; (r16, r17, r21)
|
||||||
ldi xh, HIGH(com2RecvBuffer)
|
brcs com2ReceivePacket_bufferAvailable
|
||||||
|
|
||||||
ld r16, X ; check: buffer in use?
|
|
||||||
tst r16
|
|
||||||
breq com2ReceivePacket_bufferAvailable
|
|
||||||
|
|
||||||
ldi xl, LOW(com2StatsNoBufferError) ; buffer in use, don't release
|
ldi xl, LOW(com2StatsNoBufferError) ; buffer in use, don't release
|
||||||
ldi xh, HIGH(com2StatsNoBufferError) ; just increment error counter
|
ldi xh, HIGH(com2StatsNoBufferError) ; just increment error counter
|
||||||
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
||||||
@@ -300,6 +319,39 @@ com2ReceivePacket:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
com2ReceivePacket_bufferAvailable:
|
com2ReceivePacket_bufferAvailable:
|
||||||
|
push xl
|
||||||
|
push xh
|
||||||
|
rcall com2ReceivePacketIntoX
|
||||||
|
pop xh
|
||||||
|
pop xl
|
||||||
|
brcs com2ReceivePacket_received
|
||||||
|
rcall COM2_BufferDeallocBack
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
com2ReceivePacket_received:
|
||||||
|
rcall com2CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
|
||||||
|
brcs com2ReceivePacket_crcOkay
|
||||||
|
ldi xl, LOW(com2StatsContentError)
|
||||||
|
ldi xh, HIGH(com2StatsContentError)
|
||||||
|
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
com2ReceivePacket_crcOkay:
|
||||||
|
ldi xl, LOW(com2StatsPacketsIn)
|
||||||
|
ldi xh, HIGH(com2StatsPacketsIn)
|
||||||
|
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; receive packet into buffer pointed to by X.
|
||||||
|
;
|
||||||
|
; OUT:
|
||||||
|
; - CFLAG: set if okay (packet received), cleared on error
|
||||||
|
; REGS: r16, r17, x (r18, r19, r20, r21, r22)
|
||||||
|
com2ReceivePacketIntoX:
|
||||||
; read destination address
|
; read destination address
|
||||||
rcall com2ReceiveByte ; read byte (R16, R17, R20, R21, R22)
|
rcall com2ReceiveByte ; read byte (R16, R17, R20, R21, R22)
|
||||||
brcc com2ReceivePacket_ioError
|
brcc com2ReceivePacket_ioError
|
||||||
@@ -311,7 +363,6 @@ com2ReceivePacket_bufferAvailable:
|
|||||||
breq com2ReceivePacket_acceptAddr
|
breq com2ReceivePacket_acceptAddr
|
||||||
clc ; not for me
|
clc ; not for me
|
||||||
ret
|
ret
|
||||||
|
|
||||||
com2ReceivePacket_acceptAddr:
|
com2ReceivePacket_acceptAddr:
|
||||||
st X+, r16 ; store dest address, lock buffer
|
st X+, r16 ; store dest address, lock buffer
|
||||||
; read msg length
|
; read msg length
|
||||||
@@ -330,32 +381,18 @@ com2ReceivePacket_loop:
|
|||||||
st X+, r16
|
st X+, r16
|
||||||
dec r17
|
dec r17
|
||||||
brne com2ReceivePacket_loop
|
brne com2ReceivePacket_loop
|
||||||
|
|
||||||
ldi xl, LOW(com2RecvBuffer)
|
|
||||||
ldi xh, HIGH(com2RecvBuffer)
|
|
||||||
rcall com2CheckMessageInBuffer ; (R16, R17, R18, R19, R20, X)
|
|
||||||
brcc com2ReceivePacket_contentError
|
|
||||||
; done, increment packet counter, set flags
|
|
||||||
ldi xl, LOW(com2StatsPacketsIn)
|
|
||||||
ldi xh, HIGH(com2StatsPacketsIn)
|
|
||||||
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
|
||||||
sec
|
sec
|
||||||
ret
|
ret
|
||||||
|
|
||||||
com2ReceivePacket_ioError:
|
com2ReceivePacket_ioError:
|
||||||
ldi xl, LOW(com2StatsIoError)
|
ldi xl, LOW(com2StatsIoError)
|
||||||
ldi xh, HIGH(com2StatsIoError)
|
ldi xh, HIGH(com2StatsIoError)
|
||||||
rjmp com2ReceivePacket_incCounter
|
rjmp com2ReceivePacket_incCounter
|
||||||
|
|
||||||
com2ReceivePacket_contentError:
|
com2ReceivePacket_contentError:
|
||||||
ldi xl, LOW(com2StatsContentError)
|
ldi xl, LOW(com2StatsContentError)
|
||||||
ldi xh, HIGH(com2StatsContentError)
|
ldi xh, HIGH(com2StatsContentError)
|
||||||
rjmp com2ReceivePacket_incCounter
|
rjmp com2ReceivePacket_incCounter
|
||||||
|
|
||||||
com2ReceivePacket_incCounter:
|
com2ReceivePacket_incCounter:
|
||||||
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
rcall Utils_IncrementCounter16 ; (r18, r19, 22)
|
||||||
clr r16
|
|
||||||
sts com2RecvBuffer, r16 ; unlock buffer
|
|
||||||
clc
|
clc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@@ -378,6 +415,7 @@ COM2_SendPacketAtX:
|
|||||||
in r15, SREG
|
in r15, SREG
|
||||||
push r15
|
push r15
|
||||||
cli
|
cli
|
||||||
|
Utils_WaitNanoSecs COM_BIT_LENGTH, 0, r22 ; wait for one bit duration
|
||||||
; check for ATTN line: busy?
|
; check for ATTN line: busy?
|
||||||
cbi COM_PORT_ATTN, COM_PINNUM_ATTN ; disable pullup on ATTN
|
cbi COM_PORT_ATTN, COM_PINNUM_ATTN ; disable pullup on ATTN
|
||||||
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN as input
|
cbi COM_DDR_ATTN, COM_PINNUM_ATTN ; set ATTN as input
|
||||||
@@ -478,7 +516,9 @@ com2IsrPcint0:
|
|||||||
push r22
|
push r22
|
||||||
push xh
|
push xh
|
||||||
push xl
|
push xl
|
||||||
rcall com2ReceivePacket ; (r16, r17, r18, r19, r20, r21, r22, x)
|
push r15
|
||||||
|
rcall com2ReceivePacket ; (r16, r17, r18, r19, r20, r21, r22, x)
|
||||||
|
pop r15
|
||||||
lds xl, com2Interrupts
|
lds xl, com2Interrupts
|
||||||
lds xh, com2Interrupts+1
|
lds xh, com2Interrupts+1
|
||||||
adiw xh:xl, 1
|
adiw xh:xl, 1
|
||||||
@@ -494,8 +534,8 @@ com2IsrPcint0:
|
|||||||
pop r17
|
pop r17
|
||||||
pop r16
|
pop r16
|
||||||
pop r1
|
pop r1
|
||||||
|
|
||||||
com2IsrPcint0_end:
|
com2IsrPcint0_end:
|
||||||
|
out SREG, r15
|
||||||
pop r15
|
pop r15
|
||||||
reti
|
reti
|
||||||
|
|
||||||
@@ -799,6 +839,174 @@ com2CalcCrc8_l1:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
; buffer code
|
||||||
|
; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM_BufferAlloc
|
||||||
|
;
|
||||||
|
; Allocate a transfer buffer.
|
||||||
|
; IN:
|
||||||
|
; - nothing
|
||||||
|
; OUT:
|
||||||
|
; - CFLAG: set if okay, clear otherwise
|
||||||
|
; - X: pointer to allocated buffer in SRAM
|
||||||
|
; MODIFIED REGISTERS: r16, r17, r21
|
||||||
|
|
||||||
|
|
||||||
|
COM2_BufferAlloc:
|
||||||
|
in r21, SREG ; save global interrupt enable bit from SREG
|
||||||
|
cli
|
||||||
|
lds r17, com2RecvBuffersUsed
|
||||||
|
cpi r17, COM2_BUFFER_NUM
|
||||||
|
brcc COM2_AllocBuffer_error ; no buffer available
|
||||||
|
inc r17 ; increment number of buffers used
|
||||||
|
sts com2RecvBuffersUsed, r17 ; store new value
|
||||||
|
lds r16, com2MaxBuffersUsed ; calc max buffers used
|
||||||
|
cp r16, r17
|
||||||
|
brcc COM2_AllocBuffer_l0
|
||||||
|
sts com2MaxBuffersUsed, r17
|
||||||
|
COM2_AllocBuffer_l0:
|
||||||
|
lds r16, com2RecvBuffersWritePos ; get current write pos
|
||||||
|
mov r17, r16 ; increment for next call
|
||||||
|
inc r17
|
||||||
|
cpi r17, COM2_BUFFER_NUM ; CF set if COM_BUFFER_NUM > R17
|
||||||
|
brcs COM2_AllocBuffer_l1
|
||||||
|
clr r17 ; wraparound
|
||||||
|
COM2_AllocBuffer_l1:
|
||||||
|
sts com2RecvBuffersWritePos, r17 ; store new writepos for next caller
|
||||||
|
rcall COM2_BufferPosToX ; (R16, R17)
|
||||||
|
out SREG, r21 ; restore global interrupt enable bit in SREG
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
COM2_AllocBuffer_error:
|
||||||
|
out SREG, r21
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM2_BufferDeallocBack
|
||||||
|
;
|
||||||
|
; Release a transfer buffer at the end of the list by decreasing the write pos.
|
||||||
|
; This releases the last allocated buffer!
|
||||||
|
;
|
||||||
|
; IN:
|
||||||
|
; - nothing
|
||||||
|
; OUT:
|
||||||
|
; - CFLAG: set if okay, clear otherwise
|
||||||
|
; MODIFIED REGISTERS: r16, r17, r21
|
||||||
|
|
||||||
|
COM2_BufferDeallocBack:
|
||||||
|
in r21, SREG ; save global interrupt enable bit from SREG
|
||||||
|
cli
|
||||||
|
lds r17, com2RecvBuffersUsed
|
||||||
|
tst r17
|
||||||
|
breq COM2_BufferDeallocBack_error ; no buffer allocated, nothing to release
|
||||||
|
dec r17
|
||||||
|
sts com2RecvBuffersUsed, r17 ; store new value
|
||||||
|
lds r17, com2RecvBuffersWritePos
|
||||||
|
tst r17 ; 0?
|
||||||
|
brne COM2_BufferDeallocBack_l1 ; nope go directly decrement r17
|
||||||
|
ldi r17, COM2_BUFFER_NUM ; wrap-around
|
||||||
|
COM2_BufferDeallocBack_l1:
|
||||||
|
dec r17
|
||||||
|
sts com2RecvBuffersWritePos, r17
|
||||||
|
out SREG, r21
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
COM2_BufferDeallocBack_error:
|
||||||
|
out SREG, r21
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM2_BufferDeallocFront
|
||||||
|
;
|
||||||
|
; Release a transfer buffer by increasing the read pos.
|
||||||
|
;
|
||||||
|
; IN:
|
||||||
|
; - nothing
|
||||||
|
; OUT:
|
||||||
|
; - CFLAG: set if okay, clear otherwise
|
||||||
|
; MODIFIED REGISTERS: r16, r17, r21
|
||||||
|
|
||||||
|
COM2_BufferDeallocFront:
|
||||||
|
in r21, SREG ; save global interrupt enable bit from SREG
|
||||||
|
cli
|
||||||
|
lds r17, com2RecvBuffersUsed
|
||||||
|
tst r17
|
||||||
|
breq COM2_BufferDeallocFront_error ; no buffer allocated, nothing to release
|
||||||
|
dec r17
|
||||||
|
sts com2RecvBuffersUsed, r17 ; store new value
|
||||||
|
lds r17, com2RecvBuffersReadPos
|
||||||
|
inc r17
|
||||||
|
cpi r17, COM2_BUFFER_NUM
|
||||||
|
brcs COM2_BufferDeallocFront_l1
|
||||||
|
clr r17 ; wrap-around
|
||||||
|
COM2_BufferDeallocFront_l1:
|
||||||
|
sts com2RecvBuffersReadPos, r17
|
||||||
|
out SREG, r21
|
||||||
|
sec
|
||||||
|
ret
|
||||||
|
COM2_BufferDeallocFront_error:
|
||||||
|
out SREG, r21
|
||||||
|
clc
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
; ---------------------------------------------------------------------------
|
||||||
|
; COM2_BufferPosToX
|
||||||
|
;
|
||||||
|
; Get a pointer to the SRAM position of the given buffer.
|
||||||
|
; CAVE: Code must correspond to COM2_BUFFER_SIZE!!
|
||||||
|
; IN:
|
||||||
|
; - R16: buffer number (starting with 0)
|
||||||
|
; OUT:
|
||||||
|
; - X: pointer to buffer in SRAM
|
||||||
|
; MODIFIED REGISTERS: R16, R17
|
||||||
|
|
||||||
|
COM2_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(com2RecvBuffers)
|
||||||
|
ldi r17, HIGH(com2RecvBuffers)
|
||||||
|
add xl, r16
|
||||||
|
adc xh, r17
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
COM2_END:
|
COM2_END:
|
||||||
.equ MODULE_SIZE_COM2 = COM2_END-COM2_BEGIN
|
.equ MODULE_SIZE_COM2 = COM2_END-COM2_BEGIN
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,13 @@
|
|||||||
|
|
||||||
cproAddressDataBegin:
|
cproAddressDataBegin:
|
||||||
cproAddressFlags: .byte 1
|
cproAddressFlags: .byte 1
|
||||||
cproAddresModeTimer: .byte 2
|
|
||||||
cproAddrRangeBegin: .byte 1
|
cproAddrRangeBegin: .byte 1
|
||||||
cproAddrRangeEnd: .byte 1
|
cproAddrRangeEnd: .byte 1
|
||||||
cproAddressWaitCounter: .byte 1 ; counter for seconds to wait for all nodes to respond
|
|
||||||
cproUsedAddresses: .byte 16 ; one bit per address known to b in use
|
cproUsedAddresses: .byte 16 ; one bit per address known to b in use
|
||||||
cproAddressDataEnd:
|
cproAddressDataEnd:
|
||||||
|
|
||||||
|
cproAddresModeTimer: .byte 2 ; timer must not be zeroed, this is done by the timer module!!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
; ***************************************************************************
|
; ***************************************************************************
|
||||||
@@ -109,20 +109,25 @@ CPRO_StartReclaimAddrProcedure:
|
|||||||
ldi xl, LOW(EEPROM_OFFS_COMADDR)
|
ldi xl, LOW(EEPROM_OFFS_COMADDR)
|
||||||
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
|
ldi xh, HIGH(EEPROM_OFFS_COMADDR)
|
||||||
in r15, SREG
|
in r15, SREG
|
||||||
cli
|
push r15
|
||||||
rcall Utils_ReadEepromIncr ; (R16)
|
cli
|
||||||
tst r16
|
rcall Utils_ReadEepromIncr ; (R16)
|
||||||
breq CPRO_StartReclaimAddrProcedure_l1
|
tst r16
|
||||||
cpi r16, 0xff
|
breq CPRO_StartReclaimAddrProcedure_l1
|
||||||
breq CPRO_StartReclaimAddrProcedure_l1
|
cpi r16, 0xff
|
||||||
sts cproAddrRangeBegin, r16 ; currently claimed address
|
breq CPRO_StartReclaimAddrProcedure_l1
|
||||||
ldi r16, CPRO_MODE_SEND_RECLAIM_ADDR
|
sts cproAddrRangeBegin, r16 ; currently claimed address
|
||||||
sts cproMode, r16
|
ldi r16, CPRO_MODE_SEND_RECLAIM_ADDR
|
||||||
rcall cproAddressSetTimer1s ; use singleshot timer, send after 1s
|
sts cproMode, r16
|
||||||
|
rcall cproAddressSetTimer1s ; use singleshot timer, send after 1s
|
||||||
|
pop r15
|
||||||
|
out SREG, r15
|
||||||
sec
|
sec
|
||||||
ret
|
ret
|
||||||
CPRO_StartReclaimAddrProcedure_l1:
|
CPRO_StartReclaimAddrProcedure_l1:
|
||||||
rcall CPRO_StartGetAddrProcedure
|
rcall CPRO_StartGetAddrProcedure
|
||||||
|
pop r15
|
||||||
|
out SREG, r15
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,50 +22,35 @@
|
|||||||
; IN:
|
; IN:
|
||||||
; - R16: destination address
|
; - R16: destination address
|
||||||
; OUT:
|
; OUT:
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; - nothing
|
||||||
; MODIFIED REGS: R6, R16, R17, R18, R20 (R3, R4, R15, R19, R21, X)
|
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
||||||
|
|
||||||
CPRO_EnqueueMemStats:
|
|
||||||
mov r6, r16
|
|
||||||
|
|
||||||
rcall COM_AllocBufferAndGetXY ; (r16, r17, r21)
|
|
||||||
brcc CPRO_EnqueueMemStats_error
|
|
||||||
|
|
||||||
|
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 xh
|
||||||
push xl
|
push xl
|
||||||
mov r16, r6
|
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
||||||
ldi r17, CPRO_PAYLOAD_FLAGS_UID | CPRO_PAYLOAD_FLAGS_SECONDS | (8<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM)
|
|
||||||
ldi r18, CPRO_CMD_MEMSTATS
|
|
||||||
rcall cproBeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
; payload
|
; payload
|
||||||
|
ldi r20, LOW(RAMEND)
|
||||||
|
ldi r21, HIGH(RAMEND)
|
||||||
in r17, SPL
|
in r17, SPL
|
||||||
st X+, r17 ; current stackpointer
|
sub r20, r17
|
||||||
|
st X+, r20 ; stack used
|
||||||
in r17, SPH
|
in r17, SPH
|
||||||
st X+, r17
|
sbc r21, r17
|
||||||
lds r17, comRecvBuffersUsed
|
st X+, r21
|
||||||
|
lds r17, com2RecvBuffersUsed
|
||||||
st X+, r17 ; used buffers
|
st X+, r17 ; used buffers
|
||||||
lds r17, comMaxBuffersUsed
|
lds r17, com2MaxBuffersUsed
|
||||||
st X+, r17 ; max used buffers
|
st X+, r17 ; max used buffers
|
||||||
lds r17, comStatsSendNoBuffer
|
lds r17, com2StatsNoBufferError
|
||||||
st X+, r17 ; sendNoBuffer
|
|
||||||
lds r17, comStatsSendNoBuffer+1
|
|
||||||
st X+, r17
|
|
||||||
lds r17, comStatsRecvNoBuffer
|
|
||||||
st X+, r17 ; recvNoBuffer
|
st X+, r17 ; recvNoBuffer
|
||||||
lds r17, comStatsRecvNoBuffer+1
|
lds r17, com2StatsNoBufferError+1
|
||||||
st X+, r17
|
st X+, r17
|
||||||
pop xl
|
pop xl
|
||||||
pop xh
|
pop xh
|
||||||
rcall comCalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
||||||
|
|
||||||
; 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_EnqueueMemStats_error
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
CPRO_EnqueueMemStats_error:
|
|
||||||
clc
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
||||||
|
|
||||||
CPRO_WriteComRecvStats:
|
CPRO_WriteComRecvStats:
|
||||||
ldi r17, COM2_PAYLOAD_FLAGS_UID | (8<<COM2_PAYLOAD_FLAGS_SHIFT_NUM) ; seconds + 8 bytes payload
|
ldi r17, COM2_PAYLOAD_FLAGS_UID | (12<<COM2_PAYLOAD_FLAGS_SHIFT_NUM) ; seconds + 12 bytes payload
|
||||||
ldi r18, CPRO_CMD_COMRECVSTATS
|
ldi r18, CPRO_CMD_COMRECVSTATS
|
||||||
push xh
|
push xh
|
||||||
push xl
|
push xl
|
||||||
@@ -48,6 +48,14 @@ CPRO_WriteComRecvStats:
|
|||||||
st X+, r16
|
st X+, r16
|
||||||
lds r16, com2StatsNoBufferError+1
|
lds r16, com2StatsNoBufferError+1
|
||||||
st X+, r16
|
st X+, r16
|
||||||
|
lds r16, com2StatsHandled
|
||||||
|
st X+, r16
|
||||||
|
lds r16, com2StatsHandled+1
|
||||||
|
st X+, r16
|
||||||
|
lds r16, com2StatsMissed
|
||||||
|
st X+, r16
|
||||||
|
lds r16, com2StatsMissed+1
|
||||||
|
st X+, r16
|
||||||
pop xl
|
pop xl
|
||||||
pop xh
|
pop xh
|
||||||
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
||||||
|
|||||||
@@ -17,49 +17,34 @@
|
|||||||
|
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
; Enqueue a MEMSTATS packet.
|
; Write a SYSSTATS packet.
|
||||||
;
|
;
|
||||||
; IN:
|
; IN:
|
||||||
; - R16: destination address
|
; - R16: destination address
|
||||||
|
; - X : buffer to write to
|
||||||
; OUT:
|
; OUT:
|
||||||
; - CFLAG: set if okay, clear otherwise
|
; - nothing
|
||||||
; MODIFIED REGS: R6, R16, R17, R18, R20 (R3, R4, R15, R19, R21, X)
|
; REGS: R3, R4, R16, R17, R18, X (R19, R20, R21)
|
||||||
|
|
||||||
CPRO_EnqueueSysStats:
|
|
||||||
mov r6, r16
|
|
||||||
|
|
||||||
rcall COM_AllocBufferAndGetXY ; (r16, r17, r21)
|
|
||||||
brcc CPRO_EnqueueSysStats_error
|
|
||||||
|
|
||||||
|
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 xh
|
||||||
push xl
|
push xl
|
||||||
mov r16, r6
|
rcall COM2_BeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
||||||
ldi r17, CPRO_PAYLOAD_FLAGS_UID | CPRO_PAYLOAD_FLAGS_SECONDS | (4<<CPRO_PAYLOAD_FLAGS_SHIFT_NUM)
|
|
||||||
ldi r18, CPRO_CMD_SYSSTATS
|
|
||||||
rcall cproBeginMsgWithVariablePayload ; (R3, R4, R16, R17, R18, R19, R20, R21, X)
|
|
||||||
; payload
|
; payload
|
||||||
lds r17, comInterrupts
|
lds r17, com2Interrupts
|
||||||
st X+, r17 ; com interrupts
|
st X+, r17 ; com interrupts
|
||||||
lds r17, comInterrupts+1
|
lds r17, com2Interrupts+1
|
||||||
st X+, r17
|
st X+, r17
|
||||||
|
|
||||||
lds r17, timerInterrupts
|
lds r17, timerInterrupts
|
||||||
st X+, r17 ; timer interrupts
|
st X+, r17 ; timer interrupts
|
||||||
lds r17, timerInterrupts+1
|
lds r17, timerInterrupts+1
|
||||||
st X+, r17
|
st X+, r17
|
||||||
pop xl
|
pop xl
|
||||||
pop xh
|
pop xh
|
||||||
rcall comCalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
rcall com2CalcAndAddChecksumByte ; (R16, R17, R18, R19, X)
|
||||||
|
|
||||||
; 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_EnqueueSysStats_error
|
|
||||||
sec
|
|
||||||
ret
|
|
||||||
CPRO_EnqueueSysStats_error:
|
|
||||||
clc
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
.equ AQHOME_FW_MODULE_TWIMASTER = 4
|
.equ AQHOME_FW_MODULE_TWIMASTER = 4
|
||||||
.equ AQHOME_FW_MODULE_LCD = 5
|
.equ AQHOME_FW_MODULE_LCD = 5
|
||||||
.equ AQHOME_FW_MODULE_SI7021 = 6
|
.equ AQHOME_FW_MODULE_SI7021 = 6
|
||||||
|
.equ AQHOME_FW_MODULE_STATS = 7
|
||||||
|
|
||||||
|
|
||||||
.equ AQHOME_FW_TYPE_ATT84_BASE = 0
|
.equ AQHOME_FW_TYPE_ATT84_BASE = 0
|
||||||
|
|||||||
25
avr/main.asm
25
avr/main.asm
@@ -128,6 +128,10 @@ initModules:
|
|||||||
rcall SI7021_Init
|
rcall SI7021_Init
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
rcall Stats_Init
|
||||||
|
#endif
|
||||||
|
|
||||||
; done
|
; done
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@@ -163,6 +167,10 @@ runModulesUntilIdle_Com:
|
|||||||
brne runModulesUntilIdle_Com
|
brne runModulesUntilIdle_Com
|
||||||
runModulesUntilIdle_ComEnd:
|
runModulesUntilIdle_ComEnd:
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULES_STATS
|
||||||
|
rcall Stats_Run
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
; add more modules here
|
; add more modules here
|
||||||
@@ -253,6 +261,7 @@ printTimerMark:
|
|||||||
|
|
||||||
|
|
||||||
printSendStats:
|
printSendStats:
|
||||||
|
#if 0
|
||||||
in r15, SREG ; debug
|
in r15, SREG ; debug
|
||||||
push r15
|
push r15
|
||||||
cli
|
cli
|
||||||
@@ -291,8 +300,7 @@ printSendStats:
|
|||||||
out SREG, r15
|
out SREG, r15
|
||||||
ret
|
ret
|
||||||
|
|
||||||
#if 0
|
#else
|
||||||
printSendStats:
|
|
||||||
in r15, SREG ; debug
|
in r15, SREG ; debug
|
||||||
push r15
|
push r15
|
||||||
cli
|
cli
|
||||||
@@ -323,14 +331,12 @@ printSendStats:
|
|||||||
ldi zl, LOW(textAddress)
|
ldi zl, LOW(textAddress)
|
||||||
ldi zh, HIGH(textAddress)
|
ldi zh, HIGH(textAddress)
|
||||||
rcall LCD_PrintFromFlash
|
rcall LCD_PrintFromFlash
|
||||||
lds r16, comAddress
|
lds r16, com2Address
|
||||||
rcall LCD_PrintHexByte
|
rcall LCD_PrintHexByte
|
||||||
ldi r16, 32
|
ldi r16, 32
|
||||||
rcall LCD_PrintChar
|
rcall LCD_PrintChar
|
||||||
lds r16, cproMode
|
lds r16, cproMode
|
||||||
rcall LCD_PrintHexByte
|
rcall LCD_PrintHexByte
|
||||||
lds r16, cproAddressWaitCounter
|
|
||||||
rcall LCD_PrintHexByte
|
|
||||||
ldi r16, 32
|
ldi r16, 32
|
||||||
rcall LCD_PrintChar
|
rcall LCD_PrintChar
|
||||||
lds r16, cproAddrRangeBegin
|
lds r16, cproAddrRangeBegin
|
||||||
@@ -358,8 +364,8 @@ printSendStats:
|
|||||||
ldi zl, LOW(textStatsPacketsIn)
|
ldi zl, LOW(textStatsPacketsIn)
|
||||||
ldi zh, HIGH(textStatsPacketsIn)
|
ldi zh, HIGH(textStatsPacketsIn)
|
||||||
rcall LCD_PrintFromFlash
|
rcall LCD_PrintFromFlash
|
||||||
lds r18, comStatsPacketsIn
|
lds r18, com2StatsPacketsIn
|
||||||
lds r19, comStatsPacketsIn+1
|
lds r19, com2StatsPacketsIn+1
|
||||||
rcall LCD_PrintHexWord
|
rcall LCD_PrintHexWord
|
||||||
|
|
||||||
ldi r18, 0
|
ldi r18, 0
|
||||||
@@ -368,15 +374,14 @@ printSendStats:
|
|||||||
ldi zl, LOW(textStatsPacketsOut)
|
ldi zl, LOW(textStatsPacketsOut)
|
||||||
ldi zh, HIGH(textStatsPacketsOut)
|
ldi zh, HIGH(textStatsPacketsOut)
|
||||||
rcall LCD_PrintFromFlash
|
rcall LCD_PrintFromFlash
|
||||||
lds r18, comStatsPacketsOut
|
lds r18, com2StatsPacketsOut
|
||||||
lds r19, comStatsPacketsOut+1
|
lds r19, com2StatsPacketsOut+1
|
||||||
rcall LCD_PrintHexWord
|
rcall LCD_PrintHexWord
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pop r15
|
pop r15
|
||||||
out SREG, r15
|
out SREG, r15
|
||||||
ret
|
ret
|
||||||
#endif ; if 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
103
avr/stats.asm
Normal file
103
avr/stats.asm
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
; ***************************************************************************
|
||||||
|
; 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 = 3
|
||||||
|
.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
|
||||||
|
ldi xl, LOW(com2SendBuffer)
|
||||||
|
ldi xh, HIGH(com2SendBuffer)
|
||||||
|
ldi r16, 0xff
|
||||||
|
|
||||||
|
lds r17, statsRemaining
|
||||||
|
tst r17
|
||||||
|
breq Stats_Run_done
|
||||||
|
|
||||||
|
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:
|
||||||
|
; add more stats here
|
||||||
|
rjmp Stats_Run_done
|
||||||
|
Stats_Run_SendPacket:
|
||||||
|
rcall COM2_SendPacket
|
||||||
|
brcc Stats_Run_done ; only decreemnt 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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -410,8 +410,8 @@ Utils_UpdateSeedInEeprom:
|
|||||||
; REGS: R16, X
|
; REGS: R16, X
|
||||||
|
|
||||||
Utils_ReadUid:
|
Utils_ReadUid:
|
||||||
|
in r15, SREG
|
||||||
push r15
|
push r15
|
||||||
in r15, SREG
|
|
||||||
cli
|
cli
|
||||||
ldi xl, LOW(EEPROM_OFFS_UUID)
|
ldi xl, LOW(EEPROM_OFFS_UUID)
|
||||||
ldi xh, HIGH(EEPROM_OFFS_UUID)
|
ldi xh, HIGH(EEPROM_OFFS_UUID)
|
||||||
@@ -489,8 +489,8 @@ Utils_SetupUid_generate:
|
|||||||
; REGS: R16, X
|
; REGS: R16, X
|
||||||
|
|
||||||
Utils_ReadSeed:
|
Utils_ReadSeed:
|
||||||
|
in r15, SREG
|
||||||
push r15
|
push r15
|
||||||
in r15, SREG
|
|
||||||
cli
|
cli
|
||||||
ldi xl, LOW(EEPROM_OFFS_SEED)
|
ldi xl, LOW(EEPROM_OFFS_SEED)
|
||||||
ldi xh, HIGH(EEPROM_OFFS_SEED)
|
ldi xh, HIGH(EEPROM_OFFS_SEED)
|
||||||
@@ -514,8 +514,8 @@ Utils_ReadSeed:
|
|||||||
; OUT:
|
; OUT:
|
||||||
; REGS: R16, X, (R17)
|
; REGS: R16, X, (R17)
|
||||||
Utils_WriteSeed:
|
Utils_WriteSeed:
|
||||||
|
in r15, SREG
|
||||||
push r15
|
push r15
|
||||||
in r15, SREG
|
|
||||||
cli
|
cli
|
||||||
ldi xl, LOW(EEPROM_OFFS_SEED)
|
ldi xl, LOW(EEPROM_OFFS_SEED)
|
||||||
ldi xh, HIGH(EEPROM_OFFS_SEED)
|
ldi xh, HIGH(EEPROM_OFFS_SEED)
|
||||||
|
|||||||
Reference in New Issue
Block a user