main.asm: CLI while measuring and preparing packet. Directly call onSystemStart.

This commit is contained in:
Martin Preuss
2023-02-06 21:55:10 +01:00
parent 7e3dfa12fa
commit 4d4bdf3203
2 changed files with 39 additions and 49 deletions

View File

@@ -15,6 +15,9 @@ main:
rcall initModules rcall initModules
sei ; Enable interrupts sei ; Enable interrupts
rcall onSystemStart
ldi xl, LOW(blinkPattern) ; debug: set blink pattern ldi xl, LOW(blinkPattern) ; debug: set blink pattern
ldi xh, HIGH(blinkPattern) ldi xh, HIGH(blinkPattern)
ldi zl, LOW(ledA3Flash) ldi zl, LOW(ledA3Flash)
@@ -245,39 +248,44 @@ printSendStats:
#ifdef MODULES_COM #ifdef MODULES_COM
Main_SendValueMsg: Main_SendValueMsg:
lds r16, comAddress ; do we have an address assigned? in r15, SREG
tst r16 push r15
breq sendValueMsg_done ; no, do nothing cli
; send message for current temp lds r16, comAddress ; do we have an address assigned?
lds r22, si7021Flags tst r16
mov r16, r22 breq sendValueMsg_done ; no, do nothing
andi r16, SI7021_FLAGS_TEMP_VALID ; send message for current temp
breq sendValueMsg_checkHum lds r22, si7021Flags
ldi r16, 0xff ; destination address mov r16, r22
ldi r17, VALUE_ID_TEMP1 ; value id andi r16, SI7021_FLAGS_TEMP_VALID
push r22 breq sendValueMsg_checkHum
ldi r22, AQHOME_VALUETYPE_TEMP ldi r16, 0xff ; destination address
lds r18, si7021LastTemp ; value ldi r17, VALUE_ID_TEMP1 ; value id
lds r19, si7021LastTemp+1 push r22
ldi r20, 100 ; denominator ldi r22, AQHOME_VALUETYPE_TEMP
clr r21 lds r18, si7021LastTemp ; value
rcall CPRO_EnqueueValue lds r19, si7021LastTemp+1
pop r22 ldi r20, 100 ; denominator
clr r21
rcall CPRO_EnqueueValue
pop r22
sendValueMsg_checkHum: sendValueMsg_checkHum:
mov r16, r22 mov r16, r22
andi r16, SI7021_FLAGS_HUM_VALID andi r16, SI7021_FLAGS_HUM_VALID
breq sendValueMsg_done breq sendValueMsg_done
ldi r16, 0xff ; destination address ldi r16, 0xff ; destination address
ldi r17, VALUE_ID_HUM1 ; value id ldi r17, VALUE_ID_HUM1 ; value id
push r22 push r22
ldi r22, AQHOME_VALUETYPE_HUMIDITY ldi r22, AQHOME_VALUETYPE_HUMIDITY
lds r18, si7021LastHumidity ; value lds r18, si7021LastHumidity ; value
lds r19, si7021LastHumidity+1 lds r19, si7021LastHumidity+1
ldi r20, 1 ; denominator ldi r20, 1 ; denominator
clr r21 clr r21
rcall CPRO_EnqueueValue rcall CPRO_EnqueueValue
pop r22 pop r22
sendValueMsg_done: sendValueMsg_done:
pop r15
out SREG, r15
ret ret
#endif #endif
#endif #endif

View File

@@ -6,8 +6,6 @@
.equ TIMER_FLAGS_100MS = 1 .equ TIMER_FLAGS_100MS = 1
.equ TIMER_FLAGS_1S = 2 .equ TIMER_FLAGS_1S = 2
.equ TIMER_STATE_SYSSTART = 8 ; onSysStart was already called
@@ -19,7 +17,6 @@
timerModuleData: timerModuleData:
timerModuleTickCounter: .byte 1 ; only low byte used timerModuleTickCounter: .byte 1 ; only low byte used
timerModuleFlags: .byte 1 timerModuleFlags: .byte 1
timerModuleState: .byte 1
timerModuleCounter10s: .byte 1 timerModuleCounter10s: .byte 1
timerModuleCounter1m: .byte 1 timerModuleCounter1m: .byte 1
timerModuleCounterSecs: .byte 4 timerModuleCounterSecs: .byte 4
@@ -100,25 +97,10 @@ Timer_Fini:
Timer_Run: Timer_Run:
in r15, SREG in r15, SREG
cli cli
lds r18, timerModuleState
mov r16, r18 ; r18: state
ori r16, TIMER_STATE_SYSSTART
sts timerModuleState, r16
lds r17, timerModuleFlags lds r17, timerModuleFlags
clr r16 clr r16
sts timerModuleFlags, r16 sts timerModuleFlags, r16
out SREG, r15 ; restore global IRQ flag out SREG, r15 ; restore global IRQ flag
; call onSystemStart when first run
mov r16, r18
andi r16, TIMER_STATE_SYSSTART
brne Timer_Run_check100
push r17
rcall onSystemStart
pop r17
Timer_Run_check100:
mov r16, r17 mov r16, r17
andi r16, TIMER_FLAGS_100MS andi r16, TIMER_FLAGS_100MS
breq Timer_Run_l1 breq Timer_Run_l1