Skip to content

Commit 1583cbc

Browse files
committed
Use common us_ticker.c for NRF51 and NRF52 boards
1 parent cca4090 commit 1583cbc

File tree

2 files changed

+8
-147
lines changed

2 files changed

+8
-147
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/us_ticker.c

Lines changed: 0 additions & 145 deletions
This file was deleted.

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/us_ticker.c renamed to targets/TARGET_NORDIC/TARGET_NRF5x/us_ticker.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ void us_ticker_init(void)
7070

7171
/* Configure timer as follows:
7272
* - timer mode,
73-
* - timer width 16 bits,
73+
* - timer width 16 bits for NRF51 and 32 bits for NRF52,
7474
* - timer freq 1 MHz.
7575
*/
7676
nrf_timer_mode_set(NRF_TIMER1, NRF_TIMER_MODE_TIMER);
7777

7878
nrf_timer_frequency_set(NRF_TIMER1, NRF_TIMER_FREQ_1MHz);
7979

80+
#ifdef NRF52
81+
nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_32);
82+
#else
8083
nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_16);
84+
#endif
8185

8286
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, 0);
8387

@@ -110,7 +114,9 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
110114
{
111115
core_util_critical_section_enter();
112116

113-
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, timestamp & 0xFFFF);
117+
const uint32_t counter_mask = ((1 << US_TICKER_COUNTER_BITS) - 1);
118+
119+
nrf_timer_cc_write(NRF_TIMER1, NRF_TIMER_CC_CHANNEL0, timestamp & counter_mask);
114120

115121
if (!nrf_timer_int_enable_check(NRF_TIMER1, nrf_timer_compare_int_get(NRF_TIMER_CC_CHANNEL0))) {
116122
nrf_timer_event_clear(NRF_TIMER1, NRF_TIMER_EVENT_COMPARE0);

0 commit comments

Comments
 (0)