|
27 | 27 |
|
28 | 28 | #include <stdint.h> |
29 | 29 | #include "supervisor/port.h" |
| 30 | +#include "supervisor/shared/tick.h" |
30 | 31 | #include "boards/board.h" |
31 | | -#include "tick.h" |
32 | 32 | #include "irq.h" |
33 | 33 | #include "csr.h" |
34 | 34 |
|
| 35 | +// Global millisecond tick count. 1024 per second because most RTCs are clocked with 32.768khz |
| 36 | +// crystals. |
| 37 | +volatile uint64_t raw_ticks = 0; |
| 38 | +volatile int subsecond = 0; |
| 39 | +__attribute__((section(".ramtext"))) |
| 40 | +void SysTick_Handler(void) { |
| 41 | + timer0_ev_pending_write(1); |
| 42 | + raw_ticks += 1; |
| 43 | + subsecond += 1; |
| 44 | + // We track subsecond ticks so that we can increment raw_ticks one extra every 40 ms. We do this |
| 45 | + // every 40 except 0 to make it 24 increments and not 25. |
| 46 | + if (subsecond == 1000) { |
| 47 | + subsecond = 0; |
| 48 | + } else if (subsecond % 40 == 0) { |
| 49 | + raw_ticks += 1; |
| 50 | + } |
| 51 | + supervisor_tick(); |
| 52 | +} |
| 53 | + |
| 54 | +static void tick_init(void) { |
| 55 | + int t; |
| 56 | + |
| 57 | + timer0_en_write(0); |
| 58 | + t = CONFIG_CLOCK_FREQUENCY / 1000; // 1000 kHz tick |
| 59 | + timer0_reload_write(t); |
| 60 | + timer0_load_write(t); |
| 61 | + timer0_en_write(1); |
| 62 | + timer0_ev_enable_write(1); |
| 63 | + timer0_ev_pending_write(1); |
| 64 | + irq_setmask(irq_getmask() | (1 << TIMER0_INTERRUPT)); |
| 65 | +} |
| 66 | + |
35 | 67 | safe_mode_t port_init(void) { |
36 | 68 | irq_setmask(0); |
37 | 69 | irq_setie(1); |
@@ -83,3 +115,21 @@ void port_set_saved_word(uint32_t value) { |
83 | 115 | uint32_t port_get_saved_word(void) { |
84 | 116 | return _ebss; |
85 | 117 | } |
| 118 | + |
| 119 | +uint64_t port_get_raw_ticks(uint8_t* subticks) { |
| 120 | + return raw_ticks; |
| 121 | +} |
| 122 | + |
| 123 | +// Enable 1/1024 second tick. |
| 124 | +void port_enable_tick(void) { |
| 125 | +} |
| 126 | + |
| 127 | +// Disable 1/1024 second tick. |
| 128 | +void port_disable_tick(void) { |
| 129 | +} |
| 130 | + |
| 131 | +void port_interrupt_after_ticks(uint32_t ticks) { |
| 132 | +} |
| 133 | + |
| 134 | +void port_sleep_until_interrupt(void) { |
| 135 | +} |
0 commit comments