テスト用です。

Dependencies:   mbed

Committer:
jksoft
Date:
Tue Oct 11 11:09:42 2016 +0000
Revision:
0:8468a4403fea
SB??ver;

Who changed what in which revision?

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