amiro-apps / middleware / apps_urtosal.h @ 7f26dc6b
History | View | Annotate | Download (9.233 KB)
| 1 | 6d4ba740 | Thomas Schöpping | /*
|
|---|---|---|---|
| 2 | AMiRo-Apps is a collection of applications for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | Copyright (C) 2018..2020 Thomas Schöpping et al.
|
||
| 4 | |||
| 5 | This program is free software: you can redistribute it and/or modify
|
||
| 6 | it under the terms of the GNU General Public License as published by
|
||
| 7 | the Free Software Foundation, either version 3 of the License, or
|
||
| 8 | (at your option) any later version.
|
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful,
|
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 13 | GNU General Public License for more details.
|
||
| 14 | |||
| 15 | You should have received a copy of the GNU General Public License
|
||
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
| 17 | */
|
||
| 18 | |||
| 19 | #ifndef APPS_URTOSAL_H
|
||
| 20 | #define APPS_URTOSAL_H
|
||
| 21 | |||
| 22 | /*============================================================================*/
|
||
| 23 | /* DEPENDENCIES */
|
||
| 24 | /*============================================================================*/
|
||
| 25 | |||
| 26 | #include <amiroos.h> |
||
| 27 | |||
| 28 | /*============================================================================*/
|
||
| 29 | /* DEBUG */
|
||
| 30 | /*============================================================================*/
|
||
| 31 | |||
| 32 | #define urtDebugAssert(condition) aosDbgAssert(condition)
|
||
| 33 | |||
| 34 | /*============================================================================*/
|
||
| 35 | /* MUTEX */
|
||
| 36 | /*============================================================================*/
|
||
| 37 | |||
| 38 | /**
|
||
| 39 | * @brief Mutex lock type.
|
||
| 40 | */
|
||
| 41 | typedef mutex_t urt_osMutex_t;
|
||
| 42 | |||
| 43 | #define urtMutexInit(mutex) chMtxObjectInit(mutex)
|
||
| 44 | |||
| 45 | #define urtMutexLock(mutex) chMtxLock(mutex)
|
||
| 46 | |||
| 47 | #define urtMutexTryLock(mutex) chMtxTryLock(mutex)
|
||
| 48 | |||
| 49 | #define urtMutexUnlock(mutex) chMtxUnlock(mutex)
|
||
| 50 | |||
| 51 | /*============================================================================*/
|
||
| 52 | /* CONDITION VARIABLE */
|
||
| 53 | /*============================================================================*/
|
||
| 54 | |||
| 55 | /**
|
||
| 56 | * @brief Condition variable type.
|
||
| 57 | */
|
||
| 58 | typedef condition_variable_t urt_osCondvar_t;
|
||
| 59 | |||
| 60 | #define urtCondvarInit(condvar) chCondObjectInit(condvar)
|
||
| 61 | |||
| 62 | #define urtCondvarSignal(condvar) chCondSignal(condvar)
|
||
| 63 | |||
| 64 | #define urtCondvarBroadcast condvar) chCondBroadcast(condvar)
|
||
| 65 | |||
| 66 | /*============================================================================*/
|
||
| 67 | /* EVENTS */
|
||
| 68 | /*============================================================================*/
|
||
| 69 | |||
| 70 | /**
|
||
| 71 | * @brief Type representing an event source object.
|
||
| 72 | */
|
||
| 73 | typedef event_source_t urt_osEventSource_t;
|
||
| 74 | |||
| 75 | /**
|
||
| 76 | * @brief Type representing an event listener object.
|
||
| 77 | */
|
||
| 78 | typedef event_listener_t urt_osEventListener_t;
|
||
| 79 | |||
| 80 | /**
|
||
| 81 | * @brief Type representing event masks.
|
||
| 82 | * @details Event masks can be used to distinguish and filter events.
|
||
| 83 | */
|
||
| 84 | typedef eventmask_t urt_osEventMask_t;
|
||
| 85 | |||
| 86 | /**
|
||
| 87 | * @brief Type representing event flags.
|
||
| 88 | * @details Event flags can be used to represent rudimentary metadata or to filter events.
|
||
| 89 | */
|
||
| 90 | typedef eventflags_t urt_osEventFlags_t;
|
||
| 91 | |||
| 92 | /**
|
||
| 93 | * @brief Event mask, which is handles with highest priority.
|
||
| 94 | */
|
||
| 95 | #define URT_EVENTMASK_MAXPRIO EVENT_MASK(0) |
||
| 96 | |||
| 97 | #define urtEventSourceInit(source) chEvtObjectInit(source)
|
||
| 98 | |||
| 99 | #define urtEventSourceBroadcast(source, flags) chEvtBroadcastFlags(source, flags)
|
||
| 100 | |||
| 101 | #define urtEventListenerInit(listener) (void)listener |
||
| 102 | |||
| 103 | #define urtEventListenerGetFlags(listener) (urt_osEventFlags_t)(listener->flags)
|
||
| 104 | |||
| 105 | #define urtEventListenerClearFlags(listener) (urt_osEventFlags_t)chEvtGetAndClearFlags(listener)
|
||
| 106 | |||
| 107 | #define urtEventRegister(source, listener, mask, flags) chEvtRegisterMaskWithFlags(source, listener, mask, flags)
|
||
| 108 | |||
| 109 | #define urtEventUnregister(source, listener) chEvtUnregister(source, listener)
|
||
| 110 | |||
| 111 | /*============================================================================*/
|
||
| 112 | /* STREAMS */
|
||
| 113 | /*============================================================================*/
|
||
| 114 | |||
| 115 | #define urtPrintf(fmt, ...) aosprintf(fmt, ##__VA_ARGS__) |
||
| 116 | |||
| 117 | #define urtErrPrintf(fmt, ...) aosprintf(fmt, ##__VA_ARGS__) |
||
| 118 | |||
| 119 | /*============================================================================*/
|
||
| 120 | /* TIME */
|
||
| 121 | /*============================================================================*/
|
||
| 122 | |||
| 123 | /**
|
||
| 124 | * @brief The urt_osTime_t represents time at an arbitrary precision.
|
||
| 125 | */
|
||
| 126 | typedef aos_timestamp_t urt_osTime_t;
|
||
| 127 | |||
| 128 | #define urtTime2Us(time) (*((urt_osTime_t*)time))
|
||
| 129 | |||
| 130 | #define urtTimeAddUs(time, offset) (*((urt_osTime_t*)time) + offset)
|
||
| 131 | |||
| 132 | /*============================================================================*/
|
||
| 133 | /* THREAD */
|
||
| 134 | /*============================================================================*/
|
||
| 135 | |||
| 136 | /**
|
||
| 137 | * @brief Thread object type.
|
||
| 138 | */
|
||
| 139 | typedef thread_t urt_osThread_t;
|
||
| 140 | |||
| 141 | /**
|
||
| 142 | * @brief Thread priority data type.
|
||
| 143 | */
|
||
| 144 | typedef tprio_t urt_osThreadPrio_t;
|
||
| 145 | |||
| 146 | /**
|
||
| 147 | * @brief Minimum thread priority.
|
||
| 148 | */
|
||
| 149 | #define URT_THREAD_PRIO_LOW_MIN AOS_THD_LOWPRIO_MIN
|
||
| 150 | |||
| 151 | /**
|
||
| 152 | * @brief Maximum thread priority for low priority class threads.
|
||
| 153 | */
|
||
| 154 | #define URT_THREAD_PRIO_LOW_MAX AOS_THD_LOWPRIO_MAX
|
||
| 155 | |||
| 156 | /**
|
||
| 157 | * @brief Minimum thread priority for normal priority class threads.
|
||
| 158 | */
|
||
| 159 | #define URT_THREAD_PRIO_NORMAL_MIN AOS_THD_NORMALPRIO_MIN
|
||
| 160 | |||
| 161 | /**
|
||
| 162 | * @brief Maximum thread priority for normal priority class threads.
|
||
| 163 | */
|
||
| 164 | #define URT_THREAD_PRIO_NORMAL_MAX AOS_THD_NORMALPRIO_MAX
|
||
| 165 | |||
| 166 | /**
|
||
| 167 | * @brief Minimum thread priority for high priority class threads.
|
||
| 168 | */
|
||
| 169 | #define URT_THREAD_PRIO_HIGH_MIN AOS_THD_HIGHPRIO_MIN
|
||
| 170 | |||
| 171 | /**
|
||
| 172 | * @brief Maximum thread priority for high priority class threads.
|
||
| 173 | */
|
||
| 174 | #define URT_THREAD_PRIO_HIGH_MAX AOS_THD_HIGHPRIO_MAX
|
||
| 175 | |||
| 176 | /**
|
||
| 177 | * @brief Minimum thread priority for real-time class threads.
|
||
| 178 | */
|
||
| 179 | #define URT_THREAD_PRIO_RT_MIN AOS_THD_RTPRIO_MIN
|
||
| 180 | |||
| 181 | /**
|
||
| 182 | * @brief maximum thread priority for real-time class threads.
|
||
| 183 | */
|
||
| 184 | #define URT_THREAD_PRIO_RT_MAX AOS_THD_RTPRIO_MAX
|
||
| 185 | |||
| 186 | /**
|
||
| 187 | * @brief Maximum number of seconds a thread can sleep.
|
||
| 188 | */
|
||
| 189 | #define URT_THREAD_SLEEP_MAX (float)AOS_THD_MAX_SLEEP_S |
||
| 190 | |||
| 191 | /**
|
||
| 192 | * @brief Maximum number of seconds a thread can sleep.
|
||
| 193 | */
|
||
| 194 | #define URT_THREAD_SSLEEP_MAX (unsigned int)AOS_THD_MAX_SLEEP_S |
||
| 195 | |||
| 196 | /**
|
||
| 197 | * @brief Maximum number of milliseconds a thread can sleep.
|
||
| 198 | */
|
||
| 199 | #define URT_THREAD_MSLEEP_MAX (unsigned int)AOS_THD_MAX_SLEEP_MS |
||
| 200 | |||
| 201 | /**
|
||
| 202 | * @brief Maximum number of microseconds a thread can sleep.
|
||
| 203 | */
|
||
| 204 | #define URT_THREAD_USLEEP_MAX (urt_delay_t)AOS_THD_MAX_SLEEP_US
|
||
| 205 | |||
| 206 | /**
|
||
| 207 | * @brief Macro function to layout a thread memory.
|
||
| 208 | * @details The overall memory required for a thread usually is a combination of the stack and some further data (i.e. the thread object itself).
|
||
| 209 | * The layout in memory as well as the metadata may differ between kernels and event hardware ports.
|
||
| 210 | *
|
||
| 211 | * @param[in] varname The name of the resulting buffer variable.
|
||
| 212 | * @param[in] stacksize The size of the thread's stack.
|
||
| 213 | */
|
||
| 214 | #define URT_THREAD_MEMORY(varname, stacksize) THD_WORKING_AREA(varname, stacksize)
|
||
| 215 | |||
| 216 | #define urtThreadStart(thread) chThdStart(thread)
|
||
| 217 | |||
| 218 | #define urtThreadYield() chThdYield()
|
||
| 219 | |||
| 220 | #define urtThreadGetPriority() chThdGetPriorityX()
|
||
| 221 | |||
| 222 | #define urtThreadSetPriority(prio) { \
|
||
| 223 | aosDbgCheck(prio >= URT_THREAD_PRIO_LOW_MIN && prio <= URT_THREAD_PRIO_RT_MAX) \ |
||
| 224 | chThdSetPriority(prio); \ |
||
| 225 | } |
||
| 226 | |||
| 227 | #define urtThreadSleep(seconds) aosThdSleep(seconds)
|
||
| 228 | |||
| 229 | #define urtThreadSSleep(seconds) aosThdSSleep(seconds)
|
||
| 230 | |||
| 231 | #define urtThreadMSleep(seconds) aosThdMSleep(seconds)
|
||
| 232 | |||
| 233 | #define urtThreadUSleep(seconds) aosThdUSleep(seconds)
|
||
| 234 | |||
| 235 | #define urtThreadSleepUntil(time) aosThdSleepUntil(time)
|
||
| 236 | |||
| 237 | #define urtThreadExit() chThdExit(MSG_OK)
|
||
| 238 | |||
| 239 | #define urtThreadJoin(thread) (void)chThdWait(thread) |
||
| 240 | |||
| 241 | #define urtThreadGetSelf() chThdGetSelfX()
|
||
| 242 | |||
| 243 | #define urtThreadGetChildren(thread) (thread->children)
|
||
| 244 | |||
| 245 | #define urtThreadGetSibling(thread) (thread->sibling)
|
||
| 246 | |||
| 247 | #define urtThreadGetParent(thread) (thread->parent)
|
||
| 248 | |||
| 249 | /*============================================================================*/
|
||
| 250 | /* TIMER */
|
||
| 251 | /*============================================================================*/
|
||
| 252 | |||
| 253 | /**
|
||
| 254 | * @brief Timer object type.
|
||
| 255 | */
|
||
| 256 | typedef aos_timer_t urt_osTimer_t;
|
||
| 257 | |||
| 258 | #define urtTimerInit(timer) aosTimerInit(timer)
|
||
| 259 | |||
| 260 | #define urtTimerReset(timer) aosTimerReset(timer)
|
||
| 261 | |||
| 262 | #define urtTimerIsArmeed(timer) aosTimerIsArmed(timer)
|
||
| 263 | |||
| 264 | #endif /* APPS_URTOSAL_H */ |