From 47b464519d4227459677a1b86838d67f7090b83c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 5 Nov 2017 07:20:21 +0000 Subject: Updated OS-less osal for Cortex-M. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10948 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/osal/os-less/ARMCMx/osal.h | 111 +++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 43 deletions(-) (limited to 'os/hal/osal/os-less') diff --git a/os/hal/osal/os-less/ARMCMx/osal.h b/os/hal/osal/os-less/ARMCMx/osal.h index d38035325..3fa1d040d 100644 --- a/os/hal/osal/os-less/ARMCMx/osal.h +++ b/os/hal/osal/os-less/ARMCMx/osal.h @@ -46,7 +46,7 @@ #endif #if !defined(TRUE) || defined(__DOXYGEN__) -#define TRUE 1 +#define TRUE (!FALSE) #endif #define OSAL_SUCCESS false @@ -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) /** @} */ /** @@ -176,6 +176,11 @@ typedef int32_t msg_t; */ typedef uint32_t systime_t; +/** + * @brief Type of system time counter. + */ +typedef uint32_t sysinterval_t; + /** * @brief Type of realtime counter. */ @@ -196,6 +201,11 @@ typedef struct { */ typedef thread_t * thread_reference_t; +/** + * @brief Type of an event flags mask. + */ +typedef uint32_t eventflags_t; + /** * @brief Type of an event flags object. * @note The content of this structure is not part of the API and should @@ -213,11 +223,6 @@ typedef struct event_source event_source_t; */ typedef void (*eventcallback_t)(event_source_t *esp); -/** - * @brief Type of an event flags mask. - */ -typedef uint32_t eventflags_t; - /** * @brief Events source object. * @note The content of this structure is not part of the API and should @@ -282,7 +287,6 @@ typedef struct { } \ } while (false) - /** * @brief Function parameters check. * @details If the condition check fails then the OSAL panics and halts. @@ -303,7 +307,6 @@ typedef struct { } \ } while (false) - /** * @brief I-Class state check. * @note Implementation is optional. @@ -357,41 +360,41 @@ 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) \ - ((systime_t)((uint32_t)(sec) * (uint32_t)OSAL_ST_FREQUENCY)) +#define OSAL_S2I(secs) \ + ((systime_t)((uint32_t)(secs) * (uint32_t)OSAL_ST_FREQUENCY)) /** * @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) \ - ((systime_t)((((uint32_t)(msec)) * \ - ((uint32_t)OSAL_ST_FREQUENCY) + 999UL) / 1000UL)) +#define OSAL_MS2I(msecs) \ + ((systime_t)((((((uint32_t)(msecs)) * \ + ((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL)) /** * @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) \ - ((systime_t)((((uint32_t)(usec)) * \ - ((uint32_t)OSAL_ST_FREQUENCY) + 999999UL) / 1000000UL)) +#define OSAL_US2I(usecs) \ + ((systime_t)((((((uint32_t)(usecs)) * \ + ((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL)) /** @} */ /** @@ -450,11 +453,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 @@ -463,11 +466,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 @@ -476,11 +479,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)) /** @} */ /*===========================================================================*/ @@ -498,13 +501,13 @@ extern "C" { void osalOsTimerHandlerI(void); void osalOsRescheduleS(void); systime_t osalOsGetSystemTimeX(void); - void osalThreadSleepS(systime_t time); - void osalThreadSleep(systime_t time); + void osalThreadSleepS(sysinterval_t time); + void osalThreadSleep(sysinterval_t time); msg_t osalThreadSuspendS(thread_reference_t *trp); - msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, systime_t timeout); + msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, sysinterval_t timeout); void osalThreadResumeI(thread_reference_t *trp, msg_t msg); void osalThreadResumeS(thread_reference_t *trp, msg_t msg); - msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, systime_t timeout); + msg_t osalThreadEnqueueTimeoutS(threads_queue_t *tqp, sysinterval_t timeout); void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg); void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg); void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags); @@ -595,11 +598,6 @@ static inline void osalSysLockFromISR(void) { */ static inline void osalSysUnlockFromISR(void) { -#if CORTEX_MODEL == 0 - __enable_irq(); -#else - __set_BASEPRI(0); -#endif } /** @@ -650,6 +648,35 @@ static inline void osalSysRestoreStatusX(syssts_t sts) { #endif } +/** + * @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 systime + (systime_t)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 (sysinterval_t)((systime_t)(end - start)); +} + /** * @brief Checks if the specified time is within the specified time window. * @note When start==end then the function returns always true because the @@ -664,9 +691,9 @@ static inline void osalSysRestoreStatusX(syssts_t sts) { * * @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 (bool)((time - start) < (end - start)); } @@ -681,14 +708,12 @@ static inline bool osalOsIsTimeWithinX(systime_t time, static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) { osalDbgCheck(tqp != NULL); - - (void)tqp; } /** - * @brief Initializes an event flags object. + * @brief Initializes an event source object. * - * @param[out] esp pointer to the event flags object + * @param[out] esp pointer to the event source object * * @init */ -- cgit v1.2.3