2014-04-06 11:43:13 -04:00
|
|
|
/**
|
2015-04-28 13:45:35 -04:00
|
|
|
* @file
|
|
|
|
* @brief QP native, platform-independent priority sets of 8 or 64 elements.
|
|
|
|
* @ingroup qf
|
|
|
|
* @cond
|
2014-04-06 11:43:13 -04:00
|
|
|
******************************************************************************
|
|
|
|
* Last updated for version 5.3.0
|
|
|
|
* Last updated on 2014-02-24
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
|
|
|
* Q u a n t u m L e a P s
|
|
|
|
* ---------------------------
|
|
|
|
* innovating embedded systems
|
|
|
|
*
|
2014-04-06 11:43:13 -04:00
|
|
|
* Copyright (C) Quantum Leaps, www.state-machine.com.
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
|
|
|
* This program is open source software: you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as published
|
2013-10-16 16:44:03 -04:00
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
2012-08-14 18:07:04 -04:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Alternatively, this program may be distributed and modified under the
|
|
|
|
* terms of Quantum Leaps commercial licenses, which expressly supersede
|
|
|
|
* the GNU General Public License and are specifically designed for
|
|
|
|
* licensees interested in retaining the proprietary status of their code.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Contact information:
|
2014-04-06 11:43:13 -04:00
|
|
|
* Web: www.state-machine.com
|
|
|
|
* Email: info@state-machine.com
|
|
|
|
******************************************************************************
|
2015-04-28 13:45:35 -04:00
|
|
|
* @endcond
|
2014-04-06 11:43:13 -04:00
|
|
|
*/
|
2012-08-14 18:07:04 -04:00
|
|
|
#ifndef qpset_h
|
|
|
|
#define qpset_h
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2014-04-06 11:43:13 -04:00
|
|
|
/*! Priority Set of up to 8 elements for building various schedulers */
|
|
|
|
/**
|
2012-08-14 18:07:04 -04:00
|
|
|
* The priority set represents the set of active objects that are ready to
|
|
|
|
* run and need to be considered by the scheduling algorithm. The set is
|
|
|
|
* capable of storing up to 8 priority levels.
|
|
|
|
*
|
|
|
|
* The priority set allows to build cooperative multitasking schedulers
|
|
|
|
* to manage up to 8 tasks.
|
|
|
|
*/
|
2014-04-06 11:43:13 -04:00
|
|
|
typedef struct {
|
|
|
|
uint_fast8_t volatile bits; /*!< bitmask with a bit for each element */
|
2012-08-14 18:07:04 -04:00
|
|
|
} QPSet8;
|
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Evaluates to TRUE if the priority set @p me_ has elements */
|
2014-04-06 11:43:13 -04:00
|
|
|
#define QPSet8_isEmpty(me_) ((me_)->bits == (uint_fast8_t)0)
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Evaluates to TRUE if the priority set @p me_ is empty */
|
2014-04-06 11:43:13 -04:00
|
|
|
#define QPSet8_notEmpty(me_) ((me_)->bits != (uint_fast8_t)0)
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Evaluates to TRUE if the priority set @p me_ has element @p n_ */
|
2012-08-14 18:07:04 -04:00
|
|
|
#define QPSet8_hasElement(me_, n_) \
|
2014-04-06 11:43:13 -04:00
|
|
|
(((me_)->bits & (uint_fast8_t)Q_ROM_BYTE(QF_pwr2Lkup[(n_)])) \
|
|
|
|
!= (uint_fast8_t)0)
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Insert element @p n_ into the set @p me_, n_= 1..8 */
|
2012-08-14 18:07:04 -04:00
|
|
|
#define QPSet8_insert(me_, n_) \
|
2014-04-06 11:43:13 -04:00
|
|
|
((me_)->bits |= (uint_fast8_t)Q_ROM_BYTE(QF_pwr2Lkup[(n_)]))
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Remove element n_ from the set @p me_, n_= 1..8 */
|
2012-08-14 18:07:04 -04:00
|
|
|
#define QPSet8_remove(me_, n_) \
|
2014-04-06 11:43:13 -04:00
|
|
|
((me_)->bits &= (uint_fast8_t)Q_ROM_BYTE(QF_invPwr2Lkup[(n_)]))
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2014-04-06 11:43:13 -04:00
|
|
|
/*! Find the maximum element in the set, and assign it to n_ */
|
2015-04-28 13:45:35 -04:00
|
|
|
/** @note if the set @p me_ is empty, @p n_ is set to zero.
|
2012-08-14 18:07:04 -04:00
|
|
|
*/
|
2014-04-06 11:43:13 -04:00
|
|
|
#define QPSet8_findMax(me_, n_) \
|
|
|
|
((n_) = (uint_fast8_t)QF_LOG2((me_)->bits))
|
2012-08-14 18:07:04 -04:00
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************************/
|
2014-04-06 11:43:13 -04:00
|
|
|
/*! Priority Set of up to 64 elements for building various schedulers */
|
|
|
|
/**
|
2012-08-14 18:07:04 -04:00
|
|
|
* The priority set represents the set of active objects that are ready to
|
|
|
|
* run and need to be considered by the scheduling algorithm. The set is
|
|
|
|
* capable of storing up to 64 priority levels.
|
|
|
|
*
|
|
|
|
* The priority set allows to build cooperative multitasking schedulers
|
|
|
|
* to manage up to 64 tasks. It is also used in the Quantum Kernel (QK)
|
|
|
|
* preemptive scheduler.
|
|
|
|
*/
|
2014-04-06 11:43:13 -04:00
|
|
|
typedef struct {
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/** @brief bimask representing 8-element subsets of the set
|
2012-08-14 18:07:04 -04:00
|
|
|
*
|
2013-09-23 14:34:35 -04:00
|
|
|
* Each bit in the bytes set represents a subset (8-elements)
|
2015-04-28 13:45:35 -04:00
|
|
|
* as follows: @n
|
|
|
|
* bit 0 in bytes is 1 when bits[0] is not empty @n
|
|
|
|
* bit 1 in bytes is 1 when bits[1] is not empty @n
|
|
|
|
* bit 2 in bytes is 1 when bits[2] is not empty @n
|
|
|
|
* bit 3 in bytes is 1 when bits[3] is not empty @n
|
|
|
|
* bit 4 in bytes is 1 when bits[4] is not empty @n
|
|
|
|
* bit 5 in bytes is 1 when bits[5] is not empty @n
|
|
|
|
* bit 6 in bytes is 1 when bits[6] is not empty @n
|
|
|
|
* bit 7 in bytes is 1 when bits[7] is not empty @n
|
2012-08-14 18:07:04 -04:00
|
|
|
*/
|
2014-04-06 11:43:13 -04:00
|
|
|
uint_fast8_t volatile bytes;
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/** @brief bits representing elements in the set as follows: @n
|
|
|
|
* bits[0] represent elements 1..8 @n
|
|
|
|
* bits[1] represent elements 9..16 @n
|
|
|
|
* bits[2] represent elements 17..24 @n
|
|
|
|
* bits[3] represent elements 25..32 @n
|
|
|
|
* bits[4] represent elements 33..40 @n
|
|
|
|
* bits[5] represent elements 41..48 @n
|
|
|
|
* bits[6] represent elements 49..56 @n
|
|
|
|
* bits[7] represent elements 57..64 @n
|
2012-08-14 18:07:04 -04:00
|
|
|
*/
|
2014-04-06 11:43:13 -04:00
|
|
|
uint_fast8_t volatile bits[8];
|
2012-08-14 18:07:04 -04:00
|
|
|
} QPSet64;
|
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Evaluates to TRUE if the priority set @p me_ has elements */
|
2014-04-06 11:43:13 -04:00
|
|
|
#define QPSet64_isEmpty(me_) ((me_)->bytes == (uint_fast8_t)0)
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Evaluates to TRUE if the priority set @p me is empty */
|
2014-04-06 11:43:13 -04:00
|
|
|
#define QPSet64_notEmpty(me_) ((me_)->bytes != (uint_fast8_t)0)
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Evaluates to TRUE if the priority set @p me_ has element @p n_. */
|
2012-08-14 18:07:04 -04:00
|
|
|
#define QPSet64_hasElement(me_, n_) \
|
2013-09-23 14:34:35 -04:00
|
|
|
(((me_)->bits[Q_ROM_BYTE(QF_div8Lkup[(n_)])] \
|
2014-04-06 11:43:13 -04:00
|
|
|
& (uint_fast8_t)Q_ROM_BYTE(QF_pwr2Lkup[(n_)])) != ((uint_fast8_t)0)
|
2012-08-14 18:07:04 -04:00
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! insert element @p n_ into the set @p me_, n_= 1..64 */
|
2012-08-14 18:07:04 -04:00
|
|
|
#define QPSet64_insert(me_, n_) do { \
|
2014-04-06 11:43:13 -04:00
|
|
|
uint_fast8_t m_ = (uint_fast8_t)Q_ROM_BYTE(QF_div8Lkup[(n_)]); \
|
|
|
|
(me_)->bits[m_] |= (uint_fast8_t)Q_ROM_BYTE(QF_pwr2Lkup[(n_)]); \
|
|
|
|
(me_)->bytes |= (uint_fast8_t)Q_ROM_BYTE(QF_pwr2Lkup[m_ \
|
|
|
|
+ (uint_fast8_t)1]); \
|
2012-08-14 18:07:04 -04:00
|
|
|
} while (0)
|
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Remove element n_ from the set @p me_, n_= 1..64 */
|
2012-08-14 18:07:04 -04:00
|
|
|
#define QPSet64_remove(me_, n_) do { \
|
2014-04-06 11:43:13 -04:00
|
|
|
uint_fast8_t m_ = (uint_fast8_t)Q_ROM_BYTE(QF_div8Lkup[(n_)]); \
|
|
|
|
if (((me_)->bits[m_] &= (uint_fast8_t)Q_ROM_BYTE( \
|
|
|
|
QF_invPwr2Lkup[(n_)])) == (uint_fast8_t)0) { \
|
|
|
|
(me_)->bytes &= (uint_fast8_t)Q_ROM_BYTE( \
|
|
|
|
QF_invPwr2Lkup[m_ + (uint_fast8_t)1]); \
|
2012-08-14 18:07:04 -04:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/*! Find the maximum element in the set, and assign it to @p n_ */
|
|
|
|
/** @note if the set @p me_ is empty, @p n_ is set to zero.
|
2012-08-14 18:07:04 -04:00
|
|
|
*/
|
|
|
|
#define QPSet64_findMax(me_, n_) do { \
|
2014-04-06 11:43:13 -04:00
|
|
|
if ((me_)->bytes != (uint_fast8_t)0) { \
|
|
|
|
(n_) = (uint_fast8_t)QF_LOG2((me_)->bytes) - (uint_fast8_t)1; \
|
|
|
|
(n_) = (uint_fast8_t)QF_LOG2((me_)->bits[(n_)]) \
|
|
|
|
+ (uint_fast8_t)((n_) << 3); \
|
2012-08-14 18:07:04 -04:00
|
|
|
} \
|
|
|
|
else { \
|
2014-04-06 11:43:13 -04:00
|
|
|
(n_) = (uint_fast8_t)0; \
|
2012-08-14 18:07:04 -04:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-04-06 11:43:13 -04:00
|
|
|
#endif /* qpset_h */
|
2012-08-14 18:07:04 -04:00
|
|
|
|