2013-08-02 11:45:33 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2013-11-19 15:16:41 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2013-11-19 15:16:41 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2013-11-19 15:16:41 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file osal.h
|
|
|
|
* @brief OSAL module header.
|
|
|
|
*
|
|
|
|
* @addtogroup OSAL
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _OSAL_H_
|
|
|
|
#define _OSAL_H_
|
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Common constants
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#if !defined(FALSE) || defined(__DOXYGEN__)
|
|
|
|
#define FALSE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(TRUE) || defined(__DOXYGEN__)
|
2015-03-08 21:19:58 +00:00
|
|
|
#define TRUE 1
|
2013-08-02 11:45:33 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-11 15:05:09 +00:00
|
|
|
#define OSAL_SUCCESS false
|
|
|
|
#define OSAL_FAILED true
|
2013-08-02 11:45:33 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Messages
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-11 15:05:09 +00:00
|
|
|
#define MSG_OK (msg_t)0
|
|
|
|
#define MSG_RESET (msg_t)-1
|
|
|
|
#define MSG_TIMEOUT (msg_t)-2
|
2013-08-02 11:45:33 +00:00
|
|
|
/** @} */
|
|
|
|
|
2014-11-02 16:38:13 +00:00
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @name Special time constants
|
|
|
|
* @{
|
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
#define TIME_IMMEDIATE ((systime_t)0)
|
|
|
|
#define TIME_INFINITE ((systime_t)-1)
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Systick modes.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#define OSAL_ST_MODE_NONE 0
|
|
|
|
#define OSAL_ST_MODE_PERIODIC 1
|
|
|
|
#define OSAL_ST_MODE_FREERUNNING 2
|
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Systick parameters.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Size in bits of the @p systick_t type.
|
|
|
|
*/
|
|
|
|
#define OSAL_ST_RESOLUTION 32
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Required systick frequency or resolution.
|
|
|
|
*/
|
|
|
|
#define OSAL_ST_FREQUENCY 1000
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Systick mode required by the underlying OS.
|
|
|
|
*/
|
|
|
|
#define OSAL_ST_MODE OSAL_ST_MODE_PERIODIC
|
2013-08-02 11:45:33 +00:00
|
|
|
/** @} */
|
|
|
|
|
2015-03-26 11:12:55 +00:00
|
|
|
/**
|
|
|
|
* @name IRQ-related constants
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Total priority levels.
|
2015-03-27 09:51:45 +00:00
|
|
|
* @brief Implementation not mandatory.
|
2015-03-26 11:12:55 +00:00
|
|
|
*/
|
|
|
|
#define OSAL_IRQ_PRIORITY_LEVELS 16U
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Highest IRQ priority for HAL drivers.
|
2015-03-27 09:51:45 +00:00
|
|
|
* @brief Implementation not mandatory.
|
2015-03-26 11:12:55 +00:00
|
|
|
*/
|
|
|
|
#define OSAL_IRQ_MAXIMUM_PRIORITY 0U
|
|
|
|
/** @} */
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-03-08 21:19:58 +00:00
|
|
|
/**
|
|
|
|
* @brief Enables OSAL assertions.
|
|
|
|
*/
|
|
|
|
#if !defined(OSAL_DBG_ENABLE_ASSERTS) || defined(__DOXYGEN__)
|
|
|
|
#define OSAL_DBG_ENABLE_ASSERTS FALSE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enables OSAL functions parameters checks.
|
|
|
|
*/
|
|
|
|
#if !defined(OSAL_DBG_ENABLE_CHECKS) || defined(__DOXYGEN__)
|
|
|
|
#define OSAL_DBG_ENABLE_CHECKS FALSE
|
|
|
|
#endif
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/**
|
2014-11-02 16:38:13 +00:00
|
|
|
* @brief Type of a system status word.
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
typedef uint32_t syssts_t;
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of a message.
|
|
|
|
*/
|
|
|
|
typedef int32_t msg_t;
|
|
|
|
|
|
|
|
/**
|
2013-08-04 13:38:53 +00:00
|
|
|
* @brief Type of system time counter.
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
2013-08-04 13:38:53 +00:00
|
|
|
typedef uint32_t systime_t;
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2014-11-02 16:38:13 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of realtime counter.
|
|
|
|
*/
|
|
|
|
typedef uint32_t rtcnt_t;
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of a thread reference.
|
|
|
|
*/
|
2014-11-01 17:01:38 +00:00
|
|
|
typedef void * thread_reference_t;
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2014-11-02 16:38:13 +00:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* an entirely different way.
|
|
|
|
* @note Retrieval and clearing of the flags are not defined in this
|
|
|
|
* API and are implementation-dependent.
|
|
|
|
*/
|
|
|
|
typedef struct event_source event_source_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of an event source callback.
|
|
|
|
* @note This type is not part of the OSAL API and is provided
|
|
|
|
* exclusively as an example and for convenience.
|
|
|
|
*/
|
2015-03-08 21:19:58 +00:00
|
|
|
typedef void (*eventcallback_t)(event_source_t *esp);
|
2014-11-02 16:38:13 +00:00
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of an event flags mask.
|
|
|
|
*/
|
|
|
|
typedef uint32_t eventflags_t;
|
|
|
|
|
|
|
|
/**
|
2014-11-02 16:38:13 +00:00
|
|
|
* @brief Events source object.
|
2013-08-02 11:45:33 +00:00
|
|
|
* @note The content of this structure is not part of the API and should
|
|
|
|
* not be relied upon. Implementers may define this structure in
|
|
|
|
* an entirely different way.
|
|
|
|
* @note Retrieval and clearing of the flags are not defined in this
|
|
|
|
* API and are implementation-dependent.
|
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
struct event_source {
|
|
|
|
volatile eventflags_t flags; /**< @brief Stored event flags. */
|
|
|
|
eventcallback_t cb; /**< @brief Event source callback. */
|
|
|
|
void *param; /**< @brief User defined field. */
|
|
|
|
};
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of a mutex.
|
|
|
|
* @note If the OS does not support mutexes or there is no OS then them
|
|
|
|
* mechanism can be simulated.
|
|
|
|
*/
|
|
|
|
typedef uint32_t mutex_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Type of a thread queue.
|
|
|
|
* @details A thread queue is a queue of sleeping threads, queued threads
|
|
|
|
* can be dequeued one at time or all together.
|
2015-03-24 10:30:27 +00:00
|
|
|
* @note If the OSAL is implemented on a bare metal machine without RTOS
|
2014-11-02 16:38:13 +00:00
|
|
|
* then the queue can be implemented as a single thread reference.
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
thread_reference_t tr;
|
|
|
|
} threads_queue_t;
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2014-11-02 16:38:13 +00:00
|
|
|
/**
|
|
|
|
* @name Debug related macros
|
|
|
|
* @{
|
|
|
|
*/
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @brief Condition assertion.
|
2014-11-02 16:38:13 +00:00
|
|
|
* @details If the condition check fails then the OSAL panics with a
|
|
|
|
* message and halts.
|
2013-08-02 11:45:33 +00:00
|
|
|
* @note The condition is tested only if the @p OSAL_ENABLE_ASSERTIONS
|
|
|
|
* switch is enabled.
|
|
|
|
* @note The remark string is not currently used except for putting a
|
|
|
|
* comment in the code about the assertion.
|
|
|
|
*
|
|
|
|
* @param[in] c the condition to be verified to be true
|
|
|
|
* @param[in] remark a remark string
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2015-03-08 21:19:58 +00:00
|
|
|
#define osalDbgAssert(c, remark) do { \
|
|
|
|
/*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
|
|
|
|
if (OSAL_DBG_ENABLE_ASSERTS != FALSE) { \
|
|
|
|
if (!(c)) { \
|
|
|
|
/*lint -restore*/ \
|
|
|
|
osalSysHalt(__func__); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Function parameters check.
|
|
|
|
* @details If the condition check fails then the OSAL panics and halts.
|
|
|
|
* @note The condition is tested only if the @p OSAL_ENABLE_CHECKS switch
|
|
|
|
* is enabled.
|
|
|
|
*
|
|
|
|
* @param[in] c the condition to be verified to be true
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2015-03-08 21:19:58 +00:00
|
|
|
#define osalDbgCheck(c) do { \
|
|
|
|
/*lint -save -e506 -e774 [2.1, 14.3] Can be a constant by design.*/ \
|
|
|
|
if (OSAL_DBG_ENABLE_CHECKS != FALSE) { \
|
|
|
|
if (!(c)) { \
|
|
|
|
/*lint -restore*/ \
|
|
|
|
osalSysHalt(__func__); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (false)
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief I-Class state check.
|
2014-11-02 16:38:13 +00:00
|
|
|
* @note Implementation is optional.
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
|
|
|
#define osalDbgCheckClassI()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief S-Class state check.
|
2014-11-02 16:38:13 +00:00
|
|
|
* @note Implementation is optional.
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
|
|
|
#define osalDbgCheckClassS()
|
2014-11-02 16:38:13 +00:00
|
|
|
/** @} */
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2014-11-02 16:38:13 +00:00
|
|
|
/**
|
|
|
|
* @name IRQ service routines wrappers
|
|
|
|
* @{
|
|
|
|
*/
|
2015-03-26 11:12:55 +00:00
|
|
|
/**
|
|
|
|
* @brief Priority level verification macro.
|
|
|
|
*/
|
|
|
|
#define OSAL_IRQ_IS_VALID_PRIORITY(n) \
|
|
|
|
(((n) >= OSAL_IRQ_MAXIMUM_PRIORITY) && ((n) < OSAL_IRQ_PRIORITY_LEVELS))
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @brief IRQ prologue code.
|
|
|
|
* @details This macro must be inserted at the start of all IRQ handlers.
|
|
|
|
*/
|
|
|
|
#define OSAL_IRQ_PROLOGUE()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief IRQ epilogue code.
|
|
|
|
* @details This macro must be inserted at the end of all IRQ handlers.
|
|
|
|
*/
|
|
|
|
#define OSAL_IRQ_EPILOGUE()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief IRQ handler function declaration.
|
|
|
|
* @details This macro hides the details of an ISR function declaration.
|
|
|
|
*
|
|
|
|
* @param[in] id a vector name as defined in @p vectors.s
|
|
|
|
*/
|
|
|
|
#define OSAL_IRQ_HANDLER(id) void id(void)
|
2014-11-02 16:38:13 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Time conversion utilities
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Seconds to system ticks.
|
|
|
|
* @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
|
|
|
|
* @return The number of ticks.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define OSAL_S2ST(sec) \
|
2015-03-11 15:05:09 +00:00
|
|
|
((systime_t)((uint32_t)(sec) * (uint32_t)OSAL_ST_FREQUENCY))
|
2014-11-02 16:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* @return The number of ticks.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define OSAL_MS2ST(msec) \
|
2015-03-11 15:05:09 +00:00
|
|
|
((systime_t)((((((uint32_t)(msec)) * \
|
|
|
|
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000UL) + 1UL))
|
2014-11-02 16:38:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
* @return The number of ticks.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define OSAL_US2ST(usec) \
|
2015-03-11 15:05:09 +00:00
|
|
|
((systime_t)((((((uint32_t)(usec)) * \
|
|
|
|
((uint32_t)OSAL_ST_FREQUENCY)) - 1UL) / 1000000UL) + 1UL))
|
2014-11-02 16:38:13 +00:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name Sleep macros using absolute time
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief Delays the invoking thread for the specified number of seconds.
|
|
|
|
* @note The specified time is rounded up to a value allowed by the real
|
|
|
|
* system tick clock.
|
|
|
|
* @note The maximum specifiable value is implementation dependent.
|
|
|
|
*
|
|
|
|
* @param[in] sec time in seconds, must be different from zero
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define osalThreadSleepSeconds(sec) osalThreadSleep(OSAL_S2ST(sec))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Delays the invoking thread for the specified number of
|
|
|
|
* milliseconds.
|
|
|
|
* @note The specified time is rounded up to a value allowed by the real
|
|
|
|
* system tick clock.
|
|
|
|
* @note The maximum specifiable value is implementation dependent.
|
|
|
|
*
|
|
|
|
* @param[in] msec time in milliseconds, must be different from zero
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define osalThreadSleepMilliseconds(msec) osalThreadSleep(OSAL_MS2ST(msec))
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Delays the invoking thread for the specified number of
|
|
|
|
* microseconds.
|
|
|
|
* @note The specified time is rounded up to a value allowed by the real
|
|
|
|
* system tick clock.
|
|
|
|
* @note The maximum specifiable value is implementation dependent.
|
|
|
|
*
|
|
|
|
* @param[in] usec time in microseconds, must be different from zero
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
#define osalThreadSleepMicroseconds(usec) osalThreadSleep(OSAL_US2ST(usec))
|
|
|
|
/** @} */
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-03-08 21:19:58 +00:00
|
|
|
extern const char *osal_halt_msg;
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void osalInit(void);
|
|
|
|
void osalSysHalt(const char *reason);
|
2015-03-24 10:30:27 +00:00
|
|
|
void osalSysPolledDelayX(rtcnt_t cycles);
|
|
|
|
void osalOsTimerHandlerI(void);
|
|
|
|
void osalOsRescheduleS(void);
|
|
|
|
systime_t osalOsGetSystemTimeX(void);
|
|
|
|
void osalThreadSleepS(systime_t time);
|
|
|
|
void osalThreadSleep(systime_t time);
|
|
|
|
msg_t osalThreadSuspendS(thread_reference_t *trp);
|
|
|
|
msg_t osalThreadSuspendTimeoutS(thread_reference_t *trp, systime_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);
|
2014-11-02 16:38:13 +00:00
|
|
|
void osalThreadDequeueNextI(threads_queue_t *tqp, msg_t msg);
|
|
|
|
void osalThreadDequeueAllI(threads_queue_t *tqp, msg_t msg);
|
2015-03-24 10:30:27 +00:00
|
|
|
void osalEventBroadcastFlagsI(event_source_t *esp, eventflags_t flags);
|
|
|
|
void osalEventBroadcastFlags(event_source_t *esp, eventflags_t flags);
|
|
|
|
void osalEventSetCallback(event_source_t *esp,
|
|
|
|
eventcallback_t cb,
|
|
|
|
void *param);
|
|
|
|
void osalMutexLock(mutex_t *mp);
|
|
|
|
void osalMutexUnlock(mutex_t *mp);
|
2013-08-02 11:45:33 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module inline functions. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2015-03-24 10:30:27 +00:00
|
|
|
/**
|
|
|
|
* @brief Disables interrupts globally.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void osalSysDisable(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enables interrupts globally.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void osalSysEnable(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @brief Enters a critical zone from thread context.
|
|
|
|
* @note This function cannot be used for reentrant critical zones.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void osalSysLock(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Leaves a critical zone from thread context.
|
|
|
|
* @note This function cannot be used for reentrant critical zones.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void osalSysUnlock(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enters a critical zone from ISR context.
|
|
|
|
* @note This function cannot be used for reentrant critical zones.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void osalSysLockFromISR(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Leaves a critical zone from ISR context.
|
|
|
|
* @note This function cannot be used for reentrant critical zones.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void osalSysUnlockFromISR(void) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-02 16:38:13 +00:00
|
|
|
* @brief Returns the execution status and enters a critical zone.
|
|
|
|
* @details This functions enters into a critical zone and can be called
|
|
|
|
* from any context. Because its flexibility it is less efficient
|
|
|
|
* than @p chSysLock() which is preferable when the calling context
|
|
|
|
* is known.
|
|
|
|
* @post The system is in a critical zone.
|
2013-08-02 11:45:33 +00:00
|
|
|
*
|
2014-11-02 16:38:13 +00:00
|
|
|
* @return The previous system status, the encoding of this
|
|
|
|
* status word is architecture-dependent and opaque.
|
2013-08-02 11:45:33 +00:00
|
|
|
*
|
2014-11-02 16:38:13 +00:00
|
|
|
* @xclass
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
static inline syssts_t osalSysGetStatusAndLockX(void) {
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2015-03-11 15:05:09 +00:00
|
|
|
return (syssts_t)0;
|
2013-08-02 11:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-11-02 16:38:13 +00:00
|
|
|
* @brief Restores the specified execution status and leaves a critical zone.
|
|
|
|
* @note A call to @p chSchRescheduleS() is automatically performed
|
|
|
|
* if exiting the critical zone and if not in ISR context.
|
2013-08-02 11:45:33 +00:00
|
|
|
*
|
2014-11-02 16:38:13 +00:00
|
|
|
* @param[in] sts the system status to be restored.
|
2013-08-02 11:45:33 +00:00
|
|
|
*
|
2014-11-02 16:38:13 +00:00
|
|
|
* @xclass
|
2013-08-02 11:45:33 +00:00
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
static inline void osalSysRestoreStatusX(syssts_t sts) {
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2014-11-01 17:01:38 +00:00
|
|
|
(void)sts;
|
2013-08-02 11:45:33 +00:00
|
|
|
}
|
|
|
|
|
2014-11-02 16:38:13 +00:00
|
|
|
/**
|
|
|
|
* @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.
|
|
|
|
* @note This function can be called from any context.
|
|
|
|
*
|
|
|
|
* @param[in] time the time to be verified
|
|
|
|
* @param[in] start the start of the time window (inclusive)
|
|
|
|
* @param[in] end the end of the time window (non inclusive)
|
|
|
|
* @retval true current time within the specified time window.
|
|
|
|
* @retval false current time not within the specified time window.
|
|
|
|
*
|
|
|
|
* @xclass
|
|
|
|
*/
|
|
|
|
static inline bool osalOsIsTimeWithinX(systime_t time,
|
|
|
|
systime_t start,
|
|
|
|
systime_t end) {
|
|
|
|
|
2015-03-08 21:19:58 +00:00
|
|
|
return (bool)((time - start) < (end - start));
|
2014-11-02 16:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes a threads queue object.
|
|
|
|
*
|
|
|
|
* @param[out] tqp pointer to the threads queue object
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
|
|
|
static inline void osalThreadQueueObjectInit(threads_queue_t *tqp) {
|
|
|
|
|
2015-03-24 10:30:27 +00:00
|
|
|
osalDbgCheck(tqp != NULL);
|
2014-11-02 16:38:13 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 11:45:33 +00:00
|
|
|
/**
|
|
|
|
* @brief Initializes an event flags object.
|
|
|
|
*
|
|
|
|
* @param[out] esp pointer to the event flags object
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
static inline void osalEventObjectInit(event_source_t *esp) {
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
osalDbgCheck(esp != NULL);
|
|
|
|
|
2015-03-11 15:05:09 +00:00
|
|
|
esp->flags = (eventflags_t)0;
|
2014-11-02 16:38:13 +00:00
|
|
|
esp->cb = NULL;
|
|
|
|
esp->param = NULL;
|
2013-08-02 11:45:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Initializes s @p mutex_t object.
|
|
|
|
*
|
|
|
|
* @param[out] mp pointer to the @p mutex_t object
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
2014-11-02 16:38:13 +00:00
|
|
|
static inline void osalMutexObjectInit(mutex_t *mp) {
|
2013-08-02 11:45:33 +00:00
|
|
|
|
2015-03-24 10:30:27 +00:00
|
|
|
osalDbgCheck(mp != NULL);
|
2013-08-02 11:45:33 +00:00
|
|
|
|
|
|
|
*mp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _OSAL_H_ */
|
|
|
|
|
|
|
|
/** @} */
|