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