QP/C  5.9.8
qf_act.c
Go to the documentation of this file.
1 
40 #define QP_IMPL /* this is QP implementation */
41 #include "qf_port.h" /* QF port */
42 #include "qf_pkg.h" /* QF package-scope interface */
43 #include "qassert.h" /* QP embedded systems-friendly assertions */
44 #ifdef Q_SPY /* QS software tracing enabled? */
45  #include "qs_port.h" /* include QS port */
46 #else
47  #include "qs_dummy.h" /* disable the QS software tracing */
48 #endif /* Q_SPY */
49 
50 Q_DEFINE_THIS_MODULE("qf_act")
51 
52 /* public objects ***********************************************************/
53 QActive *QF_active_[QF_MAX_ACTIVE + 1]; /* to be used by QF ports only */
54 
55 /****************************************************************************/
69 void QF_add_(QActive * const a) {
70  uint_fast8_t p = a->prio;
72 
78  Q_REQUIRE_ID(100, ((uint_fast8_t)0 < p)
79  && (p <= (uint_fast8_t)QF_MAX_ACTIVE)
80  && (QF_active_[p] == (QActive *)0));
81 
83 
84  QF_active_[p] = a; /* register the active object at this priority */
85 
87  QS_TIME_(); /* timestamp */
88  QS_OBJ_(a); /* the active object */
89  QS_U8_((uint8_t)p); /* the priority of the active object */
91 
92  QF_CRIT_EXIT_();
93 }
94 
95 /****************************************************************************/
109 void QF_remove_(QActive * const a) {
110  uint_fast8_t p = a->prio;
112 
117  Q_REQUIRE_ID(200, ((uint_fast8_t)0 < p)
118  && (p <= (uint_fast8_t)QF_MAX_ACTIVE)
119  && (QF_active_[p] == a));
120 
121  QF_CRIT_ENTRY_();
122 
123  QF_active_[p] = (QActive *)0; /* free-up the priority level */
124  a->super.state.fun = Q_STATE_CAST(0); /* invalidate the state */
125 
127  QS_TIME_(); /* timestamp */
128  QS_OBJ_(a); /* the active object */
129  QS_U8_((uint8_t)p); /* the priority of the active object */
131 
132  QF_CRIT_EXIT_();
133 }
134 
135 /****************************************************************************/
143 #define QF_PTR_INC_(p_) (++(p_))
144 
145 /****************************************************************************/
159 void QF_bzero(void * const start, uint_fast16_t len) {
160  uint8_t *ptr = (uint8_t *)start;
161  while (len != (uint_fast16_t)0) {
162  *ptr = (uint8_t)0;
163  QF_PTR_INC_(ptr);
164  --len;
165  }
166 }
167 
168 /* log-base-2 implementation ************************************************/
169 #ifndef QF_LOG2
170 
171 /* log-base-2 lookup table **************************************************/
172 uint8_t const QF_log2Lkup[256] = {
173  (uint8_t)0, (uint8_t)1, (uint8_t)2, (uint8_t)2,
174  (uint8_t)3, (uint8_t)3, (uint8_t)3, (uint8_t)3,
175  (uint8_t)4, (uint8_t)4, (uint8_t)4, (uint8_t)4,
176  (uint8_t)4, (uint8_t)4, (uint8_t)4, (uint8_t)4,
177  (uint8_t)5, (uint8_t)5, (uint8_t)5, (uint8_t)5,
178  (uint8_t)5, (uint8_t)5, (uint8_t)5, (uint8_t)5,
179  (uint8_t)5, (uint8_t)5, (uint8_t)5, (uint8_t)5,
180  (uint8_t)5, (uint8_t)5, (uint8_t)5, (uint8_t)5,
181  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
182  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
183  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
184  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
185  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
186  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
187  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
188  (uint8_t)6, (uint8_t)6, (uint8_t)6, (uint8_t)6,
189  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
190  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
191  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
192  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
193  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
194  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
195  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
196  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
197  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
198  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
199  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
200  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
201  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
202  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
203  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
204  (uint8_t)7, (uint8_t)7, (uint8_t)7, (uint8_t)7,
205  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
206  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
207  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
208  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
209  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
210  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
211  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
212  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
213  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
214  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
215  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
216  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
217  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
218  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
219  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
220  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
221  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
222  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
223  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
224  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
225  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
226  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
227  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
228  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
229  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
230  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
231  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
232  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
233  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
234  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
235  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8,
236  (uint8_t)8, (uint8_t)8, (uint8_t)8, (uint8_t)8
237 };
238 
239 #if (__STDC_VERSION__ >= 199901L) /* is it C99 compiler? */
240 
241  extern inline uint_fast8_t QF_LOG2(uint32_t x);
242 
243 #else
244 
245  /* out-of line definition of the function QF_LOG2() */
246  uint_fast8_t QF_LOG2(uint32_t x) {
247  uint_fast8_t n;
248  uint_fast8_t i;
249 
250  if ((x >> 16) != (uint32_t)0) {
251  if ((x >> 24) != (uint32_t)0) {
252  i = (uint_fast8_t)(x >> 24);
253  n = (uint_fast8_t)24;
254  }
255  else {
256  i = (uint_fast8_t)(x >> 16);
257  n = (uint_fast8_t)16;
258  }
259  }
260  else {
261  if ((x >> 8) != (uint32_t)0) {
262  i = (uint_fast8_t)(x >> 8);
263  n = (uint_fast8_t)8;
264  }
265  else {
266  i = (uint_fast8_t)(x);
267  n = (uint_fast8_t)0;
268  }
269  }
270  return (uint_fast8_t)QF_log2Lkup[i] + n;
271  }
272 
273 
274 #endif /* __STDC_VERSION__ */
275 
276 #endif /* QF_LOG2 */
#define QF_PTR_INC_(p_)
Definition: qf_act.c:143
QActive * QF_active_[QF_MAX_ACTIVE+1]
array of registered active objects
Definition: qf_act.c:53
QStateHandler fun
pointer to a state-handler function
Definition: qep.h:249
#define QF_CRIT_ENTRY_()
This is an internal macro for entering a critical section.
Definition: qf_pkg.h:69
#define QF_CRIT_STAT_
This is an internal macro for defining the critical section status type.
Definition: qf_pkg.h:57
#define QS_BEGIN_NOCRIT_(rec_, objFilter_, obj_)
Internal macro to begin a QS record without entering critical section.
Definition: qs.h:686
void QF_remove_(QActive *const a)
Remove the active object from the framework.
Definition: qf_act.c:109
#define Q_DEFINE_THIS_MODULE(name_)
Define the user-specified module name for assertions in this file.
Definition: qassert.h:101
unsigned char uint8_t
exact-width 8-bit unsigned int
Definition: stdint.h:28
void QF_add_(QActive *const a)
Register an active object to be managed by the framework.
Definition: qf_act.c:69
#define Q_STATE_CAST(handler_)
Perform cast to QStateHandler.
Definition: qep.h:226
union QHsmAttr state
current active state (state-variable)
Definition: qep.h:282
unsigned int uint_fast8_t
fast at-least 8-bit unsigned int
Definition: stdint.h:35
Internal (package scope) QF/C interface.
QHsm super
inherits QHsm
Definition: qf.h:111
unsigned long uint32_t
exact-width 32-bit unsigned int
Definition: stdint.h:30
an AO has been added to QF (started)
Definition: qs.h:81
void const * locFilter[MAX_OBJ]
local QS filters
Definition: qs.h:1069
active object
Definition: qs.h:1058
void QF_bzero(void *const start, uint_fast16_t len)
Clear a specified region of memory to zero.
Definition: qf_act.c:159
unsigned int uint_fast16_t
fast at-least 16-bit unsigned int
Definition: stdint.h:37
#define QF_MAX_ACTIVE
The maximum number of active objects in the application.
Definition: qf_port.h:58
Customizable and memory-efficient assertions for embedded systems.
#define Q_REQUIRE_ID(id_, test_)
Assertion for checking preconditions with user-specified assertion-id.
Definition: qassert.h:254
#define QS_OBJ_(obj_)
Internal macro to output an unformatted object pointer data element.
Definition: qs.h:744
uint8_t const QF_log2Lkup[256]
Lookup table for (log2(n) + 1), where n = 0..255.
Definition: qf_act.c:172
#define QS_TIME_()
Internal macro to output time stamp to a QS record.
Definition: qs.h:205
#define QS_END_NOCRIT_()
Internal QS macro to end a QS record without exiting critical section.
Definition: qs.h:700
#define QS_U8_(data_)
Internal QS macro to output an unformatted uint8_t data element.
Definition: qs.h:705
Active Object (based on QHsm implementation)
Definition: qf.h:110
an AO has been removed from QF (stopped)
Definition: qs.h:82
uint_fast8_t prio
QF priority (1..QF_MAX_ACTIVE) of this active object.
Definition: qf.h:153
#define QF_CRIT_EXIT_()
This is an internal macro for exiting a critical section.
Definition: qf_pkg.h:81