konashi/SBBLEのテスト

Dependencies:   BLE_API mbed

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Committer:
robo8080
Date:
Sat Aug 16 02:10:08 2014 +0000
Revision:
5:61109bce11fe
test1

Who changed what in which revision?

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