avr: started reworking COM module.

- sending and receiving now basically works again, but too often the
  read buffer is in use when trying to receive a message.
This commit is contained in:
Martin Preuss
2023-04-12 15:30:38 +02:00
parent 0feceeb96e
commit 024d40fc95
21 changed files with 1816 additions and 1926 deletions

View File

@@ -61,9 +61,10 @@
#define MODULES_TIMER
#define MODULES_COM
;#define MODULES_COM_WITH_ADDR_PROTO
#define MODULES_LED
#define MODULES_TWI_MASTER
;#define MODULES_LCD
#define MODULES_LCD
#define MODULES_SI7021
@@ -199,7 +200,7 @@
rjmp main ; Reset vector
reti ; EXT_INT0
rjmp comIsrPcint0 ; PCI0
rjmp com2IsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -222,18 +223,14 @@
.include "utils.asm"
.include "timer.asm"
.include "led.asm"
.include "com.asm"
.include "com2.asm"
.include "comproto.asm"
.include "comproto_addr.asm"
.include "comproto_stats.asm"
.include "comproto_device.asm"
.include "comproto_memstats.asm"
.include "comproto_sysstats.asm"
.include "comproto_values.asm"
;.include "comproto_debug.asm"
;.include "comproto_twi.asm"
.include "comproto_recvstats.asm"
.include "comproto_pong.asm"
;.include "comproto_values.asm"
.include "twimaster.asm"
;.include "lcd.asm"
.include "lcd.asm"
.include "si7021.asm"
@@ -250,7 +247,7 @@ sramTimerEnqueueMemStats: .byte 2
sramTimerEnqueueSysStats: .byte 2
sramTimerEnqueueValues: .byte 2
sramTimerSI7021Measure: .byte 2
sramPeriodicalLcdMark: .byte 2
; ***************************************************************************
@@ -271,12 +268,13 @@ blinkPattern: .db 2, 50, 0xff, 0xff ; 1 short blink, 2s pause, restart
timerList:
; SRAM variable/counter routine flags secs (0=don't start or restart)
.dw sramTimerProtocolEverySec, CPRO_OnEverySecond, 0, 1 ; every 1s
.dw sramTimerEnqueueComStats, enqueueComStats, TIMER_FLAGS_IF_ADDR, 300 ; every 5m
.dw sramTimerEnqueueMemStats, enqueueMemStats, TIMER_FLAGS_IF_ADDR, 300 ; every 5m
.dw sramTimerEnqueueSysStats, enqueueSysStats, TIMER_FLAGS_IF_ADDR, 60 ; every 60s
.dw sramTimerSI7021Measure, SI7021_PeriodicMeasurement, 0, 30 ; every 30s
.dw sramTimerEnqueueValues, Main_SendValueMsg, TIMER_FLAGS_IF_ADDR, 60 ; every 1m
#ifdef MODULES_COM_WITH_ADDR_PROTO
; .dw cproAddresModeTimer, CPRO_Address_OnTimer, 0, 0 ; (no restart)
#endif
.dw sramTimerEnqueueComStats, enqueueComStats, TIMER_FLAGS_IF_ADDR, 10 ; every 30s
.dw sramPeriodicalLcdMark, periodicalLcdMark, 0, 1 ; every sec
; .dw sramTimerSI7021Measure, SI7021_PeriodicMeasurement, 0, 30 ; every 30s
; .dw sramTimerEnqueueValues, Main_SendValueMsg, TIMER_FLAGS_IF_ADDR, 60 ; every 1m
.dw 0 ; end of list
@@ -290,33 +288,51 @@ timerList:
; Called on first time run, i.e. on system start. No arguments, no results.
onSystemStart:
; todo: setup once timer to start reclaiming address
rcall CPRO_StartReclaimAddrProcedure
ldi r16, 2 ; DEBUG: set static address
sts com2Address, r16
; rcall printStartSendPackage
; ldi r16, 0xff ; send to everybody
; ldi xl, LOW(com2SendBuffer)
; ldi xh, HIGH(com2SendBuffer)
; rcall CPRO_WriteComRecvStats
; rcall printStartSendPackage
; rcall COM2_SendPacket
; rcall printEndSendPackage
; rcall printSendStats
ret
periodicalLcdMark:
rcall printTimerMark
ret
enqueueComStats:
rcall printSendStats
ldi r16, 0xff ; send to everybody
rcall CPRO_EnqueueComSendStats
ldi r16, 0xff ; send to everybody
rjmp CPRO_EnqueueComRecvStats
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
enqueueMemStats:
ldi r16, 0xff ; send to everybody
rcall CPRO_EnqueueMemStats
ldi r16, 0xff ; send to everybody
rjmp CPRO_EnqueueDevice
; ldi r16, 0xff ; send to everybody
; rjmp CPRO_EnqueueDevice
enqueueSysStats:
ldi r16, 0xff ; send to everybody
rjmp CPRO_EnqueueSysStats
;enqueueSysStats:
; ldi r16, 0xff ; send to everybody
; rjmp CPRO_EnqueueSysStats
@@ -344,15 +360,17 @@ onEvery100ms:
;
; Called after a packet was received via COM module. Add your routine calls here.
;
; The packet will be removed from buffer in any case after return from this call.
; The packet will be released in any case after return from this call.
; IN:
; - Y : pointer to received buffer
; - X : pointer to received buffer
; OUT:
; - CFLAG: set if handled, cleared otherwise
; USED: depending on called routines
onPacketReceived:
rcall CPRO_OnPacketReceived
; rcall CPRO_OnPacketReceived
sbi PINA, PORTA2 ; debug (toggle)
ret