blob: 5401933eb7b4be881748375b1ab268e732743e3c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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);
|