QP/C++  6.9.3
Real-Time Embedded Framework
qf_act.cpp
Go to the documentation of this file.
1 
39 #define QP_IMPL // this is QP implementation
40 #include "qf_port.hpp" // QF port
41 #include "qf_pkg.hpp" // QF package-scope interface
42 #include "qassert.h" // QP embedded systems-friendly assertions
43 #ifdef Q_SPY // QS software tracing enabled?
44  #include "qs_port.hpp" // QS port
45  #include "qs_pkg.hpp" // QS facilities for pre-defined trace records
46 #else
47  #include "qs_dummy.hpp" // disable the QS software tracing
48 #endif // Q_SPY
49 
50 //****************************************************************************
57 #define QF_PTR_INC_(p_) (++(p_))
58 
59 namespace QP {
60 
61 Q_DEFINE_THIS_MODULE("qf_act")
62 
63 // public objects ************************************************************
64 QActive *QF::active_[QF_MAX_ACTIVE + 1U]; // to be used by QF ports only
65 
66 //****************************************************************************
79 void QF::add_(QActive * const a) noexcept {
80  std::uint_fast8_t const p = static_cast<std::uint_fast8_t>(a->m_prio);
81 
82  Q_REQUIRE_ID(100, (0U < p) && (p <= QF_MAX_ACTIVE)
83  && (active_[p] == nullptr));
85  QF_CRIT_E_();
86  active_[p] = a; // registger the active object at this priority
87  QF_CRIT_X_();
88 }
89 
90 //****************************************************************************
103 void QF::remove_(QActive * const a) noexcept {
104  std::uint_fast8_t const p = static_cast<std::uint_fast8_t>(a->m_prio);
105 
106  Q_REQUIRE_ID(200, (0U < p) && (p <= QF_MAX_ACTIVE)
107  && (active_[p] == a));
108 
110  QF_CRIT_E_();
111  active_[p] = nullptr; // free-up the priority level
112  a->m_state.fun = nullptr; // invalidate the state
113  QF_CRIT_X_();
114 }
115 
116 //****************************************************************************
129 void QF::bzero(void * const start, std::uint_fast16_t const len) noexcept {
130  std::uint8_t *ptr = static_cast<std::uint8_t *>(start);
131  for (std::uint_fast16_t n = len; n > 0U; --n) {
132  *ptr = 0U;
133  QF_PTR_INC_(ptr);
134  }
135 }
136 
137 } // namespace QP
138 
139 // Log-base-2 calculations ...
140 #ifndef QF_LOG2
141 
149 extern "C" {
150 
152  static std::uint8_t const log2LUT[16] = {
153  0U, 1U, 2U, 2U, 3U, 3U, 3U, 3U,
154  4U, 4U, 4U, 4U, 4U, 4U, 4U, 4U
155  };
156  std::uint_fast8_t n = 0U;
157  QP::QPSetBits t;
158 
159 #if (QF_MAX_ACTIVE > 16U)
160  t = static_cast<QP::QPSetBits>(x >> 16U);
161  if (t != 0U) {
162  n += 16U;
163  x = t;
164  }
165 #endif
166 #if (QF_MAX_ACTIVE > 8U)
167  t = (x >> 8U);
168  if (t != 0U) {
169  n += 8U;
170  x = t;
171  }
172 #endif
173  t = (x >> 4U);
174  if (t != 0U) {
175  n += 4U;
176  x = t;
177  }
178  return n + log2LUT[x];
179  }
180 
181 } // extern "C"
182 
183 #endif // QF_LOG2
184 
unsigned int uint_fast16_t
Definition: 16bit/stdint.h:38
unsigned char uint8_t
Definition: 16bit/stdint.h:29
unsigned int uint_fast8_t
Definition: 16bit/stdint.h:36
static void bzero(void *const start, std::uint_fast16_t const len) noexcept
Clear a specified region of memory to zero.
Definition: qf_act.cpp:129
static void add_(QActive *const a) noexcept
Register an active object to be managed by the framework.
Definition: qf_act.cpp:79
static QActive * active_[QF_MAX_ACTIVE+1U]
array of registered active objects
Definition: qf.hpp:580
static void remove_(QActive *const a) noexcept
Remove the active object from the framework.
Definition: qf_act.cpp:103
Definition: struct.dox:1
std::uint8_t QPSetBits
Definition: qpset.hpp:52
Customizable and memory-efficient assertions for embedded systems.
#define Q_DEFINE_THIS_MODULE(name_)
Definition: qassert.h:120
#define Q_REQUIRE_ID(id_, test_)
Definition: qassert.h:279
std::uint_fast8_t QF_LOG2(QP::QPSetBits x) noexcept
Definition: qf_act.cpp:151
#define QF_PTR_INC_(p_)
Definition: qf_act.cpp:57
Internal (package scope) QF/C++ interface.
#define QF_CRIT_STAT_
Definition: qf_pkg.hpp:56
#define QF_CRIT_X_()
Definition: qf_pkg.hpp:77
#define QF_CRIT_E_()
Definition: qf_pkg.hpp:66
Dummy definitions of the QS macros that avoid code generation from the QS instrumentation.
Internal (package scope) QS/C++ interface.
QS/C++ port to a 32-bit CPU, generic compiler.
#define QF_MAX_ACTIVE
Definition: qxk/qf_port.hpp:57