Nordic stack and drivers for the mbed BLE API
Dependents: BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate writable_gatt ... more
TARGET_MCU_NRF51822/sdk/source/libraries/timer/app_timer.h@638:c90ae1400bf2, 2016-09-14 (annotated)
- Committer:
- Vincent Coubard
- Date:
- Wed Sep 14 14:39:43 2016 +0100
- Revision:
- 638:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Vincent Coubard |
638:c90ae1400bf2 | 1 | /* |
Vincent Coubard |
638:c90ae1400bf2 | 2 | * Copyright (c) Nordic Semiconductor ASA |
Vincent Coubard |
638:c90ae1400bf2 | 3 | * All rights reserved. |
Vincent Coubard |
638:c90ae1400bf2 | 4 | * |
Vincent Coubard |
638:c90ae1400bf2 | 5 | * Redistribution and use in source and binary forms, with or without modification, |
Vincent Coubard |
638:c90ae1400bf2 | 6 | * are permitted provided that the following conditions are met: |
Vincent Coubard |
638:c90ae1400bf2 | 7 | * |
Vincent Coubard |
638:c90ae1400bf2 | 8 | * 1. Redistributions of source code must retain the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 9 | * list of conditions and the following disclaimer. |
Vincent Coubard |
638:c90ae1400bf2 | 10 | * |
Vincent Coubard |
638:c90ae1400bf2 | 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, this |
Vincent Coubard |
638:c90ae1400bf2 | 12 | * list of conditions and the following disclaimer in the documentation and/or |
Vincent Coubard |
638:c90ae1400bf2 | 13 | * other materials provided with the distribution. |
Vincent Coubard |
638:c90ae1400bf2 | 14 | * |
Vincent Coubard |
638:c90ae1400bf2 | 15 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of other |
Vincent Coubard |
638:c90ae1400bf2 | 16 | * contributors to this software may be used to endorse or promote products |
Vincent Coubard |
638:c90ae1400bf2 | 17 | * derived from this software without specific prior written permission. |
Vincent Coubard |
638:c90ae1400bf2 | 18 | * |
Vincent Coubard |
638:c90ae1400bf2 | 19 | * |
Vincent Coubard |
638:c90ae1400bf2 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
Vincent Coubard |
638:c90ae1400bf2 | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
Vincent Coubard |
638:c90ae1400bf2 | 22 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Vincent Coubard |
638:c90ae1400bf2 | 23 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
Vincent Coubard |
638:c90ae1400bf2 | 24 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
Vincent Coubard |
638:c90ae1400bf2 | 25 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
Vincent Coubard |
638:c90ae1400bf2 | 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
Vincent Coubard |
638:c90ae1400bf2 | 27 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
Vincent Coubard |
638:c90ae1400bf2 | 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
Vincent Coubard |
638:c90ae1400bf2 | 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Vincent Coubard |
638:c90ae1400bf2 | 30 | * |
Vincent Coubard |
638:c90ae1400bf2 | 31 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 32 | |
Vincent Coubard |
638:c90ae1400bf2 | 33 | /** @file |
Vincent Coubard |
638:c90ae1400bf2 | 34 | * |
Vincent Coubard |
638:c90ae1400bf2 | 35 | * @defgroup app_timer Application Timer |
Vincent Coubard |
638:c90ae1400bf2 | 36 | * @{ |
Vincent Coubard |
638:c90ae1400bf2 | 37 | * @ingroup app_common |
Vincent Coubard |
638:c90ae1400bf2 | 38 | * |
Vincent Coubard |
638:c90ae1400bf2 | 39 | * @brief Application timer functionality. |
Vincent Coubard |
638:c90ae1400bf2 | 40 | * |
Vincent Coubard |
638:c90ae1400bf2 | 41 | * @details This module enables the application to create multiple timer instances based on the RTC1 |
Vincent Coubard |
638:c90ae1400bf2 | 42 | * peripheral. Checking for time-outs and invokation of user time-out handlers is performed |
Vincent Coubard |
638:c90ae1400bf2 | 43 | * in the RTC1 interrupt handler. List handling is done using a software interrupt (SWI0). |
Vincent Coubard |
638:c90ae1400bf2 | 44 | * Both interrupt handlers are running in APP_LOW priority level. |
Vincent Coubard |
638:c90ae1400bf2 | 45 | * |
Vincent Coubard |
638:c90ae1400bf2 | 46 | * @details When calling app_timer_start() or app_timer_stop(), the timer operation is just queued, |
Vincent Coubard |
638:c90ae1400bf2 | 47 | * and the software interrupt is triggered. The actual timer start/stop operation is |
Vincent Coubard |
638:c90ae1400bf2 | 48 | * executed by the SWI0 interrupt handler. Since the SWI0 interrupt is running in APP_LOW, |
Vincent Coubard |
638:c90ae1400bf2 | 49 | * if the application code calling the timer function is running in APP_LOW or APP_HIGH, |
Vincent Coubard |
638:c90ae1400bf2 | 50 | * the timer operation will not be performed until the application handler has returned. |
Vincent Coubard |
638:c90ae1400bf2 | 51 | * This will be the case, for example, when stopping a timer from a time-out handler when not using |
Vincent Coubard |
638:c90ae1400bf2 | 52 | * the scheduler. |
Vincent Coubard |
638:c90ae1400bf2 | 53 | * |
Vincent Coubard |
638:c90ae1400bf2 | 54 | * @details Use the USE_SCHEDULER parameter of the APP_TIMER_INIT() macro to select if the |
Vincent Coubard |
638:c90ae1400bf2 | 55 | * @ref app_scheduler should be used or not. Even if the scheduler is |
Vincent Coubard |
638:c90ae1400bf2 | 56 | * not used, app_timer.h will include app_scheduler.h, so when |
Vincent Coubard |
638:c90ae1400bf2 | 57 | * compiling, app_scheduler.h must be available in one of the compiler include paths. |
Vincent Coubard |
638:c90ae1400bf2 | 58 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 59 | |
Vincent Coubard |
638:c90ae1400bf2 | 60 | #ifndef APP_TIMER_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 61 | #define APP_TIMER_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 62 | |
Vincent Coubard |
638:c90ae1400bf2 | 63 | #include <stdint.h> |
Vincent Coubard |
638:c90ae1400bf2 | 64 | #include <stdbool.h> |
Vincent Coubard |
638:c90ae1400bf2 | 65 | #include <stdio.h> |
Vincent Coubard |
638:c90ae1400bf2 | 66 | #include "app_error.h" |
Vincent Coubard |
638:c90ae1400bf2 | 67 | #include "app_util.h" |
Vincent Coubard |
638:c90ae1400bf2 | 68 | #include "compiler_abstraction.h" |
Vincent Coubard |
638:c90ae1400bf2 | 69 | |
Vincent Coubard |
638:c90ae1400bf2 | 70 | #define APP_TIMER_CLOCK_FREQ 32768 /**< Clock frequency of the RTC timer used to implement the app timer module. */ |
Vincent Coubard |
638:c90ae1400bf2 | 71 | #define APP_TIMER_MIN_TIMEOUT_TICKS 5 /**< Minimum value of the timeout_ticks parameter of app_timer_start(). */ |
Vincent Coubard |
638:c90ae1400bf2 | 72 | |
Vincent Coubard |
638:c90ae1400bf2 | 73 | #define APP_TIMER_NODE_SIZE 32 /**< Size of app_timer.timer_node_t (used to allocate data). */ |
Vincent Coubard |
638:c90ae1400bf2 | 74 | #define APP_TIMER_USER_OP_SIZE 24 /**< Size of app_timer.timer_user_op_t (only for use inside APP_TIMER_BUF_SIZE()). */ |
Vincent Coubard |
638:c90ae1400bf2 | 75 | #define APP_TIMER_USER_SIZE 8 /**< Size of app_timer.timer_user_t (only for use inside APP_TIMER_BUF_SIZE()). */ |
Vincent Coubard |
638:c90ae1400bf2 | 76 | #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()). */ |
Vincent Coubard |
638:c90ae1400bf2 | 77 | |
Vincent Coubard |
638:c90ae1400bf2 | 78 | /**@brief Compute number of bytes required to hold the application timer data structures. |
Vincent Coubard |
638:c90ae1400bf2 | 79 | * |
Vincent Coubard |
638:c90ae1400bf2 | 80 | * @param[in] OP_QUEUE_SIZE Size of queues holding timer operations that are pending execution. |
Vincent Coubard |
638:c90ae1400bf2 | 81 | * Note that due to the queue implementation, this size must be one more |
Vincent Coubard |
638:c90ae1400bf2 | 82 | * than the size that is actually needed. |
Vincent Coubard |
638:c90ae1400bf2 | 83 | * |
Vincent Coubard |
638:c90ae1400bf2 | 84 | * @return Required application timer buffer size (in bytes). |
Vincent Coubard |
638:c90ae1400bf2 | 85 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 86 | #define APP_TIMER_BUF_SIZE(OP_QUEUE_SIZE) \ |
Vincent Coubard |
638:c90ae1400bf2 | 87 | ( \ |
Vincent Coubard |
638:c90ae1400bf2 | 88 | ( \ |
Vincent Coubard |
638:c90ae1400bf2 | 89 | APP_TIMER_INT_LEVELS \ |
Vincent Coubard |
638:c90ae1400bf2 | 90 | * \ |
Vincent Coubard |
638:c90ae1400bf2 | 91 | (APP_TIMER_USER_SIZE + ((OP_QUEUE_SIZE) + 1) * APP_TIMER_USER_OP_SIZE) \ |
Vincent Coubard |
638:c90ae1400bf2 | 92 | ) \ |
Vincent Coubard |
638:c90ae1400bf2 | 93 | ) |
Vincent Coubard |
638:c90ae1400bf2 | 94 | |
Vincent Coubard |
638:c90ae1400bf2 | 95 | /**@brief Convert milliseconds to timer ticks. |
Vincent Coubard |
638:c90ae1400bf2 | 96 | * |
Vincent Coubard |
638:c90ae1400bf2 | 97 | * This macro uses 64-bit integer arithmetic, but as long as the macro parameters are |
Vincent Coubard |
638:c90ae1400bf2 | 98 | * constants (i.e. defines), the computation will be done by the preprocessor. |
Vincent Coubard |
638:c90ae1400bf2 | 99 | * |
Vincent Coubard |
638:c90ae1400bf2 | 100 | * When using this macro, ensure that the |
Vincent Coubard |
638:c90ae1400bf2 | 101 | * values provided as input result in an output value that is supported by the |
Vincent Coubard |
638:c90ae1400bf2 | 102 | * @ref app_timer_start function. For example, when the ticks for 1 ms is needed, the |
Vincent Coubard |
638:c90ae1400bf2 | 103 | * maximum possible value of PRESCALER must be 6, when @ref APP_TIMER_CLOCK_FREQ is 32768. |
Vincent Coubard |
638:c90ae1400bf2 | 104 | * This will result in a ticks value as 5. Any higher value for PRESCALER will result in a |
Vincent Coubard |
638:c90ae1400bf2 | 105 | * ticks value that is not supported by this module. |
Vincent Coubard |
638:c90ae1400bf2 | 106 | * |
Vincent Coubard |
638:c90ae1400bf2 | 107 | * @param[in] MS Milliseconds. |
Vincent Coubard |
638:c90ae1400bf2 | 108 | * @param[in] PRESCALER Value of the RTC1 PRESCALER register (must be the same value that was |
Vincent Coubard |
638:c90ae1400bf2 | 109 | * passed to APP_TIMER_INIT()). |
Vincent Coubard |
638:c90ae1400bf2 | 110 | * |
Vincent Coubard |
638:c90ae1400bf2 | 111 | * @return Number of timer ticks. |
Vincent Coubard |
638:c90ae1400bf2 | 112 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 113 | #define APP_TIMER_TICKS(MS, PRESCALER)\ |
Vincent Coubard |
638:c90ae1400bf2 | 114 | ((uint32_t)ROUNDED_DIV((MS) * (uint64_t)APP_TIMER_CLOCK_FREQ, ((PRESCALER) + 1) * 1000)) |
Vincent Coubard |
638:c90ae1400bf2 | 115 | |
Vincent Coubard |
638:c90ae1400bf2 | 116 | typedef struct app_timer_t { uint32_t data[CEIL_DIV(APP_TIMER_NODE_SIZE, sizeof(uint32_t))]; } app_timer_t; |
Vincent Coubard |
638:c90ae1400bf2 | 117 | |
Vincent Coubard |
638:c90ae1400bf2 | 118 | /**@brief Timer ID type. |
Vincent Coubard |
638:c90ae1400bf2 | 119 | * Never declare a variable of this type, but use the macro @ref APP_TIMER_DEF instead.*/ |
Vincent Coubard |
638:c90ae1400bf2 | 120 | typedef app_timer_t * app_timer_id_t; |
Vincent Coubard |
638:c90ae1400bf2 | 121 | |
Vincent Coubard |
638:c90ae1400bf2 | 122 | /** |
Vincent Coubard |
638:c90ae1400bf2 | 123 | * @brief Create a timer identifier and statically allocate memory for the timer. |
Vincent Coubard |
638:c90ae1400bf2 | 124 | * |
Vincent Coubard |
638:c90ae1400bf2 | 125 | * @param timer_id Name of the timer identifier variable that will be used to control the timer. |
Vincent Coubard |
638:c90ae1400bf2 | 126 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 127 | #define APP_TIMER_DEF(timer_id) \ |
Vincent Coubard |
638:c90ae1400bf2 | 128 | static app_timer_t timer_id##_data = { {0} }; \ |
Vincent Coubard |
638:c90ae1400bf2 | 129 | static const app_timer_id_t timer_id = &timer_id##_data |
Vincent Coubard |
638:c90ae1400bf2 | 130 | |
Vincent Coubard |
638:c90ae1400bf2 | 131 | |
Vincent Coubard |
638:c90ae1400bf2 | 132 | /**@brief Application time-out handler type. */ |
Vincent Coubard |
638:c90ae1400bf2 | 133 | typedef void (*app_timer_timeout_handler_t)(void * p_context); |
Vincent Coubard |
638:c90ae1400bf2 | 134 | |
Vincent Coubard |
638:c90ae1400bf2 | 135 | /**@brief Type of function for passing events from the timer module to the scheduler. */ |
Vincent Coubard |
638:c90ae1400bf2 | 136 | typedef uint32_t (*app_timer_evt_schedule_func_t) (app_timer_timeout_handler_t timeout_handler, |
Vincent Coubard |
638:c90ae1400bf2 | 137 | void * p_context); |
Vincent Coubard |
638:c90ae1400bf2 | 138 | |
Vincent Coubard |
638:c90ae1400bf2 | 139 | /**@brief Timer modes. */ |
Vincent Coubard |
638:c90ae1400bf2 | 140 | typedef enum |
Vincent Coubard |
638:c90ae1400bf2 | 141 | { |
Vincent Coubard |
638:c90ae1400bf2 | 142 | APP_TIMER_MODE_SINGLE_SHOT, /**< The timer will expire only once. */ |
Vincent Coubard |
638:c90ae1400bf2 | 143 | APP_TIMER_MODE_REPEATED /**< The timer will restart each time it expires. */ |
Vincent Coubard |
638:c90ae1400bf2 | 144 | } app_timer_mode_t; |
Vincent Coubard |
638:c90ae1400bf2 | 145 | |
Vincent Coubard |
638:c90ae1400bf2 | 146 | /**@brief Initialize the application timer module. |
Vincent Coubard |
638:c90ae1400bf2 | 147 | * |
Vincent Coubard |
638:c90ae1400bf2 | 148 | * @details This macro handles dimensioning and allocation of the memory buffer required by the timer, |
Vincent Coubard |
638:c90ae1400bf2 | 149 | * making sure that the buffer is correctly aligned. It will also connect the timer module |
Vincent Coubard |
638:c90ae1400bf2 | 150 | * to the scheduler (if specified). |
Vincent Coubard |
638:c90ae1400bf2 | 151 | * |
Vincent Coubard |
638:c90ae1400bf2 | 152 | * @note This module assumes that the LFCLK is already running. If it is not, the module will |
Vincent Coubard |
638:c90ae1400bf2 | 153 | * be non-functional, since the RTC will not run. If you do not use a SoftDevice, you |
Vincent Coubard |
638:c90ae1400bf2 | 154 | * must start the LFCLK manually. See the rtc_example's lfclk_config() function |
Vincent Coubard |
638:c90ae1400bf2 | 155 | * for an example of how to do this. If you use a SoftDevice, the LFCLK is started on |
Vincent Coubard |
638:c90ae1400bf2 | 156 | * SoftDevice init. |
Vincent Coubard |
638:c90ae1400bf2 | 157 | * |
Vincent Coubard |
638:c90ae1400bf2 | 158 | * |
Vincent Coubard |
638:c90ae1400bf2 | 159 | * @param[in] PRESCALER Value of the RTC1 PRESCALER register. This will decide the |
Vincent Coubard |
638:c90ae1400bf2 | 160 | * timer tick rate. Set to 0 for no prescaling. |
Vincent Coubard |
638:c90ae1400bf2 | 161 | * @param[in] OP_QUEUES_SIZE Size of queues holding timer operations that are pending execution. |
Vincent Coubard |
638:c90ae1400bf2 | 162 | * @param[in] SCHEDULER_FUNC Pointer to scheduler event handler |
Vincent Coubard |
638:c90ae1400bf2 | 163 | * |
Vincent Coubard |
638:c90ae1400bf2 | 164 | * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it |
Vincent Coubard |
638:c90ae1400bf2 | 165 | * several times as long as it is from the same location, for example, to do a re-initialization). |
Vincent Coubard |
638:c90ae1400bf2 | 166 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 167 | /*lint -emacro(506, APP_TIMER_INIT) */ /* Suppress "Constant value Boolean */ |
Vincent Coubard |
638:c90ae1400bf2 | 168 | #define APP_TIMER_INIT(PRESCALER, OP_QUEUES_SIZE, SCHEDULER_FUNC) \ |
Vincent Coubard |
638:c90ae1400bf2 | 169 | do \ |
Vincent Coubard |
638:c90ae1400bf2 | 170 | { \ |
Vincent Coubard |
638:c90ae1400bf2 | 171 | static uint32_t APP_TIMER_BUF[CEIL_DIV(APP_TIMER_BUF_SIZE((OP_QUEUES_SIZE) + 1), \ |
Vincent Coubard |
638:c90ae1400bf2 | 172 | sizeof(uint32_t))]; \ |
Vincent Coubard |
638:c90ae1400bf2 | 173 | uint32_t ERR_CODE = app_timer_init((PRESCALER), \ |
Vincent Coubard |
638:c90ae1400bf2 | 174 | (OP_QUEUES_SIZE) + 1, \ |
Vincent Coubard |
638:c90ae1400bf2 | 175 | APP_TIMER_BUF, \ |
Vincent Coubard |
638:c90ae1400bf2 | 176 | SCHEDULER_FUNC); \ |
Vincent Coubard |
638:c90ae1400bf2 | 177 | APP_ERROR_CHECK(ERR_CODE); \ |
Vincent Coubard |
638:c90ae1400bf2 | 178 | } while (0) |
Vincent Coubard |
638:c90ae1400bf2 | 179 | |
Vincent Coubard |
638:c90ae1400bf2 | 180 | |
Vincent Coubard |
638:c90ae1400bf2 | 181 | |
Vincent Coubard |
638:c90ae1400bf2 | 182 | /**@brief Function for initializing the timer module. |
Vincent Coubard |
638:c90ae1400bf2 | 183 | * |
Vincent Coubard |
638:c90ae1400bf2 | 184 | * Normally, initialization should be done using the APP_TIMER_INIT() macro, because that macro will both |
Vincent Coubard |
638:c90ae1400bf2 | 185 | * allocate the buffers needed by the timer module (including aligning the buffers correctly) |
Vincent Coubard |
638:c90ae1400bf2 | 186 | * and take care of connecting the timer module to the scheduler (if specified). |
Vincent Coubard |
638:c90ae1400bf2 | 187 | * |
Vincent Coubard |
638:c90ae1400bf2 | 188 | * @param[in] prescaler Value of the RTC1 PRESCALER register. Set to 0 for no prescaling. |
Vincent Coubard |
638:c90ae1400bf2 | 189 | * @param[in] op_queues_size Size of queues holding timer operations that are pending |
Vincent Coubard |
638:c90ae1400bf2 | 190 | * execution. Note that due to the queue implementation, this size must |
Vincent Coubard |
638:c90ae1400bf2 | 191 | * be one more than the size that is actually needed. |
Vincent Coubard |
638:c90ae1400bf2 | 192 | * @param[in] p_buffer Pointer to memory buffer for internal use in the app_timer |
Vincent Coubard |
638:c90ae1400bf2 | 193 | * module. The size of the buffer can be computed using the |
Vincent Coubard |
638:c90ae1400bf2 | 194 | * APP_TIMER_BUF_SIZE() macro. The buffer must be aligned to a |
Vincent Coubard |
638:c90ae1400bf2 | 195 | * 4 byte boundary. |
Vincent Coubard |
638:c90ae1400bf2 | 196 | * @param[in] evt_schedule_func Function for passing time-out events to the scheduler. Point to |
Vincent Coubard |
638:c90ae1400bf2 | 197 | * app_timer_evt_schedule() to connect to the scheduler. Set to NULL |
Vincent Coubard |
638:c90ae1400bf2 | 198 | * to make the timer module call the time-out handler directly from |
Vincent Coubard |
638:c90ae1400bf2 | 199 | * the timer interrupt handler. |
Vincent Coubard |
638:c90ae1400bf2 | 200 | * |
Vincent Coubard |
638:c90ae1400bf2 | 201 | * @retval NRF_SUCCESS If the module was initialized successfully. |
Vincent Coubard |
638:c90ae1400bf2 | 202 | * @retval NRF_ERROR_INVALID_PARAM If a parameter was invalid (buffer not aligned to a 4 byte |
Vincent Coubard |
638:c90ae1400bf2 | 203 | * boundary or NULL). |
Vincent Coubard |
638:c90ae1400bf2 | 204 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 205 | uint32_t app_timer_init(uint32_t prescaler, |
Vincent Coubard |
638:c90ae1400bf2 | 206 | uint8_t op_queues_size, |
Vincent Coubard |
638:c90ae1400bf2 | 207 | void * p_buffer, |
Vincent Coubard |
638:c90ae1400bf2 | 208 | app_timer_evt_schedule_func_t evt_schedule_func); |
Vincent Coubard |
638:c90ae1400bf2 | 209 | |
Vincent Coubard |
638:c90ae1400bf2 | 210 | /**@brief Function for creating a timer instance. |
Vincent Coubard |
638:c90ae1400bf2 | 211 | * |
Vincent Coubard |
638:c90ae1400bf2 | 212 | * @param[in] p_timer_id Pointer to timer identifier. |
Vincent Coubard |
638:c90ae1400bf2 | 213 | * @param[in] mode Timer mode. |
Vincent Coubard |
638:c90ae1400bf2 | 214 | * @param[in] timeout_handler Function to be executed when the timer expires. |
Vincent Coubard |
638:c90ae1400bf2 | 215 | * |
Vincent Coubard |
638:c90ae1400bf2 | 216 | * @retval NRF_SUCCESS If the timer was successfully created. |
Vincent Coubard |
638:c90ae1400bf2 | 217 | * @retval NRF_ERROR_INVALID_PARAM If a parameter was invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 218 | * @retval NRF_ERROR_INVALID_STATE If the application timer module has not been initialized or |
Vincent Coubard |
638:c90ae1400bf2 | 219 | * the timer is running. |
Vincent Coubard |
638:c90ae1400bf2 | 220 | * |
Vincent Coubard |
638:c90ae1400bf2 | 221 | * @note This function does the timer allocation in the caller's context. It is also not protected |
Vincent Coubard |
638:c90ae1400bf2 | 222 | * by a critical region. Therefore care must be taken not to call it from several interrupt |
Vincent Coubard |
638:c90ae1400bf2 | 223 | * levels simultaneously. |
Vincent Coubard |
638:c90ae1400bf2 | 224 | * @note The function can be called again on the timer instance and will re-initialize the instance if |
Vincent Coubard |
638:c90ae1400bf2 | 225 | * the timer is not running. |
Vincent Coubard |
638:c90ae1400bf2 | 226 | * @attention The FreeRTOS and RTX app_timer implementation does not allow app_timer_create to |
Vincent Coubard |
638:c90ae1400bf2 | 227 | * be called on the previously initialized instance. |
Vincent Coubard |
638:c90ae1400bf2 | 228 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 229 | uint32_t app_timer_create(app_timer_id_t const * p_timer_id, |
Vincent Coubard |
638:c90ae1400bf2 | 230 | app_timer_mode_t mode, |
Vincent Coubard |
638:c90ae1400bf2 | 231 | app_timer_timeout_handler_t timeout_handler); |
Vincent Coubard |
638:c90ae1400bf2 | 232 | |
Vincent Coubard |
638:c90ae1400bf2 | 233 | /**@brief Function for starting a timer. |
Vincent Coubard |
638:c90ae1400bf2 | 234 | * |
Vincent Coubard |
638:c90ae1400bf2 | 235 | * @param[in] timer_id Timer identifier. |
Vincent Coubard |
638:c90ae1400bf2 | 236 | * @param[in] timeout_ticks Number of ticks (of RTC1, including prescaling) to time-out event |
Vincent Coubard |
638:c90ae1400bf2 | 237 | * (minimum 5 ticks). |
Vincent Coubard |
638:c90ae1400bf2 | 238 | * @param[in] p_context General purpose pointer. Will be passed to the time-out handler when |
Vincent Coubard |
638:c90ae1400bf2 | 239 | * the timer expires. |
Vincent Coubard |
638:c90ae1400bf2 | 240 | * |
Vincent Coubard |
638:c90ae1400bf2 | 241 | * @retval NRF_SUCCESS If the timer was successfully started. |
Vincent Coubard |
638:c90ae1400bf2 | 242 | * @retval NRF_ERROR_INVALID_PARAM If a parameter was invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 243 | * @retval NRF_ERROR_INVALID_STATE If the application timer module has not been initialized or the timer |
Vincent Coubard |
638:c90ae1400bf2 | 244 | * has not been created. |
Vincent Coubard |
638:c90ae1400bf2 | 245 | * @retval NRF_ERROR_NO_MEM If the timer operations queue was full. |
Vincent Coubard |
638:c90ae1400bf2 | 246 | * |
Vincent Coubard |
638:c90ae1400bf2 | 247 | * @note The minimum timeout_ticks value is 5. |
Vincent Coubard |
638:c90ae1400bf2 | 248 | * @note For multiple active timers, time-outs occurring in close proximity to each other (in the |
Vincent Coubard |
638:c90ae1400bf2 | 249 | * range of 1 to 3 ticks) will have a positive jitter of maximum 3 ticks. |
Vincent Coubard |
638:c90ae1400bf2 | 250 | * @note When calling this method on a timer that is already running, the second start operation |
Vincent Coubard |
638:c90ae1400bf2 | 251 | * is ignored. |
Vincent Coubard |
638:c90ae1400bf2 | 252 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 253 | uint32_t app_timer_start(app_timer_id_t timer_id, uint32_t timeout_ticks, void * p_context); |
Vincent Coubard |
638:c90ae1400bf2 | 254 | |
Vincent Coubard |
638:c90ae1400bf2 | 255 | /**@brief Function for stopping the specified timer. |
Vincent Coubard |
638:c90ae1400bf2 | 256 | * |
Vincent Coubard |
638:c90ae1400bf2 | 257 | * @param[in] timer_id Timer identifier. |
Vincent Coubard |
638:c90ae1400bf2 | 258 | * |
Vincent Coubard |
638:c90ae1400bf2 | 259 | * @retval NRF_SUCCESS If the timer was successfully stopped. |
Vincent Coubard |
638:c90ae1400bf2 | 260 | * @retval NRF_ERROR_INVALID_PARAM If a parameter was invalid. |
Vincent Coubard |
638:c90ae1400bf2 | 261 | * @retval NRF_ERROR_INVALID_STATE If the application timer module has not been initialized or the timer |
Vincent Coubard |
638:c90ae1400bf2 | 262 | * has not been created. |
Vincent Coubard |
638:c90ae1400bf2 | 263 | * @retval NRF_ERROR_NO_MEM If the timer operations queue was full. |
Vincent Coubard |
638:c90ae1400bf2 | 264 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 265 | uint32_t app_timer_stop(app_timer_id_t timer_id); |
Vincent Coubard |
638:c90ae1400bf2 | 266 | |
Vincent Coubard |
638:c90ae1400bf2 | 267 | /**@brief Function for stopping all running timers. |
Vincent Coubard |
638:c90ae1400bf2 | 268 | * |
Vincent Coubard |
638:c90ae1400bf2 | 269 | * @retval NRF_SUCCESS If all timers were successfully stopped. |
Vincent Coubard |
638:c90ae1400bf2 | 270 | * @retval NRF_ERROR_INVALID_STATE If the application timer module has not been initialized. |
Vincent Coubard |
638:c90ae1400bf2 | 271 | * @retval NRF_ERROR_NO_MEM If the timer operations queue was full. |
Vincent Coubard |
638:c90ae1400bf2 | 272 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 273 | uint32_t app_timer_stop_all(void); |
Vincent Coubard |
638:c90ae1400bf2 | 274 | |
Vincent Coubard |
638:c90ae1400bf2 | 275 | /**@brief Function for returning the current value of the RTC1 counter. |
Vincent Coubard |
638:c90ae1400bf2 | 276 | * |
Vincent Coubard |
638:c90ae1400bf2 | 277 | * @param[out] p_ticks Current value of the RTC1 counter. |
Vincent Coubard |
638:c90ae1400bf2 | 278 | * |
Vincent Coubard |
638:c90ae1400bf2 | 279 | * @retval NRF_SUCCESS If the counter was successfully read. |
Vincent Coubard |
638:c90ae1400bf2 | 280 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 281 | uint32_t app_timer_cnt_get(uint32_t * p_ticks); |
Vincent Coubard |
638:c90ae1400bf2 | 282 | |
Vincent Coubard |
638:c90ae1400bf2 | 283 | /**@brief Function for computing the difference between two RTC1 counter values. |
Vincent Coubard |
638:c90ae1400bf2 | 284 | * |
Vincent Coubard |
638:c90ae1400bf2 | 285 | * @param[in] ticks_to Value returned by app_timer_cnt_get(). |
Vincent Coubard |
638:c90ae1400bf2 | 286 | * @param[in] ticks_from Value returned by app_timer_cnt_get(). |
Vincent Coubard |
638:c90ae1400bf2 | 287 | * @param[out] p_ticks_diff Number of ticks from ticks_from to ticks_to. |
Vincent Coubard |
638:c90ae1400bf2 | 288 | * |
Vincent Coubard |
638:c90ae1400bf2 | 289 | * @retval NRF_SUCCESS If the counter difference was successfully computed. |
Vincent Coubard |
638:c90ae1400bf2 | 290 | */ |
Vincent Coubard |
638:c90ae1400bf2 | 291 | uint32_t app_timer_cnt_diff_compute(uint32_t ticks_to, |
Vincent Coubard |
638:c90ae1400bf2 | 292 | uint32_t ticks_from, |
Vincent Coubard |
638:c90ae1400bf2 | 293 | uint32_t * p_ticks_diff); |
Vincent Coubard |
638:c90ae1400bf2 | 294 | |
Vincent Coubard |
638:c90ae1400bf2 | 295 | #endif // APP_TIMER_H__ |
Vincent Coubard |
638:c90ae1400bf2 | 296 | |
Vincent Coubard |
638:c90ae1400bf2 | 297 | /** @} */ |