com2w: simplified module.

This commit is contained in:
Martin Preuss
2025-09-01 23:23:30 +02:00
parent 5ae7f821e4
commit 3270a71cb0

View File

@@ -10,6 +10,8 @@
#ifndef AVR_MODULES_COM2W_COM2W_H
#define AVR_MODULES_COM2W_COM2W_H
; only currently working com2w module!
.macro M_COM2WCLKSETLOW
@@ -210,7 +212,6 @@ com2wReceiveNextPkg_copyLoop:
#ifdef MODULES_LED_ACTIVITY
rcall LedActivity_Trigger ; (r16)
#endif
sec
rjmp com2wReceiveNextPkg_end
com2wReceiveNextPkg_eCrc:
push r16
@@ -226,7 +227,6 @@ com2wReceiveNextPkg_eMissed:
; fall-through to release buffer
com2wReceiveNextPkg_relBuffer:
rcall NET_Buffer_ReleaseByNum ; (R16, X)
clc
com2wReceiveNextPkg_end:
ret
; @end
@@ -370,7 +370,6 @@ com2wSendByte_sent:
; Receive a packet into buffer pointed to by X.
; Expects interrupts to be disabled.
;
; @param R18 COM address to listen to
; @param R19 max buffer size
; @param X buffer to receive to
; @return CFLAG set if msg received, cleared on error (see R16)
@@ -378,30 +377,16 @@ com2wSendByte_sent:
; @clobbers r16, r17, r18, r19, r20, r22, r24, r25, X
com2wRecvMsg:
mov r21, r18 ; address
; check buffer size
subi r19, 2
brcs com2wRecvMsg_eBadSize
; read destination address
rcall com2wRecvByte ; (r17, r18, r20, r22)
brcc com2wRecvMsg_eIo
; check destination address
rjmp com2wRecvMsg_forMe ; DEBUG: don't check address
cp r16, r21
breq com2wRecvMsg_forMe
cpi r16, 0xff
breq com2wRecvMsg_forMe
clr r16
rjmp com2wRecvMsg_clcRet
com2wRecvMsg_forMe:
; store in buffer
subi r19, 1
brcs com2wRecvMsg_eBadSize
st X+, r16
; read remaining msg size
rcall com2wRecvByte ; (r17, r18, r20, r22)
brcc com2wRecvMsg_eIo
; store in buffer
subi r19, 1
brcs com2wRecvMsg_eBadSize
st X+, r16
inc r16 ; account for CRC byte
sub r19, r16
@@ -468,10 +453,10 @@ com2wRecvByte:
ldi r17, 8
clr r16
com2wRecvByte_loop:
ldi r20, 50 ; wait up to 500us for clock low
ldi r20, 100 ; wait up to 1ms for clock low
rcall com2wWaitForClockLowMulti10Us ; (R20, R22)
brcc com2wRecvByte_end
ldi r20, 100 ; wait up to 1ms for clock high
ldi r20, 100 ; wait up to 1ms for clock high
rcall com2wWaitForClockHighMulti10Us ; (R20, R22)
brcc com2wRecvByte_end
; handle received bit