From a47f5705d3f6abf4abaffa949f7bb50132507d94 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 15 Oct 2017 06:51:20 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/rt5_dev_point1@10822 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/osal/nil/osal.h | 5 +- os/hal/osal/rt/osal.h | 138 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 110 insertions(+), 33 deletions(-) (limited to 'os/hal/osal') diff --git a/os/hal/osal/nil/osal.h b/os/hal/osal/nil/osal.h index 5f3ff1bc5..9a8d16d12 100644 --- a/os/hal/osal/nil/osal.h +++ b/os/hal/osal/nil/osal.h @@ -875,8 +875,9 @@ static inline void osalEventBroadcastFlags(event_source_t *esp, osalDbgCheck(esp != NULL); chSysLock(); - osalEventBroadcastFlagsI(esp, flags); - chSchRescheduleS(); + esp->flags |= flags; + if (esp->cb != NULL) { + esp->cb(esp); chSysUnlock(); } diff --git a/os/hal/osal/rt/osal.h b/os/hal/osal/rt/osal.h index 07072e88f..c81edef4f 100644 --- a/os/hal/osal/rt/osal.h +++ b/os/hal/osal/rt/osal.h @@ -67,8 +67,8 @@ * @name Special time constants * @{ */ -#define TIME_IMMEDIATE ((systime_t)0) -#define TIME_INFINITE ((systime_t)-1) +#define TIME_IMMEDIATE ((sysinterval_t)0) +#define TIME_INFINITE ((sysinterval_t)-1) /** @} */ #endif @@ -148,6 +148,13 @@ typedef int32_t msg_t; typedef uint32_t systime_t; #endif +#if 0 +/** + * @brief Type of system time counter. + */ +typedef uint32_t sysinterval_t; +#endif + #if 0 /** * @brief Type of realtime counter. @@ -179,14 +186,15 @@ typedef uint32_t eventflags_t; * API and are implementation-dependent. */ typedef struct { - volatile eventflags_t flags; /**< @brief Flags stored into the - object. */ + volatile eventflags_t flags; /**< @brief Stored event flags. */ + eventcallback_t cb; /**< @brief Event source callback. */ + void *param; /**< @brief User defined field. */ } event_source_t; #endif /** * @brief Type of a mutex. - * @note If the OS does not support mutexes or there is no OS then them + * @note If the OS does not support mutexes or there is no OS then the * mechanism can be simulated. */ #if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__) @@ -304,36 +312,36 @@ typedef struct { * @details Converts from seconds to system ticks number. * @note The result is rounded upward to the next tick boundary. * - * @param[in] sec number of seconds + * @param[in] secs number of seconds * @return The number of ticks. * * @api */ -#define OSAL_S2ST(sec) S2ST(sec) +#define OSAL_S2I(secs) TIME_S2I(secs) /** * @brief Milliseconds to system ticks. * @details Converts from milliseconds to system ticks number. * @note The result is rounded upward to the next tick boundary. * - * @param[in] msec number of milliseconds + * @param[in] msecs number of milliseconds * @return The number of ticks. * * @api */ -#define OSAL_MS2ST(msec) TIME_MS2I(msec) +#define OSAL_MS2I(msecs) TIME_MS2I(msecs) /** * @brief Microseconds to system ticks. * @details Converts from microseconds to system ticks number. * @note The result is rounded upward to the next tick boundary. * - * @param[in] usec number of microseconds + * @param[in] usecs number of microseconds * @return The number of ticks. * * @api */ -#define OSAL_US2ST(usec) TIME_US2I(usec) +#define OSAL_US2I(usecs) TIME_US2I(usecs) /** @} */ /** @@ -392,11 +400,11 @@ typedef struct { * system tick clock. * @note The maximum specifiable value is implementation dependent. * - * @param[in] sec time in seconds, must be different from zero + * @param[in] secs time in seconds, must be different from zero * * @api */ -#define osalThreadSleepSeconds(sec) osalThreadSleep(OSAL_S2ST(sec)) +#define osalThreadSleepSeconds(secs) osalThreadSleep(OSAL_S2I(secs)) /** * @brief Delays the invoking thread for the specified number of @@ -405,11 +413,11 @@ typedef struct { * system tick clock. * @note The maximum specifiable value is implementation dependent. * - * @param[in] msec time in milliseconds, must be different from zero + * @param[in] msecs time in milliseconds, must be different from zero * * @api */ -#define osalThreadSleepMilliseconds(msec) osalThreadSleep(OSAL_MS2ST(msec)) +#define osalThreadSleepMilliseconds(msecs) osalThreadSleep(OSAL_MS2I(msecs)) /** * @brief Delays the invoking thread for the specified number of @@ -418,11 +426,11 @@ typedef struct { * system tick clock. * @note The maximum specifiable value is implementation dependent. * - * @param[in] usec time in microseconds, must be different from zero + * @param[in] usecs time in microseconds, must be different from zero * * @api */ -#define osalThreadSleepMicroseconds(usec) osalThreadSleep(OSAL_US2ST(usec)) +#define osalThreadSleepMicroseconds(usecs) osalThreadSleep(OSAL_US2I(usecs)) /** @} */ /*===========================================================================*/ @@ -618,6 +626,35 @@ static inline systime_t osalOsGetSystemTimeX(void) { return chVTGetSystemTimeX(); } +/** + * @brief Adds an interval to a system time returning a system time. + * + * @param[in] systime base system time + * @param[in] interval interval to be added + * @return The new system time. + * + * @xclass + */ +static inline systime_t osalTimeAddX(systime_t systime, + sysinterval_t interval) { + + return chTimeAddX(systime, interval); +} + +/** + * @brief Subtracts two system times returning an interval. + * + * @param[in] start first system time + * @param[in] end second system time + * @return The interval representing the time difference. + * + * @xclass + */ +static inline sysinterval_t osalTimeDiffX(systime_t start, systime_t end) { + + return chTimeDiffX(start, end); +} + /** * @brief Checks if the specified time is within the specified time window. * @note When start==end then the function returns always true because the @@ -632,9 +669,9 @@ static inline systime_t osalOsGetSystemTimeX(void) { * * @xclass */ -static inline bool osalOsIsTimeWithinX(systime_t time, - systime_t start, - systime_t end) { +static inline bool osalTimeIsInRangeX(systime_t time, + systime_t start, + systime_t end) { return chTimeIsInRangeX(time, start, end); } @@ -642,7 +679,7 @@ static inline bool osalOsIsTimeWithinX(systime_t time, /** * @brief Suspends the invoking thread for the specified time. * - * @param[in] time the delay in system ticks, the special values are + * @param[in] delay the delay in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE is allowed but interpreted as a * normal time specification. @@ -651,15 +688,15 @@ static inline bool osalOsIsTimeWithinX(systime_t time, * * @sclass */ -static inline void osalThreadSleepS(systime_t time) { +static inline void osalThreadSleepS(sysinterval_t delay) { - chThdSleepS(time); + chThdSleepS(delay); } /** * @brief Suspends the invoking thread for the specified time. * - * @param[in] time the delay in system ticks, the special values are + * @param[in] delay the delay in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE is allowed but interpreted as a * normal time specification. @@ -668,9 +705,9 @@ static inline void osalThreadSleepS(systime_t time) { * * @api */ -static inline void osalThreadSleep(systime_t time) { +static inline void osalThreadSleep(sysinterval_t delay) { - chThdSleep(time); + chThdSleep(delay); } /** @@ -708,7 +745,7 @@ static inline msg_t osalThreadSuspendS(thread_reference_t *trp) { * @sclass */ static inline msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, - systime_t timeout) { + sysinterval_t timeout) { return chThdSuspendTimeoutS(trp, timeout); } @@ -761,7 +798,7 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) { * dequeued or the specified timeouts expires. * * @param[in] tqp pointer to the threads queue object - * @param[in] time the timeout in system ticks, the special values are + * @param[in] timeout the timeout in system ticks, the special values are * handled as follow: * - @a TIME_INFINITE the thread enters an infinite sleep * state. @@ -779,9 +816,9 @@ static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) { * @sclass */ static inline msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, - systime_t time) { + sysinterval_t timeout) { - return chThdEnqueueTimeoutS(tqp, time); + return chThdEnqueueTimeoutS(tqp, timeout); } /** @@ -823,9 +860,13 @@ static inline void osalEventObjectInit(event_source_t *esp) { chEvtObjectInit(esp); } #else -static inline void osalEventObjectInit(event_source_t *esp) { +static inline void osalEventObjectInit(osal_event_source_t *esp) { + + osalDbgCheck(esp != NULL); esp->flags = 0; + esp->cb = NULL; + esp->param = NULL; } #endif @@ -847,7 +888,12 @@ static inline void osalEventBroadcastFlagsI(event_source_t *esp, static inline void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags) { + osalDbgCheck(esp != NULL); + esp->flags |= flags; + if (esp->cb != NULL) { + esp->cb(esp); + } } #endif @@ -868,12 +914,42 @@ static inline void osalEventBroadcastFlags(event_source_t *esp, #else static inline void osalEventBroadcastFlags(event_source_t *esp, eventflags_t flags) { + + osalDbgCheck(esp != NULL); + osalSysLock(); esp->flags |= flags; + if (esp->cb != NULL) { + esp->cb(esp); osalSysUnlock(); } #endif +#if !CH_CFG_USE_EVENTS || defined(__DOXYGEN__) +/** + * @brief Event callback setup. + * @note The callback is invoked from ISR context and can + * only invoke I-Class functions. The callback is meant + * to wakeup the task that will handle the event by + * calling @p osalEventGetAndClearFlagsI(). + * + * @param[in] esp pointer to the event flags object + * @param[in] cb pointer to the callback function + * @param[in] param parameter to be passed to the callback function + * + * @api + */ +static inline void osalEventSetCallback(event_source_t *esp, + eventcallback_t cb, + void *param) { + + osalDbgCheck(esp != NULL); + + esp->cb = cb; + esp->param = param; +} +#endif + /** * @brief Initializes s @p mutex_t object. * -- cgit v1.2.3