テスト用
Fork of nRF51822 by
nordic/nrf-sdk/app_common/app_timer.h@65:98215c4f3a25, 2014-09-08 (annotated)
- Committer:
- Rohit Grover
- Date:
- Mon Sep 08 17:21:46 2014 +0100
- Revision:
- 65:98215c4f3a25
- Parent:
- 56:a1071b629aa3
Release 0.1.3
Update to v6.1.0 of Nordic's SDK.
Bugfixes
~~~~~~~~
- Handle all valid disconnection reasons.
Compatible with Release 0.1.1 of the BLE_API.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bogdanm | 0:eff01767de02 | 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. |
bogdanm | 0:eff01767de02 | 2 | * |
bogdanm | 0:eff01767de02 | 3 | * The information contained herein is property of Nordic Semiconductor ASA. |
bogdanm | 0:eff01767de02 | 4 | * Terms and conditions of usage are described in detail in NORDIC |
bogdanm | 0:eff01767de02 | 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. |
bogdanm | 0:eff01767de02 | 6 | * |
bogdanm | 0:eff01767de02 | 7 | * Licensees are granted free, non-transferable use of the information. NO |
bogdanm | 0:eff01767de02 | 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from |
bogdanm | 0:eff01767de02 | 9 | * the file. |
bogdanm | 0:eff01767de02 | 10 | * |
bogdanm | 0:eff01767de02 | 11 | */ |
bogdanm | 0:eff01767de02 | 12 | |
bogdanm | 0:eff01767de02 | 13 | /** @file |
bogdanm | 0:eff01767de02 | 14 | * |
bogdanm | 0:eff01767de02 | 15 | * @defgroup app_timer Application Timer |
bogdanm | 0:eff01767de02 | 16 | * @{ |
bogdanm | 0:eff01767de02 | 17 | * @ingroup app_common |
bogdanm | 0:eff01767de02 | 18 | * |
bogdanm | 0:eff01767de02 | 19 | * @brief Application timer functionality. |
bogdanm | 0:eff01767de02 | 20 | * |
bogdanm | 0:eff01767de02 | 21 | * @details It enables the application to create multiple timer instances based on the RTC1 |
bogdanm | 0:eff01767de02 | 22 | * peripheral. Checking for timeouts and invokation of user timeout handlers is performed |
bogdanm | 0:eff01767de02 | 23 | * in the RTC1 interrupt handler. List handling is done using a software interrupt (SWI0). |
bogdanm | 0:eff01767de02 | 24 | * Both interrupt handlers are running in APP_LOW priority level. |
bogdanm | 0:eff01767de02 | 25 | * |
bogdanm | 0:eff01767de02 | 26 | * @note When calling app_timer_start() or app_timer_stop(), the timer operation is just queued, |
bogdanm | 0:eff01767de02 | 27 | * and the software interrupt is triggered. The actual timer start/stop operation is |
bogdanm | 0:eff01767de02 | 28 | * executed by the SWI0 interrupt handler. Since the SWI0 interrupt is running in APP_LOW, |
bogdanm | 0:eff01767de02 | 29 | * if the application code calling the timer function is running in APP_LOW or APP_HIGH, |
bogdanm | 0:eff01767de02 | 30 | * the timer operation will not be performed until the application handler has returned. |
bogdanm | 0:eff01767de02 | 31 | * This will be the case e.g. when stopping a timer from a timeout handler when not using |
bogdanm | 0:eff01767de02 | 32 | * the scheduler. |
bogdanm | 0:eff01767de02 | 33 | * |
bogdanm | 0:eff01767de02 | 34 | * @details Use the USE_SCHEDULER parameter of the APP_TIMER_INIT() macro to select if the |
bogdanm | 0:eff01767de02 | 35 | * @ref app_scheduler is to be used or not. |
bogdanm | 0:eff01767de02 | 36 | * |
bogdanm | 0:eff01767de02 | 37 | * @note Even if the scheduler is not used, app_timer.h will include app_scheduler.h, so when |
bogdanm | 0:eff01767de02 | 38 | * compiling, app_scheduler.h must be available in one of the compiler include paths. |
bogdanm | 0:eff01767de02 | 39 | */ |
bogdanm | 0:eff01767de02 | 40 | |
bogdanm | 0:eff01767de02 | 41 | #ifndef APP_TIMER_H__ |
bogdanm | 0:eff01767de02 | 42 | #define APP_TIMER_H__ |
bogdanm | 0:eff01767de02 | 43 | |
bogdanm | 0:eff01767de02 | 44 | #include <stdint.h> |
bogdanm | 0:eff01767de02 | 45 | #include <stdbool.h> |
bogdanm | 0:eff01767de02 | 46 | #include <stdio.h> |
bogdanm | 0:eff01767de02 | 47 | #include "app_error.h" |
bogdanm | 0:eff01767de02 | 48 | #include "app_util.h" |
bogdanm | 0:eff01767de02 | 49 | #include "app_scheduler.h" |
bogdanm | 0:eff01767de02 | 50 | #include "compiler_abstraction.h" |
bogdanm | 0:eff01767de02 | 51 | |
Rohit Grover |
45:3c4df37ed83e | 52 | #ifdef __cplusplus |
Rohit Grover |
45:3c4df37ed83e | 53 | extern "C" { |
Rohit Grover |
45:3c4df37ed83e | 54 | #endif // #ifdef __cplusplus |
Rohit Grover |
45:3c4df37ed83e | 55 | |
bogdanm | 0:eff01767de02 | 56 | #define APP_TIMER_SCHED_EVT_SIZE sizeof(app_timer_event_t) /**< Size of button events being passed through the scheduler (is to be used for computing the maximum size of scheduler events). */ |
bogdanm | 0:eff01767de02 | 57 | #define APP_TIMER_CLOCK_FREQ 32768 /**< Clock frequency of the RTC timer used to implement the app timer module. */ |
bogdanm | 0:eff01767de02 | 58 | #define APP_TIMER_MIN_TIMEOUT_TICKS 5 /**< Minimum value of the timeout_ticks parameter of app_timer_start(). */ |
bogdanm | 0:eff01767de02 | 59 | |
bogdanm | 0:eff01767de02 | 60 | #define APP_TIMER_NODE_SIZE 40 /**< Size of app_timer.timer_node_t (only for use inside APP_TIMER_BUF_SIZE()). */ |
bogdanm | 0:eff01767de02 | 61 | #define APP_TIMER_USER_OP_SIZE 24 /**< Size of app_timer.timer_user_op_t (only for use inside APP_TIMER_BUF_SIZE()). */ |
bogdanm | 0:eff01767de02 | 62 | #define APP_TIMER_USER_SIZE 8 /**< Size of app_timer.timer_user_t (only for use inside APP_TIMER_BUF_SIZE()). */ |
bogdanm | 0:eff01767de02 | 63 | #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()). */ |
bogdanm | 0:eff01767de02 | 64 | |
Rohit Grover |
56:a1071b629aa3 | 65 | #define MAX_RTC_COUNTER_VAL 0x00FFFFFF /**< Maximum value of the RTC counter. */ |
Rohit Grover |
56:a1071b629aa3 | 66 | |
bogdanm | 0:eff01767de02 | 67 | /**@brief Compute number of bytes required to hold the application timer data structures. |
bogdanm | 0:eff01767de02 | 68 | * |
bogdanm | 0:eff01767de02 | 69 | * @param[in] MAX_TIMERS Maximum number of timers that can be created at any given time. |
bogdanm | 0:eff01767de02 | 70 | * @param[in] OP_QUEUE_SIZE Size of queues holding timer operations that are pending execution. |
bogdanm | 0:eff01767de02 | 71 | * NOTE: Due to the queue implementation, this size must be one more |
bogdanm | 0:eff01767de02 | 72 | * than the size that is actually needed. |
bogdanm | 0:eff01767de02 | 73 | * |
bogdanm | 0:eff01767de02 | 74 | * @return Required application timer buffer size (in bytes). |
bogdanm | 0:eff01767de02 | 75 | */ |
bogdanm | 0:eff01767de02 | 76 | #define APP_TIMER_BUF_SIZE(MAX_TIMERS, OP_QUEUE_SIZE) \ |
bogdanm | 0:eff01767de02 | 77 | ( \ |
bogdanm | 0:eff01767de02 | 78 | ((MAX_TIMERS) * APP_TIMER_NODE_SIZE) \ |
bogdanm | 0:eff01767de02 | 79 | + \ |
bogdanm | 0:eff01767de02 | 80 | ( \ |
bogdanm | 0:eff01767de02 | 81 | APP_TIMER_INT_LEVELS \ |
bogdanm | 0:eff01767de02 | 82 | * \ |
bogdanm | 0:eff01767de02 | 83 | (APP_TIMER_USER_SIZE + ((OP_QUEUE_SIZE) + 1) * APP_TIMER_USER_OP_SIZE) \ |
bogdanm | 0:eff01767de02 | 84 | ) \ |
bogdanm | 0:eff01767de02 | 85 | ) |
bogdanm | 0:eff01767de02 | 86 | |
bogdanm | 0:eff01767de02 | 87 | /**@brief Convert milliseconds to timer ticks. |
bogdanm | 0:eff01767de02 | 88 | * |
bogdanm | 0:eff01767de02 | 89 | * @note This macro uses 64 bit integer arithmetic, but as long as the macro parameters are |
bogdanm | 0:eff01767de02 | 90 | * constants (i.e. defines), the computation will be done by the preprocessor. |
bogdanm | 0:eff01767de02 | 91 | * |
bogdanm | 0:eff01767de02 | 92 | * @param[in] MS Milliseconds. |
bogdanm | 0:eff01767de02 | 93 | * @param[in] PRESCALER Value of the RTC1 PRESCALER register (must be the same value that was |
Rohit Grover |
65:98215c4f3a25 | 94 | * passed to APP_TIMER_INIT()). |
Rohit Grover |
65:98215c4f3a25 | 95 | * |
Rohit Grover |
65:98215c4f3a25 | 96 | * @note When using this macro, it is the responsibility of the developer to ensure that the |
bogdanm | 0:eff01767de02 | 97 | * values provided as input result in an output value that is supported by the |
bogdanm | 0:eff01767de02 | 98 | * @ref app_timer_start function. For example, when the ticks for 1 ms is needed, the |
bogdanm | 0:eff01767de02 | 99 | * maximum possible value of PRESCALER must be 6, when @ref APP_TIMER_CLOCK_FREQ is 32768. |
bogdanm | 0:eff01767de02 | 100 | * This will result in a ticks value as 5. Any higher value for PRESCALER will result in a |
bogdanm | 0:eff01767de02 | 101 | * ticks value that is not supported by this module. |
bogdanm | 0:eff01767de02 | 102 | * |
bogdanm | 0:eff01767de02 | 103 | * @return Number of timer ticks. |
bogdanm | 0:eff01767de02 | 104 | */ |
bogdanm | 0:eff01767de02 | 105 | #define APP_TIMER_TICKS(MS, PRESCALER)\ |
bogdanm | 0:eff01767de02 | 106 | ((uint32_t)ROUNDED_DIV((MS) * (uint64_t)APP_TIMER_CLOCK_FREQ, ((PRESCALER) + 1) * 1000)) |
bogdanm | 0:eff01767de02 | 107 | |
bogdanm | 0:eff01767de02 | 108 | /**@brief Timer id type. */ |
bogdanm | 0:eff01767de02 | 109 | typedef uint32_t app_timer_id_t; |
bogdanm | 0:eff01767de02 | 110 | |
Rohit Grover |
56:a1071b629aa3 | 111 | #define TIMER_NULL ((app_timer_id_t)(0 - 1)) /**< Invalid timer id. */ |
Rohit Grover |
56:a1071b629aa3 | 112 | |
bogdanm | 0:eff01767de02 | 113 | /**@brief Application timeout handler type. */ |
bogdanm | 0:eff01767de02 | 114 | typedef void (*app_timer_timeout_handler_t)(void * p_context); |
bogdanm | 0:eff01767de02 | 115 | |
bogdanm | 0:eff01767de02 | 116 | /**@brief Type of function for passing events from the timer module to the scheduler. */ |
bogdanm | 0:eff01767de02 | 117 | typedef uint32_t (*app_timer_evt_schedule_func_t) (app_timer_timeout_handler_t timeout_handler, |
bogdanm | 0:eff01767de02 | 118 | void * p_context); |
bogdanm | 0:eff01767de02 | 119 | |
bogdanm | 0:eff01767de02 | 120 | /**@brief Timer modes. */ |
bogdanm | 0:eff01767de02 | 121 | typedef enum |
bogdanm | 0:eff01767de02 | 122 | { |
bogdanm | 0:eff01767de02 | 123 | APP_TIMER_MODE_SINGLE_SHOT, /**< The timer will expire only once. */ |
bogdanm | 0:eff01767de02 | 124 | APP_TIMER_MODE_REPEATED /**< The timer will restart each time it expires. */ |
bogdanm | 0:eff01767de02 | 125 | } app_timer_mode_t; |
bogdanm | 0:eff01767de02 | 126 | |
bogdanm | 0:eff01767de02 | 127 | /**@brief Macro for initializing the application timer module. |
bogdanm | 0:eff01767de02 | 128 | * |
bogdanm | 0:eff01767de02 | 129 | * @details It will handle dimensioning and allocation of the memory buffer required by the timer, |
bogdanm | 0:eff01767de02 | 130 | * making sure that the buffer is correctly aligned. It will also connect the timer module |
bogdanm | 0:eff01767de02 | 131 | * to the scheduler (if specified). |
bogdanm | 0:eff01767de02 | 132 | * |
Rohit Grover |
65:98215c4f3a25 | 133 | * @note This module assumes that the LFCLK is already running. If it isn't, the module will |
Rohit Grover |
65:98215c4f3a25 | 134 | * be non-functional, since the RTC will not run. If you don't use a softdevice, you'll |
Rohit Grover |
65:98215c4f3a25 | 135 | * have to start the LFCLK manually. See the rtc_example's \ref lfclk_config() function |
Rohit Grover |
65:98215c4f3a25 | 136 | * for an example of how to do this. If you use a softdevice, the LFCLK is started on |
Rohit Grover |
65:98215c4f3a25 | 137 | * softdevice init. |
Rohit Grover |
37:c29c330d942c | 138 | * |
Rohit Grover |
37:c29c330d942c | 139 | * |
bogdanm | 0:eff01767de02 | 140 | * @param[in] PRESCALER Value of the RTC1 PRESCALER register. This will decide the |
bogdanm | 0:eff01767de02 | 141 | * timer tick rate. Set to 0 for no prescaling. |
bogdanm | 0:eff01767de02 | 142 | * @param[in] MAX_TIMERS Maximum number of timers that can be created at any given time. |
bogdanm | 0:eff01767de02 | 143 | * @param[in] OP_QUEUES_SIZE Size of queues holding timer operations that are pending execution. |
bogdanm | 0:eff01767de02 | 144 | * @param[in] USE_SCHEDULER TRUE if the application is using the event scheduler, |
bogdanm | 0:eff01767de02 | 145 | * FALSE otherwise. |
bogdanm | 0:eff01767de02 | 146 | * |
bogdanm | 0:eff01767de02 | 147 | * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it |
bogdanm | 0:eff01767de02 | 148 | * several times as long as it is from the same location, e.g. to do a reinitialization). |
bogdanm | 0:eff01767de02 | 149 | */ |
bogdanm | 0:eff01767de02 | 150 | /*lint -emacro(506, APP_TIMER_INIT) */ /* Suppress "Constant value Boolean */ |
bogdanm | 0:eff01767de02 | 151 | #define APP_TIMER_INIT(PRESCALER, MAX_TIMERS, OP_QUEUES_SIZE, USE_SCHEDULER) \ |
bogdanm | 0:eff01767de02 | 152 | do \ |
bogdanm | 0:eff01767de02 | 153 | { \ |
bogdanm | 0:eff01767de02 | 154 | static uint32_t APP_TIMER_BUF[CEIL_DIV(APP_TIMER_BUF_SIZE((MAX_TIMERS), \ |
bogdanm | 0:eff01767de02 | 155 | (OP_QUEUES_SIZE) + 1), \ |
bogdanm | 0:eff01767de02 | 156 | sizeof(uint32_t))]; \ |
bogdanm | 0:eff01767de02 | 157 | uint32_t ERR_CODE = app_timer_init((PRESCALER), \ |
bogdanm | 0:eff01767de02 | 158 | (MAX_TIMERS), \ |
bogdanm | 0:eff01767de02 | 159 | (OP_QUEUES_SIZE) + 1, \ |
bogdanm | 0:eff01767de02 | 160 | APP_TIMER_BUF, \ |
bogdanm | 0:eff01767de02 | 161 | (USE_SCHEDULER) ? app_timer_evt_schedule : NULL); \ |
bogdanm | 0:eff01767de02 | 162 | APP_ERROR_CHECK(ERR_CODE); \ |
bogdanm | 0:eff01767de02 | 163 | } while (0) |
bogdanm | 0:eff01767de02 | 164 | |
bogdanm | 0:eff01767de02 | 165 | /**@brief Function for initializing the timer module. |
bogdanm | 0:eff01767de02 | 166 | * |
bogdanm | 0:eff01767de02 | 167 | * @note Normally initialization should be done using the APP_TIMER_INIT() macro, as that will both |
bogdanm | 0:eff01767de02 | 168 | * allocate the buffers needed by the timer module (including aligning the buffers correctly, |
bogdanm | 0:eff01767de02 | 169 | * and also take care of connecting the timer module to the scheduler (if specified). |
bogdanm | 0:eff01767de02 | 170 | * |
bogdanm | 0:eff01767de02 | 171 | * @param[in] prescaler Value of the RTC1 PRESCALER register. Set to 0 for no prescaling. |
bogdanm | 0:eff01767de02 | 172 | * @param[in] max_timers Maximum number of timers that can be created at any given time. |
bogdanm | 0:eff01767de02 | 173 | * @param[in] op_queues_size Size of queues holding timer operations that are pending |
bogdanm | 0:eff01767de02 | 174 | * execution. NOTE: Due to the queue implementation, this size must |
bogdanm | 0:eff01767de02 | 175 | * be one more than the size that is actually needed. |
bogdanm | 0:eff01767de02 | 176 | * @param[in] p_buffer Pointer to memory buffer for internal use in the app_timer |
bogdanm | 0:eff01767de02 | 177 | * module. The size of the buffer can be computed using the |
bogdanm | 0:eff01767de02 | 178 | * APP_TIMER_BUF_SIZE() macro. The buffer must be aligned to a |
bogdanm | 0:eff01767de02 | 179 | * 4 byte boundary. |
bogdanm | 0:eff01767de02 | 180 | * @param[in] evt_schedule_func Function for passing timeout events to the scheduler. Point to |
bogdanm | 0:eff01767de02 | 181 | * app_timer_evt_schedule() to connect to the scheduler. Set to NULL |
bogdanm | 0:eff01767de02 | 182 | * to make the timer module call the timeout handler directly from |
bogdanm | 0:eff01767de02 | 183 | * the timer interrupt handler. |
bogdanm | 0:eff01767de02 | 184 | * |
bogdanm | 0:eff01767de02 | 185 | * @retval NRF_SUCCESS Successful initialization. |
bogdanm | 0:eff01767de02 | 186 | * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte |
bogdanm | 0:eff01767de02 | 187 | * boundary or NULL). |
bogdanm | 0:eff01767de02 | 188 | */ |
Rohit Grover |
65:98215c4f3a25 | 189 | uint32_t app_timer_init(uint32_t prescaler, |
bogdanm | 0:eff01767de02 | 190 | uint8_t max_timers, |
bogdanm | 0:eff01767de02 | 191 | uint8_t op_queues_size, |
bogdanm | 0:eff01767de02 | 192 | void * p_buffer, |
bogdanm | 0:eff01767de02 | 193 | app_timer_evt_schedule_func_t evt_schedule_func); |
bogdanm | 0:eff01767de02 | 194 | |
bogdanm | 0:eff01767de02 | 195 | /**@brief Function for creating a timer instance. |
bogdanm | 0:eff01767de02 | 196 | * |
bogdanm | 0:eff01767de02 | 197 | * @param[out] p_timer_id Id of the newly created timer. |
bogdanm | 0:eff01767de02 | 198 | * @param[in] mode Timer mode. |
bogdanm | 0:eff01767de02 | 199 | * @param[in] timeout_handler Function to be executed when the timer expires. |
bogdanm | 0:eff01767de02 | 200 | * |
bogdanm | 0:eff01767de02 | 201 | * @retval NRF_SUCCESS Timer was successfully created. |
bogdanm | 0:eff01767de02 | 202 | * @retval NRF_ERROR_INVALID_PARAM Invalid parameter. |
bogdanm | 0:eff01767de02 | 203 | * @retval NRF_ERROR_INVALID_STATE Application timer module has not been initialized. |
bogdanm | 0:eff01767de02 | 204 | * @retval NRF_ERROR_NO_MEM Maximum number of timers has already been reached. |
bogdanm | 0:eff01767de02 | 205 | * |
bogdanm | 0:eff01767de02 | 206 | * @note This function does the timer allocation in the caller's context. It is also not protected |
bogdanm | 0:eff01767de02 | 207 | * by a critical region. Therefore care must be taken not to call it from several interrupt |
bogdanm | 0:eff01767de02 | 208 | * levels simultaneously. |
bogdanm | 0:eff01767de02 | 209 | */ |
bogdanm | 0:eff01767de02 | 210 | uint32_t app_timer_create(app_timer_id_t * p_timer_id, |
bogdanm | 0:eff01767de02 | 211 | app_timer_mode_t mode, |
bogdanm | 0:eff01767de02 | 212 | app_timer_timeout_handler_t timeout_handler); |
bogdanm | 0:eff01767de02 | 213 | |
bogdanm | 0:eff01767de02 | 214 | /**@brief Function for starting a timer. |
bogdanm | 0:eff01767de02 | 215 | * |
bogdanm | 0:eff01767de02 | 216 | * @param[in] timer_id Id of timer to start. |
bogdanm | 0:eff01767de02 | 217 | * @param[in] timeout_ticks Number of ticks (of RTC1, including prescaling) to timeout event |
bogdanm | 0:eff01767de02 | 218 | * (minimum 5 ticks). |
bogdanm | 0:eff01767de02 | 219 | * @param[in] p_context General purpose pointer. Will be passed to the timeout handler when |
bogdanm | 0:eff01767de02 | 220 | * the timer expires. |
bogdanm | 0:eff01767de02 | 221 | * |
bogdanm | 0:eff01767de02 | 222 | * @retval NRF_SUCCESS Timer was successfully started. |
bogdanm | 0:eff01767de02 | 223 | * @retval NRF_ERROR_INVALID_PARAM Invalid parameter. |
bogdanm | 0:eff01767de02 | 224 | * @retval NRF_ERROR_INVALID_STATE Application timer module has not been initialized, or timer |
bogdanm | 0:eff01767de02 | 225 | * has not been created. |
bogdanm | 0:eff01767de02 | 226 | * @retval NRF_ERROR_NO_MEM Timer operations queue was full. |
bogdanm | 0:eff01767de02 | 227 | * |
bogdanm | 0:eff01767de02 | 228 | * @note The minimum timeout_ticks value is 5. |
bogdanm | 0:eff01767de02 | 229 | * @note For multiple active timers, timeouts occurring in close proximity to each other (in the |
bogdanm | 0:eff01767de02 | 230 | * range of 1 to 3 ticks) will have a positive jitter of maximum 3 ticks. |
bogdanm | 0:eff01767de02 | 231 | * @note When calling this method on a timer which is already running, the second start operation |
bogdanm | 0:eff01767de02 | 232 | * will be ignored. |
bogdanm | 0:eff01767de02 | 233 | */ |
bogdanm | 0:eff01767de02 | 234 | uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context); |
bogdanm | 0:eff01767de02 | 235 | |
bogdanm | 0:eff01767de02 | 236 | /**@brief Function for stopping the specified timer. |
bogdanm | 0:eff01767de02 | 237 | * |
bogdanm | 0:eff01767de02 | 238 | * @param[in] timer_id Id of timer to stop. |
bogdanm | 0:eff01767de02 | 239 | * |
bogdanm | 0:eff01767de02 | 240 | * @retval NRF_SUCCESS Timer was successfully stopped. |
bogdanm | 0:eff01767de02 | 241 | * @retval NRF_ERROR_INVALID_PARAM Invalid parameter. |
bogdanm | 0:eff01767de02 | 242 | * @retval NRF_ERROR_INVALID_STATE Application timer module has not been initialized, or timer |
bogdanm | 0:eff01767de02 | 243 | * has not been created. |
bogdanm | 0:eff01767de02 | 244 | * @retval NRF_ERROR_NO_MEM Timer operations queue was full. |
bogdanm | 0:eff01767de02 | 245 | */ |
bogdanm | 0:eff01767de02 | 246 | uint32_t app_timer_stop(app_timer_id_t timer_id); |
bogdanm | 0:eff01767de02 | 247 | |
bogdanm | 0:eff01767de02 | 248 | /**@brief Function for stopping all running timers. |
bogdanm | 0:eff01767de02 | 249 | * |
bogdanm | 0:eff01767de02 | 250 | * @retval NRF_SUCCESS All timers were successfully stopped. |
bogdanm | 0:eff01767de02 | 251 | * @retval NRF_ERROR_INVALID_STATE Application timer module has not been initialized. |
bogdanm | 0:eff01767de02 | 252 | * @retval NRF_ERROR_NO_MEM Timer operations queue was full. |
bogdanm | 0:eff01767de02 | 253 | */ |
bogdanm | 0:eff01767de02 | 254 | uint32_t app_timer_stop_all(void); |
bogdanm | 0:eff01767de02 | 255 | |
Rohit Grover |
56:a1071b629aa3 | 256 | /**@brief Function for returning the current value of the RTC1 counter. The |
Rohit Grover |
56:a1071b629aa3 | 257 | * value includes overflow bits to extend the range to 64-bits. |
bogdanm | 0:eff01767de02 | 258 | * |
bogdanm | 0:eff01767de02 | 259 | * @param[out] p_ticks Current value of the RTC1 counter. |
bogdanm | 0:eff01767de02 | 260 | * |
bogdanm | 0:eff01767de02 | 261 | * @retval NRF_SUCCESS Counter was successfully read. |
bogdanm | 0:eff01767de02 | 262 | */ |
Rohit Grover |
56:a1071b629aa3 | 263 | uint32_t app_timer_cnt_get(uint64_t * p_ticks); |
bogdanm | 0:eff01767de02 | 264 | |
bogdanm | 0:eff01767de02 | 265 | /**@brief Function for computing the difference between two RTC1 counter values. |
bogdanm | 0:eff01767de02 | 266 | * |
bogdanm | 0:eff01767de02 | 267 | * @param[in] ticks_to Value returned by app_timer_cnt_get(). |
bogdanm | 0:eff01767de02 | 268 | * @param[in] ticks_from Value returned by app_timer_cnt_get(). |
bogdanm | 0:eff01767de02 | 269 | * @param[out] p_ticks_diff Number of ticks from ticks_from to ticks_to. |
bogdanm | 0:eff01767de02 | 270 | * |
bogdanm | 0:eff01767de02 | 271 | * @retval NRF_SUCCESS Counter difference was successfully computed. |
bogdanm | 0:eff01767de02 | 272 | */ |
bogdanm | 0:eff01767de02 | 273 | uint32_t app_timer_cnt_diff_compute(uint32_t ticks_to, |
bogdanm | 0:eff01767de02 | 274 | uint32_t ticks_from, |
bogdanm | 0:eff01767de02 | 275 | uint32_t * p_ticks_diff); |
bogdanm | 0:eff01767de02 | 276 | |
bogdanm | 0:eff01767de02 | 277 | |
bogdanm | 0:eff01767de02 | 278 | // Type and functions for connecting the timer to the scheduler: |
bogdanm | 0:eff01767de02 | 279 | |
bogdanm | 0:eff01767de02 | 280 | /**@cond NO_DOXYGEN */ |
bogdanm | 0:eff01767de02 | 281 | typedef struct |
bogdanm | 0:eff01767de02 | 282 | { |
bogdanm | 0:eff01767de02 | 283 | app_timer_timeout_handler_t timeout_handler; |
bogdanm | 0:eff01767de02 | 284 | void * p_context; |
bogdanm | 0:eff01767de02 | 285 | } app_timer_event_t; |
bogdanm | 0:eff01767de02 | 286 | |
bogdanm | 0:eff01767de02 | 287 | static __INLINE void app_timer_evt_get(void * p_event_data, uint16_t event_size) |
bogdanm | 0:eff01767de02 | 288 | { |
bogdanm | 0:eff01767de02 | 289 | app_timer_event_t * p_timer_event = (app_timer_event_t *)p_event_data; |
Rohit Grover |
65:98215c4f3a25 | 290 | |
bogdanm | 0:eff01767de02 | 291 | APP_ERROR_CHECK_BOOL(event_size == sizeof(app_timer_event_t)); |
bogdanm | 0:eff01767de02 | 292 | p_timer_event->timeout_handler(p_timer_event->p_context); |
bogdanm | 0:eff01767de02 | 293 | } |
bogdanm | 0:eff01767de02 | 294 | |
bogdanm | 0:eff01767de02 | 295 | static __INLINE uint32_t app_timer_evt_schedule(app_timer_timeout_handler_t timeout_handler, |
bogdanm | 0:eff01767de02 | 296 | void * p_context) |
bogdanm | 0:eff01767de02 | 297 | { |
bogdanm | 0:eff01767de02 | 298 | app_timer_event_t timer_event; |
bogdanm | 0:eff01767de02 | 299 | |
bogdanm | 0:eff01767de02 | 300 | timer_event.timeout_handler = timeout_handler; |
bogdanm | 0:eff01767de02 | 301 | timer_event.p_context = p_context; |
Rohit Grover |
65:98215c4f3a25 | 302 | |
bogdanm | 0:eff01767de02 | 303 | return app_sched_event_put(&timer_event, sizeof(timer_event), app_timer_evt_get); |
bogdanm | 0:eff01767de02 | 304 | } |
bogdanm | 0:eff01767de02 | 305 | /**@endcond */ |
bogdanm | 0:eff01767de02 | 306 | |
Rohit Grover |
45:3c4df37ed83e | 307 | #ifdef __cplusplus |
Rohit Grover |
45:3c4df37ed83e | 308 | } |
Rohit Grover |
45:3c4df37ed83e | 309 | #endif // #ifdef __cplusplus |
Rohit Grover |
45:3c4df37ed83e | 310 | |
bogdanm | 0:eff01767de02 | 311 | #endif // APP_TIMER_H__ |
bogdanm | 0:eff01767de02 | 312 | |
bogdanm | 0:eff01767de02 | 313 | /** @} */ |