avr: cleanup motion module.

This commit is contained in:
Martin Preuss
2024-12-15 22:54:38 +01:00
parent 090e178ed1
commit 9d71ff27a7
2 changed files with 44 additions and 26 deletions

View File

@@ -219,15 +219,6 @@ runModules_ComEnd:
rcall Ds18b20_Run rcall Ds18b20_Run
#endif #endif
#ifdef MODULES_MOTION
rcall Motion_Run
#endif
#ifdef MODULES_MOTION_LIGHT
; rcall MotionLight_Run
#endif
#ifdef MODULES_TCRT1000 #ifdef MODULES_TCRT1000
rcall TCRT1K_Run rcall TCRT1K_Run

View File

@@ -8,57 +8,78 @@
; *************************************************************************** ; ***************************************************************************
.equ MOTION_SEND_1_AFTER = 1 ; send motion message after 100ms ; ***************************************************************************
.equ MOTION_SEND_2_AFTER = 11 ; send motion message after 1100ms ; defs
;.equ MOTION_SEND_3_AFTER = 50 ; repeat motion message after 5s
.equ MOTION_RESTART_AFTER = 100 ; restart motion report counter after 10s .equ MOTION_SEND_1_AFTER = 1 ; send motion message after 100ms
.equ MOTION_SEND_2_AFTER = 11 ; send motion message after 1100ms
.equ MOTION_RESTART_AFTER = 100 ; restart motion report counter after 10s
.equ MOTION_UPCOUNTER_VALUE = 50 .equ MOTION_UPCOUNTER_VALUE = 50 ; keep MOTION state active for at least 5s
; ***************************************************************************
; data
.dseg .dseg
motionDataBegin: motionDataBegin:
;motionCurrentState: .byte 1 motionStateCounter: .byte 1
motionStateCounter: .byte 1 motionUpCounter: .byte 1
motionUpCounter: .byte 1
motionDataEnd: motionDataEnd:
; ***************************************************************************
; code
.cseg .cseg
; ---------------------------------------------------------------------------
; @routine Motion_Init @global
;
; @return CFLAG set if okay, clear on error
; @clobbers R16, R17, X
Motion_Init: Motion_Init:
; preset SRAM data area ; preset SRAM data area
ldi xh, HIGH(motionDataBegin) ldi xh, HIGH(motionDataBegin)
ldi xl, LOW(motionDataBegin) ldi xl, LOW(motionDataBegin)
clr r16 clr r16
ldi r17, (motionDataEnd-motionDataBegin) ldi r17, (motionDataEnd-motionDataBegin)
rcall Utils_FillSram rcall Utils_FillSram ; (R17, X)
; setup pins ; setup pins
cbi MOTION_DDR, MOTION_PIN ; set DATA port as input cbi MOTION_DDR, MOTION_PIN ; set DATA port as input
cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD
sec sec
ret ret
; @end
; ---------------------------------------------------------------------------
; @routine Motion_Fini @global
;
; @clobbers none
Motion_Fini: Motion_Fini:
cbi MOTION_DDR, MOTION_PIN ; set DATA port as input cbi MOTION_DDR, MOTION_PIN ; set DATA port as input
cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD
ret ret
; @end
Motion_Run: ; ---------------------------------------------------------------------------
clc ; @routine Motion_Every100ms @global
ret ;
; @clobbers any
Motion_Every100ms: Motion_Every100ms:
clr r16 clr r16
@@ -76,7 +97,6 @@ Motion_Every100ms:
; reached 0, virtual state is now NO_MOTION ; reached 0, virtual state is now NO_MOTION
sts motionStateCounter, r17 sts motionStateCounter, r17
ret ret
Motion_Every100ms_up: Motion_Every100ms_up:
; motion is active, keep uptimer up ; motion is active, keep uptimer up
ldi r17, MOTION_UPCOUNTER_VALUE ldi r17, MOTION_UPCOUNTER_VALUE
@@ -102,10 +122,16 @@ Motion_Every100ms_send:
rjmp Motion_SendReport rjmp Motion_SendReport
Motion_Every100ms_end: Motion_Every100ms_end:
ret ret
; @end
; ---------------------------------------------------------------------------
; @routine Motion_SendReport @global
;
; @param R18 sensor value ; @param R18 sensor value
; @return CFLAG set if okay, cleared on error
; @clobbers any
Motion_SendReport: Motion_SendReport:
ldi r16, 0xff ; destination address ldi r16, 0xff ; destination address
@@ -116,8 +142,9 @@ Motion_SendReport:
clr r21 clr r21
ldi xl, LOW(com2SendBuffer) ldi xl, LOW(com2SendBuffer)
ldi xh, HIGH(com2SendBuffer) ldi xh, HIGH(com2SendBuffer)
rcall CPRO_WriteReportValue rcall CPRO_WriteReportValue ; (R16, R17, R18, R19, R20, R21)
rjmp COM2_SendPacket rjmp COM2_SendPacket ; any (depending on implementation)
; @end