From 9d71ff27a7647db43ca383a0411d01b3ece74683 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 15 Dec 2024 22:54:38 +0100 Subject: [PATCH] avr: cleanup motion module. --- avr/main_all.asm | 9 ------ avr/modules/motion/main.asm | 61 ++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/avr/main_all.asm b/avr/main_all.asm index f730cb4..dd78341 100644 --- a/avr/main_all.asm +++ b/avr/main_all.asm @@ -219,15 +219,6 @@ runModules_ComEnd: rcall Ds18b20_Run #endif -#ifdef MODULES_MOTION - rcall Motion_Run -#endif - - -#ifdef MODULES_MOTION_LIGHT -; rcall MotionLight_Run -#endif - #ifdef MODULES_TCRT1000 rcall TCRT1K_Run diff --git a/avr/modules/motion/main.asm b/avr/modules/motion/main.asm index 5318f2d..2263d8a 100644 --- a/avr/modules/motion/main.asm +++ b/avr/modules/motion/main.asm @@ -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 -;.equ MOTION_SEND_3_AFTER = 50 ; repeat motion message after 5s -.equ MOTION_RESTART_AFTER = 100 ; restart motion report counter after 10s +; *************************************************************************** +; defs + +.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 motionDataBegin: -;motionCurrentState: .byte 1 -motionStateCounter: .byte 1 -motionUpCounter: .byte 1 + motionStateCounter: .byte 1 + motionUpCounter: .byte 1 motionDataEnd: +; *************************************************************************** +; code + .cseg +; --------------------------------------------------------------------------- +; @routine Motion_Init @global +; +; @return CFLAG set if okay, clear on error +; @clobbers R16, R17, X + Motion_Init: ; preset SRAM data area ldi xh, HIGH(motionDataBegin) ldi xl, LOW(motionDataBegin) clr r16 ldi r17, (motionDataEnd-motionDataBegin) - rcall Utils_FillSram + rcall Utils_FillSram ; (R17, X) ; setup pins cbi MOTION_DDR, MOTION_PIN ; set DATA port as input cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD sec ret +; @end + +; --------------------------------------------------------------------------- +; @routine Motion_Fini @global +; +; @clobbers none + Motion_Fini: cbi MOTION_DDR, MOTION_PIN ; set DATA port as input cbi MOTION_OUTPUT, MOTION_PIN ; disable internal pullup for TXD ret +; @end -Motion_Run: - clc - ret - - +; --------------------------------------------------------------------------- +; @routine Motion_Every100ms @global +; +; @clobbers any Motion_Every100ms: clr r16 @@ -76,7 +97,6 @@ Motion_Every100ms: ; reached 0, virtual state is now NO_MOTION sts motionStateCounter, r17 ret - Motion_Every100ms_up: ; motion is active, keep uptimer up ldi r17, MOTION_UPCOUNTER_VALUE @@ -102,10 +122,16 @@ Motion_Every100ms_send: rjmp Motion_SendReport Motion_Every100ms_end: ret +; @end +; --------------------------------------------------------------------------- +; @routine Motion_SendReport @global +; ; @param R18 sensor value +; @return CFLAG set if okay, cleared on error +; @clobbers any Motion_SendReport: ldi r16, 0xff ; destination address @@ -116,8 +142,9 @@ Motion_SendReport: clr r21 ldi xl, LOW(com2SendBuffer) ldi xh, HIGH(com2SendBuffer) - rcall CPRO_WriteReportValue - rjmp COM2_SendPacket + rcall CPRO_WriteReportValue ; (R16, R17, R18, R19, R20, R21) + rjmp COM2_SendPacket ; any (depending on implementation) +; @end