Skip to content

Commit e4353fa

Browse files
committed
cleanup
1 parent a67469f commit e4353fa

File tree

2 files changed

+18
-46
lines changed

2 files changed

+18
-46
lines changed

examples/nordic/nrf5x/src/blinky.zig

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,16 @@ pub const microzig_options = microzig.Options{
1818
pub fn main() !void {
1919
board.init();
2020

21-
uart.apply(.{
22-
.tx_pin = board.uart_tx,
23-
.rx_pin = board.uart_rx,
24-
});
25-
26-
nrf.uart.init_logger(uart);
27-
2821
while (true) {
2922
board.led1.toggle();
30-
std.log.info("Now: {}uS", .{time.get_time_since_boot().to_us()});
31-
std.log.info("period: {x}", .{time.period});
32-
std.log.info("INTENSET: {x:0>8}", .{microzig.chip.peripherals.RTC0.INTENSET.raw});
33-
std.log.info("Counter: {x:0>6}", .{microzig.chip.peripherals.RTC0.COUNTER.read().COUNTER});
34-
std.log.info("Interrupt en {}", .{microzig.cpu.interrupt.is_enabled(.RTC0)});
35-
std.log.info("Interrupt prio{}", .{microzig.cpu.interrupt.get_priority(.RTC0)});
3623
time.sleep_ms(500);
3724

38-
// board.led1.toggle();
39-
// board.led2.toggle();
40-
// std.log.info("Now: {}", .{time.get_time_since_boot()});
41-
// time.sleep_ms(500);
42-
//
43-
// board.led2.toggle();
44-
// board.led3.toggle();
45-
// std.log.info("Now: {}", .{time.get_time_since_boot()});
46-
// time.sleep_ms(500);
25+
board.led1.toggle();
26+
board.led2.toggle();
27+
time.sleep_ms(500);
28+
29+
board.led2.toggle();
30+
board.led3.toggle();
31+
time.sleep_ms(500);
4732
}
4833
}

port/nordic/nrf5x/src/hal/time.zig

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
///
22
/// Basic timekeeping for the nRF5x series MCUs.
33
///
4-
/// This module uses RTC0 and hogs CC[3]
4+
/// This module uses RTC0 and hogs CC[2]
55
/// It also sets up an interrupt to fire at certain values so that we are able to count them and
66
/// keep time for centuries.
77
const std = @import("std");
@@ -18,10 +18,9 @@ const version: enum {
1818
else => compatibility.unsupported_chip("time"),
1919
};
2020

21-
const timer = microzig.chip.peripherals.TIMER0; // DELETEME
2221
const rtc = microzig.chip.peripherals.RTC0;
2322
const interrupts = microzig.chip.peripherals.interrupts;
24-
const COMPARE_INDEX = 3;
23+
const COMPARE_INDEX = 2;
2524
const TIMER_BITS = 23;
2625

2726
// Must use @atomic to load an store from here.
@@ -35,26 +34,21 @@ pub fn init() void {
3534
// 'period' on two different events:
3635
// First, when it hits the halfway point, and again on overflow.
3736

38-
// TODO: Put this in clocks hal
39-
// Set clock source
37+
// TODO: Use clocks hal
38+
// Set clock source and start clock
4039
microzig.chip.peripherals.CLOCK.LFCLKSRC.modify(.{ .SRC = .RC });
4140
// Start LFCLK
4241
microzig.chip.peripherals.CLOCK.TASKS_LFCLKSTART.write_raw(1);
42+
// Enable RTC0 interrupt
4343
microzig.cpu.interrupt.enable(.RTC0);
44-
microzig.cpu.interrupt.enable_interrupts();
45-
// microzip.cpu
4644

4745
// Enable interrupt firing on compare AND on overflow
48-
rtc.INTENSET.write_raw(0x00080002);
49-
// rtc.INTENSET.modify(.{
50-
// // .TICK = .Enabled, // This triggers!
51-
// .COMPARE3 = .Enabled,
52-
// .OVRFLW = .Enabled,
53-
// });
46+
rtc.INTENSET.modify(.{
47+
.COMPARE2 = .Enabled,
48+
.OVRFLW = .Enabled,
49+
});
5450
// Set the comparator to trigger on overflow of bottom 23 bits
55-
rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x8000 }); // DELETEME Just to not have to wait too
56-
// long for the interrupt to fire
57-
// rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x800000 });
51+
rtc.CC[COMPARE_INDEX].write(.{ .COMPARE = 0x800000 });
5852

5953
// Clear counter, then start timer
6054
switch (version) {
@@ -70,27 +64,20 @@ pub fn init() void {
7064

7165
// Wait for clear
7266
while (rtc.COUNTER.read().COUNTER != 0) {}
73-
// TODO: Set priority
74-
// Enable interrupt
75-
// TODO: Use an interrupt hal
76-
// VectorTable.RTC0 = rtc_overflow_interrupt;
7767
}
7868

7969
/// Handle both overflow and compare interrupts. Update the period which acts as the high bits of
8070
/// the elapsed time.
8171
pub fn rtc_overflow_interrupt() callconv(.c) void {
8272
if (rtc.EVENTS_OVRFLW.raw == 1) {
83-
rtc.EVENTS_OVRFLW.raw = 0;
84-
std.log.info("overflow!", .{}); // DELETEME
73+
rtc.EVENTS_OVRFLW.write_raw(0);
8574
next_period();
8675
}
8776

8877
if (rtc.EVENTS_COMPARE[COMPARE_INDEX].raw == 1) {
8978
rtc.EVENTS_COMPARE[COMPARE_INDEX].write_raw(0);
90-
std.log.info("compare!", .{}); // DELETEME
9179
next_period();
9280
}
93-
@panic("lol");
9481
}
9582

9683
inline fn next_period() void {

0 commit comments

Comments
 (0)