ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file chevents.h 00029 * @brief Events macros and structures. 00030 * 00031 * @addtogroup events 00032 * @{ 00033 */ 00034 00035 #ifndef _CHEVENTS_H_ 00036 #define _CHEVENTS_H_ 00037 00038 #if CH_USE_EVENTS 00039 00040 typedef struct EventListener EventListener; 00041 00042 /** 00043 * @brief Event Listener structure. 00044 */ 00045 struct EventListener { 00046 EventListener *el_next; /**< @brief Next Event Listener 00047 registered on the Event 00048 Source. */ 00049 Thread *el_listener; /**< @brief Thread interested in the 00050 Event Source. */ 00051 eventmask_t el_mask; /**< @brief Event flags mask associated 00052 by the thread to the Event 00053 Source. */ 00054 }; 00055 00056 /** 00057 * @brief Event Source structure. 00058 */ 00059 typedef struct EventSource { 00060 EventListener *es_next; /**< @brief First Event Listener 00061 registered on the Event 00062 Source. */ 00063 } EventSource; 00064 00065 /** 00066 * @brief Data part of a static event source initializer. 00067 * @details This macro should be used when statically initializing an event 00068 * source that is part of a bigger structure. 00069 * @param name the name of the event source variable 00070 */ 00071 #define _EVENTSOURCE_DATA(name) {(void *)(&name)} 00072 00073 /** 00074 * @brief Static event source initializer. 00075 * @details Statically initialized event sources require no explicit 00076 * initialization using @p chEvtInit(). 00077 * 00078 * @param name the name of the event source variable 00079 */ 00080 #define EVENTSOURCE_DECL(name) EventSource name = _EVENTSOURCE_DATA(name) 00081 00082 /** All events allowed mask.*/ 00083 #define ALL_EVENTS ((eventmask_t)-1) 00084 00085 /** Returns the event mask from the event identifier.*/ 00086 #define EVENT_MASK(eid) ((eventmask_t)(1 << (eid))) 00087 00088 /** 00089 * @brief Registers an Event Listener on an Event Source. 00090 * @note Multiple Event Listeners can use the same event identifier, the 00091 * listener will share the callback function. 00092 * 00093 * @param[in] esp pointer to the @p EventSource structure 00094 * @param[out] elp pointer to the @p EventListener structure 00095 * @param[in] eid numeric identifier assigned to the Event Listener. The 00096 * identifier is used as index for the event callback 00097 * function. 00098 * The value must range between zero and the size, in bit, 00099 * of the @p eventid_t type minus one. 00100 */ 00101 #define chEvtRegister(esp, elp, eid) chEvtRegisterMask(esp, elp, EVENT_MASK(eid)) 00102 00103 /** 00104 * @brief Initializes an Event Source. 00105 * @note Can be used with interrupts disabled or enabled. 00106 * 00107 * @param[in] esp pointer to the @p EventSource structure 00108 */ 00109 #define chEvtInit(esp) \ 00110 ((esp)->es_next = (EventListener *)(void *)(esp)) 00111 00112 /** 00113 * @brief Verifies if there is at least one @p EventListener registered. 00114 * @note Can be called with interrupts disabled or enabled. 00115 * 00116 * @param[in] esp pointer to the @p EventSource structure 00117 */ 00118 #define chEvtIsListening(esp) \ 00119 ((void *)(esp) != (void *)(esp)->es_next) 00120 00121 /** 00122 * @brief Event Handler callback function. 00123 */ 00124 typedef void (*evhandler_t)(eventid_t); 00125 00126 #ifdef __cplusplus 00127 extern "C" { 00128 #endif 00129 void chEvtRegisterMask(EventSource *esp, 00130 EventListener *elp, 00131 eventmask_t mask); 00132 void chEvtUnregister(EventSource *esp, EventListener *elp); 00133 eventmask_t chEvtClear(eventmask_t mask); 00134 eventmask_t chEvtPend(eventmask_t mask); 00135 void chEvtSignal(Thread *tp, eventmask_t mask); 00136 void chEvtSignalI(Thread *tp, eventmask_t mask); 00137 void chEvtBroadcast(EventSource *esp); 00138 void chEvtBroadcastI(EventSource *esp); 00139 void chEvtDispatch(const evhandler_t *handlers, eventmask_t mask); 00140 #if CH_OPTIMIZE_SPEED || !CH_USE_EVENTS_TIMEOUT 00141 eventmask_t chEvtWaitOne(eventmask_t mask); 00142 eventmask_t chEvtWaitAny(eventmask_t mask); 00143 eventmask_t chEvtWaitAll(eventmask_t mask); 00144 #endif 00145 #if CH_USE_EVENTS_TIMEOUT 00146 eventmask_t chEvtWaitOneTimeout(eventmask_t mask, systime_t time); 00147 eventmask_t chEvtWaitAnyTimeout(eventmask_t mask, systime_t time); 00148 eventmask_t chEvtWaitAllTimeout(eventmask_t mask, systime_t time); 00149 #endif 00150 #ifdef __cplusplus 00151 } 00152 #endif 00153 00154 #if !CH_OPTIMIZE_SPEED && CH_USE_EVENTS_TIMEOUT 00155 #define chEvtWaitOne(mask) chEvtWaitOneTimeout(mask, TIME_INFINITE) 00156 #define chEvtWaitAny(mask) chEvtWaitAnyTimeout(mask, TIME_INFINITE) 00157 #define chEvtWaitAll(mask) chEvtWaitAllTimeout(mask, TIME_INFINITE) 00158 #endif 00159 00160 #endif /* CH_USE_EVENTS */ 00161 00162 #endif /* _CHEVENTS_H_ */ 00163 00164 /** @} */