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) 2012 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 app_scheduler Scheduler
jksoft 1:48f6e08a3ac2 16 * @{
jksoft 1:48f6e08a3ac2 17 * @ingroup app_common
jksoft 1:48f6e08a3ac2 18 *
jksoft 1:48f6e08a3ac2 19 * @brief The scheduler is used for transferring execution from the interrupt context to the main
jksoft 1:48f6e08a3ac2 20 * context.
jksoft 1:48f6e08a3ac2 21 *
jksoft 1:48f6e08a3ac2 22 * @details See @ref ble_sdk_apps_seq_diagrams for sequence diagrams illustrating the flow of events
jksoft 1:48f6e08a3ac2 23 * when using the Scheduler.
jksoft 1:48f6e08a3ac2 24 *
jksoft 1:48f6e08a3ac2 25 * @section app_scheduler_req Requirements:
jksoft 1:48f6e08a3ac2 26 *
jksoft 1:48f6e08a3ac2 27 * @subsection main_context_logic Logic in main context:
jksoft 1:48f6e08a3ac2 28 *
jksoft 1:48f6e08a3ac2 29 * - Define an event handler for each type of event expected.
jksoft 1:48f6e08a3ac2 30 * - Initialize the scheduler by calling the APP_SCHED_INIT() macro before entering the
jksoft 1:48f6e08a3ac2 31 * application main loop.
jksoft 1:48f6e08a3ac2 32 * - Call app_sched_execute() from the main loop each time the application wakes up because of an
jksoft 1:48f6e08a3ac2 33 * event (typically when sd_app_evt_wait() returns).
jksoft 1:48f6e08a3ac2 34 *
jksoft 1:48f6e08a3ac2 35 * @subsection int_context_logic Logic in interrupt context:
jksoft 1:48f6e08a3ac2 36 *
jksoft 1:48f6e08a3ac2 37 * - In the interrupt handler, call app_sched_event_put()
jksoft 1:48f6e08a3ac2 38 * with the appropriate data and event handler. This will insert an event into the
jksoft 1:48f6e08a3ac2 39 * scheduler's queue. The app_sched_execute() function will pull this event and call its
jksoft 1:48f6e08a3ac2 40 * handler in the main context.
jksoft 1:48f6e08a3ac2 41 *
jksoft 1:48f6e08a3ac2 42 * For an example usage of the scheduler, please see the implementations of
jksoft 1:48f6e08a3ac2 43 * @ref ble_sdk_app_hids_mouse and @ref ble_sdk_app_hids_keyboard.
jksoft 1:48f6e08a3ac2 44 *
jksoft 1:48f6e08a3ac2 45 * @image html scheduler_working.jpg The high level design of the scheduler
jksoft 1:48f6e08a3ac2 46 */
jksoft 1:48f6e08a3ac2 47
jksoft 1:48f6e08a3ac2 48 #ifndef APP_SCHEDULER_H__
jksoft 1:48f6e08a3ac2 49 #define APP_SCHEDULER_H__
jksoft 1:48f6e08a3ac2 50
jksoft 1:48f6e08a3ac2 51 #include <stdint.h>
jksoft 1:48f6e08a3ac2 52 #include "app_error.h"
jksoft 1:48f6e08a3ac2 53
jksoft 1:48f6e08a3ac2 54 #define APP_SCHED_EVENT_HEADER_SIZE 8 /**< Size of app_scheduler.event_header_t (only for use inside APP_SCHED_BUF_SIZE()). */
jksoft 1:48f6e08a3ac2 55
jksoft 1:48f6e08a3ac2 56 /**@brief Compute number of bytes required to hold the scheduler buffer.
jksoft 1:48f6e08a3ac2 57 *
jksoft 1:48f6e08a3ac2 58 * @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler.
jksoft 1:48f6e08a3ac2 59 * @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events
jksoft 1:48f6e08a3ac2 60 * that can be scheduled for execution).
jksoft 1:48f6e08a3ac2 61 *
jksoft 1:48f6e08a3ac2 62 * @return Required scheduler buffer size (in bytes).
jksoft 1:48f6e08a3ac2 63 */
jksoft 1:48f6e08a3ac2 64 #define APP_SCHED_BUF_SIZE(EVENT_SIZE, QUEUE_SIZE) \
jksoft 1:48f6e08a3ac2 65 (((EVENT_SIZE) + APP_SCHED_EVENT_HEADER_SIZE) * ((QUEUE_SIZE) + 1))
jksoft 1:48f6e08a3ac2 66
jksoft 1:48f6e08a3ac2 67 /**@brief Scheduler event handler type. */
jksoft 1:48f6e08a3ac2 68 typedef void (*app_sched_event_handler_t)(void * p_event_data, uint16_t event_size);
jksoft 1:48f6e08a3ac2 69
jksoft 1:48f6e08a3ac2 70 /**@brief Macro for initializing the event scheduler.
jksoft 1:48f6e08a3ac2 71 *
jksoft 1:48f6e08a3ac2 72 * @details It will also handle dimensioning and allocation of the memory buffer required by the
jksoft 1:48f6e08a3ac2 73 * scheduler, making sure the buffer is correctly aligned.
jksoft 1:48f6e08a3ac2 74 *
jksoft 1:48f6e08a3ac2 75 * @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler.
jksoft 1:48f6e08a3ac2 76 * @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events
jksoft 1:48f6e08a3ac2 77 * that can be scheduled for execution).
jksoft 1:48f6e08a3ac2 78 *
jksoft 1:48f6e08a3ac2 79 * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
jksoft 1:48f6e08a3ac2 80 * several times as long as it is from the same location, e.g. to do a reinitialization).
jksoft 1:48f6e08a3ac2 81 */
jksoft 1:48f6e08a3ac2 82 #define APP_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE) \
jksoft 1:48f6e08a3ac2 83 do \
jksoft 1:48f6e08a3ac2 84 { \
jksoft 1:48f6e08a3ac2 85 static uint32_t APP_SCHED_BUF[CEIL_DIV(APP_SCHED_BUF_SIZE((EVENT_SIZE), (QUEUE_SIZE)), \
jksoft 1:48f6e08a3ac2 86 sizeof(uint32_t))]; \
jksoft 1:48f6e08a3ac2 87 uint32_t ERR_CODE = app_sched_init((EVENT_SIZE), (QUEUE_SIZE), APP_SCHED_BUF); \
jksoft 1:48f6e08a3ac2 88 APP_ERROR_CHECK(ERR_CODE); \
jksoft 1:48f6e08a3ac2 89 } while (0)
jksoft 1:48f6e08a3ac2 90
jksoft 1:48f6e08a3ac2 91 /**@brief Function for initializing the Scheduler.
jksoft 1:48f6e08a3ac2 92 *
jksoft 1:48f6e08a3ac2 93 * @details It must be called before entering the main loop.
jksoft 1:48f6e08a3ac2 94 *
jksoft 1:48f6e08a3ac2 95 * @param[in] max_event_size Maximum size of events to be passed through the scheduler.
jksoft 1:48f6e08a3ac2 96 * @param[in] queue_size Number of entries in scheduler queue (i.e. the maximum number of
jksoft 1:48f6e08a3ac2 97 * events that can be scheduled for execution).
jksoft 1:48f6e08a3ac2 98 * @param[in] p_event_buffer Pointer to memory buffer for holding the scheduler queue. It must
jksoft 1:48f6e08a3ac2 99 * be dimensioned using the APP_SCHED_BUFFER_SIZE() macro. The buffer
jksoft 1:48f6e08a3ac2 100 * must be aligned to a 4 byte boundary.
jksoft 1:48f6e08a3ac2 101 *
jksoft 1:48f6e08a3ac2 102 * @note Normally initialization should be done using the APP_SCHED_INIT() macro, as that will both
jksoft 1:48f6e08a3ac2 103 * allocate the scheduler buffer, and also align the buffer correctly.
jksoft 1:48f6e08a3ac2 104 *
jksoft 1:48f6e08a3ac2 105 * @retval NRF_SUCCESS Successful initialization.
jksoft 1:48f6e08a3ac2 106 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte
jksoft 1:48f6e08a3ac2 107 * boundary).
jksoft 1:48f6e08a3ac2 108 */
jksoft 1:48f6e08a3ac2 109 uint32_t app_sched_init(uint16_t max_event_size, uint16_t queue_size, void * p_evt_buffer);
jksoft 1:48f6e08a3ac2 110
jksoft 1:48f6e08a3ac2 111 /**@brief Function for executing all scheduled events.
jksoft 1:48f6e08a3ac2 112 *
jksoft 1:48f6e08a3ac2 113 * @details This function must be called from within the main loop. It will execute all events
jksoft 1:48f6e08a3ac2 114 * scheduled since the last time it was called.
jksoft 1:48f6e08a3ac2 115 */
jksoft 1:48f6e08a3ac2 116 void app_sched_execute(void);
jksoft 1:48f6e08a3ac2 117
jksoft 1:48f6e08a3ac2 118 /**@brief Function for scheduling an event.
jksoft 1:48f6e08a3ac2 119 *
jksoft 1:48f6e08a3ac2 120 * @details Puts an event into the event queue.
jksoft 1:48f6e08a3ac2 121 *
jksoft 1:48f6e08a3ac2 122 * @param[in] p_event_data Pointer to event data to be scheduled.
jksoft 1:48f6e08a3ac2 123 * @param[in] p_event_size Size of event data to be scheduled.
jksoft 1:48f6e08a3ac2 124 * @param[in] handler Event handler to receive the event.
jksoft 1:48f6e08a3ac2 125 *
jksoft 1:48f6e08a3ac2 126 * @return NRF_SUCCESS on success, otherwise an error code.
jksoft 1:48f6e08a3ac2 127 */
jksoft 1:48f6e08a3ac2 128 uint32_t app_sched_event_put(void * p_event_data,
jksoft 1:48f6e08a3ac2 129 uint16_t event_size,
jksoft 1:48f6e08a3ac2 130 app_sched_event_handler_t handler);
jksoft 1:48f6e08a3ac2 131
jksoft 1:48f6e08a3ac2 132 #endif // APP_SCHEDULER_H__
jksoft 1:48f6e08a3ac2 133
jksoft 1:48f6e08a3ac2 134 /** @} */