diff options
Diffstat (limited to 'os/hal')
| -rw-r--r-- | os/hal/osal/lib/osal_vt.c | 20 | ||||
| -rw-r--r-- | os/hal/osal/lib/osal_vt.h | 14 | ||||
| -rw-r--r-- | os/hal/osal/os-less/ARMCMx/osal.h | 111 | 
3 files changed, 81 insertions, 64 deletions
diff --git a/os/hal/osal/lib/osal_vt.c b/os/hal/osal/lib/osal_vt.c index 8954b5c8f..b6f520a8e 100644 --- a/os/hal/osal/lib/osal_vt.c +++ b/os/hal/osal/lib/osal_vt.c @@ -66,7 +66,7 @@ void vtInit(void) {    /* Virtual Timers initialization.*/
    vtlist.vt_next = vtlist.vt_prev = (void *)&vtlist;
 -  vtlist.vt_time = (systime_t)-1;
 +  vtlist.vt_delta = (sysinterval_t)-1;
    vtlist.vt_systime = 0;
  }
 @@ -97,8 +97,8 @@ void vtDoTickI(void) {    if (&vtlist != (virtual_timers_list_t *)vtlist.vt_next) {
      virtual_timer_t *vtp;
 -    --vtlist.vt_next->vt_time;
 -    while (!(vtp = vtlist.vt_next)->vt_time) {
 +    --vtlist.vt_next->vt_delta;
 +    while (!(vtp = vtlist.vt_next)->vt_delta) {
        vtfunc_t fn = vtp->vt_func;
        vtp->vt_func = (vtfunc_t)NULL;
        vtp->vt_next->vt_prev = (void *)&vtlist;
 @@ -115,7 +115,7 @@ void vtDoTickI(void) {   * @note    The associated function is invoked from interrupt context.
   *
   * @param[out] vtp      the @p virtual_timer_t structure pointer
 - * @param[in] time      the number of ticks before the operation timeouts, the
 + * @param[in] timeout   the number of ticks before the operation timeouts, the
   *                      special values are handled as follow:
   *                      - @a TIME_INFINITE is allowed but interpreted as a
   *                        normal time specification.
 @@ -129,23 +129,23 @@ void vtDoTickI(void) {   *
   * @iclass
   */
 -void vtSetI(virtual_timer_t *vtp, systime_t time,
 +void vtSetI(virtual_timer_t *vtp, sysinterval_t timeout,
              vtfunc_t vtfunc, void *par) {
    virtual_timer_t *p;
    vtp->vt_par = par;
    vtp->vt_func = vtfunc;
    p = vtlist.vt_next;
 -  while (p->vt_time < time) {
 -    time -= p->vt_time;
 +  while (p->vt_delta < timeout) {
 +    timeout -= p->vt_delta;
      p = p->vt_next;
    }
    vtp->vt_prev = (vtp->vt_next = p)->vt_prev;
    vtp->vt_prev->vt_next = p->vt_prev = vtp;
 -  vtp->vt_time = time;
 +  vtp->vt_delta = timeout;
    if (p != (void *)&vtlist)
 -    p->vt_time -= time;
 +    p->vt_delta -= timeout;
  }
  /**
 @@ -159,7 +159,7 @@ void vtSetI(virtual_timer_t *vtp, systime_t time,  void vtResetI(virtual_timer_t *vtp) {
    if (vtp->vt_next != (void *)&vtlist)
 -    vtp->vt_next->vt_time += vtp->vt_time;
 +    vtp->vt_next->vt_delta += vtp->vt_delta;
    vtp->vt_prev->vt_next = vtp->vt_next;
    vtp->vt_next->vt_prev = vtp->vt_prev;
    vtp->vt_func = (vtfunc_t)NULL;
 diff --git a/os/hal/osal/lib/osal_vt.h b/os/hal/osal/lib/osal_vt.h index e46365c37..14e54efc8 100644 --- a/os/hal/osal/lib/osal_vt.h +++ b/os/hal/osal/lib/osal_vt.h @@ -29,14 +29,6 @@  /* Module constants.                                                         */
  /*===========================================================================*/
 -/**
 - * @name    Special time constants
 - * @{
 - */
 -#define TIME_IMMEDIATE                      ((systime_t)0)
 -#define TIME_INFINITE                       ((systime_t)-1)
 -/** @} */
 -
  /*===========================================================================*/
  /* Module pre-compile time settings.                                         */
  /*===========================================================================*/
 @@ -73,7 +65,7 @@ typedef struct {                                                  list.                       */
    virtual_timer_t       *vt_prev;   /**< @brief Last timer in the timers
                                                  list.                       */
 -  systime_t             vt_time;    /**< @brief Must be initialized to -1.  */
 +  sysinterval_t         vt_delta;   /**< @brief Must be initialized to -1.  */
    volatile systime_t    vt_systime; /**< @brief System Time counter.        */
  } virtual_timers_list_t;
 @@ -90,7 +82,7 @@ struct virtual_timer {                                                  list.                       */
    virtual_timer_t       *vt_prev;   /**< @brief Previous timer in the timers
                                                  list.                       */
 -  systime_t             vt_time;    /**< @brief Time delta before timeout.  */
 +  sysinterval_t         vt_delta;   /**< @brief Time delta before timeout.  */
    vtfunc_t              vt_func;    /**< @brief Timer callback function
                                                  pointer.                    */
    void                  *vt_par;    /**< @brief Timer callback function
 @@ -115,7 +107,7 @@ extern "C" {    void vtInit(void);
    bool vtIsArmedI(virtual_timer_t *vtp);
    void vtDoTickI(void);
 -  void vtSetI(virtual_timer_t *vtp, systime_t time,
 +  void vtSetI(virtual_timer_t *vtp, sysinterval_t timeout,
                vtfunc_t vtfunc, void *par);
    void vtResetI(virtual_timer_t *vtp);
  #ifdef __cplusplus
 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)
  /** @} */
  /**
 @@ -177,6 +177,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.
   */
  typedef uint32_t rtcnt_t;
 @@ -197,6 +202,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
   *          not be relied upon. Implementers may define this structure in
 @@ -214,11 +224,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
   *          not be relied upon. Implementers may define this structure in
 @@ -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
  }
  /**
 @@ -651,6 +649,35 @@ static inline void osalSysRestoreStatusX(syssts_t sts) {  }
  /**
 + * @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
   *          whole time range is specified.
 @@ -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
   */
  | 
