テスト用です。

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) 2013 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 softdevice_handler SoftDevice Event Handler
jksoft 0:8468a4403fea 16 * @{
jksoft 0:8468a4403fea 17 * @ingroup app_common
jksoft 0:8468a4403fea 18 * @brief API for initializing and disabling the SoftDevice
jksoft 0:8468a4403fea 19 *
jksoft 0:8468a4403fea 20 * @details This API contains the functions and defines exposed by the @ref lib_softdevice_handler.
jksoft 0:8468a4403fea 21 * For more information on the library and how the application should use it, please refer
jksoft 0:8468a4403fea 22 * @ref lib_softdevice_handler.
jksoft 0:8468a4403fea 23 *
jksoft 0:8468a4403fea 24 * @note Use the USE_SCHEDULER parameter of the SOFTDEVICE_HANDLER_INIT() macro to select if
jksoft 0:8468a4403fea 25 * the @ref app_scheduler is to be used or not.
jksoft 0:8468a4403fea 26 *
jksoft 0:8468a4403fea 27 * @note Even if the scheduler is not used, softdevice_handler.h will include app_scheduler.h.
jksoft 0:8468a4403fea 28 * So when compiling, app_scheduler.h must be available in one of the compiler include
jksoft 0:8468a4403fea 29 * paths.
jksoft 0:8468a4403fea 30 */
jksoft 0:8468a4403fea 31
jksoft 0:8468a4403fea 32 #ifndef SOFTDEVICE_HANDLER_H__
jksoft 0:8468a4403fea 33 #define SOFTDEVICE_HANDLER_H__
jksoft 0:8468a4403fea 34
jksoft 0:8468a4403fea 35 #include <stdlib.h>
jksoft 0:8468a4403fea 36 #include "nordic_common.h"
jksoft 0:8468a4403fea 37 #include "nrf_sdm.h"
jksoft 0:8468a4403fea 38 #include "app_error.h"
jksoft 0:8468a4403fea 39 #include "app_scheduler.h"
jksoft 0:8468a4403fea 40 #include "app_util.h"
jksoft 0:8468a4403fea 41 #include "ble_stack_handler_types.h"
jksoft 0:8468a4403fea 42 #include "ant_stack_handler_types.h"
jksoft 0:8468a4403fea 43
jksoft 0:8468a4403fea 44 #ifdef __cplusplus
jksoft 0:8468a4403fea 45 extern "C" {
jksoft 0:8468a4403fea 46 #endif // #ifdef __cplusplus
jksoft 0:8468a4403fea 47
jksoft 0:8468a4403fea 48 #define SOFTDEVICE_SCHED_EVT_SIZE 0 /**< Size of button events being passed through the scheduler (is to be used for computing the maximum size of scheduler events). For SoftDevice events, this size is 0, since the events are being pulled in the event handler. */
jksoft 0:8468a4403fea 49 #define SYS_EVT_MSG_BUF_SIZE sizeof(uint32_t) /**< Size of System (SOC) event message buffer. */
jksoft 0:8468a4403fea 50
jksoft 0:8468a4403fea 51 /**@brief Type of function for passing events from the stack handler module to the scheduler. */
jksoft 0:8468a4403fea 52 typedef uint32_t (*softdevice_evt_schedule_func_t) (void);
jksoft 0:8468a4403fea 53
jksoft 0:8468a4403fea 54 /**@brief Application System (SOC) event handler type. */
jksoft 0:8468a4403fea 55 typedef void (*sys_evt_handler_t) (uint32_t evt_id);
jksoft 0:8468a4403fea 56
jksoft 0:8468a4403fea 57
jksoft 0:8468a4403fea 58 /**@brief Macro for initializing the stack event handler.
jksoft 0:8468a4403fea 59 *
jksoft 0:8468a4403fea 60 * @details It will handle dimensioning and allocation of the memory buffer required for reading
jksoft 0:8468a4403fea 61 * events from the stack, making sure the buffer is correctly aligned. It will also
jksoft 0:8468a4403fea 62 * connect the stack event handler to the scheduler (if specified).
jksoft 0:8468a4403fea 63 *
jksoft 0:8468a4403fea 64 * @param[in] CLOCK_SOURCE Low frequency clock source and accuracy (type nrf_clock_lfclksrc_t,
jksoft 0:8468a4403fea 65 * see sd_softdevice_enable() for details).
jksoft 0:8468a4403fea 66 * @param[in] USE_SCHEDULER TRUE if the application is using the event scheduler, FALSE
jksoft 0:8468a4403fea 67 * otherwise.
jksoft 0:8468a4403fea 68 *
jksoft 0:8468a4403fea 69 * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
jksoft 0:8468a4403fea 70 * several times as long as it is from the same location, that is to do a
jksoft 0:8468a4403fea 71 * reinitialization).
jksoft 0:8468a4403fea 72 */
jksoft 0:8468a4403fea 73 /*lint -emacro(506, SOFTDEVICE_HANDLER_INIT) */ /* Suppress "Constant value Boolean */
jksoft 0:8468a4403fea 74 #define SOFTDEVICE_HANDLER_INIT(CLOCK_SOURCE, \
jksoft 0:8468a4403fea 75 USE_SCHEDULER) \
jksoft 0:8468a4403fea 76 do \
jksoft 0:8468a4403fea 77 { \
jksoft 0:8468a4403fea 78 static uint32_t EVT_BUFFER[CEIL_DIV(MAX( \
jksoft 0:8468a4403fea 79 MAX(BLE_STACK_EVT_MSG_BUF_SIZE, \
jksoft 0:8468a4403fea 80 ANT_STACK_EVT_STRUCT_SIZE), \
jksoft 0:8468a4403fea 81 SYS_EVT_MSG_BUF_SIZE \
jksoft 0:8468a4403fea 82 ), \
jksoft 0:8468a4403fea 83 sizeof(uint32_t))]; \
jksoft 0:8468a4403fea 84 uint32_t ERR_CODE; \
jksoft 0:8468a4403fea 85 ERR_CODE = softdevice_handler_init((CLOCK_SOURCE), \
jksoft 0:8468a4403fea 86 EVT_BUFFER, \
jksoft 0:8468a4403fea 87 sizeof(EVT_BUFFER), \
jksoft 0:8468a4403fea 88 (USE_SCHEDULER) ? softdevice_evt_schedule : NULL); \
jksoft 0:8468a4403fea 89 APP_ERROR_CHECK(ERR_CODE); \
jksoft 0:8468a4403fea 90 } while (0)
jksoft 0:8468a4403fea 91
jksoft 0:8468a4403fea 92
jksoft 0:8468a4403fea 93 /**@brief Function for initializing the stack handler module.
jksoft 0:8468a4403fea 94 *
jksoft 0:8468a4403fea 95 * @details Enables the SoftDevice and the stack event interrupt handler.
jksoft 0:8468a4403fea 96 *
jksoft 0:8468a4403fea 97 * @note This function must be called before calling any function in the SoftDevice API.
jksoft 0:8468a4403fea 98 *
jksoft 0:8468a4403fea 99 * @note Normally initialization should be done using the SOFTDEVICE_HANDLER_INIT() macro,
jksoft 0:8468a4403fea 100 * as that will both allocate the event buffer, and also align the buffer correctly.
jksoft 0:8468a4403fea 101 *
jksoft 0:8468a4403fea 102 * @param[in] clock_source Low frequency clock source to be used by the SoftDevice.
jksoft 0:8468a4403fea 103 * @param[in] p_evt_buffer Buffer for holding one stack event. Since heap is not being
jksoft 0:8468a4403fea 104 * used, this buffer must be provided by the application. The
jksoft 0:8468a4403fea 105 * buffer must be large enough to hold the biggest stack event the
jksoft 0:8468a4403fea 106 * application is supposed to handle. The buffer must be aligned to
jksoft 0:8468a4403fea 107 * a 4 byte boundary. This parameter is unused if neither BLE nor
jksoft 0:8468a4403fea 108 * ANT stack support is required.
jksoft 0:8468a4403fea 109 * @param[in] evt_buffer_size Size of SoftDevice event buffer. This parameter is unused if
jksoft 0:8468a4403fea 110 * BLE stack support is not required.
jksoft 0:8468a4403fea 111 * @param[in] evt_schedule_func Function for passing events to the scheduler. Point to
jksoft 0:8468a4403fea 112 * ble_ant_stack_evt_schedule() to connect to the scheduler.
jksoft 0:8468a4403fea 113 * Set to NULL to make the stack handler module call the event
jksoft 0:8468a4403fea 114 * handler directly from the stack event interrupt handler.
jksoft 0:8468a4403fea 115 *
jksoft 0:8468a4403fea 116 * @retval NRF_SUCCESS Successful initialization.
jksoft 0:8468a4403fea 117 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte
jksoft 0:8468a4403fea 118 * boundary) or NULL.
jksoft 0:8468a4403fea 119 */
jksoft 0:8468a4403fea 120 uint32_t softdevice_handler_init(nrf_clock_lfclksrc_t clock_source,
jksoft 0:8468a4403fea 121 void * p_evt_buffer,
jksoft 0:8468a4403fea 122 uint16_t evt_buffer_size,
jksoft 0:8468a4403fea 123 softdevice_evt_schedule_func_t evt_schedule_func);
jksoft 0:8468a4403fea 124
jksoft 0:8468a4403fea 125
jksoft 0:8468a4403fea 126 /**@brief Function for disabling the SoftDevice.
jksoft 0:8468a4403fea 127 *
jksoft 0:8468a4403fea 128 * @details This function will disable the SoftDevice. It will also update the internal state
jksoft 0:8468a4403fea 129 * of this module.
jksoft 0:8468a4403fea 130 */
jksoft 0:8468a4403fea 131 uint32_t softdevice_handler_sd_disable(void);
jksoft 0:8468a4403fea 132
jksoft 0:8468a4403fea 133
jksoft 0:8468a4403fea 134 /**@brief Function for registering for System (SOC) events.
jksoft 0:8468a4403fea 135 *
jksoft 0:8468a4403fea 136 * @details The application should use this function to register for receiving System (SOC)
jksoft 0:8468a4403fea 137 * events from the SoftDevice. If the application does not call this function, then any
jksoft 0:8468a4403fea 138 * System (SOC) events that may be generated by the SoftDevice will NOT be fetched. Once
jksoft 0:8468a4403fea 139 * the application has registered for the events, it is not possible to possible to
jksoft 0:8468a4403fea 140 * cancel the registration. However, it is possible to register a different function for
jksoft 0:8468a4403fea 141 * handling the events at any point of time.
jksoft 0:8468a4403fea 142 *
jksoft 0:8468a4403fea 143 * @param[in] sys_evt_handler Function to be called for each received System (SOC) event.
jksoft 0:8468a4403fea 144 *
jksoft 0:8468a4403fea 145 * @retval NRF_SUCCESS Successful registration.
jksoft 0:8468a4403fea 146 * @retval NRF_ERROR_NULL Null pointer provided as input.
jksoft 0:8468a4403fea 147 */
jksoft 0:8468a4403fea 148 uint32_t softdevice_sys_evt_handler_set(sys_evt_handler_t sys_evt_handler);
jksoft 0:8468a4403fea 149
jksoft 0:8468a4403fea 150
jksoft 0:8468a4403fea 151 // Functions for connecting the Stack Event Handler to the scheduler:
jksoft 0:8468a4403fea 152 /**@cond NO_DOXYGEN */
jksoft 0:8468a4403fea 153 void intern_softdevice_events_execute(void);
jksoft 0:8468a4403fea 154
jksoft 0:8468a4403fea 155 static __INLINE void softdevice_evt_get(void * p_event_data, uint16_t event_size)
jksoft 0:8468a4403fea 156 {
jksoft 0:8468a4403fea 157 APP_ERROR_CHECK_BOOL(event_size == 0);
jksoft 0:8468a4403fea 158 intern_softdevice_events_execute();
jksoft 0:8468a4403fea 159 }
jksoft 0:8468a4403fea 160
jksoft 0:8468a4403fea 161 static __INLINE uint32_t softdevice_evt_schedule(void)
jksoft 0:8468a4403fea 162 {
jksoft 0:8468a4403fea 163 return app_sched_event_put(NULL, 0, softdevice_evt_get);
jksoft 0:8468a4403fea 164 }
jksoft 0:8468a4403fea 165 /**@endcond */
jksoft 0:8468a4403fea 166
jksoft 0:8468a4403fea 167 #ifdef __cplusplus
jksoft 0:8468a4403fea 168 }
jksoft 0:8468a4403fea 169 #endif // #ifdef __cplusplus
jksoft 0:8468a4403fea 170
jksoft 0:8468a4403fea 171 #endif // SOFTDEVICE_HANDLER_H__
jksoft 0:8468a4403fea 172
jksoft 0:8468a4403fea 173 /** @} */