Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions hw/bsp/nordic_pca10156/syscfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ syscfg.vals:
MYNEWT_DOWNLOADER: nrfutil
JLINK_TARGET: CORTEX-M33
MYNEWT_DOWNLOADER_MFG_IMAGE_FLASH_OFFSET: 0x0

syscfg.vals.BLE_CONTROLLER:
TIMER_0: 0
TIMER_5: 1
OS_CPUTIME_FREQ: 31250
# OS_CPUTIME_FREQ: 32768
OS_CPUTIME_TIMER_NUM: 5
BLE_LL_RFMGMT_ENABLE_TIME: 1500
26 changes: 8 additions & 18 deletions hw/mcu/nordic/nrf54lxx/src/hal_os_tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,12 @@ struct hal_os_tick {
};
struct hal_os_tick g_hal_os_tick;

uint64_t hal_grtc_counter_get(void);

static inline uint64_t
nrf54l_os_tick_counter(void)
{
uint32_t counterl_val, counterh_val, counterh;
uint64_t counter;

do {
counterl_val = nrf_grtc_sys_counter_low_get(NRF_GRTC);
counterh = nrf_grtc_sys_counter_high_get(NRF_GRTC);
counterh_val = counterh & NRF_GRTC_SYSCOUNTERH_VALUE_MASK;
} while (counterh & NRF_GRTC_SYSCOUNTERH_BUSY_MASK);

if (counterh & NRF_GRTC_SYSCOUNTERH_OVERFLOW_MASK) {
--counterh_val;
}

counter = ((uint64_t)counterh_val << 32) | counterl_val;
return counter;
return hal_grtc_counter_get();
}

static inline void
Expand Down Expand Up @@ -137,6 +125,9 @@ os_tick_idle(os_time_t ticks)
/* Set ocmp for wake up */
ocmp = g_hal_os_tick.lastocmp + (ticks * g_hal_os_tick.ticks_per_ostick);
nrf54l_os_idle_set_ocmp(ocmp);
nrf_grtc_event_clear(NRF_GRTC, OS_IDLE_CMPEV);
nrf_grtc_sys_counter_compare_event_enable(NRF_GRTC, OS_IDLE_CMPREG);
nrf_grtc_int_enable(NRF_GRTC, GRTC_COMPARE_INT_MASK(OS_IDLE_CMPREG));
}

__DSB();
Expand All @@ -147,8 +138,9 @@ os_tick_idle(os_time_t ticks)
* Update OS time and re-enable OS tick interrupt before anything else
* when coming out of the tickless regime.
*/
nrf_grtc_int_enable(NRF_GRTC, GRTC_COMPARE_INT_MASK(OS_TICK_CMPREG));
nrf54l_timer_handler();
nrf_grtc_int_disable(NRF_GRTC, GRTC_COMPARE_INT_MASK(OS_IDLE_CMPREG));
nrf_grtc_int_enable(NRF_GRTC, GRTC_COMPARE_INT_MASK(OS_TICK_CMPREG));
}
}

Expand Down Expand Up @@ -185,14 +177,12 @@ os_tick_init(uint32_t os_ticks_per_sec, int prio)

nrf_grtc_int_disable(NRF_GRTC, 0xffffffff);
nrf_grtc_int_enable(NRF_GRTC, GRTC_COMPARE_INT_MASK(OS_TICK_CMPREG));
nrf_grtc_int_enable(NRF_GRTC, GRTC_COMPARE_INT_MASK(OS_IDLE_CMPREG));

nrf_grtc_clksel_set(NRF_GRTC, NRF_GRTC_CLKSEL_LFXO);

nrf_grtc_event_clear(NRF_GRTC, OS_TICK_CMPEV);
nrf_grtc_event_clear(NRF_GRTC, OS_IDLE_CMPEV);
nrf_grtc_sys_counter_compare_event_enable(NRF_GRTC, OS_TICK_CMPREG);
nrf_grtc_sys_counter_compare_event_enable(NRF_GRTC, OS_IDLE_CMPREG);

nrf_grtc_sys_counter_interval_set(NRF_GRTC, g_hal_os_tick.ticks_per_ostick);
nrf_grtc_sys_counter_set(NRF_GRTC, true);
Expand Down
Loading
Loading