diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-06-19 21:43:26 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-07-04 10:11:02 -0400 |
commit | 045bfa4e8d177ca934815dd16fa8700543578328 (patch) | |
tree | 442330c5a3730c51c9f3d44416f0b501ddc445e1 /src/rp2040/timer.c | |
parent | 20c597635650d6a0944f9b6e33c438508a0c691f (diff) | |
download | kutter-045bfa4e8d177ca934815dd16fa8700543578328.tar.gz kutter-045bfa4e8d177ca934815dd16fa8700543578328.tar.xz kutter-045bfa4e8d177ca934815dd16fa8700543578328.zip |
rp2040: Add initial support for the rp2040 mcu
Support the rp2040 (as tested on a Raspberry Pi Pico board). This
adds basic uart, timer, gpio, and watchdog support.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/rp2040/timer.c')
-rw-r--r-- | src/rp2040/timer.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/rp2040/timer.c b/src/rp2040/timer.c new file mode 100644 index 00000000..5401933e --- /dev/null +++ b/src/rp2040/timer.c @@ -0,0 +1,70 @@ +// rp2040 timer support +// +// Copyright (C) 2021 Kevin O'Connor <kevin@koconnor.net> +// +// This file may be distributed under the terms of the GNU GPLv3 license. + +#include "board/armcm_boot.h" // armcm_enable_irq +#include "board/irq.h" // irq_disable +#include "board/misc.h" // timer_read_time +#include "board/timer_irq.h" // timer_dispatch_many +#include "command.h" // DECL_SHUTDOWN +#include "hardware/structs/resets.h" // RESETS_RESET_UART0_BITS +#include "hardware/structs/timer.h" // RESETS_RESET_UART0_BITS +#include "internal.h" // enable_pclock +#include "sched.h" // DECL_INIT + + +/**************************************************************** + * Low level timer code + ****************************************************************/ + +// Return the current time (in absolute clock ticks). +uint32_t +timer_read_time(void) +{ + return timer_hw->timerawl; +} + +static inline void +timer_set(uint32_t next) +{ + timer_hw->alarm[0] = next; +} + +// Activate timer dispatch as soon as possible +void +timer_kick(void) +{ + timer_set(timer_read_time() + 50); +} + + +/**************************************************************** + * Setup and irqs + ****************************************************************/ + +// Hardware timer IRQ handler - dispatch software timers +void __aligned(16) +TIMER0_IRQHandler(void) +{ + irq_disable(); + timer_hw->intr = 1; + uint32_t next = timer_dispatch_many(); + timer_set(next); + irq_enable(); +} + +void +timer_init(void) +{ + irq_disable(); + enable_pclock(RESETS_RESET_TIMER_BITS); + timer_hw->timelw = 0; + timer_hw->timehw = 0; + armcm_enable_irq(TIMER0_IRQHandler, TIMER_IRQ_0_IRQn, 2); + timer_hw->inte = 1; + timer_kick(); + irq_enable(); +} +DECL_INIT(timer_init); |