2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2015-01-11 13:56:55 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2015 Giovanni Di Sirio
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-05-11 06:08:17 +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
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-05-11 06:08:17 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-05-11 06:08:17 +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.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @file ch.hpp
|
|
|
|
* @brief C++ wrapper classes and definitions.
|
|
|
|
*
|
2009-08-30 07:17:22 +00:00
|
|
|
* @addtogroup cpp_library
|
2009-08-16 13:07:24 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ch.h>
|
|
|
|
|
|
|
|
#ifndef _CH_HPP_
|
|
|
|
#define _CH_HPP_
|
|
|
|
|
2013-01-03 11:32:45 +00:00
|
|
|
/**
|
2014-08-03 20:23:16 +00:00
|
|
|
* @brief ChibiOS-RT kernel-related classes and interfaces.
|
2013-01-03 11:32:45 +00:00
|
|
|
*/
|
2009-08-16 13:07:24 +00:00
|
|
|
namespace chibios_rt {
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
/* Forward declarations */
|
|
|
|
class Mutex;
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::System *
|
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
|
|
|
* @brief Class encapsulating the base system functionalities.
|
|
|
|
*/
|
|
|
|
class System {
|
|
|
|
public:
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief ChibiOS/RT initialization.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @details After executing this function the current instructions stream
|
|
|
|
* becomes the main thread.
|
|
|
|
* @pre Interrupts must be still disabled when @p chSysInit() is invoked
|
|
|
|
* and are internally enabled.
|
|
|
|
* @post The main thread is created with priority @p NORMALPRIO.
|
|
|
|
* @note This function has special, architecture-dependent, requirements,
|
|
|
|
* see the notes into the various port reference manuals.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void init(void) {
|
|
|
|
|
|
|
|
chSysInit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Halts the system.
|
|
|
|
* @details This function is invoked by the operating system when an
|
|
|
|
* unrecoverable error is detected, for example because a programming
|
|
|
|
* error in the application code that triggers an assertion while
|
|
|
|
* in debug mode.
|
|
|
|
* @note Can be invoked from any system state.
|
|
|
|
*
|
|
|
|
* @param[in] reason pointer to an error string
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
|
|
|
static inline void halt(const char *reason) {
|
|
|
|
|
|
|
|
chSysHalt(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief System integrity check.
|
|
|
|
* @details Performs an integrity check of the important ChibiOS/RT data
|
|
|
|
* structures.
|
|
|
|
* @note The appropriate action in case of failure is to halt the system
|
|
|
|
* before releasing the critical zone.
|
|
|
|
* @note If the system is corrupted then one possible outcome of this
|
|
|
|
* function is an exception caused by @p NULL or corrupted pointers
|
|
|
|
* in list elements. Exception vectors must be monitored as well.
|
|
|
|
* @note This function is not used internally, it is up to the
|
|
|
|
* application to define if and where to perform system
|
|
|
|
* checking.
|
|
|
|
* @note Performing all tests at once can be a slow operation and can
|
|
|
|
* degrade the system response time. It is suggested to execute
|
|
|
|
* one test at time and release the critical zone in between tests.
|
|
|
|
*
|
|
|
|
* @param[in] testmask Each bit in this mask is associated to a test to be
|
|
|
|
* performed.
|
|
|
|
* @return The test result.
|
|
|
|
* @retval false The test succeeded.
|
|
|
|
* @retval true Test failed.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
static inline bool integrityCheckI(unsigned int testmask) {
|
|
|
|
|
|
|
|
return chSysIntegrityCheckI(testmask);
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Enters the kernel lock mode.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void lock(void) {
|
|
|
|
|
|
|
|
chSysLock();
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Leaves the kernel lock mode.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void unlock(void) {
|
|
|
|
|
|
|
|
chSysUnlock();
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-06 09:10:58 +00:00
|
|
|
/**
|
|
|
|
* @brief Enters the kernel lock mode from within an interrupt handler.
|
|
|
|
* @note This API may do nothing on some architectures, it is required
|
|
|
|
* because on ports that support preemptable interrupt handlers
|
|
|
|
* it is required to raise the interrupt mask to the same level of
|
|
|
|
* the system mutual exclusion zone.<br>
|
|
|
|
* It is good practice to invoke this API before invoking any I-class
|
|
|
|
* syscall from an interrupt handler.
|
|
|
|
* @note This API must be invoked exclusively from interrupt handlers.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void lockFromIsr(void) {
|
|
|
|
|
|
|
|
chSysLockFromISR();
|
|
|
|
}
|
2013-01-06 09:10:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Leaves the kernel lock mode from within an interrupt handler.
|
|
|
|
*
|
|
|
|
* @note This API may do nothing on some architectures, it is required
|
|
|
|
* because on ports that support preemptable interrupt handlers
|
|
|
|
* it is required to raise the interrupt mask to the same level of
|
|
|
|
* the system mutual exclusion zone.<br>
|
|
|
|
* It is good practice to invoke this API after invoking any I-class
|
|
|
|
* syscall from an interrupt handler.
|
|
|
|
* @note This API must be invoked exclusively from interrupt handlers.
|
|
|
|
*
|
|
|
|
* @special
|
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void unlockFromIsr(void) {
|
2013-01-06 09:10:58 +00:00
|
|
|
|
2015-04-05 13:03:46 +00:00
|
|
|
chSysUnlockFromISR();
|
|
|
|
}
|
2013-01-06 09:10:58 +00:00
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Returns the system time as system ticks.
|
|
|
|
* @note The system tick time interval is implementation dependent.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2010-10-09 10:17:11 +00:00
|
|
|
* @return The system time.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline systime_t getTime(void) {
|
|
|
|
|
|
|
|
return chVTGetSystemTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the system time as system ticks.
|
|
|
|
* @note The system tick time interval is implementation dependent.
|
|
|
|
*
|
|
|
|
* @return The system time.
|
|
|
|
*
|
|
|
|
* @xclass
|
|
|
|
*/
|
|
|
|
static inline systime_t getTimeX(void) {
|
|
|
|
|
|
|
|
return chVTGetSystemTimeX();
|
|
|
|
}
|
2013-01-02 14:01:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Checks if the current system time is within the specified time
|
|
|
|
* window.
|
|
|
|
* @note When start==end then the function returns always true because the
|
|
|
|
* whole time range is specified.
|
|
|
|
*
|
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline bool isSystemTimeWithin(systime_t start, systime_t end) {
|
|
|
|
|
|
|
|
return chVTIsSystemTimeWithin(start, end);
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
};
|
|
|
|
|
2015-01-15 14:18:29 +00:00
|
|
|
#if CH_CFG_USE_MEMCORE || defined(__DOXYGEN__)
|
2013-01-03 09:52:04 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
2015-04-05 13:03:46 +00:00
|
|
|
* chibios_rt::Core *
|
2013-01-03 09:52:04 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Class encapsulating the base system functionalities.
|
|
|
|
*/
|
|
|
|
class Core {
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocates a memory block.
|
|
|
|
* @details The size of the returned block is aligned to the alignment
|
|
|
|
* type so it is not possible to allocate less
|
|
|
|
* than <code>MEM_ALIGN_SIZE</code>.
|
|
|
|
*
|
|
|
|
* @param[in] size the size of the block to be allocated
|
|
|
|
* @return A pointer to the allocated memory block.
|
|
|
|
* @retval NULL allocation failed, core memory exhausted.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void *alloc(size_t size) {
|
|
|
|
|
|
|
|
return chCoreAlloc(size);
|
|
|
|
}
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocates a memory block.
|
|
|
|
* @details The size of the returned block is aligned to the alignment
|
|
|
|
* type so it is not possible to allocate less than
|
|
|
|
* <code>MEM_ALIGN_SIZE</code>.
|
|
|
|
*
|
|
|
|
* @param[in] size the size of the block to be allocated.
|
|
|
|
* @return A pointer to the allocated memory block.
|
|
|
|
* @retval NULL allocation failed, core memory exhausted.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline void *allocI(size_t size) {
|
|
|
|
|
|
|
|
return chCoreAllocI(size);
|
|
|
|
}
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Core memory status.
|
|
|
|
*
|
|
|
|
* @return The size, in bytes, of the free core memory.
|
|
|
|
*
|
2015-04-05 13:03:46 +00:00
|
|
|
* @xclass
|
2013-01-03 09:52:04 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
static inline size_t getStatusX(void) {
|
|
|
|
|
|
|
|
return chCoreGetStatusX();
|
|
|
|
}
|
2013-01-03 09:52:04 +00:00
|
|
|
};
|
2015-01-15 14:18:29 +00:00
|
|
|
#endif /* CH_CFG_USE_MEMCORE */
|
2013-01-03 09:52:04 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Timer *
|
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Timer class.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
class Timer {
|
|
|
|
public:
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Embedded @p VirtualTimer structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::virtual_timer_t timer_ref;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Enables a virtual timer.
|
|
|
|
* @note The associated function is invoked from interrupt context.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the special values are handled as follow:
|
2013-01-02 14:01:11 +00:00
|
|
|
* - @a TIME_INFINITE is allowed but interpreted as a
|
|
|
|
* normal time specification.
|
|
|
|
* - @a TIME_IMMEDIATE this value is not allowed.
|
|
|
|
* .
|
|
|
|
* @param[in] vtfunc the timer callback function. After invoking the
|
2013-02-22 11:34:04 +00:00
|
|
|
* callback the timer is disabled and the structure
|
|
|
|
* can be disposed or reused.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @param[in] par a parameter that will be passed to the callback
|
|
|
|
* function
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
inline void setI(systime_t time, vtfunc_t vtfunc, void *par);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Resets the timer, if armed.
|
|
|
|
*
|
|
|
|
* @iclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
inline void resetI();
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Returns the timer status.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2010-10-09 10:17:11 +00:00
|
|
|
* @retval TRUE The timer is armed.
|
|
|
|
* @retval FALSE The timer already fired its callback.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
inline bool isArmedI(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
};
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
2015-04-05 13:03:46 +00:00
|
|
|
* chibios_rt::ThreadStayPoint *
|
2013-01-01 15:42:44 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2015-04-05 13:03:46 +00:00
|
|
|
* @brief Thread suspension point class.
|
|
|
|
* @details This class encapsulates a reference to a suspended thread.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
class ThreadStayPoint {
|
2009-08-16 13:07:24 +00:00
|
|
|
public:
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Pointer to the system thread.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
::thread_reference_t thread_ref;
|
2013-01-04 10:26:22 +00:00
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Suspends the current thread on the reference.
|
|
|
|
* @details The suspended thread becomes the referenced thread. It is
|
|
|
|
* possible to use this method only if the thread reference
|
|
|
|
* was set to @p NULL.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @return The incoming message.
|
|
|
|
*
|
2015-04-05 13:03:46 +00:00
|
|
|
* @sclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
inline msg_t suspendS(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
/**
|
2015-04-05 13:03:46 +00:00
|
|
|
* @brief Suspends the current thread on the reference with timeout.
|
2013-01-01 15:42:44 +00:00
|
|
|
* @details The suspended thread becomes the referenced thread. It is
|
|
|
|
* possible to use this method only if the thread reference
|
|
|
|
* was set to @p NULL.
|
|
|
|
*
|
2015-04-05 13:03:46 +00:00
|
|
|
*
|
|
|
|
* @param[in] timeout the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
|
|
|
* @retval MSG_OK if the binary semaphore has been successfully
|
|
|
|
* taken.
|
|
|
|
* @retval MSG_RESET if the binary semaphore has been reset using
|
|
|
|
* @p bsemReset().
|
|
|
|
* @retval MSG_TIMEOUT if the binary semaphore has not been signaled
|
|
|
|
* or reset within the specified timeout.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
inline msg_t suspendS(systime_t timeout);
|
2013-01-01 15:42:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resumes the currently referenced thread, if any.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] msg the wakeup message
|
|
|
|
*
|
2015-04-05 13:03:46 +00:00
|
|
|
* @iclass
|
2013-01-01 15:42:44 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
inline void resumeI(msg_t msg);
|
2013-01-01 15:42:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resumes the currently referenced thread, if any.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] msg the wakeup message
|
|
|
|
*
|
2015-04-05 13:03:46 +00:00
|
|
|
* @sclass
|
|
|
|
*/
|
|
|
|
inline void resumeS(msg_t msg);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::ThreadReference *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Thread reference class.
|
|
|
|
* @details This class encapsulates a reference to a system thread. All
|
|
|
|
* operations involving another thread are performed through
|
|
|
|
* an object of this type.
|
|
|
|
*/
|
|
|
|
class ThreadReference {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Pointer to the system thread.
|
|
|
|
*/
|
|
|
|
::thread_t *thread_ref;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Thread reference constructor.
|
|
|
|
*
|
|
|
|
* @param[in] tp the target thread. This parameter can be
|
|
|
|
* @p NULL if the thread is not known at
|
|
|
|
* creation time.
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
|
|
|
ThreadReference(thread_t *tp) : thread_ref(tp) {
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Stops the thread.
|
|
|
|
* @note The implementation is left to descendant classes and is
|
|
|
|
* optional.
|
2013-01-01 15:42:44 +00:00
|
|
|
*/
|
2015-04-05 13:03:46 +00:00
|
|
|
virtual void stop(void);
|
2013-01-01 15:42:44 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Requests a thread termination.
|
|
|
|
* @pre The target thread must be written to invoke periodically
|
|
|
|
* @p chThdShouldTerminate() and terminate cleanly if it returns
|
|
|
|
* @p TRUE.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @post The specified thread will terminate after detecting the
|
|
|
|
* termination condition.
|
2013-01-02 14:01:11 +00:00
|
|
|
*
|
|
|
|
* @api
|
2013-01-01 15:42:44 +00:00
|
|
|
*/
|
|
|
|
void requestTerminate(void);
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_WAITEXIT || defined(__DOXYGEN__)
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Blocks the execution of the invoking thread until the specified
|
|
|
|
* thread terminates then the exit code is returned.
|
|
|
|
* @details This function waits for the specified thread to terminate then
|
2013-02-22 11:34:04 +00:00
|
|
|
* decrements its reference counter, if the counter reaches zero
|
|
|
|
* then the thread working area is returned to the proper
|
|
|
|
* allocator.<br>
|
|
|
|
* The memory used by the exited thread is handled in different
|
|
|
|
* ways depending on the API that spawned the thread:
|
2013-01-02 14:01:11 +00:00
|
|
|
* - If the thread was spawned by @p chThdCreateStatic() or by
|
|
|
|
* @p chThdCreateI() then nothing happens and the thread working
|
|
|
|
* area is not released or modified in any way. This is the
|
|
|
|
* default, totally static, behavior.
|
|
|
|
* - If the thread was spawned by @p chThdCreateFromHeap() then
|
|
|
|
* the working area is returned to the system heap.
|
|
|
|
* - If the thread was spawned by @p chThdCreateFromMemoryPool()
|
|
|
|
* then the working area is returned to the owning memory pool.
|
|
|
|
* .
|
|
|
|
* @pre The configuration option @p CH_USE_WAITEXIT must be enabled in
|
|
|
|
* order to use this function.
|
|
|
|
* @post Enabling @p chThdWait() requires 2-4 (depending on the
|
|
|
|
* architecture) extra bytes in the @p Thread structure.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @post After invoking @p chThdWait() the thread pointer becomes
|
|
|
|
* invalid and must not be used as parameter for further system
|
|
|
|
* calls.
|
|
|
|
* @note If @p CH_USE_DYNAMIC is not specified this function just waits
|
|
|
|
* for the thread termination, no memory allocators are involved.
|
2013-01-02 14:01:11 +00:00
|
|
|
*
|
|
|
|
* @return The exit code from the terminated thread.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t wait(void);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_WAITEXIT */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_MESSAGES || defined(__DOXYGEN__)
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Sends a message to the thread and returns the answer.
|
|
|
|
*
|
|
|
|
* @param[in] msg the sent message
|
|
|
|
* @return The returned message.
|
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t sendMessage(msg_t msg);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Returns true if there is at least one message in queue.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @retval true A message is waiting in queue.
|
|
|
|
* @retval false A message is not waiting in queue.
|
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
bool isPendingMessage(void);
|
2013-01-03 16:17:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns an enqueued message or @p NULL.
|
|
|
|
*
|
|
|
|
* @return The incoming message.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
msg_t getMessage(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Releases the next message in queue with a reply.
|
|
|
|
*
|
|
|
|
* @param[in] msg the answer message
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void releaseMessage(msg_t msg);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_MESSAGES */
|
2013-01-01 15:42:44 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/**
|
|
|
|
* @brief Adds a set of event flags directly to specified @p Thread.
|
|
|
|
*
|
|
|
|
* @param[in] mask the event flags set to be ORed
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void signalEvents(eventmask_t mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds a set of event flags directly to specified @p Thread.
|
|
|
|
*
|
|
|
|
* @param[in] mask the event flags set to be ORed
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void signalEventsI(eventmask_t mask);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_EVENTS */
|
2013-01-02 10:11:02 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_DYNAMIC || defined(__DOXYGEN__)
|
|
|
|
#endif /* CH_CFG_USE_DYNAMIC */
|
2013-01-01 15:42:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-02-22 11:34:04 +00:00
|
|
|
* chibios_rt::BaseThread *
|
2013-01-01 15:42:44 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Abstract base class for a ChibiOS/RT thread.
|
|
|
|
* @details The thread body is the virtual function @p Main().
|
|
|
|
*/
|
2013-01-02 08:32:03 +00:00
|
|
|
class BaseThread : public ThreadReference {
|
2013-01-01 15:42:44 +00:00
|
|
|
public:
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief BaseThread constructor.
|
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
BaseThread(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Thread body function.
|
|
|
|
*
|
|
|
|
* @return The exit message.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2015-04-05 10:32:38 +00:00
|
|
|
virtual void main(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Creates and starts a system thread.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @param[in] prio thread priority
|
2013-01-02 10:11:02 +00:00
|
|
|
* @return A reference to the created thread with
|
|
|
|
* reference counter set to one.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-03 16:17:42 +00:00
|
|
|
virtual ThreadReference start(tprio_t prio);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 10:11:02 +00:00
|
|
|
* @brief Sets the current thread name.
|
|
|
|
* @pre This function only stores the pointer to the name if the option
|
|
|
|
* @p CH_USE_REGISTRY is enabled else no action is performed.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] tname thread name as a zero terminated string
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:11:02 +00:00
|
|
|
static void setName(const char *tname);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Changes the running thread priority level then reschedules if
|
|
|
|
* necessary.
|
|
|
|
* @note The function returns the real thread priority regardless of the
|
|
|
|
* current priority that could be higher than the real priority
|
|
|
|
* because the priority inheritance mechanism.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @param[in] newprio the new priority level of the running thread
|
|
|
|
* @return The old priority level.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
static tprio_t setPriority(tprio_t newprio);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Terminates the current thread.
|
|
|
|
* @details The thread goes in the @p THD_STATE_FINAL state holding the
|
|
|
|
* specified exit status code, other threads can retrieve the
|
|
|
|
* exit status code by invoking the function @p chThdWait().
|
|
|
|
* @post Eventual code after this function will never be executed,
|
|
|
|
* this function never returns. The compiler has no way to
|
|
|
|
* know this so do not assume that the compiler would remove
|
|
|
|
* the dead code.
|
2013-01-02 10:11:02 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @param[in] msg thread exit code
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:11:02 +00:00
|
|
|
static void exit(msg_t msg);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Terminates the current thread.
|
|
|
|
* @details The thread goes in the @p THD_STATE_FINAL state holding the
|
|
|
|
* specified exit status code, other threads can retrieve the
|
|
|
|
* exit status code by invoking the function @p chThdWait().
|
|
|
|
* @post Eventual code after this function will never be executed,
|
|
|
|
* this function never returns. The compiler has no way to
|
|
|
|
* know this so do not assume that the compiler would remove
|
|
|
|
* the dead code.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @param[in] msg thread exit code
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @sclass
|
|
|
|
*/
|
|
|
|
static void exitS(msg_t msg);
|
|
|
|
|
|
|
|
/**
|
2013-02-22 11:34:04 +00:00
|
|
|
* @brief Verifies if the current thread has a termination request
|
|
|
|
* pending.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @note Can be invoked in any context.
|
|
|
|
*
|
|
|
|
* @retval TRUE termination request pending.
|
|
|
|
* @retval FALSE termination request not pending.
|
|
|
|
*
|
|
|
|
* @special
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:11:02 +00:00
|
|
|
static bool shouldTerminate(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Suspends the invoking thread for the specified time.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] interval the delay in system ticks, the special values are
|
2013-01-02 14:01:11 +00:00
|
|
|
* handled as follow:
|
2013-02-22 11:34:04 +00:00
|
|
|
* - @a TIME_INFINITE the thread enters an infinite
|
|
|
|
* sleep state.
|
2013-01-02 14:01:11 +00:00
|
|
|
* - @a TIME_IMMEDIATE this value is not allowed.
|
|
|
|
* .
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
static void sleep(systime_t interval);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-02-22 11:34:04 +00:00
|
|
|
* @brief Suspends the invoking thread until the system time arrives to
|
|
|
|
* the specified value.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @param[in] time absolute system time
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
static void sleepUntil(systime_t time);
|
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Yields the time slot.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details Yields the CPU control to the next thread in the ready list
|
|
|
|
* with equal priority, if any.
|
2013-01-02 14:01:11 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static void yield(void);
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_MESSAGES || defined(__DOXYGEN__)
|
2013-01-01 15:42:44 +00:00
|
|
|
/**
|
|
|
|
* @brief Waits for a message.
|
|
|
|
*
|
|
|
|
* @return The sender thread.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static ThreadReference waitMessage(void);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_MESSAGES */
|
2013-01-02 10:11:02 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/**
|
|
|
|
* @brief Clears the pending events specified in the mask.
|
|
|
|
*
|
|
|
|
* @param[in] mask the events to be cleared
|
|
|
|
* @return The pending events that were cleared.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t getAndClearEvents(eventmask_t mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds (OR) a set of event flags on the current thread, this is
|
2013-02-22 11:34:04 +00:00
|
|
|
* @b much faster than using @p chEvtBroadcast() or
|
|
|
|
* @p chEvtSignal().
|
2013-01-02 10:11:02 +00:00
|
|
|
*
|
|
|
|
* @param[in] mask the event flags to be added
|
|
|
|
* @return The current pending events mask.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t addEvents(eventmask_t mask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Waits for a single event.
|
|
|
|
* @details A pending event among those specified in @p ewmask is selected,
|
|
|
|
* cleared and its mask returned.
|
|
|
|
* @note One and only one event is served in the function, the one with
|
|
|
|
* the lowest event id. The function is meant to be invoked into
|
|
|
|
* a loop in order to serve all the pending events.<br>
|
|
|
|
* This means that Event Listeners with a lower event identifier
|
|
|
|
* have an higher priority.
|
|
|
|
*
|
|
|
|
* @param[in] ewmask mask of the events that the function should
|
|
|
|
* wait for, @p ALL_EVENTS enables all the events
|
|
|
|
* @return The mask of the lowest id served and cleared
|
|
|
|
* event.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t waitOneEvent(eventmask_t ewmask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Waits for any of the specified events.
|
|
|
|
* @details The function waits for any event among those specified in
|
|
|
|
* @p ewmask to become pending then the events are cleared and
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* @param[in] ewmask mask of the events that the function should
|
|
|
|
* wait for, @p ALL_EVENTS enables all the events
|
|
|
|
* @return The mask of the served and cleared events.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t waitAnyEvent(eventmask_t ewmask);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Waits for all the specified event flags then clears them.
|
|
|
|
* @details The function waits for all the events specified in @p ewmask
|
|
|
|
* to become pending then the events are cleared and returned.
|
|
|
|
*
|
|
|
|
* @param[in] ewmask mask of the event ids that the function should
|
|
|
|
* wait for
|
|
|
|
* @return The mask of the served and cleared events.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t waitAllEvents(eventmask_t ewmask);
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_EVENTS_TIMEOUT || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/**
|
|
|
|
* @brief Waits for a single event.
|
|
|
|
* @details A pending event among those specified in @p ewmask is selected,
|
|
|
|
* cleared and its mask returned.
|
|
|
|
* @note One and only one event is served in the function, the one with
|
|
|
|
* the lowest event id. The function is meant to be invoked into
|
|
|
|
* a loop in order to serve all the pending events.<br>
|
|
|
|
* This means that Event Listeners with a lower event identifier
|
|
|
|
* have an higher priority.
|
|
|
|
*
|
|
|
|
* @param[in] ewmask mask of the events that the function should
|
|
|
|
* wait for, @p ALL_EVENTS enables all the events
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] time the number of ticks before the operation
|
|
|
|
* timouts
|
2013-01-02 10:11:02 +00:00
|
|
|
* @return The mask of the lowest id served and cleared
|
|
|
|
* event.
|
|
|
|
* @retval 0 if the specified timeout expired.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t waitOneEventTimeout(eventmask_t ewmask,
|
|
|
|
systime_t time);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Waits for any of the specified events.
|
|
|
|
* @details The function waits for any event among those specified in
|
|
|
|
* @p ewmask to become pending then the events are cleared and
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* @param[in] ewmask mask of the events that the function should
|
|
|
|
* wait for, @p ALL_EVENTS enables all the events
|
|
|
|
* @param[in] time the number of ticks before the operation
|
|
|
|
* timouts
|
|
|
|
* @return The mask of the served and cleared events.
|
|
|
|
* @retval 0 if the specified timeout expired.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t waitAnyEventTimeout(eventmask_t ewmask,
|
|
|
|
systime_t time);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Waits for all the specified event flags then clears them.
|
|
|
|
* @details The function waits for all the events specified in @p ewmask
|
|
|
|
* to become pending then the events are cleared and returned.
|
|
|
|
*
|
|
|
|
* @param[in] ewmask mask of the event ids that the function should
|
|
|
|
* wait for
|
|
|
|
* @param[in] time the number of ticks before the operation
|
|
|
|
* timouts
|
|
|
|
* @return The mask of the served and cleared events.
|
|
|
|
* @retval 0 if the specified timeout expired.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static eventmask_t waitAllEventsTimeout(eventmask_t ewmask,
|
|
|
|
systime_t time);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_EVENTS_TIMEOUT */
|
2013-01-02 10:47:01 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Invokes the event handlers associated to an event flags mask.
|
|
|
|
*
|
|
|
|
* @param[in] mask mask of the event flags to be dispatched
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] handlers an array of @p evhandler_t. The array must have
|
|
|
|
* size equal to the number of bits in eventmask_t.
|
2013-01-02 10:47:01 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static void dispatchEvents(const evhandler_t handlers[],
|
|
|
|
eventmask_t mask);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_EVENTS */
|
2013-01-02 14:01:11 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
|
2013-01-02 14:01:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Unlocks the next owned mutex in reverse lock order.
|
|
|
|
* @pre The invoking thread <b>must</b> have at least one owned mutex.
|
|
|
|
* @post The mutex is unlocked and removed from the per-thread stack of
|
|
|
|
* owned mutexes.
|
|
|
|
*
|
|
|
|
* @return A pointer to the unlocked mutex.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
static void unlockMutex(Mutex *mp);
|
2013-01-02 14:01:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unlocks the next owned mutex in reverse lock order.
|
|
|
|
* @pre The invoking thread <b>must</b> have at least one owned mutex.
|
|
|
|
* @post The mutex is unlocked and removed from the per-thread stack of
|
|
|
|
* owned mutexes.
|
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
|
|
|
* function must be performed before unlocking the kernel.
|
|
|
|
*
|
|
|
|
* @return A pointer to the unlocked mutex.
|
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
static void unlockMutexS(Mutex *mp);
|
2013-01-02 14:01:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unlocks all the mutexes owned by the invoking thread.
|
|
|
|
* @post The stack of owned mutexes is emptied and all the found
|
|
|
|
* mutexes are unlocked.
|
|
|
|
* @note This function is <b>MUCH MORE</b> efficient than releasing the
|
|
|
|
* mutexes one by one and not just because the call overhead,
|
2013-02-22 11:34:04 +00:00
|
|
|
* this function does not have any overhead related to the
|
|
|
|
* priority inheritance mechanism.
|
2013-01-02 14:01:11 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
static void unlockAllMutexes(void);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_MUTEXES */
|
2009-08-16 13:07:24 +00:00
|
|
|
};
|
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::BaseStaticThread *
|
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Static threads template class.
|
|
|
|
* @details This class introduces static working area allocation.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2010-10-09 10:17:11 +00:00
|
|
|
* @param N the working area size for the thread class
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
template <int N>
|
2013-01-01 15:42:44 +00:00
|
|
|
class BaseStaticThread : public BaseThread {
|
2009-08-16 13:07:24 +00:00
|
|
|
protected:
|
2014-08-03 20:23:16 +00:00
|
|
|
THD_WORKING_AREA(wa, N);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Thread constructor.
|
|
|
|
* @details The thread object is initialized but the thread is not
|
|
|
|
* started here.
|
2010-10-09 10:17:11 +00:00
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
BaseStaticThread(void) : BaseThread() {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-01 15:42:44 +00:00
|
|
|
* @brief Creates and starts a system thread.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-01 15:42:44 +00:00
|
|
|
* @param[in] prio thread priority
|
2013-01-02 10:11:02 +00:00
|
|
|
* @return A reference to the created thread with
|
|
|
|
* reference counter set to one.
|
2013-01-01 15:42:44 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-03 16:17:42 +00:00
|
|
|
virtual ThreadReference start(tprio_t prio) {
|
2015-04-05 10:32:38 +00:00
|
|
|
void _thd_start(void *arg);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-01 15:42:44 +00:00
|
|
|
thread_ref = chThdCreateStatic(wa, sizeof(wa), prio, _thd_start, this);
|
2013-01-02 10:11:02 +00:00
|
|
|
return *this;
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_SEMAPHORES || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-04 10:26:22 +00:00
|
|
|
* chibios_rt::CounterSemaphore *
|
2013-01-02 10:11:02 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Class encapsulating a semaphore.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
class CounterSemaphore {
|
2009-08-16 13:07:24 +00:00
|
|
|
public:
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Embedded @p ::Semaphore structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::semaphore_t sem;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-04 10:26:22 +00:00
|
|
|
* @brief CounterSemaphore constructor.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details The embedded @p ::Semaphore structure is initialized.
|
|
|
|
*
|
2010-10-09 10:17:11 +00:00
|
|
|
* @param[in] n the semaphore counter value, must be greater
|
|
|
|
* or equal to zero
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
CounterSemaphore(cnt_t n);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 13:30:07 +00:00
|
|
|
* @brief Performs a reset operation on the semaphore.
|
|
|
|
* @post After invoking this function all the threads waiting on the
|
2013-02-22 11:34:04 +00:00
|
|
|
* semaphore, if any, are released and the semaphore counter is
|
|
|
|
* set to the specified, non negative, value.
|
|
|
|
* @note The released threads can recognize they were waked up by a
|
|
|
|
* reset rather than a signal because the @p chSemWait() will
|
2015-04-05 13:03:46 +00:00
|
|
|
* return @p MSG_RESET instead of @p MSG_OK.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] n the new value of the semaphore counter. The value
|
|
|
|
* must be non-negative.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
void reset(cnt_t n);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 13:30:07 +00:00
|
|
|
* @brief Performs a reset operation on the semaphore.
|
|
|
|
* @post After invoking this function all the threads waiting on the
|
2013-02-22 11:34:04 +00:00
|
|
|
* semaphore, if any, are released and the semaphore counter is
|
|
|
|
* set to the specified, non negative, value.
|
2013-01-02 13:30:07 +00:00
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
2013-02-22 11:34:04 +00:00
|
|
|
* function must be performed before unlocking the kernel. Note
|
|
|
|
* that interrupt handlers always reschedule on exit so an
|
|
|
|
* explicit reschedule must not be performed in ISRs.
|
|
|
|
* @note The released threads can recognize they were waked up by a
|
|
|
|
* reset rather than a signal because the @p chSemWait() will
|
2015-04-05 13:03:46 +00:00
|
|
|
* return @p MSG_RESET instead of @p MSG_OK.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] n the new value of the semaphore counter. The value
|
|
|
|
* must be non-negative.
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void resetI(cnt_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Performs a wait operation on a semaphore.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the thread has not stopped on the semaphore or
|
2013-02-22 11:34:04 +00:00
|
|
|
* the semaphore has been signaled.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the semaphore has been reset using
|
2013-02-22 11:34:04 +00:00
|
|
|
* @p chSemReset().
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t wait(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 13:30:07 +00:00
|
|
|
* @brief Performs a wait operation on a semaphore.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the thread has not stopped on the semaphore or
|
2013-02-22 11:34:04 +00:00
|
|
|
* the semaphore has been signaled.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the semaphore has been reset using
|
2013-02-22 11:34:04 +00:00
|
|
|
* @p chSemReset().
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
|
|
|
msg_t waitS(void);
|
|
|
|
|
|
|
|
/**
|
2013-02-22 11:34:04 +00:00
|
|
|
* @brief Performs a wait operation on a semaphore with timeout
|
|
|
|
* specification.
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the thread has not stopped on the semaphore or
|
2013-02-22 11:34:04 +00:00
|
|
|
* the semaphore has been signaled.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the semaphore has been reset using
|
2013-02-22 11:34:04 +00:00
|
|
|
* @p chSemReset().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_TIMEOUT if the semaphore has not been signaled or reset
|
2013-02-22 11:34:04 +00:00
|
|
|
* within the specified timeout.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t wait(systime_t time);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-02-22 11:34:04 +00:00
|
|
|
* @brief Performs a wait operation on a semaphore with timeout
|
|
|
|
* specification.
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the thread has not stopped on the semaphore or
|
2013-02-22 11:34:04 +00:00
|
|
|
* the semaphore has been signaled.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the semaphore has been reset using
|
2013-02-22 11:34:04 +00:00
|
|
|
* @p chSemReset().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_TIMEOUT if the semaphore has not been signaled or reset
|
2013-02-22 11:34:04 +00:00
|
|
|
* within the specified timeout.
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t waitS(systime_t time);
|
2013-01-02 13:30:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Performs a signal operation on a semaphore.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
void signal(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 13:30:07 +00:00
|
|
|
/**
|
|
|
|
* @brief Performs a signal operation on a semaphore.
|
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
2013-02-22 11:34:04 +00:00
|
|
|
* function must be performed before unlocking the kernel. Note
|
|
|
|
* that interrupt handlers always reschedule on exit so an
|
|
|
|
* explicit reschedule must not be performed in ISRs.
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void signalI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds the specified value to the semaphore counter.
|
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
2013-02-22 11:34:04 +00:00
|
|
|
* function must be performed before unlocking the kernel. Note
|
|
|
|
* that interrupt handlers always reschedule on exit so an explicit
|
2013-01-02 13:30:07 +00:00
|
|
|
* reschedule must not be performed in ISRs.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] n value to be added to the semaphore counter. The
|
|
|
|
* value must be positive.
|
2013-01-02 13:30:07 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void addCounterI(cnt_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the semaphore counter value.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return The semaphore counter value.
|
|
|
|
*
|
2013-01-02 13:30:07 +00:00
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
cnt_t getCounterI(void);
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Atomic signal and wait operations.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @param[in] ssem @p Semaphore object to be signaled
|
|
|
|
* @param[in] wsem @p Semaphore object to wait on
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread
|
|
|
|
* has been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the thread has not stopped on the semaphore
|
2013-02-22 11:34:04 +00:00
|
|
|
* or the semaphore has been signaled.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the semaphore has been reset using
|
2013-02-22 11:34:04 +00:00
|
|
|
* @p chSemReset().
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
static msg_t signalWait(CounterSemaphore *ssem,
|
|
|
|
CounterSemaphore *wsem);
|
2009-08-16 13:07:24 +00:00
|
|
|
};
|
2013-01-03 09:52:04 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::BinarySemaphore *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Class encapsulating a binary semaphore.
|
|
|
|
*/
|
|
|
|
class BinarySemaphore {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Embedded @p ::Semaphore structure.
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::binary_semaphore_t bsem;
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief BinarySemaphore constructor.
|
|
|
|
* @details The embedded @p ::BinarySemaphore structure is initialized.
|
|
|
|
*
|
|
|
|
* @param[in] taken initial state of the binary semaphore:
|
|
|
|
* - @a false, the initial state is not taken.
|
|
|
|
* - @a true, the initial state is taken.
|
|
|
|
* .
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
|
|
|
BinarySemaphore(bool taken);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait operation on the binary semaphore.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the binary semaphore has been successfully
|
2013-02-22 11:34:04 +00:00
|
|
|
* taken.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the binary semaphore has been reset using
|
2013-01-03 09:52:04 +00:00
|
|
|
* @p bsemReset().
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
msg_t wait(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait operation on the binary semaphore.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the binary semaphore has been successfully
|
2013-02-22 11:34:04 +00:00
|
|
|
* taken.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the binary semaphore has been reset using
|
2013-01-03 09:52:04 +00:00
|
|
|
* @p bsemReset().
|
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
|
|
|
msg_t waitS(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait operation on the binary semaphore.
|
|
|
|
*
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the binary semaphore has been successfully
|
2013-02-22 11:34:04 +00:00
|
|
|
* taken.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the binary semaphore has been reset using
|
2013-01-03 09:52:04 +00:00
|
|
|
* @p bsemReset().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_TIMEOUT if the binary semaphore has not been signaled
|
2013-02-22 11:34:04 +00:00
|
|
|
* or reset within the specified timeout.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t wait(systime_t time);
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Wait operation on the binary semaphore.
|
|
|
|
*
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the semaphore.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the binary semaphore has been successfully
|
2013-02-22 11:34:04 +00:00
|
|
|
* taken.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the binary semaphore has been reset using
|
2013-01-03 09:52:04 +00:00
|
|
|
* @p bsemReset().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_TIMEOUT if the binary semaphore has not been signaled
|
2013-02-22 11:34:04 +00:00
|
|
|
* or reset within the specified timeout.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t waitS(systime_t time);
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reset operation on the binary semaphore.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @note The released threads can recognize they were waked up by a
|
|
|
|
* reset rather than a signal because the @p bsemWait() will
|
2015-04-05 13:03:46 +00:00
|
|
|
* return @p MSG_RESET instead of @p MSG_OK.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @param[in] taken new state of the binary semaphore
|
|
|
|
* - @a FALSE, the new state is not taken.
|
|
|
|
* - @a TRUE, the new state is taken.
|
|
|
|
* .
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void reset(bool taken);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reset operation on the binary semaphore.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @note The released threads can recognize they were waked up by a
|
|
|
|
* reset rather than a signal because the @p bsemWait() will
|
2015-04-05 13:03:46 +00:00
|
|
|
* return @p MSG_RESET instead of @p MSG_OK.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @note This function does not reschedule.
|
|
|
|
*
|
|
|
|
* @param[in] taken new state of the binary semaphore
|
|
|
|
* - @a FALSE, the new state is not taken.
|
|
|
|
* - @a TRUE, the new state is taken.
|
|
|
|
* .
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void resetI(bool taken);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Performs a signal operation on a binary semaphore.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void signal(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Performs a signal operation on a binary semaphore.
|
|
|
|
* @note This function does not reschedule.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void signalI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the binary semaphore current state.
|
|
|
|
*
|
|
|
|
* @return The binary semaphore current state.
|
|
|
|
* @retval false if the binary semaphore is not taken.
|
|
|
|
* @retval true if the binary semaphore is taken.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
bool getStateI(void);
|
|
|
|
};
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_SEMAPHORES */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_MUTEXES || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Mutex *
|
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Class encapsulating a mutex.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
class Mutex {
|
|
|
|
public:
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Embedded @p ::Mutex structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::mutex_t mutex;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Mutex object constructor.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details The embedded @p ::Mutex structure is initialized.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
Mutex(void);
|
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Tries to lock a mutex.
|
|
|
|
* @details This function attempts to lock a mutex, if the mutex is already
|
2013-02-22 11:34:04 +00:00
|
|
|
* locked by another thread then the function exits without
|
|
|
|
* waiting.
|
|
|
|
* @post The mutex is locked and inserted in the per-thread stack of
|
|
|
|
* owned mutexes.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @note This function does not have any overhead related to the
|
|
|
|
* priority inheritance mechanism because it does not try to
|
|
|
|
* enter a sleep state.
|
2010-10-09 10:17:11 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @return The operation status.
|
|
|
|
* @retval TRUE if the mutex has been successfully acquired
|
|
|
|
* @retval FALSE if the lock attempt failed.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
bool tryLock(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Tries to lock a mutex.
|
|
|
|
* @details This function attempts to lock a mutex, if the mutex is already
|
2013-02-22 11:34:04 +00:00
|
|
|
* taken by another thread then the function exits without
|
|
|
|
* waiting.
|
|
|
|
* @post The mutex is locked and inserted in the per-thread stack of
|
|
|
|
* owned mutexes.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @note This function does not have any overhead related to the
|
|
|
|
* priority inheritance mechanism because it does not try to
|
|
|
|
* enter a sleep state.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @return The operation status.
|
|
|
|
* @retval TRUE if the mutex has been successfully acquired
|
|
|
|
* @retval FALSE if the lock attempt failed.
|
|
|
|
*
|
|
|
|
* @sclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 14:01:11 +00:00
|
|
|
bool tryLockS(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Locks the specified mutex.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @post The mutex is locked and inserted in the per-thread stack of
|
|
|
|
* owned mutexes.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 14:01:11 +00:00
|
|
|
void lock(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Locks the specified mutex.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @post The mutex is locked and inserted in the per-thread stack of
|
|
|
|
* owned mutexes.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @sclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 14:01:11 +00:00
|
|
|
void lockS(void);
|
2014-08-26 11:51:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unlocks the next owned mutex in reverse lock order.
|
|
|
|
* @pre The invoking thread <b>must</b> have at least one owned mutex.
|
|
|
|
* @post The mutex is unlocked and removed from the per-thread stack of
|
|
|
|
* owned mutexes.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void unlock(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unlocks the next owned mutex in reverse lock order.
|
|
|
|
* @pre The invoking thread <b>must</b> have at least one owned mutex.
|
|
|
|
* @post The mutex is unlocked and removed from the per-thread stack of
|
|
|
|
* owned mutexes.
|
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
|
|
|
* function must be performed before unlocking the kernel.
|
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
|
|
|
void unlockS(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
};
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_CONDVARS || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::CondVar *
|
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Class encapsulating a conditional variable.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
class CondVar {
|
|
|
|
public:
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Embedded @p ::CondVar structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::condition_variable_t condvar;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief CondVar object constructor.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details The embedded @p ::CondVar structure is initialized.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
|
|
|
CondVar(void);
|
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Signals one thread that is waiting on the condition variable.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
void signal(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Signals one thread that is waiting on the condition variable.
|
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
2013-02-22 11:34:04 +00:00
|
|
|
* function must be performed before unlocking the kernel. Note
|
|
|
|
* that interrupt handlers always reschedule on exit so an
|
|
|
|
* explicit reschedule must not be performed in ISRs.
|
2013-01-02 14:01:11 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void signalI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Signals all threads that are waiting on the condition variable.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
void broadcast(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 14:01:11 +00:00
|
|
|
* @brief Signals all threads that are waiting on the condition variable.
|
|
|
|
* @post This function does not reschedule so a call to a rescheduling
|
2013-02-22 11:34:04 +00:00
|
|
|
* function must be performed before unlocking the kernel. Note
|
|
|
|
* that interrupt handlers always reschedule on exit so an
|
|
|
|
* explicit reschedule must not be performed in ISRs.
|
2010-02-21 07:24:53 +00:00
|
|
|
*
|
2013-01-02 14:01:11 +00:00
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void broadcastI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Waits on the condition variable releasing the mutex lock.
|
|
|
|
* @details Releases the currently owned mutex, waits on the condition
|
2013-02-22 11:34:04 +00:00
|
|
|
* variable, and finally acquires the mutex again. All the
|
|
|
|
* sequence is performed atomically.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @pre The invoking thread <b>must</b> have at least one owned mutex.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the condition variable.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the condvar has been signaled using
|
2013-01-02 14:01:11 +00:00
|
|
|
* @p chCondSignal().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the condvar has been signaled using
|
2013-01-02 14:01:11 +00:00
|
|
|
* @p chCondBroadcast().
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-01 15:42:44 +00:00
|
|
|
msg_t wait(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-01-02 14:01:11 +00:00
|
|
|
/**
|
|
|
|
* @brief Waits on the condition variable releasing the mutex lock.
|
|
|
|
* @details Releases the currently owned mutex, waits on the condition
|
2013-02-22 11:34:04 +00:00
|
|
|
* variable, and finally acquires the mutex again. All the
|
|
|
|
* sequence is performed atomically.
|
2013-01-02 14:01:11 +00:00
|
|
|
* @pre The invoking thread <b>must</b> have at least one owned mutex.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return A message specifying how the invoking thread has
|
|
|
|
* been released from the condition variable.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the condvar has been signaled using
|
2013-01-02 14:01:11 +00:00
|
|
|
* @p chCondSignal().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the condvar has been signaled using
|
2013-01-02 14:01:11 +00:00
|
|
|
* @p chCondBroadcast().
|
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
|
|
|
msg_t waitS(void);
|
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_CONDVARS_TIMEOUT || defined(__DOXYGEN__)
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Waits on the CondVar while releasing the controlling mutex.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2010-10-09 10:17:11 +00:00
|
|
|
* @param[in] time the number of ticks before the operation fails
|
|
|
|
* @return The wakep mode.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_OK if the condvar was signaled using
|
2010-10-09 10:17:11 +00:00
|
|
|
* @p chCondSignal().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_RESET if the condvar was signaled using
|
2010-10-09 10:17:11 +00:00
|
|
|
* @p chCondBroadcast().
|
2015-04-05 13:03:46 +00:00
|
|
|
* @retval MSG_TIMEOUT if the condvar was not signaled within the
|
2010-10-09 10:17:11 +00:00
|
|
|
* specified timeout.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t wait(systime_t time);
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_CONDVARS_TIMEOUT */
|
2009-08-16 13:07:24 +00:00
|
|
|
};
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_CONDVARS */
|
|
|
|
#endif /* CH_CFG_USE_MUTEXES */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_EVENTS || defined(__DOXYGEN__)
|
2013-01-02 10:11:02 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
2013-02-22 11:34:04 +00:00
|
|
|
* chibios_rt::EvtListener *
|
2013-01-02 10:11:02 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Class encapsulating an event listener.
|
|
|
|
*/
|
2013-01-02 10:47:01 +00:00
|
|
|
class EvtListener {
|
2013-01-02 10:11:02 +00:00
|
|
|
public:
|
|
|
|
/**
|
2013-02-22 11:34:04 +00:00
|
|
|
* @brief Embedded @p ::EventListener structure.
|
2013-01-02 10:11:02 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::event_listener_t ev_listener;
|
2013-01-02 10:11:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the pending flags from the listener and clears them.
|
|
|
|
*
|
|
|
|
* @return The flags added to the listener by the
|
|
|
|
* associated event source.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
eventflags_t getAndClearFlags(void);
|
2013-01-03 18:28:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the flags associated to an @p EventListener.
|
|
|
|
* @details The flags are returned and the @p EventListener flags mask is
|
|
|
|
* cleared.
|
|
|
|
*
|
|
|
|
* @return The flags added to the listener by the associated
|
|
|
|
* event source.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
eventflags_t getAndClearFlagsI(void);
|
2013-01-02 10:11:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-02-22 11:34:04 +00:00
|
|
|
* chibios_rt::EvtSource *
|
2013-01-02 10:11:02 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Class encapsulating an event source.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:47:01 +00:00
|
|
|
class EvtSource {
|
2009-08-16 13:07:24 +00:00
|
|
|
public:
|
|
|
|
/**
|
2013-02-22 11:34:04 +00:00
|
|
|
* @brief Embedded @p ::EventSource structure.
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::event_source_t ev_source;
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 10:47:01 +00:00
|
|
|
* @brief EvtSource object constructor.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The embedded @p ::EventSource structure is initialized.
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:47:01 +00:00
|
|
|
EvtSource(void);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Registers a listener on the event source.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-02 10:47:01 +00:00
|
|
|
* @param[in] elp pointer to the @p EvtListener object
|
2010-10-09 10:17:11 +00:00
|
|
|
* @param[in] eid numeric identifier assigned to the Event
|
|
|
|
* Listener
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:47:01 +00:00
|
|
|
void registerOne(chibios_rt::EvtListener *elp, eventid_t eid);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Registers an Event Listener on an Event Source.
|
|
|
|
* @note Multiple Event Listeners can specify the same bits to be added.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2013-01-02 10:47:01 +00:00
|
|
|
* @param[in] elp pointer to the @p EvtListener object
|
2010-10-09 10:17:11 +00:00
|
|
|
* @param[in] emask the mask of event flags to be pended to the
|
|
|
|
* thread when the event source is broadcasted
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:47:01 +00:00
|
|
|
void registerMask(chibios_rt::EvtListener *elp, eventmask_t emask);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2010-10-09 10:17:11 +00:00
|
|
|
* @brief Unregisters a listener.
|
2009-08-16 13:07:24 +00:00
|
|
|
* @details The specified listeners is no more signaled by the event
|
2010-10-09 10:17:11 +00:00
|
|
|
* source.
|
2009-08-16 13:07:24 +00:00
|
|
|
*
|
2010-10-09 10:17:11 +00:00
|
|
|
* @param[in] elp the listener to be unregistered
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-01-02 10:47:01 +00:00
|
|
|
void unregister(chibios_rt::EvtListener *elp);
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2013-01-02 10:11:02 +00:00
|
|
|
* @brief Broadcasts on an event source.
|
|
|
|
* @details All the listeners registered on the event source are signaled
|
|
|
|
* and the flags are added to the listener's flags mask.
|
2013-01-01 09:37:24 +00:00
|
|
|
*
|
|
|
|
* @param[in] flags the flags set to be added to the listener
|
|
|
|
* flags mask
|
2013-01-01 15:46:10 +00:00
|
|
|
*
|
|
|
|
* @api
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
void broadcastFlags(eventflags_t flags);
|
2013-01-01 09:37:24 +00:00
|
|
|
|
2013-01-02 08:32:03 +00:00
|
|
|
/**
|
2013-01-02 10:11:02 +00:00
|
|
|
* @brief Broadcasts on an event source.
|
|
|
|
* @details All the listeners registered on the event source are signaled
|
|
|
|
* and the flags are added to the listener's flags mask.
|
2013-01-02 08:32:03 +00:00
|
|
|
*
|
|
|
|
* @param[in] flags the flags set to be added to the listener
|
|
|
|
* flags mask
|
|
|
|
*
|
2013-01-02 10:11:02 +00:00
|
|
|
* @iclass
|
2013-01-02 08:32:03 +00:00
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
void broadcastFlagsI(eventflags_t flags);
|
2013-01-02 10:11:02 +00:00
|
|
|
};
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_EVENTS */
|
2013-01-02 15:00:20 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_QUEUES || defined(__DOXYGEN__)
|
2013-01-03 09:52:04 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-04 10:26:22 +00:00
|
|
|
* chibios_rt::InQueue *
|
2013-01-03 09:52:04 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Class encapsulating an input queue.
|
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
class InQueue {
|
2013-01-03 09:52:04 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* @brief Embedded @p ::InputQueue structure.
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::input_queue_t iq;
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2013-01-04 10:26:22 +00:00
|
|
|
* @brief InQueue constructor.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @param[in] bp pointer to a memory area allocated as queue buffer
|
|
|
|
* @param[in] size size of the queue buffer
|
|
|
|
* @param[in] infy pointer to a callback function that is invoked when
|
2013-02-22 11:34:04 +00:00
|
|
|
* data is read from the queue. The value can be
|
|
|
|
* @p NULL.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @param[in] link application defined pointer
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
InQueue(uint8_t *bp, size_t size, qnotify_t infy, void *link);
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the filled space into an input queue.
|
|
|
|
*
|
|
|
|
* @return The number of full bytes in the queue.
|
|
|
|
* @retval 0 if the queue is empty.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
size_t getFullI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the empty space into an input queue.
|
|
|
|
*
|
|
|
|
* @return The number of empty bytes in the queue.
|
|
|
|
* @retval 0 if the queue is full.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
size_t getEmptyI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Evaluates to @p TRUE if the specified input queue is empty.
|
|
|
|
*
|
|
|
|
* @return The queue status.
|
|
|
|
* @retval false if the queue is not empty.
|
|
|
|
* @retval true if the queue is empty.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
bool isEmptyI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Evaluates to @p TRUE if the specified input queue is full.
|
|
|
|
*
|
|
|
|
* @return The queue status.
|
|
|
|
* @retval FALSE if the queue is not full.
|
|
|
|
* @retval TRUE if the queue is full.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
bool isFullI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resets an input queue.
|
|
|
|
* @details All the data in the input queue is erased and lost, any waiting
|
|
|
|
* thread is resumed with status @p Q_RESET.
|
|
|
|
* @note A reset operation can be used by a low level driver in order to
|
|
|
|
* obtain immediate attention from the high level layers.
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void resetI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Input queue write.
|
|
|
|
* @details A byte value is written into the low end of an input queue.
|
|
|
|
*
|
|
|
|
* @param[in] b the byte value to be written in the queue
|
|
|
|
* @return The operation status.
|
|
|
|
* @retval Q_OK if the operation has been completed with success.
|
|
|
|
* @retval Q_FULL if the queue is full and the operation cannot be
|
|
|
|
* completed.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
msg_t putI(uint8_t b);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Input queue read.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details This function reads a byte value from an input queue. If the
|
|
|
|
* queue is empty then the calling thread is suspended until a
|
|
|
|
* byte arrives in the queue.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @return A byte value from the queue.
|
|
|
|
* @retval Q_RESET if the queue has been reset.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
msg_t get();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Input queue read with timeout.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details This function reads a byte value from an input queue. If the
|
|
|
|
* queue is empty then the calling thread is suspended until a
|
|
|
|
* byte arrives in the queue or a timeout occurs.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @note The callback is invoked before reading the character from the
|
|
|
|
* buffer or before entering the state @p THD_STATE_WTQUEUE.
|
|
|
|
*
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return A byte value from the queue.
|
|
|
|
* @retval Q_TIMEOUT if the specified time expired.
|
|
|
|
* @retval Q_RESET if the queue has been reset.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t get(systime_t time);
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Input queue read with timeout.
|
|
|
|
* @details The function reads data from an input queue into a buffer. The
|
|
|
|
* operation completes when the specified amount of data has been
|
|
|
|
* transferred or after the specified timeout or if the queue has
|
|
|
|
* been reset.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @note The function is not atomic, if you need atomicity it is
|
|
|
|
* suggested to use a semaphore or a mutex for mutual exclusion.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @note The callback is invoked before reading each character from the
|
|
|
|
* buffer or before entering the state @p THD_STATE_WTQUEUE.
|
|
|
|
*
|
|
|
|
* @param[out] bp pointer to the data buffer
|
|
|
|
* @param[in] n the maximum amount of data to be transferred, the
|
|
|
|
* value 0 is reserved
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The number of bytes effectively transferred.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
size_t read(uint8_t *bp, size_t n, systime_t time);
|
2013-01-03 09:52:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-04 10:26:22 +00:00
|
|
|
* chibios_rt::InQueueBuffer *
|
2013-01-03 09:52:04 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Template class encapsulating an input queue and its buffer.
|
|
|
|
*
|
|
|
|
* @param N size of the input queue
|
|
|
|
*/
|
|
|
|
template <int N>
|
2013-01-04 10:26:22 +00:00
|
|
|
class InQueueBuffer : public InQueue {
|
2013-01-03 09:52:04 +00:00
|
|
|
private:
|
|
|
|
uint8_t iq_buf[N];
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2013-01-04 10:26:22 +00:00
|
|
|
* @brief InQueueBuffer constructor.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] infy input notify callback function
|
|
|
|
* @param[in] link parameter to be passed to the callback
|
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
InQueueBuffer(qnotify_t infy, void *link) : InQueue(iq_buf, N,
|
|
|
|
infy, link) {
|
2013-01-03 09:52:04 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-04 10:26:22 +00:00
|
|
|
* chibios_rt::OutQueue *
|
2013-01-03 09:52:04 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Class encapsulating an output queue.
|
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
class OutQueue {
|
2013-01-03 09:52:04 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* @brief Embedded @p ::OutputQueue structure.
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::output_queue_t oq;
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2013-01-04 10:26:22 +00:00
|
|
|
* @brief OutQueue constructor.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @param[in] bp pointer to a memory area allocated as queue buffer
|
|
|
|
* @param[in] size size of the queue buffer
|
|
|
|
* @param[in] onfy pointer to a callback function that is invoked when
|
2013-02-22 11:34:04 +00:00
|
|
|
* data is written to the queue. The value can be
|
|
|
|
* @p NULL.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @param[in] link application defined pointer
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
OutQueue(uint8_t *bp, size_t size, qnotify_t onfy, void *link);
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the filled space into an output queue.
|
|
|
|
*
|
|
|
|
* @return The number of full bytes in the queue.
|
|
|
|
* @retval 0 if the queue is empty.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
size_t getFullI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the empty space into an output queue.
|
|
|
|
*
|
|
|
|
* @return The number of empty bytes in the queue.
|
|
|
|
* @retval 0 if the queue is full.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
size_t getEmptyI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Evaluates to @p TRUE if the specified output queue is empty.
|
|
|
|
*
|
|
|
|
* @return The queue status.
|
|
|
|
* @retval false if the queue is not empty.
|
|
|
|
* @retval true if the queue is empty.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
bool isEmptyI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Evaluates to @p TRUE if the specified output queue is full.
|
|
|
|
*
|
|
|
|
* @return The queue status.
|
|
|
|
* @retval FALSE if the queue is not full.
|
|
|
|
* @retval TRUE if the queue is full.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
bool isFullI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resets an output queue.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details All the data in the output queue is erased and lost, any
|
|
|
|
* waiting thread is resumed with status @p Q_RESET.
|
|
|
|
* @note A reset operation can be used by a low level driver in order
|
|
|
|
* to obtain immediate attention from the high level layers.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void resetI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Output queue write.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details This function writes a byte value to an output queue. If the
|
|
|
|
* queue is full then the calling thread is suspended until there
|
|
|
|
* is space in the queue.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @param[in] b the byte value to be written in the queue
|
|
|
|
* @return The operation status.
|
|
|
|
* @retval Q_OK if the operation succeeded.
|
|
|
|
* @retval Q_RESET if the queue has been reset.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
msg_t put(uint8_t b);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Output queue write with timeout.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details This function writes a byte value to an output queue. If the
|
|
|
|
* queue is full then the calling thread is suspended until there
|
|
|
|
* is space in the queue or a timeout occurs.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @note The callback is invoked after writing the character into the
|
|
|
|
* buffer.
|
|
|
|
*
|
|
|
|
* @param[in] b the byte value to be written in the queue
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
|
|
|
* @retval Q_OK if the operation succeeded.
|
|
|
|
* @retval Q_TIMEOUT if the specified time expired.
|
|
|
|
* @retval Q_RESET if the queue has been reset.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
msg_t put(uint8_t b, systime_t time);
|
2013-01-03 09:52:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Output queue read.
|
|
|
|
* @details A byte value is read from the low end of an output queue.
|
|
|
|
*
|
|
|
|
* @return The byte value from the queue.
|
|
|
|
* @retval Q_EMPTY if the queue is empty.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
msg_t getI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Output queue write with timeout.
|
|
|
|
* @details The function writes data from a buffer to an output queue. The
|
|
|
|
* operation completes when the specified amount of data has been
|
|
|
|
* transferred or after the specified timeout or if the queue has
|
|
|
|
* been reset.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @note The function is not atomic, if you need atomicity it is
|
|
|
|
* suggested to use a semaphore or a mutex for mutual exclusion.
|
2013-01-03 09:52:04 +00:00
|
|
|
* @note The callback is invoked after writing each character into the
|
|
|
|
* buffer.
|
|
|
|
*
|
|
|
|
* @param[out] bp pointer to the data buffer
|
|
|
|
* @param[in] n the maximum amount of data to be transferred, the
|
|
|
|
* value 0 is reserved
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The number of bytes effectively transferred.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-10 18:36:23 +00:00
|
|
|
size_t write(const uint8_t *bp, size_t n, systime_t time);
|
2013-01-03 09:52:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-04 10:26:22 +00:00
|
|
|
* chibios_rt::OutQueueBuffer *
|
2013-01-03 09:52:04 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Template class encapsulating an output queue and its buffer.
|
|
|
|
*
|
|
|
|
* @param N size of the output queue
|
|
|
|
*/
|
|
|
|
template <int N>
|
2013-01-04 10:26:22 +00:00
|
|
|
class OutQueueBuffer : public OutQueue {
|
2013-01-03 09:52:04 +00:00
|
|
|
private:
|
|
|
|
uint8_t oq_buf[N];
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2013-01-04 10:26:22 +00:00
|
|
|
* @brief OutQueueBuffer constructor.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] onfy output notify callback function
|
|
|
|
* @param[in] link parameter to be passed to the callback
|
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
|
|
|
*/
|
2013-01-04 10:26:22 +00:00
|
|
|
OutQueueBuffer(qnotify_t onfy, void *link) : OutQueue(oq_buf, N,
|
|
|
|
onfy, link) {
|
2013-01-03 09:52:04 +00:00
|
|
|
}
|
|
|
|
};
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_QUEUES */
|
2013-01-03 09:52:04 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__)
|
2013-01-02 15:00:20 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::Mailbox *
|
|
|
|
*------------------------------------------------------------------------*/
|
2013-01-02 18:42:39 +00:00
|
|
|
/**
|
2014-09-11 08:36:13 +00:00
|
|
|
* @brief Base mailbox class.
|
|
|
|
*
|
|
|
|
* @param T type of objects that mailbox able to handle
|
2013-01-02 18:42:39 +00:00
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
template <typename T>
|
|
|
|
class MailboxBase {
|
2013-01-02 15:00:20 +00:00
|
|
|
public:
|
2014-09-11 08:36:13 +00:00
|
|
|
|
2013-01-02 15:00:20 +00:00
|
|
|
/**
|
|
|
|
* @brief Embedded @p ::Mailbox structure.
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::mailbox_t mb;
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Mailbox constructor.
|
|
|
|
* @details The embedded @p ::Mailbox structure is initialized.
|
|
|
|
*
|
|
|
|
* @param[in] buf pointer to the messages buffer as an array of
|
|
|
|
* @p msg_t
|
|
|
|
* @param[in] n number of elements in the buffer array
|
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2013-01-02 15:00:20 +00:00
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
MailboxBase(msg_t *buf, cnt_t n) {
|
2014-09-14 08:07:55 +00:00
|
|
|
|
2014-09-11 08:36:13 +00:00
|
|
|
chMBObjectInit(&mb, buf, n);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Resets a Mailbox object.
|
2015-04-05 13:03:46 +00:00
|
|
|
* @details All the waiting threads are resumed with status @p MSG_RESET
|
2013-02-22 11:34:04 +00:00
|
|
|
* and the queued messages are lost.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
void reset(void) {
|
|
|
|
|
|
|
|
chMBReset(&mb);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts a message into a mailbox.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The invoking thread waits until a empty slot in the mailbox
|
|
|
|
* becomes available or the specified time runs out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @param[in] msg the message to be posted on the mailbox
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly posted.
|
|
|
|
* @retval MSG_RESET if the mailbox has been reset while waiting.
|
|
|
|
* @retval MSG_TIMEOUT if the operation has timed out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t post(T msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPost(&mb, reinterpret_cast<msg_t>(msg), time);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts a message into a mailbox.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The invoking thread waits until a empty slot in the mailbox
|
|
|
|
* becomes available or the specified time runs out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @param[in] msg the message to be posted on the mailbox
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly posted.
|
|
|
|
* @retval MSG_RESET if the mailbox has been reset while waiting.
|
|
|
|
* @retval MSG_TIMEOUT if the operation has timed out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t postS(T msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPostS(&mb, reinterpret_cast<msg_t>(msg), time);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts a message into a mailbox.
|
|
|
|
* @details This variant is non-blocking, the function returns a timeout
|
|
|
|
* condition if the queue is full.
|
|
|
|
*
|
|
|
|
* @param[in] msg the message to be posted on the mailbox
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly posted.
|
|
|
|
* @retval MSG_TIMEOUT if the mailbox is full and the message cannot be
|
2013-01-02 15:00:20 +00:00
|
|
|
* posted.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t postI(T msg) {
|
|
|
|
|
|
|
|
return chMBPostI(&mb, reinterpret_cast<msg_t>(msg));
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts an high priority message into a mailbox.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The invoking thread waits until a empty slot in the mailbox
|
|
|
|
* becomes available or the specified time runs out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @param[in] msg the message to be posted on the mailbox
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly posted.
|
|
|
|
* @retval MSG_RESET if the mailbox has been reset while waiting.
|
|
|
|
* @retval MSG_TIMEOUT if the operation has timed out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t postAhead(T msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPostAhead(&mb, reinterpret_cast<msg_t>(msg), time);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts an high priority message into a mailbox.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The invoking thread waits until a empty slot in the mailbox
|
|
|
|
* becomes available or the specified time runs out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @param[in] msg the message to be posted on the mailbox
|
|
|
|
* @param[in] time the number of ticks before the operation timeouts,
|
|
|
|
* the following special values are allowed:
|
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly posted.
|
|
|
|
* @retval MSG_RESET if the mailbox has been reset while waiting.
|
|
|
|
* @retval MSG_TIMEOUT if the operation has timed out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t postAheadS(T msg, systime_t time) {
|
|
|
|
|
|
|
|
return chMBPostAheadS(&mb, reinterpret_cast<msg_t>(msg), time);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Posts an high priority message into a mailbox.
|
|
|
|
* @details This variant is non-blocking, the function returns a timeout
|
|
|
|
* condition if the queue is full.
|
|
|
|
*
|
|
|
|
* @param[in] msg the message to be posted on the mailbox
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly posted.
|
|
|
|
* @retval MSG_TIMEOUT if the mailbox is full and the message cannot be
|
2013-01-02 15:00:20 +00:00
|
|
|
* posted.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t postAheadI(T msg) {
|
|
|
|
|
|
|
|
return chMBPostAheadI(&mb, reinterpret_cast<msg_t>(msg));
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieves a message from a mailbox.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The invoking thread waits until a message is posted in the
|
|
|
|
* mailbox or the specified time runs out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[out] msgp pointer to a message variable for the received
|
|
|
|
* @param[in] time message the number of ticks before the operation
|
|
|
|
* timeouts, the following special values are allowed:
|
2013-01-02 15:00:20 +00:00
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly fetched.
|
|
|
|
* @retval MSG_RESET if the mailbox has been reset while waiting.
|
|
|
|
* @retval MSG_TIMEOUT if the operation has timed out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t fetch(T *msgp, systime_t time) {
|
|
|
|
|
|
|
|
return chMBFetch(&mb, reinterpret_cast<msg_t*>(msgp), time);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieves a message from a mailbox.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @details The invoking thread waits until a message is posted in the
|
|
|
|
* mailbox or the specified time runs out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[out] msgp pointer to a message variable for the received
|
|
|
|
* @param[in] time message the number of ticks before the operation
|
|
|
|
* timeouts, the following special values are allowed:
|
2013-01-02 15:00:20 +00:00
|
|
|
* - @a TIME_IMMEDIATE immediate timeout.
|
|
|
|
* - @a TIME_INFINITE no timeout.
|
|
|
|
* .
|
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly fetched.
|
|
|
|
* @retval MSG_RESET if the mailbox has been reset while waiting.
|
|
|
|
* @retval MSG_TIMEOUT if the operation has timed out.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
|
|
|
* @sclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t fetchS(T *msgp, systime_t time) {
|
|
|
|
|
|
|
|
return chMBFetchS(&mb, reinterpret_cast<msg_t*>(msgp), time);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Retrieves a message from a mailbox.
|
|
|
|
* @details This variant is non-blocking, the function returns a timeout
|
|
|
|
* condition if the queue is empty.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[out] msgp pointer to a message variable for the received
|
|
|
|
* message
|
2013-01-02 15:00:20 +00:00
|
|
|
* @return The operation status.
|
2014-09-11 08:36:13 +00:00
|
|
|
* @retval MSG_OK if a message has been correctly fetched.
|
|
|
|
* @retval MSG_TIMEOUT if the mailbox is empty and a message cannot be
|
2013-01-02 15:00:20 +00:00
|
|
|
* fetched.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
msg_t fetchI(T *msgp) {
|
|
|
|
|
|
|
|
return chMBFetchI(&mb, reinterpret_cast<msg_t*>(msgp));
|
|
|
|
}
|
2013-04-18 14:58:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the number of free message slots into a mailbox.
|
|
|
|
* @note Can be invoked in any system state but if invoked out of a
|
|
|
|
* locked state then the returned value may change after reading.
|
|
|
|
* @note The returned value can be less than zero when there are waiting
|
|
|
|
* threads on the internal semaphore.
|
|
|
|
*
|
|
|
|
* @return The number of empty message slots.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
cnt_t getFreeCountI(void) {
|
|
|
|
|
|
|
|
return chMBGetFreeCountI(&mb);
|
|
|
|
}
|
2013-04-18 14:58:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the number of used message slots into a mailbox.
|
|
|
|
* @note Can be invoked in any system state but if invoked out of a
|
|
|
|
* locked state then the returned value may change after reading.
|
|
|
|
* @note The returned value can be less than zero when there are waiting
|
|
|
|
* threads on the internal semaphore.
|
|
|
|
*
|
|
|
|
* @return The number of queued messages.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
cnt_t getUsedCountI(void) {
|
|
|
|
|
|
|
|
return chMBGetUsedCountI(&mb);
|
|
|
|
}
|
2013-01-02 15:00:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2014-09-11 08:36:13 +00:00
|
|
|
* chibios_rt::Mailbox *
|
2013-01-02 15:00:20 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
2014-09-11 08:36:13 +00:00
|
|
|
* @brief Template class encapsulating a mailbox and its messages buffer.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
2014-09-11 08:36:13 +00:00
|
|
|
* @param N length of the mailbox buffer
|
2013-01-02 15:00:20 +00:00
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
template <typename T, int N>
|
|
|
|
class Mailbox : public MailboxBase<T> {
|
2013-01-02 15:00:20 +00:00
|
|
|
private:
|
|
|
|
msg_t mb_buf[N];
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2014-09-11 08:36:13 +00:00
|
|
|
* @brief Mailbox constructor.
|
2013-01-02 15:00:20 +00:00
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2013-01-02 15:00:20 +00:00
|
|
|
*/
|
2014-09-11 08:36:13 +00:00
|
|
|
Mailbox(void) :
|
|
|
|
MailboxBase<T>(mb_buf, (cnt_t)(sizeof mb_buf / sizeof (msg_t))) {
|
2013-01-02 15:00:20 +00:00
|
|
|
}
|
|
|
|
};
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_MAILBOXES */
|
2013-01-02 18:42:39 +00:00
|
|
|
|
2014-08-03 20:23:16 +00:00
|
|
|
#if CH_CFG_USE_MEMPOOLS || defined(__DOXYGEN__)
|
2013-01-02 18:42:39 +00:00
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::MemoryPool *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Class encapsulating a mailbox.
|
|
|
|
*/
|
|
|
|
class MemoryPool {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Embedded @p ::MemoryPool structure.
|
|
|
|
*/
|
2014-08-03 20:23:16 +00:00
|
|
|
::memory_pool_t pool;
|
2013-01-02 18:42:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief MemoryPool constructor.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] size the size of the objects contained in this memory
|
|
|
|
* pool, the minimum accepted size is the size of
|
|
|
|
* a pointer to void.
|
2013-01-06 09:10:58 +00:00
|
|
|
* @param[in] provider memory provider function for the memory pool or
|
|
|
|
* @p NULL if the pool is not allowed to grow
|
|
|
|
* automatically
|
|
|
|
*
|
2013-01-03 09:52:04 +00:00
|
|
|
* @init
|
2013-01-02 18:42:39 +00:00
|
|
|
*/
|
|
|
|
MemoryPool(size_t size, memgetfunc_t provider);
|
|
|
|
|
2013-01-06 09:10:58 +00:00
|
|
|
/**
|
|
|
|
* @brief MemoryPool constructor.
|
|
|
|
*
|
2013-02-22 11:34:04 +00:00
|
|
|
* @param[in] size the size of the objects contained in this memory
|
|
|
|
* pool, the minimum accepted size is the size of
|
|
|
|
* a pointer to void.
|
2013-01-06 09:10:58 +00:00
|
|
|
* @param[in] provider memory provider function for the memory pool or
|
|
|
|
* @p NULL if the pool is not allowed to grow
|
|
|
|
* automatically
|
|
|
|
* @param[in] p pointer to the array first element
|
|
|
|
* @param[in] n number of elements in the array
|
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
|
|
|
MemoryPool(size_t size, memgetfunc_t provider, void* p, size_t n);
|
|
|
|
|
2013-01-02 18:42:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Loads a memory pool with an array of static objects.
|
|
|
|
* @pre The memory pool must be already been initialized.
|
|
|
|
* @pre The array elements must be of the right size for the specified
|
|
|
|
* memory pool.
|
|
|
|
* @post The memory pool contains the elements of the input array.
|
|
|
|
*
|
|
|
|
* @param[in] p pointer to the array first element
|
|
|
|
* @param[in] n number of elements in the array
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void loadArray(void *p, size_t n);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocates an object from a memory pool.
|
|
|
|
* @pre The memory pool must be already been initialized.
|
|
|
|
*
|
|
|
|
* @return The pointer to the allocated object.
|
|
|
|
* @retval NULL if pool is empty.
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void *allocI(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Allocates an object from a memory pool.
|
|
|
|
* @pre The memory pool must be already been initialized.
|
|
|
|
*
|
|
|
|
* @return The pointer to the allocated object.
|
|
|
|
* @retval NULL if pool is empty.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
|
|
|
void *alloc(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Releases an object into a memory pool.
|
|
|
|
* @pre The memory pool must be already been initialized.
|
|
|
|
* @pre The freed object must be of the right size for the specified
|
|
|
|
* memory pool.
|
2013-02-22 11:34:04 +00:00
|
|
|
* @pre The object must be properly aligned to contain a pointer to
|
|
|
|
* void.
|
2013-01-02 18:42:39 +00:00
|
|
|
*
|
|
|
|
* @param[in] objp the pointer to the object to be released
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void free(void *objp);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adds an object to a memory pool.
|
|
|
|
* @pre The memory pool must be already been initialized.
|
|
|
|
* @pre The added object must be of the right size for the specified
|
|
|
|
* memory pool.
|
|
|
|
* @pre The added object must be memory aligned to the size of
|
|
|
|
* @p stkalign_t type.
|
|
|
|
* @note This function is just an alias for @p chPoolFree() and has been
|
|
|
|
* added for clarity.
|
|
|
|
*
|
|
|
|
* @param[in] objp the pointer to the object to be added
|
|
|
|
*
|
|
|
|
* @iclass
|
|
|
|
*/
|
|
|
|
void freeI(void *objp);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
2013-01-07 09:53:34 +00:00
|
|
|
* chibios_rt::ObjectsPool *
|
2013-01-02 18:42:39 +00:00
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
2013-01-07 09:53:34 +00:00
|
|
|
* @brief Template class encapsulating a memory pool and its elements.
|
2013-01-02 18:42:39 +00:00
|
|
|
*/
|
|
|
|
template<class T, size_t N>
|
2013-01-07 09:53:34 +00:00
|
|
|
class ObjectsPool : public MemoryPool {
|
2013-01-02 18:42:39 +00:00
|
|
|
private:
|
2013-01-07 09:53:34 +00:00
|
|
|
/* The buffer is declared as an array of pointers to void for two
|
|
|
|
reasons:
|
|
|
|
1) The objects must be properly aligned to hold a pointer as
|
|
|
|
first field.
|
|
|
|
2) There is no need to invoke constructors for object that are
|
|
|
|
into the pool.*/
|
|
|
|
void *pool_buf[(N * sizeof (T)) / sizeof (void *)];
|
2013-01-02 18:42:39 +00:00
|
|
|
|
|
|
|
public:
|
2013-01-03 09:52:04 +00:00
|
|
|
/**
|
2013-01-07 09:53:34 +00:00
|
|
|
* @brief ObjectsPool constructor.
|
2013-01-03 09:52:04 +00:00
|
|
|
*
|
|
|
|
* @init
|
|
|
|
*/
|
2013-01-07 09:53:34 +00:00
|
|
|
ObjectsPool(void) : MemoryPool(sizeof (T), NULL) {
|
2013-01-02 18:42:39 +00:00
|
|
|
|
|
|
|
loadArray(pool_buf, N);
|
|
|
|
}
|
|
|
|
};
|
2014-08-03 20:23:16 +00:00
|
|
|
#endif /* CH_CFG_USE_MEMPOOLS */
|
2013-01-03 10:21:42 +00:00
|
|
|
|
|
|
|
/*------------------------------------------------------------------------*
|
|
|
|
* chibios_rt::BaseSequentialStreamInterface *
|
|
|
|
*------------------------------------------------------------------------*/
|
|
|
|
/**
|
|
|
|
* @brief Interface of a ::BaseSequentialStream.
|
|
|
|
* @note You can cast a ::BaseSequentialStream to this interface and use
|
|
|
|
* it, the memory layout is the same.
|
|
|
|
*/
|
|
|
|
class BaseSequentialStreamInterface {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Sequential Stream write.
|
|
|
|
* @details The function writes data from a buffer to a stream.
|
|
|
|
*
|
|
|
|
* @param[in] bp pointer to the data buffer
|
|
|
|
* @param[in] n the maximum amount of data to be transferred
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return The number of bytes transferred. The return value
|
|
|
|
* can be less than the specified number of bytes if
|
|
|
|
* an end-of-file condition has been met.
|
2013-01-03 10:21:42 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-01-03 10:22:48 +00:00
|
|
|
virtual size_t write(const uint8_t *bp, size_t n) = 0;
|
2013-01-03 10:21:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sequential Stream read.
|
|
|
|
* @details The function reads data from a stream into a buffer.
|
|
|
|
*
|
|
|
|
* @param[out] bp pointer to the data buffer
|
|
|
|
* @param[in] n the maximum amount of data to be transferred
|
2013-02-22 11:34:04 +00:00
|
|
|
* @return The number of bytes transferred. The return value
|
|
|
|
* can be less than the specified number of bytes if
|
|
|
|
* an end-of-file condition has been met.
|
2013-01-03 10:21:42 +00:00
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-01-03 10:22:48 +00:00
|
|
|
virtual size_t read(uint8_t *bp, size_t n) = 0;
|
2013-01-03 10:21:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sequential Stream blocking byte write.
|
|
|
|
* @details This function writes a byte value to a channel. If the channel
|
2013-02-22 11:34:04 +00:00
|
|
|
* is not ready to accept data then the calling thread is
|
|
|
|
* suspended.
|
2013-01-03 10:21:42 +00:00
|
|
|
*
|
|
|
|
* @param[in] b the byte value to be written to the channel
|
|
|
|
*
|
|
|
|
* @return The operation status.
|
|
|
|
* @retval Q_OK if the operation succeeded.
|
|
|
|
* @retval Q_RESET if an end-of-file condition has been met.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-01-03 10:22:48 +00:00
|
|
|
virtual msg_t put(uint8_t b) = 0;
|
2013-01-03 10:21:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sequential Stream blocking byte read.
|
|
|
|
* @details This function reads a byte value from a channel. If the data
|
|
|
|
* is not available then the calling thread is suspended.
|
|
|
|
*
|
|
|
|
* @return A byte value from the queue.
|
|
|
|
* @retval Q_RESET if an end-of-file condition has been met.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-01-03 10:22:48 +00:00
|
|
|
virtual msg_t get(void) = 0;
|
2013-01-03 10:21:42 +00:00
|
|
|
};
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _CH_HPP_ */
|
|
|
|
|
|
|
|
/** @} */
|