avr: added functions to change speed.
Main code might work at 8 MHz, but boot code is compiled for 1 MHz, so we need to set speed accordingly when rebooting into boot loader.
This commit is contained in:
29
avr/main.asm
29
avr/main.asm
@@ -1,5 +1,5 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2023 by Martin Preuss
|
||||
; copyright : (C) 2024 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
@@ -21,6 +21,7 @@
|
||||
;
|
||||
|
||||
main:
|
||||
cli
|
||||
; setup stack
|
||||
.ifdef SPH ; if SPH is defined
|
||||
ldi r16, High(RAMEND)
|
||||
@@ -30,6 +31,8 @@ main:
|
||||
out SPL, r16 ; init LSB stack pointer
|
||||
|
||||
; rcall watchdogOff ; turn off watchdog timer (sometimes it stays on after reboot)
|
||||
|
||||
rcall systemSetSpeed
|
||||
|
||||
rcall initModules
|
||||
|
||||
@@ -60,7 +63,7 @@ main:
|
||||
; sts twiMasterScanEnabled, r16
|
||||
|
||||
main_loop:
|
||||
rcall runModulesUntilIdle
|
||||
rcall runModules
|
||||
|
||||
sei ; make sure interrupts really are enabled
|
||||
; only modify SE, SM1 and SM0
|
||||
@@ -89,6 +92,7 @@ main_loop:
|
||||
|
||||
initModules:
|
||||
rcall Utils_Init
|
||||
rcall BaseTimer_Init ; unconditionally call this
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
rcall Timer_Init
|
||||
@@ -150,7 +154,7 @@ initModules:
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; runModulesUntilIdle
|
||||
; runModules
|
||||
;
|
||||
; Call run functions of the used modules. Add your routine calls here.
|
||||
;
|
||||
@@ -160,24 +164,20 @@ initModules:
|
||||
; - nothing
|
||||
; USED: depending on called routines
|
||||
|
||||
runModulesUntilIdle:
|
||||
|
||||
#ifdef MODULES_TIMER
|
||||
; TIMER module
|
||||
rcall Timer_Run
|
||||
#endif
|
||||
|
||||
runModules:
|
||||
rcall BaseTimer_Run
|
||||
|
||||
#ifdef MODULES_COM
|
||||
; COM module (call until carry flag cleared but at most 10 times to not starve other modules)
|
||||
ldi r16, 10
|
||||
runModulesUntilIdle_Com:
|
||||
runModules_Com:
|
||||
push r16
|
||||
rcall Com2_Run
|
||||
pop r16
|
||||
brcc runModulesUntilIdle_ComEnd
|
||||
brcc runModules_ComEnd
|
||||
dec r16
|
||||
brne runModulesUntilIdle_Com
|
||||
runModulesUntilIdle_ComEnd:
|
||||
brne runModules_Com
|
||||
runModules_ComEnd:
|
||||
|
||||
#endif
|
||||
|
||||
@@ -238,6 +238,7 @@ initialWait_l2: ; wait for 10ms
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef MODULES_LCD
|
||||
|
||||
printTimerMark:
|
||||
|
||||
Reference in New Issue
Block a user