Yutaka Yoshida / Mbed 2 deprecated BLE_WallbotBLE_Challenge_byYUTAKA

Dependencies:   mbed

Fork of BLE_WallbotBLE_Challenge_byYUTAKA by keisuke Yoshida

Committer:
jksoft
Date:
Wed Nov 12 02:40:34 2014 +0000
Revision:
0:76dfa9657d9d
????????

Who changed what in which revision?

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