Skip to content

Commit

Permalink
rtc
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewleech committed Mar 30, 2024
1 parent 85abfd6 commit 4c0ee29
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 0 additions & 2 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,6 @@ static inline mp_uint_t disable_irq(void) {

#endif

#define MICROPY_SOFT_TIMER_TICKS_MS uwTick

// Additional entries for use with pendsv_schedule_dispatch.
#ifndef MICROPY_BOARD_PENDSV_ENTRIES
#define MICROPY_BOARD_PENDSV_ENTRIES
Expand Down
28 changes: 20 additions & 8 deletions ports/nrf/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,15 @@
#include "nrf_clock.h"
#endif

volatile uint32_t uwTick = 0;

void SysTick_Handler(void) {
uint32_t next_tick = uwTick + 1;
uwTick = next_tick;
// void SysTick_Handler(void) {
// uint32_t next_tick = uwTick + 1;
// uwTick = next_tick;

if (soft_timer_next == next_tick) {
pendsv_schedule_dispatch(PENDSV_DISPATCH_SOFT_TIMER, soft_timer_handler);
}
}
// if (soft_timer_next == next_tick) {
// pendsv_schedule_dispatch(PENDSV_DISPATCH_SOFT_TIMER, soft_timer_handler);
// }
// }

#if MICROPY_PY_TIME_TICKS

Expand Down Expand Up @@ -108,6 +107,19 @@ static void rtc_irq_time(nrfx_rtc_int_type_t event) {
if (event == NRFX_RTC_INT_COMPARE0) {
RTC_RESCHEDULE_CC(rtc1, 0, RTC_TICK_INCREASE_MSEC)
}

if (event == NRFX_RTC_INT_COMPARE1) {
pendsv_schedule_dispatch(PENDSV_DISPATCH_SOFT_TIMER, soft_timer_handler);
}
}

uint32_t soft_timer_get_ms(void) {
return mp_hal_ticks_ms();
}

void soft_timer_schedule_at_ms(uint32_t ticks_ms) {
uint32_t counter = (uint32_t)((uint64_t)ticks_ms * 4096 / 125);
nrfx_rtc_cc_set(&rtc1, 1, nrfx_rtc_counter_get(&rtc1) + counter, true); \
}

void rtc1_init_time_ticks(void) {
Expand Down

0 comments on commit 4c0ee29

Please sign in to comment.