BLE FOTA APP

Dependencies:   BLE_API mbed

It doesn't work with the default FOTA bootloader. It use NVIC_SystemReset() to enter a bootloader.

Committer:
yihui
Date:
Fri Oct 10 03:36:28 2014 +0000
Revision:
1:a607cd9655d7
use NVIC_SystemReset() to run bootloader

Who changed what in which revision?

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