qpc/ports/freertos/qf_port.h

244 lines
10 KiB
C
Raw Normal View History

2018-01-10 18:27:33 -05:00
/**
* @file
* @brief QF/C port to FreeRTOS 10.x, ARM Cortex-M, IAR-ARM toolset
* @ingroup ports
* @cond
******************************************************************************
2020-10-01 12:48:48 -04:00
* Last updated for version 6.9.1
* Last updated on 2020-09-10
2018-01-10 18:27:33 -05:00
*
2019-12-31 15:55:08 -05:00
* Q u a n t u m L e a P s
* ------------------------
* Modern Embedded Software
2018-01-10 18:27:33 -05:00
*
2020-03-17 21:33:20 -04:00
* Copyright (C) 2005-2020 Quantum Leaps, LLC. All rights reserved.
2018-01-10 18:27:33 -05:00
*
* This program is open source software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alternatively, this program may be distributed and modified under the
* terms of Quantum Leaps commercial licenses, which expressly supersede
* the GNU General Public License and are specifically designed for
* licensees interested in retaining the proprietary status of their code.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-12-31 15:55:08 -05:00
* along with this program. If not, see <www.gnu.org/licenses>.
2018-01-10 18:27:33 -05:00
*
* Contact information:
2019-12-31 15:55:08 -05:00
* <www.state-machine.com/licensing>
* <info@state-machine.com>
2018-01-10 18:27:33 -05:00
******************************************************************************
* @endcond
*/
2019-10-27 11:57:33 -04:00
#ifndef QF_PORT_H
#define QF_PORT_H
2018-01-10 18:27:33 -05:00
/* FreeRTOS event queue and thread types */
#define QF_EQUEUE_TYPE QEQueue
#define QF_THREAD_TYPE StaticTask_t
/* The maximum number of active objects in the application, see NOTE1 */
2020-03-17 21:33:20 -04:00
#define QF_MAX_ACTIVE 32U
2018-01-10 18:27:33 -05:00
/* QF interrupt disabling/enabling (task level) */
#define QF_INT_DISABLE() taskDISABLE_INTERRUPTS()
#define QF_INT_ENABLE() taskENABLE_INTERRUPTS()
/* QF critical section for FreeRTOS (task level), see NOTE2 */
/* #define QF_CRIT_STAT_TYPE not defined */
#define QF_CRIT_ENTRY(stat_) taskENTER_CRITICAL()
#define QF_CRIT_EXIT(stat_) taskEXIT_CRITICAL()
#include "FreeRTOS.h" /* FreeRTOS master include file, see NOTE4 */
#include "task.h" /* FreeRTOS task management */
#include "qep_port.h" /* QEP port */
#include "qequeue.h" /* this QP port uses the native QF event queue */
#include "qmpool.h" /* this QP port uses the native QF memory pool */
#include "qf.h" /* QF platform-independent public interface */
/* the "FromISR" versions of the QF APIs, see NOTE3 */
#ifdef Q_SPY
#define QACTIVE_POST_FROM_ISR(me_, e_, pxHigherPrioTaskWoken_, sender_) \
2020-03-17 21:33:20 -04:00
((void)QActive_postFromISR_((me_), (e_), QF_NO_MARGIN, \
2018-01-10 18:27:33 -05:00
(pxHigherPrioTaskWoken_), (sender_)))
2020-03-17 21:33:20 -04:00
#define QACTIVE_POST_X_FROM_ISR(me_, e_, margin_, \
2018-01-10 18:27:33 -05:00
pxHigherPrioTaskWoken_, sender_) \
2020-03-17 21:33:20 -04:00
(QActive_postFromISR_((me_), (e_), (margin_), \
2018-01-10 18:27:33 -05:00
(pxHigherPrioTaskWoken_), (sender_)))
#define QF_PUBLISH_FROM_ISR(e_, pxHigherPrioTaskWoken_, sender_) \
2020-03-17 21:33:20 -04:00
(QF_publishFromISR_((e_), (pxHigherPrioTaskWoken_), \
2018-01-10 18:27:33 -05:00
(void const *)(sender_)))
#define QF_TICK_X_FROM_ISR(tickRate_, pxHigherPrioTaskWoken_, sender_) \
(QF_tickXFromISR_((tickRate_), (pxHigherPrioTaskWoken_), (sender_)))
/* this function only to be used through macros QACTIVE_POST_FROM_ISR()
* and QACTIVE_POST_X_FROM_ISR().
*/
bool QActive_postFromISR_(QActive * const me, QEvt const * const e,
uint_fast16_t const margin,
BaseType_t * const pxHigherPriorityTaskWoken,
void const * const sender);
void QF_publishFromISR_(QEvt const * const e,
BaseType_t * const pxHigherPriorityTaskWoken,
void const * const sender);
void QF_tickXFromISR_(uint_fast8_t const tickRate,
BaseType_t * const pxHigherPriorityTaskWoken,
void const * const sender);
#else
#define QACTIVE_POST_FROM_ISR(me_, e_, pxHigherPrioTaskWoken_, dummy) \
2020-03-17 21:33:20 -04:00
((void)QActive_postFromISR_((me_), (e_), QF_NO_MARGIN, \
2018-01-10 18:27:33 -05:00
(pxHigherPrioTaskWoken_)))
2020-03-17 21:33:20 -04:00
#define QACTIVE_POST_X_FROM_ISR(me_, e_, margin_, \
2018-01-10 18:27:33 -05:00
pxHigherPrioTaskWoken_, dummy) \
2020-03-17 21:33:20 -04:00
(QActive_postFromISR_((me_), (e_), (margin_), \
2018-01-10 18:27:33 -05:00
(pxHigherPrioTaskWoken_)))
#define QF_PUBLISH_FROM_ISR(e_, pxHigherPrioTaskWoken_, dummy) \
(QF_publishFromISR_((e_), (pxHigherPrioTaskWoken_)))
#define QF_TICK_X_FROM_ISR(tickRate_, pxHigherPrioTaskWoken_, dummy) \
(QF_tickXFromISR_((tickRate_), (pxHigherPrioTaskWoken_)))
bool QActive_postFromISR_(QActive * const me, QEvt const * const e,
uint_fast16_t const margin,
BaseType_t * const pxHigherPriorityTaskWoken);
void QF_publishFromISR_(QEvt const * const e,
BaseType_t * const pxHigherPriorityTaskWoken);
void QF_tickXFromISR_(uint_fast8_t const tickRate,
BaseType_t * const pxHigherPriorityTaskWoken);
#endif
#define QF_TICK_FROM_ISR(pxHigherPrioTaskWoken_, sender_) \
2020-03-17 21:33:20 -04:00
QF_TICK_X_FROM_ISR(0U, pxHigherPrioTaskWoken_, sender_)
2018-01-10 18:27:33 -05:00
#ifdef Q_EVT_CTOR /* Shall the ctor for the ::QEvt class be provided? */
2020-03-17 21:33:20 -04:00
#define Q_NEW_FROM_ISR(evtT_, sig_, ...) \
(evtT_##_ctor((evtT_ *)QF_newXFromISR_(sizeof(evtT_), \
QF_NO_MARGIN, 0), (sig_), ##__VA_ARGS__))
2018-01-10 18:27:33 -05:00
#define Q_NEW_X_FROM_ISR(e_, evtT_, margin_, sig_, ...) do { \
2020-03-17 21:33:20 -04:00
(e_) = (evtT_ *)QF_newXFromISR_(sizeof(evtT_), \
(margin_), 0); \
if ((e_) != (evtT_ *)0) { \
evtT_##_ctor((e_), (sig_), ##__VA_ARGS__); \
} \
2019-12-31 15:55:08 -05:00
} while (false)
2018-01-10 18:27:33 -05:00
#else
2020-03-17 21:33:20 -04:00
#define Q_NEW_FROM_ISR(evtT_, sig_) \
2018-01-10 18:27:33 -05:00
((evtT_ *)QF_newXFromISR_((uint_fast16_t)sizeof(evtT_), \
QF_NO_MARGIN, (sig_)))
#define Q_NEW_X_FROM_ISR(e_, evtT_, margin_, sig_) ((e_) = \
2019-12-31 15:55:08 -05:00
(evtT_ *)QF_newXFromISR_((uint_fast16_t)sizeof(evtT_), \
(margin_), (sig_)))
2018-01-10 18:27:33 -05:00
#endif /* Q_EVT_CTOR */
void QF_gcFromISR(QEvt const * const e);
/* this function only to be used through macros Q_NEW_FROM_ISR() and
* Q_NEW_X_FROM_ISR().
*/
QEvt *QF_newXFromISR_(uint_fast16_t const evtSize,
uint_fast16_t const margin, enum_t const sig);
2020-10-01 12:48:48 -04:00
void *QMPool_getFromISR(QMPool * const me, uint_fast16_t const margin,
uint_fast8_t const qs_id);
void QMPool_putFromISR(QMPool * const me, void *b, uint_fast8_t const qs_id);
2018-01-10 18:27:33 -05:00
enum FreeRTOS_TaskAttrs {
TASK_NAME_ATTR
};
/* FreeRTOS hooks prototypes (not provided by FreeRTOS) */
#if (configUSE_IDLE_HOOK > 0)
void vApplicationIdleHook(void);
#endif
#if (configUSE_TICK_HOOK > 0)
void vApplicationTickHook(void);
#endif
#if (configCHECK_FOR_STACK_OVERFLOW > 0)
void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName);
#endif
#if (configSUPPORT_STATIC_ALLOCATION > 0)
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer,
StackType_t **ppxIdleTaskStackBuffer,
uint32_t *pulIdleTaskStackSize );
#endif
/*****************************************************************************
* interface used only inside QF, but not in applications
*/
#ifdef QP_IMPL
/* FreeRTOS blocking for event queue implementation (task level) */
2020-03-17 21:33:20 -04:00
#define QACTIVE_EQUEUE_WAIT_(me_) \
2018-01-10 18:27:33 -05:00
while ((me_)->eQueue.frontEvt == (QEvt *)0) { \
2020-10-01 12:48:48 -04:00
QF_CRIT_X_(); \
2020-03-17 21:33:20 -04:00
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); \
2020-10-01 12:48:48 -04:00
QF_CRIT_E_(); \
2018-01-10 18:27:33 -05:00
}
/* FreeRTOS signaling (unblocking) for event queue (task level) */
2020-03-17 21:33:20 -04:00
#define QACTIVE_EQUEUE_SIGNAL_(me_) do { \
2020-10-01 12:48:48 -04:00
QF_CRIT_X_(); \
2018-01-10 18:27:33 -05:00
xTaskNotifyGive((TaskHandle_t)&(me_)->thread); \
2020-10-01 12:48:48 -04:00
QF_CRIT_E_(); \
2019-12-31 15:55:08 -05:00
} while (false)
2018-01-10 18:27:33 -05:00
#define QF_SCHED_STAT_
#define QF_SCHED_LOCK_(dummy) vTaskSuspendAll()
#define QF_SCHED_UNLOCK_() xTaskResumeAll()
/* native QF event pool operations */
#define QF_EPOOL_TYPE_ QMPool
#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
(QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_)))
#define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize)
2020-10-01 12:48:48 -04:00
#define QF_EPOOL_GET_(p_, e_, m_, qs_id_) \
((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qs_id_)))
#define QF_EPOOL_PUT_(p_, e_, qs_id_) \
(QMPool_put(&(p_), (e_), (qs_id_)))
2018-01-10 18:27:33 -05:00
#endif /* ifdef QP_IMPL */
/*****************************************************************************
* NOTE1:
* The maximum number of active objects QF_MAX_ACTIVE can be increased to 64,
* inclusive, but it can be reduced to save some memory. Also, the number of
* active objects cannot exceed the number of FreeRTOS task priorities,
* because each QP active object requires a unique priority level.
*
* NOTE2:
* The critical section definition applies only to the FreeRTOS "task level"
* APIs. The "FromISR" APIs are defined separately.
*
* NOTE3:
* The design of FreeRTOS requires using different APIs inside the ISRs
* (the "FromISR" variant) than at the task level. Accordingly, this port
* provides the "FromISR" variants for QP functions and "FROM_ISR" variants
* for QP macros to be used inside ISRs. ONLY THESE "FROM_ISR" VARIANTS
* ARE ALLOWED INSIDE ISRs AND CALLING THE TASK-LEVEL APIs IS AN ERROR.
*/
2019-10-27 11:57:33 -04:00
#endif /* QF_PORT_H */