Skip to content

Commit a681291

Browse files
ioannisgMaureenHelm
authored andcommitted
soc: arm: nordic nrf: use bitmode-16 for timing measurements in nrf51
nRF51 TIMER2 periperhal does not have the 32-bit bitmode, so we need to fallback to the bitmode 16. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent 6f84d7d commit a681291

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

soc/arm/nordic_nrf/timing.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212

1313
#if defined(CONFIG_NRF_RTC_TIMER)
1414

15-
1615
#define CYCLES_PER_SEC (16000000 / (1 << NRF_TIMER2->PRESCALER))
1716

1817
void timing_init(void)
1918
{
2019
NRF_TIMER2->TASKS_CLEAR = 1; /* Clear Timer */
2120
NRF_TIMER2->MODE = 0; /* Timer Mode */
2221
NRF_TIMER2->PRESCALER = 0; /* 16M Hz */
22+
#if defined(CONFIG_SOC_SERIES_NRF51X)
23+
NRF_TIMER2->BITMODE = 0; /* 16 - bit */
24+
#else
2325
NRF_TIMER2->BITMODE = 3; /* 32 - bit */
26+
#endif
2427
}
2528

2629
void timing_start(void)
@@ -42,7 +45,16 @@ timing_t timing_counter_get(void)
4245
uint64_t timing_cycles_get(volatile timing_t *const start,
4346
volatile timing_t *const end)
4447
{
48+
#if defined(CONFIG_SOC_SERIES_NRF51X)
49+
#define COUNTER_SPAN BIT(16)
50+
if (*end >= *start) {
51+
return (*end - *start);
52+
} else {
53+
return COUNTER_SPAN + *end - *start;
54+
}
55+
#else
4556
return (*end - *start);
57+
#endif
4658
}
4759

4860
uint64_t timing_freq_get(void)

0 commit comments

Comments
 (0)