To get started with Seeed Tiny BLE, include detecting motion, button and battery level.

Dependencies:   BLE_API eMPL_MPU6050 mbed nRF51822

Committer:
yihui
Date:
Wed Apr 22 07:47:17 2015 +0000
Revision:
1:fc2f9d636751
update libraries; ; delete nRF51822/nordic-sdk/components/gpiote/app_gpiote.c to solve GPIOTE_IRQHandler multiply defined issue. temperarily change nRF51822 library to folder

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 1:fc2f9d636751 1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
yihui 1:fc2f9d636751 2 *
yihui 1:fc2f9d636751 3 * The information contained herein is property of Nordic Semiconductor ASA.
yihui 1:fc2f9d636751 4 * Terms and conditions of usage are described in detail in NORDIC
yihui 1:fc2f9d636751 5 * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
yihui 1:fc2f9d636751 6 *
yihui 1:fc2f9d636751 7 * Licensees are granted free, non-transferable use of the information. NO
yihui 1:fc2f9d636751 8 * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
yihui 1:fc2f9d636751 9 * the file.
yihui 1:fc2f9d636751 10 *
yihui 1:fc2f9d636751 11 */
yihui 1:fc2f9d636751 12
yihui 1:fc2f9d636751 13 /** @file
yihui 1:fc2f9d636751 14 *
yihui 1:fc2f9d636751 15 * @defgroup app_scheduler Scheduler
yihui 1:fc2f9d636751 16 * @{
yihui 1:fc2f9d636751 17 * @ingroup app_common
yihui 1:fc2f9d636751 18 *
yihui 1:fc2f9d636751 19 * @brief The scheduler is used for transferring execution from the interrupt context to the main
yihui 1:fc2f9d636751 20 * context.
yihui 1:fc2f9d636751 21 *
yihui 1:fc2f9d636751 22 * @details See @ref seq_diagrams_sched for sequence diagrams illustrating the flow of events
yihui 1:fc2f9d636751 23 * when using the Scheduler.
yihui 1:fc2f9d636751 24 *
yihui 1:fc2f9d636751 25 * @section app_scheduler_req Requirements:
yihui 1:fc2f9d636751 26 *
yihui 1:fc2f9d636751 27 * @subsection main_context_logic Logic in main context:
yihui 1:fc2f9d636751 28 *
yihui 1:fc2f9d636751 29 * - Define an event handler for each type of event expected.
yihui 1:fc2f9d636751 30 * - Initialize the scheduler by calling the APP_SCHED_INIT() macro before entering the
yihui 1:fc2f9d636751 31 * application main loop.
yihui 1:fc2f9d636751 32 * - Call app_sched_execute() from the main loop each time the application wakes up because of an
yihui 1:fc2f9d636751 33 * event (typically when sd_app_evt_wait() returns).
yihui 1:fc2f9d636751 34 *
yihui 1:fc2f9d636751 35 * @subsection int_context_logic Logic in interrupt context:
yihui 1:fc2f9d636751 36 *
yihui 1:fc2f9d636751 37 * - In the interrupt handler, call app_sched_event_put()
yihui 1:fc2f9d636751 38 * with the appropriate data and event handler. This will insert an event into the
yihui 1:fc2f9d636751 39 * scheduler's queue. The app_sched_execute() function will pull this event and call its
yihui 1:fc2f9d636751 40 * handler in the main context.
yihui 1:fc2f9d636751 41 *
yihui 1:fc2f9d636751 42 * @if (SD_S110 && !SD_S310)
yihui 1:fc2f9d636751 43 * For an example usage of the scheduler, see the implementations of
yihui 1:fc2f9d636751 44 * @ref ble_sdk_app_hids_mouse and @ref ble_sdk_app_hids_keyboard.
yihui 1:fc2f9d636751 45 * @endif
yihui 1:fc2f9d636751 46 *
yihui 1:fc2f9d636751 47 * @image html scheduler_working.jpg The high level design of the scheduler
yihui 1:fc2f9d636751 48 */
yihui 1:fc2f9d636751 49
yihui 1:fc2f9d636751 50 #ifndef APP_SCHEDULER_H__
yihui 1:fc2f9d636751 51 #define APP_SCHEDULER_H__
yihui 1:fc2f9d636751 52
yihui 1:fc2f9d636751 53 #include <stdint.h>
yihui 1:fc2f9d636751 54 #include "app_error.h"
yihui 1:fc2f9d636751 55
yihui 1:fc2f9d636751 56 #define APP_SCHED_EVENT_HEADER_SIZE 8 /**< Size of app_scheduler.event_header_t (only for use inside APP_SCHED_BUF_SIZE()). */
yihui 1:fc2f9d636751 57
yihui 1:fc2f9d636751 58 /**@brief Compute number of bytes required to hold the scheduler buffer.
yihui 1:fc2f9d636751 59 *
yihui 1:fc2f9d636751 60 * @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler.
yihui 1:fc2f9d636751 61 * @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events
yihui 1:fc2f9d636751 62 * that can be scheduled for execution).
yihui 1:fc2f9d636751 63 *
yihui 1:fc2f9d636751 64 * @return Required scheduler buffer size (in bytes).
yihui 1:fc2f9d636751 65 */
yihui 1:fc2f9d636751 66 #define APP_SCHED_BUF_SIZE(EVENT_SIZE, QUEUE_SIZE) \
yihui 1:fc2f9d636751 67 (((EVENT_SIZE) + APP_SCHED_EVENT_HEADER_SIZE) * ((QUEUE_SIZE) + 1))
yihui 1:fc2f9d636751 68
yihui 1:fc2f9d636751 69 /**@brief Scheduler event handler type. */
yihui 1:fc2f9d636751 70 typedef void (*app_sched_event_handler_t)(void * p_event_data, uint16_t event_size);
yihui 1:fc2f9d636751 71
yihui 1:fc2f9d636751 72 /**@brief Macro for initializing the event scheduler.
yihui 1:fc2f9d636751 73 *
yihui 1:fc2f9d636751 74 * @details It will also handle dimensioning and allocation of the memory buffer required by the
yihui 1:fc2f9d636751 75 * scheduler, making sure the buffer is correctly aligned.
yihui 1:fc2f9d636751 76 *
yihui 1:fc2f9d636751 77 * @param[in] EVENT_SIZE Maximum size of events to be passed through the scheduler.
yihui 1:fc2f9d636751 78 * @param[in] QUEUE_SIZE Number of entries in scheduler queue (i.e. the maximum number of events
yihui 1:fc2f9d636751 79 * that can be scheduled for execution).
yihui 1:fc2f9d636751 80 *
yihui 1:fc2f9d636751 81 * @note Since this macro allocates a buffer, it must only be called once (it is OK to call it
yihui 1:fc2f9d636751 82 * several times as long as it is from the same location, e.g. to do a reinitialization).
yihui 1:fc2f9d636751 83 */
yihui 1:fc2f9d636751 84 #define APP_SCHED_INIT(EVENT_SIZE, QUEUE_SIZE) \
yihui 1:fc2f9d636751 85 do \
yihui 1:fc2f9d636751 86 { \
yihui 1:fc2f9d636751 87 static uint32_t APP_SCHED_BUF[CEIL_DIV(APP_SCHED_BUF_SIZE((EVENT_SIZE), (QUEUE_SIZE)), \
yihui 1:fc2f9d636751 88 sizeof(uint32_t))]; \
yihui 1:fc2f9d636751 89 uint32_t ERR_CODE = app_sched_init((EVENT_SIZE), (QUEUE_SIZE), APP_SCHED_BUF); \
yihui 1:fc2f9d636751 90 APP_ERROR_CHECK(ERR_CODE); \
yihui 1:fc2f9d636751 91 } while (0)
yihui 1:fc2f9d636751 92
yihui 1:fc2f9d636751 93 /**@brief Function for initializing the Scheduler.
yihui 1:fc2f9d636751 94 *
yihui 1:fc2f9d636751 95 * @details It must be called before entering the main loop.
yihui 1:fc2f9d636751 96 *
yihui 1:fc2f9d636751 97 * @param[in] max_event_size Maximum size of events to be passed through the scheduler.
yihui 1:fc2f9d636751 98 * @param[in] queue_size Number of entries in scheduler queue (i.e. the maximum number of
yihui 1:fc2f9d636751 99 * events that can be scheduled for execution).
yihui 1:fc2f9d636751 100 * @param[in] p_evt_buffer Pointer to memory buffer for holding the scheduler queue. It must
yihui 1:fc2f9d636751 101 * be dimensioned using the APP_SCHED_BUFFER_SIZE() macro. The buffer
yihui 1:fc2f9d636751 102 * must be aligned to a 4 byte boundary.
yihui 1:fc2f9d636751 103 *
yihui 1:fc2f9d636751 104 * @note Normally initialization should be done using the APP_SCHED_INIT() macro, as that will both
yihui 1:fc2f9d636751 105 * allocate the scheduler buffer, and also align the buffer correctly.
yihui 1:fc2f9d636751 106 *
yihui 1:fc2f9d636751 107 * @retval NRF_SUCCESS Successful initialization.
yihui 1:fc2f9d636751 108 * @retval NRF_ERROR_INVALID_PARAM Invalid parameter (buffer not aligned to a 4 byte
yihui 1:fc2f9d636751 109 * boundary).
yihui 1:fc2f9d636751 110 */
yihui 1:fc2f9d636751 111 uint32_t app_sched_init(uint16_t max_event_size, uint16_t queue_size, void * p_evt_buffer);
yihui 1:fc2f9d636751 112
yihui 1:fc2f9d636751 113 /**@brief Function for executing all scheduled events.
yihui 1:fc2f9d636751 114 *
yihui 1:fc2f9d636751 115 * @details This function must be called from within the main loop. It will execute all events
yihui 1:fc2f9d636751 116 * scheduled since the last time it was called.
yihui 1:fc2f9d636751 117 */
yihui 1:fc2f9d636751 118 void app_sched_execute(void);
yihui 1:fc2f9d636751 119
yihui 1:fc2f9d636751 120 /**@brief Function for scheduling an event.
yihui 1:fc2f9d636751 121 *
yihui 1:fc2f9d636751 122 * @details Puts an event into the event queue.
yihui 1:fc2f9d636751 123 *
yihui 1:fc2f9d636751 124 * @param[in] p_event_data Pointer to event data to be scheduled.
yihui 1:fc2f9d636751 125 * @param[in] event_size Size of event data to be scheduled.
yihui 1:fc2f9d636751 126 * @param[in] handler Event handler to receive the event.
yihui 1:fc2f9d636751 127 *
yihui 1:fc2f9d636751 128 * @return NRF_SUCCESS on success, otherwise an error code.
yihui 1:fc2f9d636751 129 */
yihui 1:fc2f9d636751 130 uint32_t app_sched_event_put(void * p_event_data,
yihui 1:fc2f9d636751 131 uint16_t event_size,
yihui 1:fc2f9d636751 132 app_sched_event_handler_t handler);
yihui 1:fc2f9d636751 133
yihui 1:fc2f9d636751 134 #ifdef APP_SCHEDULER_WITH_PAUSE
yihui 1:fc2f9d636751 135 /**@brief A function to pause the scheduler.
yihui 1:fc2f9d636751 136 *
yihui 1:fc2f9d636751 137 * @details When the scheduler is paused events are not pulled from the scheduler queue for
yihui 1:fc2f9d636751 138 * processing. The function can be called multiple times. To unblock the scheduler the
yihui 1:fc2f9d636751 139 * function @ref app_sched_resume has to be called the same number of times.
yihui 1:fc2f9d636751 140 */
yihui 1:fc2f9d636751 141 void app_sched_pause(void);
yihui 1:fc2f9d636751 142
yihui 1:fc2f9d636751 143 /**@brief A function to resume a scheduler.
yihui 1:fc2f9d636751 144 *
yihui 1:fc2f9d636751 145 * @details To unblock the scheduler this function has to be called the same number of times as
yihui 1:fc2f9d636751 146 * @ref app_sched_pause function.
yihui 1:fc2f9d636751 147 */
yihui 1:fc2f9d636751 148 void app_sched_resume(void);
yihui 1:fc2f9d636751 149 #endif
yihui 1:fc2f9d636751 150 #endif // APP_SCHEDULER_H__
yihui 1:fc2f9d636751 151
yihui 1:fc2f9d636751 152 /** @} */