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

View File

@@ -6,8 +6,6 @@
.equ TIMER_FLAGS_100MS = 1
.equ TIMER_FLAGS_1S = 2
.equ TIMER_STATE_SYSSTART = 8 ; onSysStart was already called
@@ -19,7 +17,6 @@
timerModuleData:
timerModuleTickCounter: .byte 1 ; only low byte used
timerModuleFlags: .byte 1
timerModuleState: .byte 1
timerModuleCounter10s: .byte 1
timerModuleCounter1m: .byte 1
timerModuleCounterSecs: .byte 4
@@ -100,25 +97,10 @@ Timer_Fini:
Timer_Run:
in r15, SREG
cli
lds r18, timerModuleState
mov r16, r18 ; r18: state
ori r16, TIMER_STATE_SYSSTART
sts timerModuleState, r16
lds r17, timerModuleFlags
clr r16
sts timerModuleFlags, r16
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
andi r16, TIMER_FLAGS_100MS
breq Timer_Run_l1