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:
Martin Preuss
2024-09-13 21:41:38 +02:00
parent 2d09e22ec6
commit 7a5900be25
6 changed files with 111 additions and 18 deletions

View File

@@ -100,7 +100,7 @@
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp timerIrqOC0A ; OC0A
rjmp baseTimerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
@@ -129,6 +129,8 @@ firmwareStart: rjmp main
.include "common/utils_copy_sdram.asm"
.include "common/crc8.asm"
.include "modules/basetimer/main.asm"
#ifdef MODULES_TIMER
.include "modules/timer/main.asm"
#endif
@@ -244,6 +246,26 @@ timerList:
.include "main.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
ret
systemSetBootSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
; ---------------------------------------------------------------------------
; Called on first time run, i.e. on system start. No arguments, no results.

View File

@@ -100,7 +100,7 @@
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp timerIrqOC0A ; OC0A
rjmp baseTimerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
@@ -129,6 +129,8 @@ firmwareStart: rjmp main
.include "common/utils_copy_sdram.asm"
.include "common/crc8.asm"
.include "modules/basetimer/main.asm"
#ifdef MODULES_TIMER
.include "modules/timer/main.asm"
#endif
@@ -244,6 +246,26 @@ timerList:
.include "main.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
ret
systemSetBootSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
; ---------------------------------------------------------------------------
; Called on first time run, i.e. on system start. No arguments, no results.

View File

@@ -22,6 +22,7 @@
.equ clock=1000000 ; Define the clock frequency
;.equ clock=8000000 ; Define the clock frequency
@@ -104,7 +105,7 @@
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp timerIrqOC0A ; OC0A
rjmp baseTimerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
@@ -133,6 +134,8 @@ firmwareStart: rjmp main
.include "common/utils_copy_sdram.asm"
.include "common/crc8.asm"
.include "modules/basetimer/main.asm"
#ifdef MODULES_TIMER
.include "modules/timer/main.asm"
#endif
@@ -263,6 +266,28 @@ timerList:
.include "main.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
ret
systemSetBootSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
; ---------------------------------------------------------------------------
; Called on first time run, i.e. on system start. No arguments, no results.

View File

@@ -90,7 +90,7 @@
reti ; OC1A
reti ; OC1B
reti ; OVF1
rjmp timerIrqOC0A ; OC0A
rjmp baseTimerIrqOC0A ; OC0A
reti ; OC0B
reti ; OVF0
reti ; ACI
@@ -119,6 +119,8 @@ firmwareStart: rjmp main
.include "common/utils_copy_sdram.asm"
.include "common/crc8.asm"
.include "modules/basetimer/main.asm"
#ifdef MODULES_TIMER
.include "modules/timer/main.asm"
#endif
@@ -249,6 +251,26 @@ timerList:
.include "main.asm"
systemSetSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, 0
out CLKPR, r16
out CLKPR, r17
.endif
ret
systemSetBootSpeed:
.if clock == 8000000
ldi r16, (1<<CLKPCE)
ldi r17, (1<<CLKPS1) | (1<<CLKPS0)
out CLKPR, r16
out CLKPR, r17
.endif
ret
; ---------------------------------------------------------------------------
; Called on first time run, i.e. on system start. No arguments, no results.