return a 64-bit value from app_timer_cnt_get()

This commit is contained in:
Rohit Grover 2014-08-19 08:14:57 +01:00
parent 2478b742d7
commit c06fa23971
2 changed files with 11 additions and 6 deletions

View file

@ -135,6 +135,7 @@ static uint8_t m_ticks_elapsed_q_read_ind;
static uint8_t m_ticks_elapsed_q_write_ind; /**< Timer internal elapsed ticks queue write index. */
static app_timer_evt_schedule_func_t m_evt_schedule_func; /**< Pointer to function for propagating timeout events to the scheduler. */
static bool m_rtc1_running; /**< Boolean indicating if RTC1 is running. */
static volatile uint64_t overflowBits; /**< The upper 40 bits of the 64-bit value returned by cnt_get() */
/**@brief Function for initializing the RTC1 counter.
@ -153,7 +154,7 @@ static void rtc1_init(uint32_t prescaler)
static void rtc1_start(void)
{
NRF_RTC1->EVTENSET = RTC_EVTEN_COMPARE0_Msk;
NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk;
NRF_RTC1->INTENSET = RTC_INTENSET_COMPARE0_Msk | RTC_INTENSET_OVRFLW_Msk;
NVIC_ClearPendingIRQ(RTC1_IRQn);
NVIC_EnableIRQ(RTC1_IRQn);
@ -172,7 +173,7 @@ static void rtc1_stop(void)
NVIC_DisableIRQ(RTC1_IRQn);
NRF_RTC1->EVTENCLR = RTC_EVTEN_COMPARE0_Msk;
NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
NRF_RTC1->INTENCLR = RTC_INTENSET_COMPARE0_Msk | RTC_INTENSET_OVRFLW_Msk;
NRF_RTC1->TASKS_STOP = 1;
nrf_delay_us(MAX_RTC_TASKS_DELAY);
@ -904,6 +905,9 @@ extern "C" void RTC1_IRQHandler(void)
NRF_RTC1->EVENTS_COMPARE[2] = 0;
NRF_RTC1->EVENTS_COMPARE[3] = 0;
NRF_RTC1->EVENTS_TICK = 0;
if (NRF_RTC1->EVENTS_OVRFLW) {
overflowBits += (1 << 24);
}
NRF_RTC1->EVENTS_OVRFLW = 0;
// Check for expired timers
@ -1122,9 +1126,9 @@ uint32_t app_timer_stop_all(void)
}
uint32_t app_timer_cnt_get(uint32_t * p_ticks)
uint32_t app_timer_cnt_get(uint64_t * p_ticks)
{
*p_ticks = rtc1_counter_get();
*p_ticks = overflowBits | rtc1_counter_get();
return NRF_SUCCESS;
}

View file

@ -253,13 +253,14 @@ uint32_t app_timer_stop(app_timer_id_t timer_id);
*/
uint32_t app_timer_stop_all(void);
/**@brief Function for returning the current value of the RTC1 counter.
/**@brief Function for returning the current value of the RTC1 counter. The
* value includes overflow bits to extend the range to 64-bits.
*
* @param[out] p_ticks Current value of the RTC1 counter.
*
* @retval NRF_SUCCESS Counter was successfully read.
*/
uint32_t app_timer_cnt_get(uint32_t * p_ticks);
uint32_t app_timer_cnt_get(uint64_t * p_ticks);
/**@brief Function for computing the difference between two RTC1 counter values.
*