|
1 | 1 | /// |
2 | 2 | /// Basic timekeeping for the nRF5x series MCUs. |
3 | 3 | /// |
4 | | -/// This module hogs TIMER0. |
5 | | -/// It uses CC1 as the register to read the current count from. |
| 4 | +/// This module uses RTC0 and hogs CC[3] |
6 | 5 | /// It also sets up an interrupt to fire at certain values so that we are able to count them and |
7 | 6 | /// keep time for centuries. |
8 | 7 | const std = @import("std"); |
@@ -41,12 +40,17 @@ pub fn init() void { |
41 | 40 | microzig.chip.peripherals.CLOCK.LFCLKSRC.modify(.{ .SRC = .RC }); |
42 | 41 | // Start LFCLK |
43 | 42 | microzig.chip.peripherals.CLOCK.TASKS_LFCLKSTART.write_raw(1); |
| 43 | + microzig.cpu.interrupt.enable(.RTC0); |
| 44 | + microzig.cpu.interrupt.enable_interrupts(); |
| 45 | + // microzip.cpu |
44 | 46 |
|
45 | 47 | // Enable interrupt firing on compare AND on overflow |
46 | | - rtc.INTENSET.modify(.{ |
47 | | - .COMPARE3 = .Enabled, |
48 | | - .OVRFLW = .Enabled, |
49 | | - }); |
| 48 | + rtc.INTENSET.write_raw(0x00080002); |
| 49 | + // rtc.INTENSET.modify(.{ |
| 50 | + // // .TICK = .Enabled, // This triggers! |
| 51 | + // .COMPARE3 = .Enabled, |
| 52 | + // .OVRFLW = .Enabled, |
| 53 | + // }); |
50 | 54 | // Set the comparator to trigger on overflow of bottom 23 bits |
51 | 55 | rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x8000 }); // DELETEME Just to not have to wait too |
52 | 56 | // long for the interrupt to fire |
@@ -86,6 +90,7 @@ pub fn rtc_overflow_interrupt() callconv(.c) void { |
86 | 90 | std.log.info("compare!", .{}); // DELETEME |
87 | 91 | next_period(); |
88 | 92 | } |
| 93 | + @panic("lol"); |
89 | 94 | } |
90 | 95 |
|
91 | 96 | inline fn next_period() void { |
|
0 commit comments