/*
AMiRo-Apps is a collection of applications for the Autonomous Mini Robot (AMiRo) platform.
Copyright (C) 2018..2020 Thomas Schöpping et al.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#ifndef APPS_URTOSAL_H
#define APPS_URTOSAL_H
/*============================================================================*/
/* DEPENDENCIES */
/*============================================================================*/
#include
/*============================================================================*/
/* DEBUG */
/*============================================================================*/
#define urtDebugAssert(condition) aosDbgAssert(condition)
/*============================================================================*/
/* MUTEX */
/*============================================================================*/
/**
* @brief Mutex lock type.
*/
typedef mutex_t urt_osMutex_t;
#define urtMutexInit(mutex) chMtxObjectInit(mutex)
#define urtMutexLock(mutex) chMtxLock(mutex)
#define urtMutexTryLock(mutex) chMtxTryLock(mutex)
#define urtMutexUnlock(mutex) chMtxUnlock(mutex)
/*============================================================================*/
/* CONDITION VARIABLE */
/*============================================================================*/
/**
* @brief Condition variable type.
*/
typedef condition_variable_t urt_osCondvar_t;
#define urtCondvarInit(condvar) chCondObjectInit(condvar)
#define urtCondvarSignal(condvar) chCondSignal(condvar)
#define urtCondvarBroadcast(condvar) chCondBroadcast(condvar)
/*============================================================================*/
/* EVENTS */
/*============================================================================*/
/**
* @brief Type representing an event source object.
*/
typedef event_source_t urt_osEventSource_t;
/**
* @brief Type representing an event listener object.
*/
typedef event_listener_t urt_osEventListener_t;
/**
* @brief Type representing event masks.
* @details Event masks can be used to distinguish and filter events.
*/
typedef eventmask_t urt_osEventMask_t;
/**
* @brief Type representing event flags.
* @details Event flags can be used to represent rudimentary metadata or to filter events.
*/
typedef eventflags_t urt_osEventFlags_t;
/**
* @brief Event mask, which is handled with highest priority.
*/
#define URT_EVENTMASK_MAXPRIO EVENT_MASK(0)
/**
* @brief Event mask to select all events,
*/
#define URT_EVENTMASK_ALL ALL_EVENTS
#define urtEventSourceInit(source) chEvtObjectInit(source)
#define urtEventSourceBroadcast(source, flags) chEvtBroadcastFlags(source, flags)
#define urtEventListenerInit(listener) (void)listener
#define urtEventListenerGetFlags(listener) (urt_osEventFlags_t)(listener->flags)
#define urtEventListenerClearFlags(listener) (urt_osEventFlags_t)chEvtGetAndClearFlags(listener)
#define urtEventRegister(source, listener, mask, flags) chEvtRegisterMaskWithFlags(source, listener, mask, flags)
#define urtEventUnregister(source, listener) chEvtUnregister(source, listener)
/**
* @brief Event flags
*/
#define URT_EVENTFLAG_TERMINATE (urt_osEventFlags_t)1
#define URT_EVENTFLAG_PROCEED (urt_osEventFlags_t)2
/*============================================================================*/
/* STREAMS */
/*============================================================================*/
#define urtPrintf(fmt, ...) aosprintf(fmt, ##__VA_ARGS__)
#define urtErrPrintf(fmt, ...) aosprintf(fmt, ##__VA_ARGS__)
/*============================================================================*/
/* TIME */
/*============================================================================*/
/**
* @brief The urt_osTime_t represents time at an arbitrary precision.
*/
typedef aos_timestamp_t urt_osTime_t;
#define urtTime2Us(time) (*((urt_osTime_t*)time))
#define urtTimeAddUs(time, offset) (*((urt_osTime_t*)time) + offset)
/*============================================================================*/
/* THREAD */
/*============================================================================*/
/**
* @brief Thread object type.
*/
typedef thread_t urt_osThread_t;
/**
* @brief Thread priority data type.
*/
typedef tprio_t urt_osThreadPrio_t;
/**
* @brief Minimum thread priority.
*/
#define URT_THREAD_PRIO_LOW_MIN AOS_THD_LOWPRIO_MIN
/**
* @brief Maximum thread priority for low priority class threads.
*/
#define URT_THREAD_PRIO_LOW_MAX AOS_THD_LOWPRIO_MAX
/**
* @brief Minimum thread priority for normal priority class threads.
*/
#define URT_THREAD_PRIO_NORMAL_MIN AOS_THD_NORMALPRIO_MIN
/**
* @brief Maximum thread priority for normal priority class threads.
*/
#define URT_THREAD_PRIO_NORMAL_MAX AOS_THD_NORMALPRIO_MAX
/**
* @brief Minimum thread priority for high priority class threads.
*/
#define URT_THREAD_PRIO_HIGH_MIN AOS_THD_HIGHPRIO_MIN
/**
* @brief Maximum thread priority for high priority class threads.
*/
#define URT_THREAD_PRIO_HIGH_MAX AOS_THD_HIGHPRIO_MAX
/**
* @brief Minimum thread priority for real-time class threads.
*/
#define URT_THREAD_PRIO_RT_MIN AOS_THD_RTPRIO_MIN
/**
* @brief maximum thread priority for real-time class threads.
*/
#define URT_THREAD_PRIO_RT_MAX AOS_THD_RTPRIO_MAX
/**
* @brief Maximum number of seconds a thread can sleep.
*/
#define URT_THREAD_SLEEP_MAX (float)AOS_THD_MAX_SLEEP_S
/**
* @brief Maximum number of seconds a thread can sleep.
*/
#define URT_THREAD_SSLEEP_MAX (unsigned int)AOS_THD_MAX_SLEEP_S
/**
* @brief Maximum number of milliseconds a thread can sleep.
*/
#define URT_THREAD_MSLEEP_MAX (unsigned int)AOS_THD_MAX_SLEEP_MS
/**
* @brief Maximum number of microseconds a thread can sleep.
*/
#define URT_THREAD_USLEEP_MAX (urt_delay_t)AOS_THD_MAX_SLEEP_US
/**
* @brief Macro function to layout a thread memory.
* @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).
* The layout in memory as well as the metadata may differ between kernels and event hardware ports.
*
* @param[in] varname The name of the resulting buffer variable.
* @param[in] stacksize The size of the thread's stack.
*/
#define URT_THREAD_MEMORY(varname, stacksize) THD_WORKING_AREA(varname, stacksize)
#define urtThreadStart(thread) chThdStart(thread)
#define urtThreadYield() chThdYield()
#define urtThreadGetPriority() chThdGetPriorityX()
#define urtThreadSetPriority(prio) { \
aosDbgCheck(prio >= URT_THREAD_PRIO_LOW_MIN && prio <= URT_THREAD_PRIO_RT_MAX) \
chThdSetPriority(prio); \
}
#define urtThreadSleep(seconds) aosThdSleep(seconds)
#define urtThreadSSleep(seconds) aosThdSSleep(seconds)
#define urtThreadMSleep(seconds) aosThdMSleep(seconds)
#define urtThreadUSleep(seconds) aosThdUSleep(seconds)
#define urtThreadSleepUntil(time) aosThdSleepUntil(time)
#define urtThreadExit() chThdExit(MSG_OK)
#define urtThreadShouldTerminate() chThdShouldTerminateX()
#define urtThreadJoin(thread) (void)chThdWait(thread)
#define urtThreadGetSelf() chThdGetSelfX()
#define urtThreadGetChildren(thread) (thread->children)
#define urtThreadGetSibling(thread) (thread->sibling)
#define urtThreadGetParent(thread) (thread->parent)
/*============================================================================*/
/* TIMER */
/*============================================================================*/
/**
* @brief Timer object type.
*/
typedef aos_timer_t urt_osTimer_t;
#define urtTimerInit(timer) aosTimerInit(timer)
#define urtTimerReset(timer) aosTimerReset(timer)
#define urtTimerIsArmeed(timer) aosTimerIsArmed(timer)
#endif /* APPS_URTOSAL_H */