Skip to content

Commit bf70d5a

Browse files
committed
Enabled lp_ticker after adjusting its implementation to the new API.
1 parent fce8a30 commit bf70d5a

File tree

4 files changed

+45
-43
lines changed

4 files changed

+45
-43
lines changed

hal/targets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,7 @@
13751375
"supported_form_factors": ["ARDUINO"],
13761376
"inherits": ["MCU_NRF51_32K"],
13771377
"progen": {"target": "nrf51-dk"},
1378-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"]
1378+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"]
13791379
},
13801380
"NRF51_DK_BOOT": {
13811381
"supported_form_factors": ["ARDUINO"],
@@ -1773,6 +1773,6 @@
17731773
"NRF52_PAN_62",
17741774
"NRF52_PAN_63"
17751775
],
1776-
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"]
1776+
"device_has": ["ANALOGIN", "ERROR_PATTERN", "I2C", "I2C_ASYNCH", "INTERRUPTIN", "LOWPOWERTIMER", "PORTIN", "PORTINOUT", "PORTOUT", "RTC", "SERIAL", "SERIAL_ASYNCH", "SLEEP", "SPI", "SPI_ASYNCH", "SPISLAVE"]
17771777
}
17781778
}

hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/common_rtc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@ extern uint32_t volatile m_common_rtc_overflows;
5050

5151
void common_rtc_init(void);
5252
uint32_t common_rtc_32bit_ticks_get(void);
53+
uint64_t common_rtc_64bit_us_get(void);
54+
void common_rtc_set_interrupt(uint32_t us_timestamp, uint32_t cc_channel,
55+
uint32_t int_mask);
5356

5457
#endif // COMMON_RTC_H

hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/lp_ticker.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,32 @@
1818
#if DEVICE_LOWPOWERTIMER
1919

2020
#include "common_rtc.h"
21-
#include "sleep_api.h"
2221

2322
void lp_ticker_init(void)
2423
{
2524
common_rtc_init();
2625
}
2726

28-
uint32_t lp_ticker_read(void)
27+
uint32_t lp_ticker_read()
2928
{
30-
return common_rtc_32bit_ticks_get();
29+
return (uint32_t)common_rtc_64bit_us_get();
3130
}
3231

33-
void lp_ticker_set_interrupt(uint32_t now, uint32_t time)
32+
void lp_ticker_set_interrupt(timestamp_t timestamp)
3433
{
35-
(void)now;
36-
nrf_rtc_cc_set(COMMON_RTC_INSTANCE, LP_TICKER_CC_CHANNEL, RTC_WRAP(time));
37-
nrf_rtc_event_enable(COMMON_RTC_INSTANCE, LP_TICKER_INT_MASK);
34+
common_rtc_set_interrupt(timestamp,
35+
LP_TICKER_CC_CHANNEL, LP_TICKER_INT_MASK);
3836
}
3937

40-
uint32_t lp_ticker_get_overflows_counter(void)
38+
void lp_ticker_disable_interrupt(void)
4139
{
42-
// Cut out the part of 'm_common_rtc_overflows' used by
43-
// 'common_rtc_32bit_ticks_get()'.
44-
return (m_common_rtc_overflows >> (32u - RTC_COUNTER_BITS));
40+
nrf_rtc_event_disable(COMMON_RTC_INSTANCE, LP_TICKER_INT_MASK);
4541
}
4642

47-
uint32_t lp_ticker_get_compare_match(void)
43+
void lp_ticker_clear_interrupt(void)
4844
{
49-
return nrf_rtc_cc_get(COMMON_RTC_INSTANCE, LP_TICKER_CC_CHANNEL);
50-
}
51-
52-
void lp_ticker_sleep_until(uint32_t now, uint32_t time)
53-
{
54-
lp_ticker_set_interrupt(now, time);
55-
sleep_t sleep_obj;
56-
mbed_enter_sleep(&sleep_obj);
57-
mbed_exit_sleep(&sleep_obj);
45+
// No implementation needed. The event that triggers the interrupt is
46+
// cleared in 'common_rtc_irq_handler'.
5847
}
5948

6049
#endif // DEVICE_LOWPOWERTIMER

hal/targets/hal/TARGET_NORDIC/TARGET_NRF5/us_ticker.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "us_ticker_api.h"
1717
#include "common_rtc.h"
1818
#include "app_util.h"
19+
#include "lp_ticker_api.h"
1920

