COM: Transformed to use normal buffers but in kind of a ringbuffer way.

There are now fixed buffers which are organized in a ringbuffer. This makes
it easier to access data stored in the buffers, also receiving packets is
now way faster with reduced risk of sync problems.
This commit is contained in:
Martin Preuss
2023-01-25 16:28:36 +01:00
parent 31f3e807f0
commit 348d808706
2 changed files with 555 additions and 295 deletions

View File

@@ -19,8 +19,6 @@
.equ COM_BIT_LENGTH = 52000 ; 104000=9600, 52000=19200, 26000=38400
.equ COM_RINGBUFFER_SIZE = 32 ; 32 bytes for now
.equ COM_DDR_DATA = DDRA
.equ COM_PORT_DATA = PORTA
.equ COM_PIN_DATA = PINA
@@ -52,7 +50,7 @@
rjmp main ; Reset vector
reti ; EXT_INT0
reti ; PCI0
rjmp comIsrPcint0 ; PCI0
reti ; PCI1
reti ; WATCHDOG
reti ; ICP1
@@ -74,7 +72,6 @@
; includes
.include "utils.asm"
.include "ringbuffer.asm"
.include "timer.asm"
.include "led.asm"
.include "com.asm"
@@ -262,14 +259,13 @@ onEverySecond:
; USED: depending on called routines
onEvery10s:
in r15, SREG ; debug
cli
push r15
ldi r17, 219
rcall COM_EnqueuePing
; rcall comHandleNextPacketInRingbuffer
pop r15
out SREG, r15
; in r15, SREG ; debug
; cli
; push r15
; ldi r16, 219
; rcall COM_EnqueuePing
; pop r15
; out SREG, r15
ret
@@ -286,8 +282,6 @@ onEvery10s:
; USED: depending on called routines
onEveryMinute:
sbi DDRA, PORTA2 ; debug
sbi PINA, PORTA2 ; debug (toggle)
ret
@@ -299,13 +293,14 @@ onEveryMinute:
;
; The packet will be removed from buffer in any case after return from this call.
; IN:
; - R18: pos of packet in ringbuffer
; - Y : pointer to ringbuffer
; - Y : pointer to received buffer
; OUT:
; - CFLAG: set if handled, cleared otherwise
; USED: depending on called routines
onPacketReceived:
sbi DDRA, PORTA2 ; debug
sbi PINA, PORTA2 ; debug (toggle)
clc ; not handled
ret
@@ -316,33 +311,42 @@ onPacketReceived:
debugSendByte:
in r15, SREG ; debug
cli
push r15
in r15, SREG ; debug
cli
push r17
push r22
ldi r17, 8
sbi DDRA, PORTA2 ; debug
cbi PORTA, PORTA2 ; debug (on)
Utils_WaitNanoSecs 100000, 0, r22 ; start with 2t low
ldi r17, 8
sbi DDRA, PORTA2 ; debug
cbi PORTA, PORTA2 ; debug (on)
Utils_WaitNanoSecs 200000, 0, r22 ; start with 2t low
debugSendByte_loop:
lsr r16
brcs debugSendByte_sendLow
cbi PORTA, PORTA2 ; debug (on)
rjmp debugSendByte_wait
debugSendByte_sendLow:
sbi PORTA, PORTA2 ; debug (off)
debugSendByte_wait:
Utils_WaitNanoSecs 100000, 0, r22
dec r17
brne debugSendByte_loop
cbi PORTA, PORTA2 ; debug (on)
Utils_WaitNanoSecs 200000, 0, r22 ; end with 2t low
sbi PORTA, PORTA2 ; debug (off)
out SREG, r15
sbi PORTA, PORTA2 ; debug (off)
nop
nop
cbi PORTA, PORTA2 ; debug (on)
Utils_WaitNanoSecs 100000, 0, r22 ; start with 2t low
debugSendByte_loop:
lsr r16
brcs debugSendByte_sendLow
cbi PORTA, PORTA2 ; debug (on)
rjmp debugSendByte_wait
debugSendByte_sendLow:
sbi PORTA, PORTA2 ; debug (off)
debugSendByte_wait:
Utils_WaitNanoSecs 100000, 0, r22
dec r17
brne debugSendByte_loop
cbi PORTA, PORTA2 ; debug (on)
Utils_WaitNanoSecs 200000, 0, r22 ; end with 2t low
sbi PORTA, PORTA2 ; debug (off)
pop r22
pop r17
out SREG, r15
pop r15
ret