iOSのBLEコントローラアプリ「RCBController」と接続し、コントローラの操作を取得するサンプルプログラムです。 mbed HRM1017で動作を確認しています。 2014.08.20時点でのBLEライブラリに対応しました。

Dependencies:   BLE_API mbed

Fork of BLE_RCBController by Junichi Katsu

Committer:
jksoft
Date:
Wed Aug 20 13:24:20 2014 +0000
Revision:
1:48f6e08a3ac2
2014.08.20?????BLE?????????????; ???mbed?????????????????; mbed HRM1017; Nordic nRF51822

Who changed what in which revision?

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