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