avr: use new code in latest nodes.
This commit is contained in:
102
avr/main_all.asm
102
avr/main_all.asm
@@ -36,12 +36,11 @@ main:
|
||||
rcall Utils_Init
|
||||
rcall Utils_SetupUid
|
||||
rcall initModules
|
||||
rcall initialWait
|
||||
rcall Utils_InitialWait
|
||||
sei ; Enable interrupts
|
||||
|
||||
rcall onSystemStart
|
||||
|
||||
|
||||
#ifdef MODULES_LED
|
||||
ldi xl, LOW(blinkPattern) ; debug: set blink pattern
|
||||
ldi xh, HIGH(blinkPattern)
|
||||
@@ -52,17 +51,13 @@ main:
|
||||
rcall Led_SetPattern
|
||||
#endif
|
||||
|
||||
; sbi DDRA, PORTA2 ; debug
|
||||
; sbi PINA, PORTA2 ; debug (toggle)
|
||||
; cbi PORTA, PORTA2 ; debug (on)
|
||||
; sbi PORTA, PORTA2 ; debug (off)
|
||||
|
||||
; ldi r16, 1
|
||||
; sts twiMasterScanEnabled, r16
|
||||
|
||||
main_loop:
|
||||
rcall runModules
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
rcall handleMessages
|
||||
#endif
|
||||
|
||||
; only modify SE, SM1 and SM0
|
||||
cli
|
||||
in r16, MCUCR
|
||||
@@ -71,7 +66,7 @@ main_loop:
|
||||
and r16, r17
|
||||
ori r16, (1<<SE) ; sleep mode "idle", enable
|
||||
out MCUCR, r16
|
||||
sei ; make sure interrupts really are enabled
|
||||
sei ; make sure interrupts really are enabled
|
||||
sleep ; sleep, wait for interrupt
|
||||
rjmp main_loop
|
||||
|
||||
@@ -79,20 +74,17 @@ main_loop:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; initModules
|
||||
; @routine initModules
|
||||
;
|
||||
; Call init functions of the used modules. Add your routine calls here.
|
||||
;
|
||||
; IN:
|
||||
; - nothing
|
||||
; OUT:
|
||||
; - nothing
|
||||
; USED: depending on called routines
|
||||
|
||||
initModules:
|
||||
; rcall Utils_Init
|
||||
rcall BaseTimer_Init ; unconditionally call this
|
||||
|
||||
#ifdef MODULES_CLOCK
|
||||
rcall Clock_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
rcall Timer_Init
|
||||
#endif
|
||||
@@ -113,6 +105,19 @@ initModules:
|
||||
rcall Com2_Init ; init COM module
|
||||
rcall CPRO_Init ; init COM protocol module
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
rcall NET_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_UART_BITBANG
|
||||
rcall UART_BitBang_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
rcall Motion_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_TWI_MASTER
|
||||
rcall TWI_Master_Init
|
||||
#endif
|
||||
@@ -151,10 +156,6 @@ initModules:
|
||||
rcall SK6812_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
rcall Motion_Init
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
rcall MotionLight_Init
|
||||
#endif
|
||||
@@ -169,6 +170,7 @@ initModules:
|
||||
|
||||
; done
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
@@ -216,11 +218,6 @@ runModules_ComEnd:
|
||||
rcall Ds18b20_Run
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_MOTION
|
||||
rcall Motion_Run
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef MODULES_MOTION_LIGHT
|
||||
; rcall MotionLight_Run
|
||||
#endif
|
||||
@@ -235,36 +232,29 @@ runModules_ComEnd:
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MODULES_NETWORK
|
||||
; ---------------------------------------------------------------------------
|
||||
; initialWait
|
||||
;
|
||||
; Initial wait to desync nodes.
|
||||
;
|
||||
; This routine waits for between 10 to 2560 milliseconds (derived from UID)
|
||||
;
|
||||
; IN:
|
||||
; - nothing
|
||||
; OUT:
|
||||
; - nothing
|
||||
; USED: r16, r17, r18, r19, r20, r21, r22, X
|
||||
; @routine handleMessages
|
||||
|
||||
initialWait:
|
||||
; setup initial wait loop
|
||||
rcall Utils_ReadUid ; (R16, X)
|
||||
clr r16
|
||||
eor r16, r18
|
||||
eor r16, r19
|
||||
eor r16, r20
|
||||
eor r16, r21
|
||||
|
||||
initialWait_l1: ; wait R16 x 10 milliseconds
|
||||
ldi r17, 200
|
||||
initialWait_l2: ; wait for 10ms
|
||||
rcall Utils_WaitFor50MicroSecs ; (R22)
|
||||
dec r17
|
||||
brne initialWait_l2
|
||||
dec r16
|
||||
brne initialWait_l1
|
||||
handleMessages:
|
||||
rcall NET_GetNextIncomingMsgNum ; R16=msg num
|
||||
brcc handleMessages_end
|
||||
rcall NET_Buffer_Locate ; X=buffer addr (R17)
|
||||
push r16
|
||||
; handle messages
|
||||
ldi yl, LOW(uart_bitbang_iface)
|
||||
ldi yh, HIGH(uart_bitbang_iface)
|
||||
rcall AppNetwork_HandleMsg
|
||||
; add more here
|
||||
pop r16
|
||||
rcall NET_Buffer_ReleaseByNum
|
||||
sec
|
||||
handleMessages_end:
|
||||
ret
|
||||
; @end
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user