Bluetooth: Controller: nRF54Lx: Use nrfx interface for bsim use (1/4)
Use nrfx interface for register access with sideeffects to facilitate bsim use. 4 part commits: 1. Add nrf_grtc interface. 2. Remove CMSIS interface use. 3. Add nrf_grtc interface, once missing bsim port available. 4. Remove CMSIS interface use, replaced by bsim port. Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
parent
f39c27bc95
commit
24465ec160
5 changed files with 60 additions and 1 deletions
|
@ -5,13 +5,14 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hal/cntr.h"
|
||||
|
||||
#include "hal/debug.h"
|
||||
|
||||
#if !defined(CONFIG_BT_CTLR_NRF_GRTC)
|
||||
#include <hal/nrf_rtc.h>
|
||||
#ifndef NRF_RTC
|
||||
#if defined(CONFIG_SOC_COMPATIBLE_NRF54LX)
|
||||
#define NRF_RTC NRF_RTC10
|
||||
|
@ -19,6 +20,8 @@
|
|||
#define NRF_RTC NRF_RTC0
|
||||
#endif /* !CONFIG_SOC_COMPATIBLE_NRF54LX */
|
||||
#endif /* !NRF_RTC */
|
||||
#else /* CONFIG_BT_CTLR_NRF_GRTC */
|
||||
#include <hal/nrf_grtc.h>
|
||||
#endif /* CONFIG_BT_CTLR_NRF_GRTC */
|
||||
|
||||
static uint8_t _refcount;
|
||||
|
@ -32,6 +35,7 @@ void cntr_init(void)
|
|||
GRTC_MODE_SYSCOUNTEREN_Msk;
|
||||
|
||||
NRF_GRTC->TASKS_CLEAR = 1U;
|
||||
nrf_grtc_task_trigger(NRF_GRTC, NRF_GRTC_TASK_CLEAR);
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_NRF_GRTC_KEEPRUNNING)
|
||||
NRF_GRTC->KEEPRUNNING =
|
||||
|
@ -52,8 +56,18 @@ void cntr_init(void)
|
|||
#endif /* CONFIG_BT_CTLR_NRF_GRTC_START */
|
||||
|
||||
NRF_GRTC->EVENTS_COMPARE[HAL_CNTR_GRTC_CC_IDX_TICKER] = 0U;
|
||||
nrf_grtc_event_clear(NRF_GRTC, HAL_CNTR_GRTC_EVENT_COMPARE_TICKER);
|
||||
|
||||
/* FIXME: Replace with nrf_grtc_int_enable when is available,
|
||||
* with ability to select/set IRQ group.
|
||||
* Shared interrupts is an option? It may add ISR latencies?
|
||||
*/
|
||||
NRF_GRTC->INTENSET1 = HAL_CNTR_GRTC_INTENSET_COMPARE_TICKER_Msk;
|
||||
if (IS_ENABLED(CONFIG_SOC_SERIES_BSIM_NRF54LX)) {
|
||||
extern void nhw_GRTC_regw_sideeffects_INTENSET(uint32_t inst, uint32_t n);
|
||||
|
||||
nhw_GRTC_regw_sideeffects_INTENSET(0, 1);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_CTLR_NRF_GRTC_START)
|
||||
NRF_GRTC->MODE = ((GRTC_MODE_SYSCOUNTEREN_Enabled <<
|
||||
|
@ -72,6 +86,7 @@ void cntr_init(void)
|
|||
0U;
|
||||
|
||||
NRF_GRTC->TASKS_START = 1U;
|
||||
nrf_grtc_task_trigger(NRF_GRTC, NRF_GRTC_TASK_START);
|
||||
#endif /* CONFIG_BT_CTLR_NRF_GRTC_START */
|
||||
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
|
@ -125,8 +140,11 @@ uint32_t cntr_cnt_get(void)
|
|||
*/
|
||||
do {
|
||||
cntr_h = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
cntr_l = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERL;
|
||||
cntr_l = nrf_grtc_sys_counter_low_get(NRF_GRTC);
|
||||
cntr_h_overflow = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h_overflow = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
} while ((cntr_h & GRTC_SYSCOUNTER_SYSCOUNTERH_BUSY_Msk) ||
|
||||
(cntr_h_overflow & GRTC_SYSCOUNTER_SYSCOUNTERH_OVERFLOW_Msk));
|
||||
|
||||
|
@ -149,13 +167,17 @@ void cntr_cmp_set(uint8_t cmp, uint32_t value)
|
|||
/* Read current syscounter value */
|
||||
do {
|
||||
cntr_h = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
cntr_l = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERL;
|
||||
cntr_l = nrf_grtc_sys_counter_low_get(NRF_GRTC);
|
||||
cntr_h_overflow = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h_overflow = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
} while ((cntr_h & GRTC_SYSCOUNTER_SYSCOUNTERH_BUSY_Msk) ||
|
||||
(cntr_h_overflow & GRTC_SYSCOUNTER_SYSCOUNTERH_OVERFLOW_Msk));
|
||||
|
||||
/* Disable capture/compare */
|
||||
NRF_GRTC->CC[cmp].CCEN = 0U;
|
||||
nrf_grtc_sys_counter_compare_event_disable(NRF_GRTC, cmp);
|
||||
|
||||
/* Set a stale value in capture value */
|
||||
stale = cntr_l - 1U;
|
||||
|
@ -163,6 +185,7 @@ void cntr_cmp_set(uint8_t cmp, uint32_t value)
|
|||
|
||||
/* Trigger a capture */
|
||||
NRF_GRTC->TASKS_CAPTURE[cmp] = 1U;
|
||||
nrf_grtc_task_trigger(NRF_GRTC, (NRF_GRTC_TASK_CAPTURE_0 + (cmp * sizeof(uint32_t))));
|
||||
|
||||
/* Wait to get a new L value */
|
||||
do {
|
||||
|
@ -182,9 +205,12 @@ void cntr_cmp_set(uint8_t cmp, uint32_t value)
|
|||
/* Set compare register values */
|
||||
NRF_GRTC->CC[cmp].CCL = value;
|
||||
NRF_GRTC->CC[cmp].CCH = cntr_h & GRTC_CC_CCH_CCH_Msk;
|
||||
nrf_grtc_sys_counter_cc_set(NRF_GRTC, cmp,
|
||||
((((uint64_t)cntr_h & GRTC_CC_CCH_CCH_Msk) << 32) | value));
|
||||
|
||||
/* Enable compare */
|
||||
NRF_GRTC->CC[cmp].CCEN = 1U;
|
||||
nrf_grtc_sys_counter_compare_event_enable(NRF_GRTC, cmp);
|
||||
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
nrf_rtc_cc_set(NRF_RTC, cmp, value);
|
||||
|
|
|
@ -6,7 +6,11 @@
|
|||
|
||||
#if defined(CONFIG_BT_CTLR_NRF_GRTC)
|
||||
#define HAL_CNTR_GRTC_CC_IDX_TICKER 10
|
||||
#define HAL_CNTR_GRTC_EVENT_COMPARE_TICKER \
|
||||
_CONCAT(NRF_GRTC_EVENT_COMPARE_, HAL_CNTR_GRTC_CC_IDX_TICKER)
|
||||
#define HAL_CNTR_GRTC_INTENSET_COMPARE_TICKER_Msk \
|
||||
_CONCAT(_CONCAT(GRTC_INTENSET1_COMPARE, HAL_CNTR_GRTC_CC_IDX_TICKER), _Msk)
|
||||
#define HAL_CNTR_GRTC_CC_IDX_RADIO 11
|
||||
#define HAL_CNTR_GRTC_EVENT_COMPARE_RADIO \
|
||||
_CONCAT(NRF_GRTC_EVENT_COMPARE_, HAL_CNTR_GRTC_CC_IDX_RADIO)
|
||||
#endif /* CONFIG_BT_CTLR_NRF_GRTC */
|
||||
|
|
|
@ -1183,6 +1183,7 @@ void radio_tmr_status_reset(void)
|
|||
{
|
||||
#if defined(CONFIG_BT_CTLR_NRF_GRTC)
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 0U;
|
||||
nrf_grtc_sys_counter_compare_event_disable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
nrf_rtc_event_disable(NRF_RTC, RTC_EVTENCLR_COMPARE2_Msk);
|
||||
#endif /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
|
@ -1226,6 +1227,7 @@ void radio_tmr_tx_status_reset(void)
|
|||
{
|
||||
#if defined(CONFIG_BT_CTLR_NRF_GRTC)
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 0U;
|
||||
nrf_grtc_sys_counter_compare_event_disable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
nrf_rtc_event_disable(NRF_RTC, RTC_EVTENCLR_COMPARE2_Msk);
|
||||
#endif /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
|
@ -1273,6 +1275,7 @@ void radio_tmr_rx_status_reset(void)
|
|||
{
|
||||
#if defined(CONFIG_BT_CTLR_NRF_GRTC)
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 0U;
|
||||
nrf_grtc_sys_counter_compare_event_disable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
nrf_rtc_event_disable(NRF_RTC, RTC_EVTENCLR_COMPARE2_Msk);
|
||||
#endif /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
|
@ -1393,6 +1396,7 @@ uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder)
|
|||
|
||||
/* Disable capture/compare */
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 0U;
|
||||
nrf_grtc_sys_counter_compare_event_disable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
|
||||
/* NOTE: We are going to use TASKS_CAPTURE to read current
|
||||
* SYSCOUNTER H and L, so that COMPARE registers can be set
|
||||
|
@ -1402,8 +1406,11 @@ uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder)
|
|||
/* Read current syscounter value */
|
||||
do {
|
||||
cntr_h = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
cntr_l = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERL;
|
||||
cntr_l = nrf_grtc_sys_counter_low_get(NRF_GRTC);
|
||||
cntr_h_overflow = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h_overflow = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
} while ((cntr_h & GRTC_SYSCOUNTER_SYSCOUNTERH_BUSY_Msk) ||
|
||||
(cntr_h_overflow & GRTC_SYSCOUNTER_SYSCOUNTERH_OVERFLOW_Msk));
|
||||
|
||||
|
@ -1413,6 +1420,8 @@ uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder)
|
|||
|
||||
/* Trigger a capture */
|
||||
NRF_GRTC->TASKS_CAPTURE[HAL_CNTR_GRTC_CC_IDX_RADIO] = 1U;
|
||||
nrf_grtc_task_trigger(NRF_GRTC, (NRF_GRTC_TASK_CAPTURE_0 +
|
||||
(HAL_CNTR_GRTC_CC_IDX_RADIO * sizeof(uint32_t))));
|
||||
|
||||
/* Wait to get a new L value */
|
||||
do {
|
||||
|
@ -1431,13 +1440,18 @@ uint32_t radio_tmr_start(uint8_t trx, uint32_t ticks_start, uint32_t remainder)
|
|||
|
||||
/* Clear compare event, if any */
|
||||
NRF_GRTC->EVENTS_COMPARE[HAL_CNTR_GRTC_CC_IDX_RADIO] = 0U;
|
||||
nrf_grtc_event_clear(NRF_GRTC, HAL_CNTR_GRTC_EVENT_COMPARE_RADIO);
|
||||
|
||||
/* Set compare register values */
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCL = ticks_start;
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCH = cntr_h & GRTC_CC_CCH_CCH_Msk;
|
||||
nrf_grtc_sys_counter_cc_set(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO,
|
||||
((((uint64_t)cntr_h & GRTC_CC_CCH_CCH_Msk) << 32) |
|
||||
ticks_start));
|
||||
|
||||
/* Enable compare */
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 1U;
|
||||
nrf_grtc_sys_counter_compare_event_enable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
nrf_rtc_cc_set(NRF_RTC, 2, ticks_start);
|
||||
|
@ -1513,6 +1527,7 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t ticks_start)
|
|||
|
||||
/* Disable capture/compare */
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 0U;
|
||||
nrf_grtc_sys_counter_compare_event_disable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
|
||||
/* NOTE: We are going to use TASKS_CAPTURE to read current
|
||||
* SYSCOUNTER H and L, so that COMPARE registers can be set
|
||||
|
@ -1522,8 +1537,11 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t ticks_start)
|
|||
/* Read current syscounter value */
|
||||
do {
|
||||
cntr_h = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
cntr_l = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERL;
|
||||
cntr_l = nrf_grtc_sys_counter_low_get(NRF_GRTC);
|
||||
cntr_h_overflow = NRF_GRTC->SYSCOUNTER[1].SYSCOUNTERH;
|
||||
cntr_h_overflow = nrf_grtc_sys_counter_high_get(NRF_GRTC);
|
||||
} while ((cntr_h & GRTC_SYSCOUNTER_SYSCOUNTERH_BUSY_Msk) ||
|
||||
(cntr_h_overflow & GRTC_SYSCOUNTER_SYSCOUNTERH_OVERFLOW_Msk));
|
||||
|
||||
|
@ -1533,6 +1551,8 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t ticks_start)
|
|||
|
||||
/* Trigger a capture */
|
||||
NRF_GRTC->TASKS_CAPTURE[HAL_CNTR_GRTC_CC_IDX_RADIO] = 1U;
|
||||
nrf_grtc_task_trigger(NRF_GRTC, (NRF_GRTC_TASK_CAPTURE_0 +
|
||||
(HAL_CNTR_GRTC_CC_IDX_RADIO * sizeof(uint32_t))));
|
||||
|
||||
/* Wait to get a new L value */
|
||||
do {
|
||||
|
@ -1551,13 +1571,18 @@ uint32_t radio_tmr_start_tick(uint8_t trx, uint32_t ticks_start)
|
|||
|
||||
/* Clear compare event, if any */
|
||||
NRF_GRTC->EVENTS_COMPARE[HAL_CNTR_GRTC_CC_IDX_RADIO] = 0U;
|
||||
nrf_grtc_event_clear(NRF_GRTC, HAL_CNTR_GRTC_EVENT_COMPARE_RADIO);
|
||||
|
||||
/* Set compare register values */
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCL = ticks_start;
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCH = cntr_h & GRTC_CC_CCH_CCH_Msk;
|
||||
nrf_grtc_sys_counter_cc_set(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO,
|
||||
((((uint64_t)cntr_h & GRTC_CC_CCH_CCH_Msk) << 32) |
|
||||
ticks_start));
|
||||
|
||||
/* Enable compare */
|
||||
NRF_GRTC->CC[HAL_CNTR_GRTC_CC_IDX_RADIO].CCEN = 1U;
|
||||
nrf_grtc_sys_counter_compare_event_enable(NRF_GRTC, HAL_CNTR_GRTC_CC_IDX_RADIO);
|
||||
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
nrf_rtc_cc_set(NRF_RTC, 2, ticks_start);
|
||||
|
|
|
@ -70,6 +70,9 @@
|
|||
/* This has to come before the ppi/dppi includes below. */
|
||||
#include "radio_nrf5_fem.h"
|
||||
|
||||
/* Include RTC/GRTC Compare Index used to Trigger Radio TXEN/RXEN */
|
||||
#include "hal/cntr.h"
|
||||
|
||||
#if defined(PPI_PRESENT)
|
||||
#include <hal/nrf_ppi.h>
|
||||
#include "radio_nrf5_ppi_resources.h"
|
||||
|
|
|
@ -122,6 +122,7 @@ static void rtc0_nrf5_isr(const void *arg)
|
|||
#if defined(CONFIG_BT_CTLR_NRF_GRTC)
|
||||
if (NRF_GRTC->EVENTS_COMPARE[HAL_CNTR_GRTC_CC_IDX_TICKER]) {
|
||||
NRF_GRTC->EVENTS_COMPARE[HAL_CNTR_GRTC_CC_IDX_TICKER] = 0U;
|
||||
nrf_grtc_event_clear(NRF_GRTC, HAL_CNTR_GRTC_EVENT_COMPARE_TICKER);
|
||||
#else /* !CONFIG_BT_CTLR_NRF_GRTC */
|
||||
if (NRF_RTC->EVENTS_COMPARE[0]) {
|
||||
nrf_rtc_event_clear(NRF_RTC, NRF_RTC_EVENT_COMPARE_0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue