Merge branch 'power' into tmp

This commit is contained in:
Rohit Grover 2014-08-29 08:31:13 +01:00
commit 04c2ea794f
4 changed files with 26 additions and 12 deletions

View File

@ -61,7 +61,6 @@ static void sys_evt_dispatch(uint32_t sys_evt)
error_t btle_init(void)
{
const bool useScheduler = false;
APP_TIMER_INIT(0 /* PRESCALAR */, 8 /* num timers */, 1 /* event queue max depth */, useScheduler);
SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_XTAL_20_PPM, useScheduler);
// Enable BLE stack

View File

@ -29,8 +29,6 @@
// (e.g. by using guard/trigger flags).
STATIC_ASSERT(RTC1_IRQ_PRI == SWI0_IRQ_PRI);
#define MAX_RTC_COUNTER_VAL 0x00FFFFFF /**< Maximum value of the RTC counter. */
#define APP_HIGH_USER_ID 0 /**< User Id for the Application High "user". */
#define APP_LOW_USER_ID 1 /**< User Id for the Application Low "user". */
#define THREAD_MODE_USER_ID 2 /**< User Id for the Thread Mode "user". */
@ -124,7 +122,6 @@ STATIC_ASSERT(sizeof(timer_user_t) % 4 == 0);
*/
typedef uint32_t timer_user_id_t;
#define TIMER_NULL ((app_timer_id_t)(0 - 1)) /**< Invalid timer id. */
#define CONTEXT_QUEUE_SIZE_MAX (2) /**< Timer internal elapsed ticks queue size. */
static uint8_t m_node_array_size; /**< Size of timer node array. */
@ -138,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.
@ -155,8 +153,12 @@ static void rtc1_init(uint32_t prescaler)
*/
static void rtc1_start(void)
{
if (m_rtc1_running) {
return;
}
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,10 +174,14 @@ static void rtc1_start(void)
*/
static void rtc1_stop(void)
{
if (!m_rtc1_running) {
return;
}
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);
@ -907,6 +913,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
@ -989,6 +998,7 @@ uint32_t app_timer_init(uint32_t prescaler,
NVIC_EnableIRQ(SWI0_IRQn);
rtc1_init(prescaler);
rtc1_start();
m_ticks_latest = rtc1_counter_get();
@ -1125,9 +1135,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

@ -62,6 +62,8 @@ extern "C" {
#define APP_TIMER_USER_SIZE 8 /**< Size of app_timer.timer_user_t (only for use inside APP_TIMER_BUF_SIZE()). */
#define APP_TIMER_INT_LEVELS 3 /**< Number of interrupt levels from where timer operations may be initiated (only for use inside APP_TIMER_BUF_SIZE()). */
#define MAX_RTC_COUNTER_VAL 0x00FFFFFF /**< Maximum value of the RTC counter. */
/**@brief Compute number of bytes required to hold the application timer data structures.
*
* @param[in] MAX_TIMERS Maximum number of timers that can be created at any given time.
@ -106,6 +108,8 @@ extern "C" {
/**@brief Timer id type. */
typedef uint32_t app_timer_id_t;
#define TIMER_NULL ((app_timer_id_t)(0 - 1)) /**< Invalid timer id. */
/**@brief Application timeout handler type. */
typedef void (*app_timer_timeout_handler_t)(void * p_context);
@ -249,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.
*

View File

@ -88,8 +88,8 @@
/*-------------------------------- TIMER ------------------------------*/
#define CFG_TIMER_PRESCALER 0 /**< Value of the RTC1 PRESCALER register. freq = (32768/(PRESCALER+1)) */
#define CFG_TIMER_MAX_INSTANCE 8 /**< Maximum number of simultaneously created timers. */
#define CFG_TIMER_OPERATION_QUEUE_SIZE 5 /**< Size of timer operation queues. */
#define CFG_TIMER_MAX_INSTANCE 1 /**< Maximum number of simultaneously created timers. */
#define CFG_TIMER_OPERATION_QUEUE_SIZE 1 /**< Size of timer operation queues. */
/*=========================================================================*/