qf_pkg.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*$file${include::qf_pkg.h} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
  2. /*
  3. * Model: qpc.qm
  4. * File: ${include::qf_pkg.h}
  5. *
  6. * This code has been generated by QM 5.2.5 <www.state-machine.com/qm>.
  7. * DO NOT EDIT THIS FILE MANUALLY. All your changes will be lost.
  8. *
  9. * This code is covered by the following QP license:
  10. * License # : LicenseRef-QL-dual
  11. * Issued to : Any user of the QP/C real-time embedded framework
  12. * Framework(s) : qpc
  13. * Support ends : 2023-12-31
  14. * License scope:
  15. *
  16. * Copyright (C) 2005 Quantum Leaps, LLC <state-machine.com>.
  17. *
  18. * SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
  19. *
  20. * This software is dual-licensed under the terms of the open source GNU
  21. * General Public License version 3 (or any later version), or alternatively,
  22. * under the terms of one of the closed source Quantum Leaps commercial
  23. * licenses.
  24. *
  25. * The terms of the open source GNU General Public License version 3
  26. * can be found at: <www.gnu.org/licenses/gpl-3.0>
  27. *
  28. * The terms of the closed source Quantum Leaps commercial licenses
  29. * can be found at: <www.state-machine.com/licensing>
  30. *
  31. * Redistributions in source code must retain this top-level comment block.
  32. * Plagiarizing this software to sidestep the license obligations is illegal.
  33. *
  34. * Contact information:
  35. * <www.state-machine.com/licensing>
  36. * <info@state-machine.com>
  37. */
  38. /*$endhead${include::qf_pkg.h} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  39. /*! @file
  40. * @brief Internal (package scope) QF/C interface.
  41. */
  42. #ifndef QF_PKG_H_
  43. #define QF_PKG_H_
  44. /*==========================================================================*/
  45. /*$declare${QF::QF-pkg} vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
  46. /*${QF::QF-pkg::ePool_[QF_MAX_EPOOL]} ......................................*/
  47. #if (QF_MAX_EPOOL > 0U)
  48. /*! array of event pools managed by QF */
  49. extern QF_EPOOL_TYPE_ QF_ePool_[QF_MAX_EPOOL];
  50. #endif /* (QF_MAX_EPOOL > 0U) */
  51. /*${QF::QF-pkg::maxPool_} ..................................................*/
  52. /*! number of initialized event pools */
  53. extern uint_fast8_t QF_maxPool_;
  54. /*${QF::QF-pkg::readySet_} .................................................*/
  55. /*! "Ready-set" of all threads used in the built-in kernels
  56. * @static @private @memberof QF
  57. */
  58. extern QPSet QF_readySet_;
  59. /*${QF::QF-pkg::bzero} .....................................................*/
  60. /*! Clear a specified region of memory to zero.
  61. * @static @public @memberof QF
  62. *
  63. * @details
  64. * Clears a memory buffer by writing zeros byte-by-byte.
  65. *
  66. * @param[in] start pointer to the beginning of a memory buffer.
  67. * @param[in] len length of the memory buffer to clear (in bytes)
  68. *
  69. * @note The main application of this function is clearing the internal QF
  70. * variables upon startup. This is done to avoid problems with non-standard
  71. * startup code provided with some compilers and toolsets (e.g., TI DSPs or
  72. * Microchip MPLAB), which does not zero the uninitialized variables, as
  73. * required by the ANSI C standard.
  74. */
  75. void QF_bzero(
  76. void * const start,
  77. uint_fast16_t const len);
  78. /*$enddecl${QF::QF-pkg} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  79. /*==========================================================================*/
  80. /* QF-specific critical section */
  81. #ifndef QF_CRIT_STAT_TYPE
  82. /*! This is an internal macro for defining the critical section
  83. * status type. */
  84. /**
  85. * @details
  86. * The purpose of this macro is to enable writing the same code for the
  87. * case when critical section status type is defined and when it is not.
  88. * If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
  89. * provides the definition of the critical section status variable.
  90. * Otherwise this macro is empty.
  91. * @sa #QF_CRIT_STAT_TYPE
  92. */
  93. #define QF_CRIT_STAT_
  94. /*! This is an internal macro for entering a critical section. */
  95. /**
  96. * @details
  97. * The purpose of this macro is to enable writing the same code for the
  98. * case when critical section status type is defined and when it is not.
  99. * If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
  100. * invokes QF_CRIT_ENTRY() passing the key variable as the parameter.
  101. * Otherwise QF_CRIT_ENTRY() is invoked with a dummy parameter.
  102. * @sa QF_CRIT_ENTRY()
  103. */
  104. #define QF_CRIT_E_() QF_CRIT_ENTRY(dummy)
  105. /*! This is an internal macro for exiting a critical section. */
  106. /**
  107. * @details
  108. * The purpose of this macro is to enable writing the same code for the
  109. * case when critical section status type is defined and when it is not.
  110. * If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
  111. * invokes #QF_CRIT_EXIT passing the key variable as the parameter.
  112. * Otherwise #QF_CRIT_EXIT is invoked with a dummy parameter.
  113. * @sa #QF_CRIT_EXIT
  114. */
  115. #define QF_CRIT_X_() QF_CRIT_EXIT(dummy)
  116. #elif (!defined QF_CRIT_STAT_)
  117. #define QF_CRIT_STAT_ QF_CRIT_STAT_TYPE critStat_;
  118. #define QF_CRIT_E_() QF_CRIT_ENTRY(critStat_)
  119. #define QF_CRIT_X_() QF_CRIT_EXIT(critStat_)
  120. #endif
  121. /*==========================================================================*/
  122. /* Assertions inside the critical section */
  123. #ifdef Q_NASSERT /* Q_NASSERT defined--assertion checking disabled */
  124. #define Q_ASSERT_CRIT_(id_, test_) ((void)0)
  125. #define Q_REQUIRE_CRIT_(id_, test_) ((void)0)
  126. #define Q_ERROR_CRIT_(id_) ((void)0)
  127. #else /* Q_NASSERT not defined--assertion checking enabled */
  128. #define Q_ASSERT_CRIT_(id_, test_) do { \
  129. if ((test_)) {} else { \
  130. QF_CRIT_X_(); \
  131. Q_onAssert(&Q_this_module_[0], (int_t)(id_)); \
  132. } \
  133. } while (false)
  134. #define Q_REQUIRE_CRIT_(id_, test_) Q_ASSERT_CRIT_((id_), (test_))
  135. #define Q_ERROR_CRIT_(id_) do { \
  136. QF_CRIT_X_(); \
  137. Q_onAssert(&Q_this_module_[0], (int_t)(id_)); \
  138. } while (false)
  139. #endif /* Q_NASSERT */
  140. /*==========================================================================*/
  141. /* The following bitmasks are for the fields of the @c refCtr_ attribute
  142. * of the QTimeEvt struct (inherited from QEvt). This attribute is NOT used
  143. * for reference counting in time events, because the @c poolId_ attribute
  144. * is zero ("immutable events").
  145. */
  146. #define QTE_IS_LINKED (1U << 7U)
  147. #define QTE_WAS_DISARMED (1U << 6U)
  148. #define QTE_TICK_RATE 0x0FU
  149. /*! @brief structure representing a free block in the Native QF Memory Pool */
  150. typedef struct QFreeBlock {
  151. struct QFreeBlock * volatile next;
  152. } QFreeBlock;
  153. /* internal helper macros ==================================================*/
  154. /*! increment the refCtr of a const event (requires casting `const` away)
  155. * @private @memberof QEvt
  156. *
  157. * @trace
  158. * @tr{PQP11_8}
  159. */
  160. static inline void QEvt_refCtr_inc_(QEvt const *me) {
  161. ++((QEvt *)me)->refCtr_;
  162. }
  163. /*! decrement the refCtr of a const event (requires casting `const` away)
  164. * @private @memberof QEvt
  165. *
  166. * @trace
  167. * @tr{PQP11_8}
  168. */
  169. static inline void QEvt_refCtr_dec_(QEvt const *me) {
  170. --((QEvt *)me)->refCtr_;
  171. }
  172. #endif /* QF_PKG_H_ */