2021

2122
//------------------------------------------------------------------------------
@@ -51,6 +52,8 @@ void COMMON_RTC_IRQ_HANDLER(void)
5152
if (nrf_rtc_event_pending(COMMON_RTC_INSTANCE, event)) {
5253
nrf_rtc_event_clear(COMMON_RTC_INSTANCE, event);
5354
nrf_rtc_event_disable(COMMON_RTC_INSTANCE, int_mask);
55+
56+
lp_ticker_irq_handler();
5457
}
5558
#endif
5659

@@ -128,27 +131,16 @@ uint32_t common_rtc_32bit_ticks_get(void)
128131
ticks += (m_common_rtc_overflows << RTC_COUNTER_BITS);
129132
return ticks;
130133
}
131-
//------------------------------------------------------------------------------
132-
133-
134-
void us_ticker_init(void)
135-
{
136-
common_rtc_init();
137-
}
138134

139-
static uint64_t us_ticker_64bit_get(void)
135+
uint64_t common_rtc_64bit_us_get(void)
140136
{
141137
uint32_t ticks = common_rtc_32bit_ticks_get();
142138
// [ticks -> microseconds]
143139
return ROUNDED_DIV(((uint64_t)ticks) * 1000000, RTC_INPUT_FREQ);
144140
}
145141

146-
uint32_t us_ticker_read()
147-
{
148-
return (uint32_t)us_ticker_64bit_get();
149-
}
150-
151-
void us_ticker_set_interrupt(timestamp_t timestamp)
142+
void common_rtc_set_interrupt(uint32_t us_timestamp, uint32_t cc_channel,
143+
uint32_t int_mask)
152144
{
153145
// The internal counter is clocked with a frequency that cannot be easily
154146
// multiplied to 1 MHz, therefore besides the translation of values
@@ -159,12 +151,13 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
159151
// is then translated to counter ticks. Finally, the lower 24 bits of thus
160152
// calculated value is written to the counter compare register to prepare
161153
// the interrupt generation.
162-
uint64_t current_time64 = us_ticker_64bit_get();
154+
uint64_t current_time64 = common_rtc_64bit_us_get();
163155
// [add upper 32 bits from the current time to the timestamp value]
164-
uint64_t timestamp64 = timestamp + (current_time64 & ~(uint64_t)0xFFFFFFFF);
156+
uint64_t timestamp64 = us_timestamp +
157+
(current_time64 & ~(uint64_t)0xFFFFFFFF);
165158
// [if the original timestamp value happens to be after the 32 bit counter
166159
// of microsends overflows, correct the upper 32 bits accordingly]
167-
if (timestamp < (uint32_t)(current_time64 & 0xFFFFFFFF)) {
160+
if (us_timestamp < (uint32_t)(current_time64 & 0xFFFFFFFF)) {
168161
timestamp64 += ((uint64_t)1 << 32);
169162
}
170163
// [microseconds -> ticks, always round the result up to avoid too early
@@ -182,9 +175,26 @@ void us_ticker_set_interrupt(timestamp_t timestamp)
182175
compare_value = closest_safe_compare;
183176
}
184177

185-
nrf_rtc_cc_set(COMMON_RTC_INSTANCE, US_TICKER_CC_CHANNEL,
186-
RTC_WRAP(compare_value));
187-
nrf_rtc_event_enable(COMMON_RTC_INSTANCE, US_TICKER_INT_MASK);
178+
nrf_rtc_cc_set(COMMON_RTC_INSTANCE, cc_channel, RTC_WRAP(compare_value));
179+
nrf_rtc_event_enable(COMMON_RTC_INSTANCE, int_mask);
180+
}
181+
//------------------------------------------------------------------------------
182+
183+
184+
void us_ticker_init(void)
185+
{
186+
common_rtc_init();
187+
}
188+
189+
uint32_t us_ticker_read()
190+
{
191+
return (uint32_t)common_rtc_64bit_us_get();
192+
}
193+
194+
void us_ticker_set_interrupt(timestamp_t timestamp)
195+
{
196+
common_rtc_set_interrupt(timestamp,
197+
US_TICKER_CC_CHANNEL, US_TICKER_INT_MASK);
188198
}
189199

190200
void us_ticker_disable_interrupt(void)

0 commit comments

Comments
 (0)