Skip to content

Commit 84d6b79

Browse files
author
Cruz Monrreal
authored
Merge pull request #7172 from mprse/NRF5x_updates
Unify RTC, lp ticker, and us ticker for NRF51 and NRF52 series
2 parents c4113ae + 02d7d25 commit 84d6b79

File tree

13 files changed

+28
-303
lines changed

13 files changed

+28
-303
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/flash_api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ int32_t flash_init(flash_t *obj)
7272

7373
if (first_init) {
7474
first_init = false;
75-
lp_ticker_init();
7675
}
7776

7877
return 0;

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/i2c_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
#include "i2c_api.h"
4141

42-
#if DEVICE_I2C
42+
#if (defined(DEVICE_I2C) && defined(DEVICE_LPTICKER))
4343

4444
#include "mbed_assert.h"
4545
#include "mbed_error.h"

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF51/trng_api.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ void trng_init(trng_t *obj)
7373

7474
if (first_init) {
7575
first_init = false;
76-
lp_ticker_init();
7776
}
7877
}
7978

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/common_rtc.h

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

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/flash_api.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*
3737
*/
3838

39-
#if DEVICE_FLASH
39+
#if (defined(DEVICE_FLASH) && defined(DEVICE_LPTICKER))
4040

4141
#include "hal/flash_api.h"
4242
#include "hal/lp_ticker_api.h"
@@ -84,8 +84,6 @@ int32_t flash_init(flash_t *obj)
8484
result = nrf_fstorage_init(&nordic_fstorage, &nrf_fstorage_nvmc, NULL);
8585
#endif
8686

87-
/* Initialize low power ticker for timeouts. */
88-
lp_ticker_init();
8987
}
9088

9189
/* Convert Nordic SDK error code to mbed HAL. */

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/i2c_api.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
*
3737
*/
3838

39-
#if DEVICE_I2C
40-
39+
#if (defined(DEVICE_I2C) && defined(DEVICE_LPTICKER))
4140
/* I2C
4241
*
4342
* This HAL implementation uses the nrf_drv_twi.h API primarily but switches to TWI for the
@@ -131,8 +130,6 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl)
131130

132131
if (first_init) {
133132
first_init = false;
134-
/* Initialize low power ticker. Used for timeouts. */
135-
lp_ticker_init();
136133

137134
/* Register interrupt handlers in driver with the NVIC. */
138135
NVIC_SetVector(SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQn, (uint32_t) SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler);

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/lp_ticker.c

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

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/us_ticker.c

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

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/us_ticker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#define US_TICKER_H
1919

2020
/* TIMER0 is reserved for SoftDevice. We will use TIMER1 for us ticker
21-
* which counter size is 16 bits. */
21+
* which counter size is 32 bits. */
2222

23-
#define US_TICKER_COUNTER_BITS 16u
23+
#define US_TICKER_COUNTER_BITS 32u
2424
#define US_TICKER_FREQ 1000000
2525

2626
#endif // US_TICKER_H

targets/TARGET_NORDIC/TARGET_NRF5x/common_rtc.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,7 @@ void common_rtc_init(void)
173173
nrf_rtc_int_disable(COMMON_RTC_INSTANCE, LP_TICKER_INT_MASK);
174174
#endif
175175

176-
nrf_drv_common_irq_enable(nrf_drv_get_IRQn(COMMON_RTC_INSTANCE),
177-
#ifdef NRF51
178-
APP_IRQ_PRIORITY_LOW
179-
#elif defined(NRF52) || defined(NRF52840_XXAA)
180-
APP_IRQ_PRIORITY_LOWEST
181-
#endif
182-
);
176+
nrf_drv_common_irq_enable(nrf_drv_get_IRQn(COMMON_RTC_INSTANCE), APP_IRQ_PRIORITY_HIGH);
183177

184178
nrf_rtc_task_trigger(COMMON_RTC_INSTANCE, NRF_RTC_TASK_START);
185179

@@ -194,6 +188,9 @@ void common_rtc_set_interrupt(uint32_t ticks_count, uint32_t cc_channel,
194188

195189
core_util_critical_section_enter();
196190

191+
/* Wrap ticks_count before comparisons. */
192+
ticks_count = RTC_WRAP(ticks_count);
193+
197194
/* COMPARE occurs when a CC register is N and the COUNTER value transitions from N-1 to N.
198195
* If the COUNTER is N, writing N+2 to a CC register is guaranteed to trigger a
199196
* COMPARE event at N+2.
@@ -202,10 +199,10 @@ void common_rtc_set_interrupt(uint32_t ticks_count, uint32_t cc_channel,
202199

203200
if (now == ticks_count ||
204201
RTC_WRAP(now + 1) == ticks_count) {
205-
ticks_count += 2;
202+
ticks_count = RTC_WRAP(ticks_count + 2);
206203
}
207204

208-
nrf_rtc_cc_set(COMMON_RTC_INSTANCE, cc_channel, RTC_WRAP(ticks_count));
205+
nrf_rtc_cc_set(COMMON_RTC_INSTANCE, cc_channel, ticks_count);
209206

210207
if (!nrf_rtc_int_is_enabled(COMMON_RTC_INSTANCE, int_mask)) {
211208
nrf_rtc_event_clear(COMMON_RTC_INSTANCE, LP_TICKER_EVENT);

0 commit comments

Comments
 (0)