diff --git a/src/interrupts/hal/rp-timer-interrupts.adb b/src/devices/rp2040/rp-timer-interrupts.adb similarity index 97% rename from src/interrupts/hal/rp-timer-interrupts.adb rename to src/devices/rp2040/rp-timer-interrupts.adb index 374791a..4d7bc86 100644 --- a/src/interrupts/hal/rp-timer-interrupts.adb +++ b/src/devices/rp2040/rp-timer-interrupts.adb @@ -4,7 +4,7 @@ -- SPDX-License-Identifier: BSD-3-Clause -- with RP2040_SVD.Interrupts; -with RP2040_SVD.TIMER; use RP2040_SVD.TIMER; +with RP2040_SVD.TIMER; use RP2040_SVD.TIMER; with Cortex_M.Hints; with RP_Interrupts; with System; diff --git a/src/devices/rp2350/rp-clock.adb b/src/devices/rp2350/rp-clock.adb index 40ed582..01c7e38 100644 --- a/src/devices/rp2350/rp-clock.adb +++ b/src/devices/rp2350/rp-clock.adb @@ -5,7 +5,7 @@ -- with RP2350_SVD.CLOCKS; use RP2350_SVD.CLOCKS; with RP2350_SVD.PLL; use RP2350_SVD.PLL; -with RP2350_SVD.TICKS; +with RP2350_SVD.TICKS; use RP2350_SVD.TICKS; with RP2350_SVD.XOSC; with RP2350_SVD.ROSC; with RP.Reset; @@ -147,7 +147,9 @@ package body RP.Clock is end if; CLOCKS_Periph.FC0_REF_KHZ.FC0_REF_KHZ := FC0_REF_KHZ_FC0_REF_KHZ_Field (Reference / 1_000); - RP2350_SVD.TICKS.TICKS_Periph.TIMER0_CTRL.ENABLE := True; + TICKS_Periph.TIMER0_CTRL.ENABLE := False; + TICKS_Periph.TIMER0_CYCLES.TIMER0_CYCLES := UInt9 (Reference / 1_000_000); + TICKS_Periph.TIMER0_CTRL.ENABLE := True; end Initialize; procedure Enable diff --git a/src/devices/rp2350/rp-timer-interrupts.adb b/src/devices/rp2350/rp-timer-interrupts.adb new file mode 100644 index 0000000..5fca91e --- /dev/null +++ b/src/devices/rp2350/rp-timer-interrupts.adb @@ -0,0 +1,99 @@ +-- +-- Copyright 2021 (C) Jeremy Grosser +-- +-- SPDX-License-Identifier: BSD-3-Clause +-- +with RP2350_SVD.Interrupts; +with RP2350_SVD.TIMER0; use RP2350_SVD.TIMER0; +with Cortex_M.Hints; +with RP_Interrupts; +with System; + +package body RP.Timer.Interrupts is + + procedure IRQ_Handler is + begin + TIMER0_Periph.INTR.ALARM_2 := True; + end IRQ_Handler; + + procedure Enable + (This : in out Delays) + is + use RP2350_SVD.Interrupts; + use System; + begin + TIMER0_Periph.INTE.ALARM_2 := True; + + RP_Interrupts.Attach_Handler + (Handler => IRQ_Handler'Access, + Id => TIMER0_IRQ_2_Interrupt, + Prio => Interrupt_Priority'First); + + RP.Timer.Set_Debug_Pause (False, False); + end Enable; + + procedure Disable + (This : in out Delays) + is + begin + TIMER0_Periph.INTE.ALARM_2 := False; + end Disable; + + function Enabled + (This : Delays) + return Boolean + is (TIMER0_Periph.INTE.ALARM_2); + + procedure Delay_Until + (This : in out Delays; + T : Time) + is + begin + if T <= Clock then + return; + end if; + TIMER0_Periph.ALARM2 := UInt32 (T and 16#FFFFFFFF#); + loop + Cortex_M.Hints.Wait_For_Interrupt; + if Clock >= T then + return; + elsif TIMER0_Periph.INTS.ALARM_2 then + -- If the high byte of the timer rolled over but we still haven't + -- reached the target time, reset the alarm and go again + TIMER0_Periph.ALARM2 := UInt32 (T and 16#FFFFFFFF#); + end if; + end loop; + end Delay_Until; + + overriding + procedure Delay_Microseconds + (This : in out Delays; + Us : Integer) + is + Deadline : constant UInt64 := UInt64 (Clock) + UInt64 (Us); + begin + if Us > 0 then + while UInt64 (Clock) < Deadline loop + null; + end loop; + end if; + end Delay_Microseconds; + + overriding + procedure Delay_Milliseconds + (This : in out Delays; + Ms : Integer) + is + begin + Delay_Until (This, Clock + (1_000 * Time (Ms))); + end Delay_Milliseconds; + + overriding + procedure Delay_Seconds + (This : in out Delays; + S : Integer) + is + begin + Delay_Until (This, Clock + (1_000_000 * Time (S))); + end Delay_Seconds; +end RP.Timer.Interrupts; diff --git a/src/startup/rp2350/crt0.S b/src/startup/rp2350/crt0.S index 2d6d120..9c64e21 100644 --- a/src/startup/rp2350/crt0.S +++ b/src/startup/rp2350/crt0.S @@ -1,145 +1,12 @@ -# 0 "rp2_common/pico_crt0/crt0.S" -# 0 "" -# 0 "" -# 1 "rp2_common/pico_crt0/crt0.S" - - - - - - -# 1 "common/pico_base_headers/include/pico.h" 1 -# 26 "common/pico_base_headers/include/pico.h" -# 1 "common/pico_base_headers/include/pico/types.h" 1 -# 27 "common/pico_base_headers/include/pico.h" 2 -# 1 "/home/synack/src/rp2040_hal/scripts/include/pico/version.h" 1 -# 28 "common/pico_base_headers/include/pico.h" 2 - - - - - -# 1 "common/pico_base_headers/include/pico/config.h" 1 -# 19 "common/pico_base_headers/include/pico/config.h" -# 1 "/home/synack/src/rp2040_hal/scripts/include/pico/config_autogen.h" 1 -# 20 "common/pico_base_headers/include/pico/config.h" 2 -# 34 "common/pico_base_headers/include/pico.h" 2 - -# 1 "rp2350/pico_platform/include/pico/platform.h" 1 -# 23 "rp2350/pico_platform/include/pico/platform.h" -# 1 "rp2_common/pico_platform_compiler/include/pico/platform/compiler.h" 1 -# 18 "rp2_common/pico_platform_compiler/include/pico/platform/compiler.h" -# 1 "rp2350/hardware_regs/include/hardware/platform_defs.h" 1 -# 19 "rp2_common/pico_platform_compiler/include/pico/platform/compiler.h" 2 -# 24 "rp2350/pico_platform/include/pico/platform.h" 2 -# 1 "rp2_common/pico_platform_sections/include/pico/platform/sections.h" 1 -# 25 "rp2350/pico_platform/include/pico/platform.h" 2 -# 1 "rp2_common/pico_platform_panic/include/pico/platform/panic.h" 1 -# 26 "rp2350/pico_platform/include/pico/platform.h" 2 -# 1 "rp2350/hardware_regs/include/hardware/regs/addressmap.h" 1 -# 27 "rp2350/pico_platform/include/pico/platform.h" 2 -# 1 "rp2350/hardware_regs/include/hardware/regs/sio.h" 1 -# 28 "rp2350/pico_platform/include/pico/platform.h" 2 -# 36 "common/pico_base_headers/include/pico.h" 2 -# 1 "common/pico_base_headers/include/pico/error.h" 1 -# 37 "common/pico_base_headers/include/pico.h" 2 -# 8 "rp2_common/pico_crt0/crt0.S" 2 -# 1 "rp2350/pico_platform/include/pico/asm_helper.S" 1 -# 20 "rp2350/pico_platform/include/pico/asm_helper.S" -.macro pico_default_asm_setup - .syntax unified .cpu cortex-m33 .fpu fpv5-sp-d16 .thumb -.endm - - -.macro regular_func x -.global \x -.type \x,%function - -.thumb_func - -\x: -.endm - -.macro weak_func x -.weak \x -.type \x,%function - -.thumb_func - -\x: -.endm - -.macro regular_func_with_section x -.section .text.\x -regular_func \x -.endm - - -.macro wrapper_func x -regular_func __wrap_\x -.endm - -.macro weak_wrapper_func x -weak_func __wrap_\x -.endm - -.macro __pre_init_with_offset func, offset, priority_string1 -.section .preinit_array.\priority_string1 -.p2align 2 -.word \func + \offset -.endm - - -.macro __pre_init func, priority_string1 -__pre_init_with_offset func, 0, priority_string1 -.endm -# 9 "rp2_common/pico_crt0/crt0.S" 2 - -# 1 "rp2350/pico_platform/include/pico/platform/cpu_regs.h" 1 -# 21 "rp2350/pico_platform/include/pico/platform/cpu_regs.h" -# 1 "rp2350/hardware_regs/include/hardware/regs/m33.h" 1 -# 22 "rp2350/pico_platform/include/pico/platform/cpu_regs.h" 2 -# 11 "rp2_common/pico_crt0/crt0.S" 2 - - - -# 1 "common/pico_binary_info/include/pico/binary_info/defs.h" 1 -# 15 "rp2_common/pico_crt0/crt0.S" 2 -# 1 "common/boot_picobin_headers/include/boot/picobin.h" 1 -# 16 "rp2_common/pico_crt0/crt0.S" 2 -# 1 "rp2_common/pico_bootrom/include/pico/bootrom.h" 1 -# 11 "rp2_common/pico_bootrom/include/pico/bootrom.h" -# 1 "rp2_common/pico_bootrom/include/pico/bootrom_constants.h" 1 - - - - - - - -# 1 "rp2_common/boot_bootrom_headers/include/boot/bootrom_constants.h" 1 -# 9 "rp2_common/pico_bootrom/include/pico/bootrom_constants.h" 2 -# 12 "rp2_common/pico_bootrom/include/pico/bootrom.h" 2 -# 17 "rp2_common/pico_crt0/crt0.S" 2 - - - - - - - -pico_default_asm_setup - .section .vectors, "ax" .align 2 -.global __vectors, __VECTOR_TABLE -__VECTOR_TABLE: +.global __vectors __vectors: .word __StackTop .word _reset_handler @@ -158,115 +25,86 @@ __vectors: .word isr_pendsv .word isr_systick - - - - - - -.macro if_irq_word num func -.if \num < 52 -.word \func -.endif -.endm - - - - - -if_irq_word 0 isr_irq0 -if_irq_word 1 isr_irq1 -if_irq_word 2 isr_irq2 -if_irq_word 3 isr_irq3 -if_irq_word 4 isr_irq4 -if_irq_word 5 isr_irq5 -if_irq_word 6 isr_irq6 -if_irq_word 7 isr_irq7 -if_irq_word 8 isr_irq8 -if_irq_word 9 isr_irq9 -if_irq_word 10 isr_irq10 -if_irq_word 11 isr_irq11 -if_irq_word 12 isr_irq12 -if_irq_word 13 isr_irq13 -if_irq_word 14 isr_irq14 -if_irq_word 15 isr_irq15 -if_irq_word 16 isr_irq16 -if_irq_word 17 isr_irq17 -if_irq_word 18 isr_irq18 -if_irq_word 19 isr_irq19 -if_irq_word 20 isr_irq20 -if_irq_word 21 isr_irq21 -if_irq_word 22 isr_irq22 -if_irq_word 23 isr_irq23 -if_irq_word 24 isr_irq24 -if_irq_word 25 isr_irq25 -if_irq_word 26 isr_irq26 -if_irq_word 27 isr_irq27 -if_irq_word 28 isr_irq28 -if_irq_word 29 isr_irq29 -if_irq_word 30 isr_irq30 -if_irq_word 31 isr_irq31 -if_irq_word 32 isr_irq32 -if_irq_word 33 isr_irq33 -if_irq_word 34 isr_irq34 -if_irq_word 35 isr_irq35 -if_irq_word 36 isr_irq36 -if_irq_word 37 isr_irq37 -if_irq_word 38 isr_irq38 -if_irq_word 39 isr_irq39 -if_irq_word 40 isr_irq40 -if_irq_word 41 isr_irq41 -if_irq_word 42 isr_irq42 -if_irq_word 43 isr_irq43 -if_irq_word 44 isr_irq44 -if_irq_word 45 isr_irq45 -if_irq_word 46 isr_irq46 -if_irq_word 47 isr_irq47 -if_irq_word 48 isr_irq48 -if_irq_word 49 isr_irq49 -if_irq_word 50 isr_irq50 -if_irq_word 51 isr_irq51 -if_irq_word 52 isr_irq52 -if_irq_word 53 isr_irq53 -if_irq_word 54 isr_irq54 -if_irq_word 55 isr_irq55 -if_irq_word 56 isr_irq56 -if_irq_word 57 isr_irq57 -if_irq_word 58 isr_irq58 -if_irq_word 59 isr_irq59 -if_irq_word 60 isr_irq60 -if_irq_word 61 isr_irq61 -if_irq_word 62 isr_irq62 -if_irq_word 63 isr_irq63 -if_irq_word 64 isr_irq64 -if_irq_word 65 isr_irq65 -if_irq_word 66 isr_irq66 -if_irq_word 67 isr_irq67 -if_irq_word 68 isr_irq68 -if_irq_word 69 isr_irq69 -if_irq_word 70 isr_irq70 -if_irq_word 71 isr_irq71 -if_irq_word 72 isr_irq72 -if_irq_word 73 isr_irq73 -if_irq_word 74 isr_irq74 -if_irq_word 75 isr_irq75 -if_irq_word 76 isr_irq76 -if_irq_word 77 isr_irq77 -if_irq_word 78 isr_irq78 -if_irq_word 79 isr_irq79 - - - - - - - -.global __default_isrs_start -__default_isrs_start: - - - - +.word isr_irq0 +.word isr_irq1 +.word isr_irq2 +.word isr_irq3 +.word isr_irq4 +.word isr_irq5 +.word isr_irq6 +.word isr_irq7 +.word isr_irq8 +.word isr_irq9 +.word isr_irq10 +.word isr_irq11 +.word isr_irq12 +.word isr_irq13 +.word isr_irq14 +.word isr_irq15 +.word isr_irq16 +.word isr_irq17 +.word isr_irq18 +.word isr_irq19 +.word isr_irq20 +.word isr_irq21 +.word isr_irq22 +.word isr_irq23 +.word isr_irq24 +.word isr_irq25 +.word isr_irq26 +.word isr_irq27 +.word isr_irq28 +.word isr_irq29 +.word isr_irq30 +.word isr_irq31 +.word isr_irq32 +.word isr_irq33 +.word isr_irq34 +.word isr_irq35 +.word isr_irq36 +.word isr_irq37 +.word isr_irq38 +.word isr_irq39 +.word isr_irq40 +.word isr_irq41 +.word isr_irq42 +.word isr_irq43 +.word isr_irq44 +.word isr_irq45 +.word isr_irq46 +.word isr_irq47 +.word isr_irq48 +.word isr_irq49 +.word isr_irq50 +.word isr_irq51 +.word isr_irq52 +.word isr_irq53 +.word isr_irq54 +.word isr_irq55 +.word isr_irq56 +.word isr_irq57 +.word isr_irq58 +.word isr_irq59 +.word isr_irq60 +.word isr_irq61 +.word isr_irq62 +.word isr_irq63 +.word isr_irq64 +.word isr_irq65 +.word isr_irq66 +.word isr_irq67 +.word isr_irq68 +.word isr_irq69 +.word isr_irq70 +.word isr_irq71 +.word isr_irq72 +.word isr_irq73 +.word isr_irq74 +.word isr_irq75 +.word isr_irq76 +.word isr_irq77 +.word isr_irq78 +.word isr_irq79 .macro decl_isr_bkpt name .weak \name @@ -276,6 +114,10 @@ __default_isrs_start: bkpt #0 .endm +.macro decl_isr name +.weak \name +.thumb_set \name,__gnat_irq_trap +.endm decl_isr_bkpt isr_invalid decl_isr_bkpt isr_nmi @@ -284,132 +126,88 @@ decl_isr_bkpt isr_svcall decl_isr_bkpt isr_pendsv decl_isr_bkpt isr_systick -.global __default_isrs_end -__default_isrs_end: - -.altmacro -.macro decl_isr name - - -.weak \name - - - -.type \name,%function -.thumb_func -\name: -.endm - -.macro if_irq_decl num func -.if \num < 52 -decl_isr \func -.endif -.endm - -if_irq_decl 0 isr_irq0 -if_irq_decl 1 isr_irq1 -if_irq_decl 2 isr_irq2 -if_irq_decl 3 isr_irq3 -if_irq_decl 4 isr_irq4 -if_irq_decl 5 isr_irq5 -if_irq_decl 6 isr_irq6 -if_irq_decl 7 isr_irq7 -if_irq_decl 8 isr_irq8 -if_irq_decl 9 isr_irq9 -if_irq_decl 10 isr_irq10 -if_irq_decl 11 isr_irq11 -if_irq_decl 12 isr_irq12 -if_irq_decl 13 isr_irq13 -if_irq_decl 14 isr_irq14 -if_irq_decl 15 isr_irq15 -if_irq_decl 16 isr_irq16 -if_irq_decl 17 isr_irq17 -if_irq_decl 18 isr_irq18 -if_irq_decl 19 isr_irq19 -if_irq_decl 20 isr_irq20 -if_irq_decl 21 isr_irq21 -if_irq_decl 22 isr_irq22 -if_irq_decl 23 isr_irq23 -if_irq_decl 24 isr_irq24 -if_irq_decl 25 isr_irq25 -if_irq_decl 26 isr_irq26 -if_irq_decl 27 isr_irq27 -if_irq_decl 28 isr_irq28 -if_irq_decl 29 isr_irq29 -if_irq_decl 30 isr_irq30 -if_irq_decl 31 isr_irq31 -if_irq_decl 32 isr_irq32 -if_irq_decl 33 isr_irq33 -if_irq_decl 34 isr_irq34 -if_irq_decl 35 isr_irq35 -if_irq_decl 36 isr_irq36 -if_irq_decl 37 isr_irq37 -if_irq_decl 38 isr_irq38 -if_irq_decl 39 isr_irq39 -if_irq_decl 40 isr_irq40 -if_irq_decl 41 isr_irq41 -if_irq_decl 42 isr_irq42 -if_irq_decl 43 isr_irq43 -if_irq_decl 44 isr_irq44 -if_irq_decl 45 isr_irq45 -if_irq_decl 46 isr_irq46 -if_irq_decl 47 isr_irq47 -if_irq_decl 48 isr_irq48 -if_irq_decl 49 isr_irq49 -if_irq_decl 50 isr_irq50 -if_irq_decl 51 isr_irq51 -if_irq_decl 52 isr_irq52 -if_irq_decl 53 isr_irq53 -if_irq_decl 54 isr_irq54 -if_irq_decl 55 isr_irq55 -if_irq_decl 56 isr_irq56 -if_irq_decl 57 isr_irq57 -if_irq_decl 58 isr_irq58 -if_irq_decl 59 isr_irq59 -if_irq_decl 60 isr_irq60 -if_irq_decl 61 isr_irq61 -if_irq_decl 62 isr_irq62 -if_irq_decl 63 isr_irq63 -if_irq_decl 64 isr_irq64 -if_irq_decl 65 isr_irq65 -if_irq_decl 66 isr_irq66 -if_irq_decl 67 isr_irq67 -if_irq_decl 68 isr_irq68 -if_irq_decl 69 isr_irq69 -if_irq_decl 70 isr_irq70 -if_irq_decl 71 isr_irq71 -if_irq_decl 72 isr_irq72 -if_irq_decl 73 isr_irq73 -if_irq_decl 74 isr_irq74 -if_irq_decl 75 isr_irq75 -if_irq_decl 76 isr_irq76 -if_irq_decl 77 isr_irq77 -if_irq_decl 78 isr_irq78 -if_irq_decl 79 isr_irq79 - - - - - -.global __unhandled_user_irq -.thumb_func -__unhandled_user_irq: - mrs r0, ipsr - subs r0, #16 -.global unhandled_user_irq_num_in_r0 -unhandled_user_irq_num_in_r0: - bkpt #0 - - +decl_isr isr_irq0 +decl_isr isr_irq1 +decl_isr isr_irq2 +decl_isr isr_irq3 +decl_isr isr_irq4 +decl_isr isr_irq5 +decl_isr isr_irq6 +decl_isr isr_irq7 +decl_isr isr_irq8 +decl_isr isr_irq9 +decl_isr isr_irq10 +decl_isr isr_irq11 +decl_isr isr_irq12 +decl_isr isr_irq13 +decl_isr isr_irq14 +decl_isr isr_irq15 +decl_isr isr_irq16 +decl_isr isr_irq17 +decl_isr isr_irq18 +decl_isr isr_irq19 +decl_isr isr_irq20 +decl_isr isr_irq21 +decl_isr isr_irq22 +decl_isr isr_irq23 +decl_isr isr_irq24 +decl_isr isr_irq25 +decl_isr isr_irq26 +decl_isr isr_irq27 +decl_isr isr_irq28 +decl_isr isr_irq29 +decl_isr isr_irq30 +decl_isr isr_irq31 +decl_isr isr_irq32 +decl_isr isr_irq33 +decl_isr isr_irq34 +decl_isr isr_irq35 +decl_isr isr_irq36 +decl_isr isr_irq37 +decl_isr isr_irq38 +decl_isr isr_irq39 +decl_isr isr_irq40 +decl_isr isr_irq41 +decl_isr isr_irq42 +decl_isr isr_irq43 +decl_isr isr_irq44 +decl_isr isr_irq45 +decl_isr isr_irq46 +decl_isr isr_irq47 +decl_isr isr_irq48 +decl_isr isr_irq49 +decl_isr isr_irq50 +decl_isr isr_irq51 +decl_isr isr_irq52 +decl_isr isr_irq53 +decl_isr isr_irq54 +decl_isr isr_irq55 +decl_isr isr_irq56 +decl_isr isr_irq57 +decl_isr isr_irq58 +decl_isr isr_irq59 +decl_isr isr_irq60 +decl_isr isr_irq61 +decl_isr isr_irq62 +decl_isr isr_irq63 +decl_isr isr_irq64 +decl_isr isr_irq65 +decl_isr isr_irq66 +decl_isr isr_irq67 +decl_isr isr_irq68 +decl_isr isr_irq69 +decl_isr isr_irq70 +decl_isr isr_irq71 +decl_isr isr_irq72 +decl_isr isr_irq73 +decl_isr isr_irq74 +decl_isr isr_irq75 +decl_isr isr_irq76 +decl_isr isr_irq77 +decl_isr isr_irq78 +decl_isr isr_irq79 .section .binary_info_header, "a" - - - - - - - binary_info_header: .word 0x7188ebf2 .word __binary_info_start @@ -417,17 +215,11 @@ binary_info_header: .word data_cpy_table .word 0xe71aa390 - -# 1 "rp2_common/pico_crt0/embedded_start_block.inc.S" 1 -# 27 "rp2_common/pico_crt0/embedded_start_block.inc.S" +# See RM: 5.1.5.1 Blocks .section .embedded_block, "a" .p2align 2 embedded_block: .word 0xffffded3 - - - - .byte 0x42 .byte 0x1 # 51 "rp2_common/pico_crt0/embedded_start_block.inc.S" @@ -436,18 +228,9 @@ embedded_block: .byte (0x80 | 0x7f) .hword (embedded_block_end - embedded_block - 16 ) / 4 .byte 0 - .word embedded_end_block - embedded_block - - - - - .word 0xab123579 embedded_block_end: -# 310 "rp2_common/pico_crt0/crt0.S" 2 - - .section .reset, "ax" # 328 "rp2_common/pico_crt0/crt0.S" diff --git a/src/svd/rp2350_svd-interrupts.ads b/src/svd/rp2350_svd-interrupts.ads index 8300bc0..6a2d384 100644 --- a/src/svd/rp2350_svd-interrupts.ads +++ b/src/svd/rp2350_svd-interrupts.ads @@ -2,12 +2,10 @@ pragma Style_Checks (Off); -- Copyright (c) 2024 Raspberry Pi Ltd. SPDX-License-Identifier: BSD-3-Clause --- This spec has been automatically generated from rp2350.svd +-- This spec has been automatically generated from RP2350.svd -- Definition of the device's interrupts -package RP2350_SVD.Interrupts - with Preelaborate -is +package RP2350_SVD.Interrupts is ---------------- -- Interrupts --