leo hendrickson
/
S
simple-mbed-cloud-client/mbed-cloud-client/sal-stack-nanostack-eventloop/nanostack-event-loop/eventOS_scheduler.h@0:25fa8795676b, 2021-04-18 (annotated)
- Committer:
- leothedragon
- Date:
- Sun Apr 18 15:20:23 2021 +0000
- Revision:
- 0:25fa8795676b
DS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:25fa8795676b | 1 | /* |
leothedragon | 0:25fa8795676b | 2 | * Copyright (c) 2014-2015 ARM Limited. All rights reserved. |
leothedragon | 0:25fa8795676b | 3 | * SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:25fa8795676b | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
leothedragon | 0:25fa8795676b | 5 | * not use this file except in compliance with the License. |
leothedragon | 0:25fa8795676b | 6 | * You may obtain a copy of the License at |
leothedragon | 0:25fa8795676b | 7 | * |
leothedragon | 0:25fa8795676b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:25fa8795676b | 9 | * |
leothedragon | 0:25fa8795676b | 10 | * Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:25fa8795676b | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
leothedragon | 0:25fa8795676b | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:25fa8795676b | 13 | * See the License for the specific language governing permissions and |
leothedragon | 0:25fa8795676b | 14 | * limitations under the License. |
leothedragon | 0:25fa8795676b | 15 | */ |
leothedragon | 0:25fa8795676b | 16 | #ifndef EVENTOS_SCHEDULER_H_ |
leothedragon | 0:25fa8795676b | 17 | #define EVENTOS_SCHEDULER_H_ |
leothedragon | 0:25fa8795676b | 18 | |
leothedragon | 0:25fa8795676b | 19 | #ifdef __cplusplus |
leothedragon | 0:25fa8795676b | 20 | extern "C" { |
leothedragon | 0:25fa8795676b | 21 | #endif |
leothedragon | 0:25fa8795676b | 22 | #include "ns_types.h" |
leothedragon | 0:25fa8795676b | 23 | |
leothedragon | 0:25fa8795676b | 24 | /* Compatibility with older ns_types.h */ |
leothedragon | 0:25fa8795676b | 25 | #ifndef NS_NORETURN |
leothedragon | 0:25fa8795676b | 26 | #define NS_NORETURN |
leothedragon | 0:25fa8795676b | 27 | #endif |
leothedragon | 0:25fa8795676b | 28 | |
leothedragon | 0:25fa8795676b | 29 | /** |
leothedragon | 0:25fa8795676b | 30 | * \brief Initialise event scheduler. |
leothedragon | 0:25fa8795676b | 31 | * |
leothedragon | 0:25fa8795676b | 32 | */ |
leothedragon | 0:25fa8795676b | 33 | extern void eventOS_scheduler_init(void); |
leothedragon | 0:25fa8795676b | 34 | |
leothedragon | 0:25fa8795676b | 35 | /** |
leothedragon | 0:25fa8795676b | 36 | * Process one event from event queue. |
leothedragon | 0:25fa8795676b | 37 | * Do not call this directly from application. Requires to be public so that simulator can call this. |
leothedragon | 0:25fa8795676b | 38 | * Use eventOS_scheduler_run() or eventOS_scheduler_run_until_idle(). |
leothedragon | 0:25fa8795676b | 39 | * \return true If there was event processed, false if the event queue was empty. |
leothedragon | 0:25fa8795676b | 40 | */ |
leothedragon | 0:25fa8795676b | 41 | bool eventOS_scheduler_dispatch_event(void); |
leothedragon | 0:25fa8795676b | 42 | |
leothedragon | 0:25fa8795676b | 43 | /** |
leothedragon | 0:25fa8795676b | 44 | * \brief Process events until no more events to process. |
leothedragon | 0:25fa8795676b | 45 | */ |
leothedragon | 0:25fa8795676b | 46 | extern void eventOS_scheduler_run_until_idle(void); |
leothedragon | 0:25fa8795676b | 47 | |
leothedragon | 0:25fa8795676b | 48 | /** |
leothedragon | 0:25fa8795676b | 49 | * \brief Start Event scheduler. |
leothedragon | 0:25fa8795676b | 50 | * Loops forever processing events from the queue. |
leothedragon | 0:25fa8795676b | 51 | * Calls eventOS_scheduler_idle() whenever event queue is empty. |
leothedragon | 0:25fa8795676b | 52 | */ |
leothedragon | 0:25fa8795676b | 53 | NS_NORETURN extern void eventOS_scheduler_run(void); |
leothedragon | 0:25fa8795676b | 54 | /** |
leothedragon | 0:25fa8795676b | 55 | * \brief Disable Event scheduler Timers |
leothedragon | 0:25fa8795676b | 56 | * |
leothedragon | 0:25fa8795676b | 57 | * \return 0 Timer Stop OK |
leothedragon | 0:25fa8795676b | 58 | * \return -1 Timer Stop Fail |
leothedragon | 0:25fa8795676b | 59 | * |
leothedragon | 0:25fa8795676b | 60 | * */ |
leothedragon | 0:25fa8795676b | 61 | int eventOS_scheduler_timer_stop(void); |
leothedragon | 0:25fa8795676b | 62 | |
leothedragon | 0:25fa8795676b | 63 | /** |
leothedragon | 0:25fa8795676b | 64 | * \brief Synch Event scheduler timer after sleep |
leothedragon | 0:25fa8795676b | 65 | * |
leothedragon | 0:25fa8795676b | 66 | * \param sleep_ticks time in milli seconds |
leothedragon | 0:25fa8795676b | 67 | * |
leothedragon | 0:25fa8795676b | 68 | * \return 0 Timer Synch OK |
leothedragon | 0:25fa8795676b | 69 | * \return -1 Timer Synch & Start Fail |
leothedragon | 0:25fa8795676b | 70 | * |
leothedragon | 0:25fa8795676b | 71 | * */ |
leothedragon | 0:25fa8795676b | 72 | int eventOS_scheduler_timer_synch_after_sleep(uint32_t sleep_ticks); |
leothedragon | 0:25fa8795676b | 73 | |
leothedragon | 0:25fa8795676b | 74 | /** |
leothedragon | 0:25fa8795676b | 75 | * \brief Read current active Tasklet ID |
leothedragon | 0:25fa8795676b | 76 | * |
leothedragon | 0:25fa8795676b | 77 | * This function not return valid information called inside interrupt |
leothedragon | 0:25fa8795676b | 78 | * |
leothedragon | 0:25fa8795676b | 79 | * \return curret active tasklet id |
leothedragon | 0:25fa8795676b | 80 | * |
leothedragon | 0:25fa8795676b | 81 | * */ |
leothedragon | 0:25fa8795676b | 82 | extern int8_t eventOS_scheduler_get_active_tasklet(void); |
leothedragon | 0:25fa8795676b | 83 | |
leothedragon | 0:25fa8795676b | 84 | /** |
leothedragon | 0:25fa8795676b | 85 | * \brief Set manually Active Tasklet ID |
leothedragon | 0:25fa8795676b | 86 | * |
leothedragon | 0:25fa8795676b | 87 | * \param tasklet requested tasklet ID |
leothedragon | 0:25fa8795676b | 88 | * |
leothedragon | 0:25fa8795676b | 89 | * */ |
leothedragon | 0:25fa8795676b | 90 | extern void eventOS_scheduler_set_active_tasklet(int8_t tasklet); |
leothedragon | 0:25fa8795676b | 91 | |
leothedragon | 0:25fa8795676b | 92 | /** |
leothedragon | 0:25fa8795676b | 93 | * \brief Event scheduler loop idle Callback. |
leothedragon | 0:25fa8795676b | 94 | |
leothedragon | 0:25fa8795676b | 95 | * Note! This method is called only by eventOS_scheduler_run, needs to be |
leothedragon | 0:25fa8795676b | 96 | * ported for the platform only if you are using eventOS_scheduler_run(). |
leothedragon | 0:25fa8795676b | 97 | */ |
leothedragon | 0:25fa8795676b | 98 | extern void eventOS_scheduler_idle(void); |
leothedragon | 0:25fa8795676b | 99 | |
leothedragon | 0:25fa8795676b | 100 | /** |
leothedragon | 0:25fa8795676b | 101 | * \brief This function will be called when stack enter idle state and start |
leothedragon | 0:25fa8795676b | 102 | * waiting signal. |
leothedragon | 0:25fa8795676b | 103 | * |
leothedragon | 0:25fa8795676b | 104 | * Note! This method is called only by reference implementation of idle. Needs |
leothedragon | 0:25fa8795676b | 105 | * to be ported for the platform only if you are using reference implementation. |
leothedragon | 0:25fa8795676b | 106 | */ |
leothedragon | 0:25fa8795676b | 107 | extern void eventOS_scheduler_wait(void); |
leothedragon | 0:25fa8795676b | 108 | |
leothedragon | 0:25fa8795676b | 109 | /** |
leothedragon | 0:25fa8795676b | 110 | * \brief This function will be called when stack receives an event. |
leothedragon | 0:25fa8795676b | 111 | */ |
leothedragon | 0:25fa8795676b | 112 | extern void eventOS_scheduler_signal(void); |
leothedragon | 0:25fa8795676b | 113 | |
leothedragon | 0:25fa8795676b | 114 | /** |
leothedragon | 0:25fa8795676b | 115 | * \brief This function will be called when stack can enter deep sleep state in detected time. |
leothedragon | 0:25fa8795676b | 116 | * |
leothedragon | 0:25fa8795676b | 117 | * Note! This method is called only by reference implementation of idle. Needs to be |
leothedragon | 0:25fa8795676b | 118 | * ported for the platform only if you are using reference implementation. |
leothedragon | 0:25fa8795676b | 119 | * |
leothedragon | 0:25fa8795676b | 120 | * \param sleep_time_ms Time in milliseconds to sleep |
leothedragon | 0:25fa8795676b | 121 | * \return time slept in milliseconds |
leothedragon | 0:25fa8795676b | 122 | */ |
leothedragon | 0:25fa8795676b | 123 | extern uint32_t eventOS_scheduler_sleep(uint32_t sleep_time_ms); |
leothedragon | 0:25fa8795676b | 124 | |
leothedragon | 0:25fa8795676b | 125 | /** |
leothedragon | 0:25fa8795676b | 126 | * \brief Lock a thread against the event loop thread |
leothedragon | 0:25fa8795676b | 127 | * |
leothedragon | 0:25fa8795676b | 128 | * This method can be provided by multi-threaded platforms to allow |
leothedragon | 0:25fa8795676b | 129 | * mutual exclusion with the event loop thread, for cases where |
leothedragon | 0:25fa8795676b | 130 | * code wants to work with both the event loop and other threads. |
leothedragon | 0:25fa8795676b | 131 | * |
leothedragon | 0:25fa8795676b | 132 | * A typical platform implementation would claim the same mutex |
leothedragon | 0:25fa8795676b | 133 | * before calling eventOS_scheduler_run() or |
leothedragon | 0:25fa8795676b | 134 | * eventOS_scheduler_dispatch(), and release it during |
leothedragon | 0:25fa8795676b | 135 | * eventOS_scheduler_idle(). |
leothedragon | 0:25fa8795676b | 136 | * |
leothedragon | 0:25fa8795676b | 137 | * The mutex must count - nested calls from one thread return |
leothedragon | 0:25fa8795676b | 138 | * immediately. Thus calling this from inside an event callback |
leothedragon | 0:25fa8795676b | 139 | * is harmless. |
leothedragon | 0:25fa8795676b | 140 | */ |
leothedragon | 0:25fa8795676b | 141 | extern void eventOS_scheduler_mutex_wait(void); |
leothedragon | 0:25fa8795676b | 142 | |
leothedragon | 0:25fa8795676b | 143 | /** |
leothedragon | 0:25fa8795676b | 144 | * \brief Release the event loop mutex |
leothedragon | 0:25fa8795676b | 145 | * |
leothedragon | 0:25fa8795676b | 146 | * Release the mutex claimed with eventOS_scheduler_mutex_wait(), |
leothedragon | 0:25fa8795676b | 147 | * allowing the event loop to continue processing. |
leothedragon | 0:25fa8795676b | 148 | */ |
leothedragon | 0:25fa8795676b | 149 | extern void eventOS_scheduler_mutex_release(void); |
leothedragon | 0:25fa8795676b | 150 | |
leothedragon | 0:25fa8795676b | 151 | /** |
leothedragon | 0:25fa8795676b | 152 | * \brief Check if the current thread owns the event mutex |
leothedragon | 0:25fa8795676b | 153 | * |
leothedragon | 0:25fa8795676b | 154 | * Check if the calling thread owns the scheduler mutex. |
leothedragon | 0:25fa8795676b | 155 | * This allows the ownership to be asserted if a function |
leothedragon | 0:25fa8795676b | 156 | * requires the mutex to be locked externally. |
leothedragon | 0:25fa8795676b | 157 | * |
leothedragon | 0:25fa8795676b | 158 | * The function is only intended as a debugging aid for |
leothedragon | 0:25fa8795676b | 159 | * users of eventOS_scheduler_mutex_wait() - it is not |
leothedragon | 0:25fa8795676b | 160 | * used by the event loop core itself. |
leothedragon | 0:25fa8795676b | 161 | * |
leothedragon | 0:25fa8795676b | 162 | * If the underlying mutex system does not support it, |
leothedragon | 0:25fa8795676b | 163 | * this may be implemented to always return true. |
leothedragon | 0:25fa8795676b | 164 | * |
leothedragon | 0:25fa8795676b | 165 | * \return true if the current thread owns the mutex |
leothedragon | 0:25fa8795676b | 166 | */ |
leothedragon | 0:25fa8795676b | 167 | extern bool eventOS_scheduler_mutex_am_owner(void); |
leothedragon | 0:25fa8795676b | 168 | |
leothedragon | 0:25fa8795676b | 169 | #ifdef __cplusplus |
leothedragon | 0:25fa8795676b | 170 | } |
leothedragon | 0:25fa8795676b | 171 | #endif |
leothedragon | 0:25fa8795676b | 172 | |
leothedragon | 0:25fa8795676b | 173 | #endif /* EVENTOS_SCHEDULER_H_ */ |