4This is just an example of a QF port for a generic C11 compiler. Other specific QF ports will define the QF facilities differently.
5@endcode_uid
6*/
7#ifndef QP_PORT_H_
8#define QP_PORT_H_
9
10#include <stdint.h>// Exact-width types. WG14/N843 C99-C11 Standard
11#include <stdbool.h>// Boolean type. WG14/N843 C99-C11 Standard
12
13/*!
14@code_uid{#Q_NORETURN, No-return specifier for the Q_onError() callback function.}
15@code_litem{Details}
16Per the Software Safety Requirement @ref SREQ_QP_FDM_00, the Q_onError() handler should never return. Starting with the C99 Standard, the no-return specification can be provided at the language level, which may allow the compiler to apply optimizations (e.g., for impossible code paths downstream of Q_onError()). Also, the no-return specification is immensely valuable for static analysis tools. Unfortunately, MISRA-C:2025 still considers the specifier `_Noreturn` as an "emergent language feature", which should not be used (MISRA-C:2025 Rule 1.4, Required). The #Q_NORETURN macro encapsulates this deviation.
17@note
18If the `Q_NORETURN` macro is not defined in the QP port (`qf_port.h`), the default will be the C99 specifier `_Noreturn` applied in `qsafe.h`.
52- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
60- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
67@code_uid{#QF_CRIT_STAT, Define the critical section status that was present before entering the critical section.}
68@code_litem{Details}
69For critical sections that are allowed to nest, the critical section status must be saved and restored at the end. This macro provides the storage for saving the status.
70@note
71This macro might be empty, in which case, the critical section status is not saved or restored. Such critical sections won't be able to nest. Also, note that the macro should be invoked without the closing semicolon.
80If the critical section status is provided, the macro saves the critical section status from before entering the critical section. Otherwise, the macro just unconditionally enters the critical section without saving the status.
81@code_fw_trace
82- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
90If the critical section status is provided, the macro restores the critical section status saved by QF_CRIT_ENTRY(). Otherwise, the macro just unconditionally exits the critical section.
91@code_fw_trace
92- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
98@code_uid{QF_CRIT_EXIT_NOP(), No-operation for exiting a critical section}
99@code_litem{Details}
100In some QF ports, the critical section exit takes effect only on the next machine instruction. If this next instruction is another entry to a critical section, the critical section won't be exited, but rather the two adjacent critical sections would be _merged_. The QF_CRIT_EXIT_NOP() macro contains minimal code required to prevent such merging of critical sections in QF ports.
101@code_fw_trace
102- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
108@code_uid{QF_CRIT_EST(), Port-specific establishing a critical section (without saving the status)}
109@code_litem{Details}
110This port-specific macro only establishes a critical section (to later call Q_onError() error handler), but since Q_onError() never returns, there is no need to exit such established critical section.
111@code_fw_trace
112- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
118@code_uid{QF_LOG2(), Port-specific integer log-base-2 of a 32-bit bitmask}
119@code_litem{Details}
120Calculate integer log-base-2 of a given bitmask (1-based) used to quickly determine the highest-number 1-bit in the bitmask. This operation is used frequently during task scheduling and publish-subscribe.
121@param[in] bitmask_ 32-bit bitmask
122@returns 1-based integer log-base-2 of the provided bitmask. Examples:
123- QF_LOG2(0x00000000U) == 0U
124- QF_LOG2(0x00000001U) == 1U
125- QF_LOG2(0x00000002U) == 2U
126- QF_LOG2(0x00000004U) == 3U
127- QF_LOG2(0x00000008U) == 4U
128- QF_LOG2(0x00000010U) == 5U
129...
130- QF_LOG2(0x80000010U) == 32U
131
132@note
133This operation is performed frequently in time-critical parts of the code. Some CPUs provide such calculation in hardware (e.g., as a machine instruction). For example, ARMv7 and higher architectures support the related CLZ (count leading zeroes) instruction, with the following relationship:
134QF_LOG2(bitmask_) == 32U - CLZ(bitmask_).
135@code_fw_trace
136- @tr{DVR_QP_MC5_D4_9B}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (CORRECT diagnostics)</i>
160 - @tr{AOU_QA_MI_00}: <i>@QPX Application should apply <u>memory isolation mechanisms</u> provided in @QPX Framework.</i>
161 @code_fw_trace
162 - @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
163 @endcode_uid
164 */
165 #define QF_MEM_SYS() QF_onMemSys()
166
167 /*!
168 @code_uid{QF_MEM_APP(), Port-specific establishing _Application Context_ for memory protection}
171 - @tr{AOU_QA_MI_00}: <i>@QPX Application should apply <u>memory isolation mechanisms</u> provided in @QPX Framework.</i>
172 @code_fw_trace
173 - @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
174 @endcode_uid
175 */
176 #define QF_MEM_APP() QF_onMemApp()
177
178#ifdef Q_SPY
179 /*!
180 @code_uid{QS_MEM_SYS(), Port-specific establishing _System Context_ for memory protection in conditional QS software tracing code.}
183 - @tr{AOU_QA_MI_00}: <i>@QPX Application should apply <u>memory isolation mechanisms</u> provided in @QPX Framework.</i>
184 @code_fw_trace
185 - @tr{DVR_QS_MC5_D4_9A}: <i>Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnosis)</i>
186 @endcode_uid
187 */
188 #define QS_MEM_SYS() QF_MEM_SYS()
189
190 /*!
191 @code_uid{QS_MEM_APP(), Port-specific establishing _Application Context_ for memory protection in conditional QS software tracing code.}
194 - @tr{AOU_QA_MI_00}: <i>@QPX Application should apply <u>memory isolation mechanisms</u> provided in @QPX Framework.</i>
195 @code_fw_trace
196 - @tr{DVR_QS_MC5_D4_9A}: <i>Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnosis)</i>
206@code_uid{QV_CPU_SLEEP(), Port-specific method to put the CPU to sleep __safely__ in the non-preemptive QV kernel (to be called from QV::QV_onIdle()).}
207@code_fw_trace
208- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
222@code_uid{QK_ISR_CONTEXT_(), Port-specific method to check if the QK kernel executes in the ISR context (used internally in QK only).}
223@returns `true` if the caller executes in the ISR context and `false` otherwise
224@code_fw_trace
225- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
231@code_uid{QK_ISR_ENTRY(), Port-specific method to inform QK kernel about the ISR entry.}
232@code_fw_trace
233- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
245@code_uid{QK_ISR_EXIT(), Port-specific method to inform QK kernel about the ISR exit.}
246@code_fw_trace
247- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
264@code_uid{QXK_ISR_CONTEXT_(), Port-specific method to check if the QXK kernel executes in the ISR context (used internally in QXK only).}
265@returns `true` if the caller executes in the ISR context and `false` otherwise
266@code_fw_trace
267- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
273@code_uid{QXK_CONTEXT_SWITCH_(), Port-specific method to trigger context switch (used internally in QXK only).}
274@code_fw_trace
275- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
281@code_uid{QXK_ISR_ENTRY(), Port-specific method to inform QXK kernel about the ISR entry.}
282@code_fw_trace
283- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
289@code_uid{QXK_ISR_EXIT(), Port-specific method to inform QXK kernel about the ISR exit.}
290@code_fw_trace
291- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
312@code_uid{QF_SCHED_LOCK_(), Port-specific method to lock the scheduler (for internal use in QF only).}
313@param[in] ceil_ priority-ceiling up to which the scheduler should be locked
314@code_fw_trace
315- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
327@code_uid{QF_SCHED_UNLOCK_(), Port-specific method to unlock the scheduler (for internal use in QF only).}
328@code_fw_trace
329- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
338// Event-Queue port interface (example) --------------------------------------
339// QActive event queue customization...
340/*!
341@code_uid{QACTIVE_EQUEUE_WAIT_(), Port-specific method to wait on an empty Active Object event queue (for internal use only).}
342@param[in,out] me_ current instance pointer (see @ref SAS_QP_OOA)
343@code_fw_trace
344- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
350@code_uid{QACTIVE_EQUEUE_SIGNAL_(), Port-specific method to signal Active Object event queue (for internal use only).}
351@param[in,out] me_ current instance pointer (see @ref SAS_QP_OOA)
352@code_fw_trace
353- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
367@code_uid{QXTHREAD_EQUEUE_SIGNAL_(), Port-specific method to signal eXtended thread event queue (for internal use only).}
368@param[in,out] me_ current instance pointer (see @ref SAS_QP_OOA)
369@code_fw_trace
370- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
393@code_uid{QF_EPOOL_INIT_(), Port-specific event pool initialization (for internal use in QF only).}
394@param[in,out] p_ event pool pointer
395@param[in] poolSto_ storage for the pool (pointer to the pool buffer)
396@param[in] poolSize_ size of the pool storage in [bytes]
397@param[in] evtSize_ event size of this pool in [bytes]
398@code_fw_trace
399- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
406@code_uid{QF_EPOOL_EVENT_SIZE_(), Port-specific event pool block-size() operation (for internal use in QF only).}
407@param[in,out] p_ event pool pointer
408@code_fw_trace
409- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
415@code_uid{QF_EPOOL_GET_(), Port-specific event pool get() operation (for internal use in QF only).}
416@param[in,out] p_ event pool pointer
417@param[out] e_ event pointer to be assigned the obtained event
418@param[in] m_ margin (# free events that must still remain in the pool)
419@param[in] qsId_ QS ID for the QS local filter
420@code_fw_trace
421- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
422- @tr{DVR_QP_MC5_R11_5}: <i>MISRA-C:2025 Rule 11.5(Advisory): A conversion should not be performed from pointer to void into pointer to object</i>
429@code_uid{QF_EPOOL_PUT_(), Port-specific event pool put() operation (for internal use in QF only).}
430@param[in,out] p_ event pool pointer
431@param[out] e_ event pointer to return to the pool
432@param[in] qsId_ QS ID for the QS local filter
433@code_fw_trace
434- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
440@code_uid{QF_EPOOL_USE_(), Port-specific event pool # used events operation (for internal use in QF only).}
441@param[in] ePool_ event pool pointer
442@returns # used events in the pool at this moment (allocated and not returned yet)
443@code_fw_trace
444- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
450@code_uid{QF_EPOOL_FREE_(), Port-specific event pool # free events operation (for internal use in QF only).}
451@param[in] ePool_ event pool pointer
452@returns # free events in the pool at this moment (available to allocate)
453@code_fw_trace
454- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>
460@code_uid{QF_EPOOL_MIN_(), Port-specific event pool minimum # events since initialization (for internal use in QF only).}
461@param[in] ePool_ event pool pointer
462@returns minimal # free events in the pool since initialization
463@code_fw_trace
464- @tr{DVR_QP_MC5_D4_9A}: <i>MISRA-C:2025 Directive 4.9(Advisory): A function should be used in preference to a function-like macro where they are interchangeable (FALSE-POSITIVE diagnostics)</i>