qf_pkg.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * @file
  3. * @brief Internal (package scope) QF/C interface.
  4. * @ingroup qf
  5. * @cond
  6. ******************************************************************************
  7. * Last updated for version 5.4.0
  8. * Last updated on 2014-12-10
  9. *
  10. * Q u a n t u m L e a P s
  11. * ---------------------------
  12. * innovating embedded systems
  13. *
  14. * Copyright (C) Quantum Leaps, www.state-machine.com.
  15. *
  16. * This program is open source software: you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as published
  18. * by the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * Alternatively, this program may be distributed and modified under the
  22. * terms of Quantum Leaps commercial licenses, which expressly supersede
  23. * the GNU General Public License and are specifically designed for
  24. * licensees interested in retaining the proprietary status of their code.
  25. *
  26. * This program is distributed in the hope that it will be useful,
  27. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. * GNU General Public License for more details.
  30. *
  31. * You should have received a copy of the GNU General Public License
  32. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  33. *
  34. * Contact information:
  35. * Web: www.state-machine.com
  36. * Email: info@state-machine.com
  37. ******************************************************************************
  38. * @endcond
  39. */
  40. #ifndef qf_pkg_h
  41. #define qf_pkg_h
  42. /****************************************************************************/
  43. /* QF-specific critical section */
  44. #ifndef QF_CRIT_STAT_TYPE
  45. /*! This is an internal macro for defining the critical section
  46. * status type. */
  47. /**
  48. * @description
  49. * The purpose of this macro is to enable writing the same code for the
  50. * case when critical section status type is defined and when it is not.
  51. * If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
  52. * provides the definition of the critical section status variable.
  53. * Otherwise this macro is empty.
  54. * @sa #QF_CRIT_STAT_TYPE
  55. */
  56. #define QF_CRIT_STAT_
  57. /*! This is an internal macro for entering a critical section. */
  58. /**
  59. * @description
  60. * The purpose of this macro is to enable writing the same code for the
  61. * case when critical section status type is defined and when it is not.
  62. * If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
  63. * invokes #QF_CRIT_ENTRY passing the key variable as the parameter.
  64. * Otherwise #QF_CRIT_ENTRY is invoked with a dummy parameter.
  65. * @sa #QF_CRIT_ENTRY
  66. */
  67. #define QF_CRIT_ENTRY_() QF_CRIT_ENTRY(dummy)
  68. /*! This is an internal macro for exiting a critical section. */
  69. /**
  70. * @description
  71. * The purpose of this macro is to enable writing the same code for the
  72. * case when critical section status type is defined and when it is not.
  73. * If the macro #QF_CRIT_STAT_TYPE is defined, this internal macro
  74. * invokes #QF_CRIT_EXIT passing the key variable as the parameter.
  75. * Otherwise #QF_CRIT_EXIT is invoked with a dummy parameter.
  76. * @sa #QF_CRIT_EXIT
  77. */
  78. #define QF_CRIT_EXIT_() QF_CRIT_EXIT(dummy)
  79. #else
  80. #define QF_CRIT_STAT_ QF_CRIT_STAT_TYPE critStat_;
  81. #define QF_CRIT_ENTRY_() QF_CRIT_ENTRY(critStat_)
  82. #define QF_CRIT_EXIT_() QF_CRIT_EXIT(critStat_)
  83. #endif
  84. /* package-scope objects ****************************************************/
  85. /*! heads of linked lists of time events, one for every clock tick rate */
  86. extern QTimeEvt QF_timeEvtHead_[QF_MAX_TICK_RATE];
  87. extern QF_EPOOL_TYPE_ QF_pool_[QF_MAX_EPOOL]; /*!< allocate event pools */
  88. extern uint_fast8_t QF_maxPool_; /*!< # of initialized event pools */
  89. extern QSubscrList *QF_subscrList_; /*!< the subscriber list array */
  90. extern enum_t QF_maxSignal_; /*!< the maximum published signal */
  91. /*! structure representing a free block in the Native QF Memory Pool */
  92. typedef struct QFreeBlock {
  93. struct QFreeBlock * volatile next;
  94. } QFreeBlock;
  95. /* internal helper macros ***************************************************/
  96. /*! increment the refCtr of an event @p e_ casting const away */
  97. #define QF_EVT_REF_CTR_INC_(e_) (++((QEvt *)(e_))->refCtr_)
  98. /*! decrement the refCtr of an event @p e_ casting const away */
  99. #define QF_EVT_REF_CTR_DEC_(e_) (--((QEvt *)(e_))->refCtr_)
  100. /*! access element at index @p i_ from the base pointer @p base_ */
  101. #define QF_PTR_AT_(base_, i_) ((base_)[(i_)])
  102. /**
  103. * @description
  104. * This macro is specifically and exclusively used for checking the range
  105. * of a block pointer returned to the pool. Such a check must rely on the
  106. * pointer arithmetic not compliant with the MISRA-C 2004 rules 17.2(req) and
  107. * 17.3(req). Defining a specific macro for this purpose allows to selectively
  108. * disable the warnings for this particular case.
  109. */
  110. #define QF_PTR_RANGE_(x_, min_, max_) (((min_) <= (x_)) && ((x_) <= (max_)))
  111. /****************************************************************************/
  112. #ifdef Q_SPY /* QS software tracing enabled? */
  113. #if (QF_EQUEUE_CTR_SIZE == 1)
  114. /*! Internal QS macro to output an unformatted event queue counter
  115. * data element. */
  116. /**
  117. * @note the counter size depends on the macro #QF_EQUEUE_CTR_SIZE.
  118. */
  119. #define QS_EQC_(ctr_) QS_u8_((uint8_t)(ctr_))
  120. #elif (QF_EQUEUE_CTR_SIZE == 2)
  121. #define QS_EQC_(ctr_) QS_u16_((uint16_t)(ctr_))
  122. #elif (QF_EQUEUE_CTR_SIZE == 4)
  123. #define QS_EQC_(ctr_) QS_u32_((uint32_t)(ctr_))
  124. #else
  125. #error "QF_EQUEUE_CTR_SIZE not defined"
  126. #endif
  127. #if (QF_EVENT_SIZ_SIZE == 1)
  128. /*! Internal QS macro to output an unformatted event size
  129. * data element. */
  130. /**
  131. * @note the event size depends on the macro #QF_EVENT_SIZ_SIZE.
  132. */
  133. #define QS_EVS_(size_) QS_u8_((uint8_t)(size_))
  134. #elif (QF_EVENT_SIZ_SIZE == 2)
  135. #define QS_EVS_(size_) QS_u16_((uint16_t)(size_))
  136. #elif (QF_EVENT_SIZ_SIZE == 4)
  137. #define QS_EVS_(size_) QS_u32_((uint32_t)(size_))
  138. #endif
  139. #if (QF_MPOOL_SIZ_SIZE == 1)
  140. /*! Internal QS macro to output an unformatted memory pool
  141. * block-size data element */
  142. /**
  143. * @note the block-size depends on the macro #QF_MPOOL_SIZ_SIZE.
  144. */
  145. #define QS_MPS_(size_) QS_u8_((uint8_t)(size_))
  146. #elif (QF_MPOOL_SIZ_SIZE == 2)
  147. #define QS_MPS_(size_) QS_u16_((uint16_t)(size_))
  148. #elif (QF_MPOOL_SIZ_SIZE == 4)
  149. #define QS_MPS_(size_) QS_u32_((uint32_t)(size_))
  150. #endif
  151. #if (QF_MPOOL_CTR_SIZE == 1)
  152. /*! Internal QS macro to output an unformatted memory pool
  153. * block-counter data element. */
  154. /**
  155. * @note the counter size depends on the macro #QF_MPOOL_CTR_SIZE.
  156. */
  157. #define QS_MPC_(ctr_) QS_u8_((uint8_t)(ctr_))
  158. #elif (QF_MPOOL_CTR_SIZE == 2)
  159. #define QS_MPC_(ctr_) QS_u16_((uint16_t)(ctr_))
  160. #elif (QF_MPOOL_CTR_SIZE == 4)
  161. #define QS_MPC_(ctr_) QS_u32_((uint16_t)(ctr_))
  162. #endif
  163. #if (QF_TIMEEVT_CTR_SIZE == 1)
  164. /*! Internal QS macro to output an unformatted time event
  165. * tick-counter data element */
  166. /**
  167. * @note the counter size depends on the macro #QF_TIMEEVT_CTR_SIZE.
  168. */
  169. #define QS_TEC_(ctr_) QS_u8_((uint8_t)(ctr_))
  170. #elif (QF_TIMEEVT_CTR_SIZE == 2)
  171. #define QS_TEC_(ctr_) QS_u16_((uint16_t)(ctr_))
  172. #elif (QF_TIMEEVT_CTR_SIZE == 4)
  173. #define QS_TEC_(ctr_) QS_u32_((uint32_t)(ctr_))
  174. #endif
  175. #endif /* Q_SPY */
  176. #endif /* qf_pkg_h */