2022-04-19 19:23:30 -04:00
|
|
|
//============================================================================
|
2022-08-11 15:36:19 -04:00
|
|
|
// QP/C++ Real-Time Embedded Framework (RTEF)
|
2023-01-19 21:14:02 -05:00
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved.
|
|
|
|
//
|
2023-01-19 21:14:02 -05:00
|
|
|
// Q u a n t u m L e a P s
|
|
|
|
// ------------------------
|
|
|
|
// Modern Embedded Software
|
|
|
|
//
|
2022-08-11 15:36:19 -04:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial
|
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// The QP/C software is dual-licensed under the terms of the open-source GNU
|
|
|
|
// General Public License (GPL) or under the terms of one of the closed-
|
|
|
|
// source Quantum Leaps commercial licenses.
|
2022-08-11 15:36:19 -04:00
|
|
|
//
|
|
|
|
// Redistributions in source code must retain this top-level comment block.
|
|
|
|
// Plagiarizing this software to sidestep the license obligations is illegal.
|
|
|
|
//
|
2024-10-15 13:15:28 -04:00
|
|
|
// NOTE:
|
|
|
|
// The GPL (see <www.gnu.org/licenses/gpl-3.0>) does NOT permit the
|
|
|
|
// incorporation of the QP/C software into proprietary programs. Please
|
|
|
|
// contact Quantum Leaps for commercial licensing options, which expressly
|
|
|
|
// supersede the GPL and are designed explicitly for licensees interested
|
|
|
|
// in using QP/C in closed-source proprietary applications.
|
|
|
|
//
|
|
|
|
// Quantum Leaps contact information:
|
|
|
|
// <www.state-machine.com/licensing>
|
2022-08-11 15:36:19 -04:00
|
|
|
// <info@state-machine.com>
|
2022-04-19 19:23:30 -04:00
|
|
|
//============================================================================
|
2024-10-15 13:15:28 -04:00
|
|
|
//! @date Last updated on: 2024-09-30
|
|
|
|
//! @version Last updated for: @ref qpcpp_8_0_0
|
2022-08-11 15:36:19 -04:00
|
|
|
//!
|
|
|
|
//! @file
|
2023-01-19 21:14:02 -05:00
|
|
|
//! @brief QP/C++ port to FreeRTOS 10.x generic C++11 compiler
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
#ifndef QP_PORT_HPP_
|
|
|
|
#define QP_PORT_HPP_
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2024-10-15 13:15:28 -04:00
|
|
|
#include <cstdint> // Exact-width types. C++11 Standard
|
|
|
|
#include "qp_config.hpp" // QP configuration from the application
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
// no-return function specifier (C++11 Standard)
|
|
|
|
#define Q_NORETURN [[ noreturn ]] void
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
// QActive customization for FreeRTOS
|
|
|
|
#define QACTIVE_EQUEUE_TYPE QueueHandle_t
|
|
|
|
#define QACTIVE_OS_OBJ_TYPE StaticQueue_t
|
|
|
|
#define QACTIVE_THREAD_TYPE StaticTask_t
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2022-08-11 15:36:19 -04:00
|
|
|
// FreeRTOS requires the "FromISR" API in QP/C++
|
2023-01-19 21:14:02 -05:00
|
|
|
#define QF_ISR_API 1
|
|
|
|
|
|
|
|
// 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
|
|
|
|
#define QF_CRIT_ENTRY() taskENTER_CRITICAL()
|
|
|
|
#define QF_CRIT_EXIT() taskEXIT_CRITICAL()
|
2022-08-11 15:36:19 -04:00
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
// include files -------------------------------------------------------------
|
|
|
|
#include "FreeRTOS.h" // FreeRTOS master include file, see NOTE3
|
|
|
|
#include "task.h" // FreeRTOS task management
|
|
|
|
#include "queue.h" // FreeRTOS queue management
|
2022-08-11 15:36:19 -04:00
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
#include "qequeue.hpp" // QP event queue (for deferring events)
|
|
|
|
#include "qmpool.hpp" // QP memory pool (for event pools)
|
|
|
|
#include "qp.hpp" // QP platform-independent public interface
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
// the "FromISR" versions of the QF APIs, see NOTE3
|
|
|
|
#ifdef Q_SPY
|
|
|
|
#define PUBLISH_FROM_ISR(e_, pxHigherPrioTaskWoken_, sender_) \
|
2023-01-19 21:14:02 -05:00
|
|
|
publishFromISR((e_), (pxHigherPrioTaskWoken_), (sender_))
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
#define POST_FROM_ISR(e_, pxHigherPrioTaskWoken_, sender_) \
|
2023-01-19 21:14:02 -05:00
|
|
|
postFromISR((e_), QP::QF::NO_MARGIN, \
|
2018-01-10 18:26:05 -05:00
|
|
|
(pxHigherPrioTaskWoken_), (sender_))
|
|
|
|
|
|
|
|
#define POST_X_FROM_ISR(e_, margin_, pxHigherPrioTaskWoken_, sender_) \
|
2023-01-19 21:14:02 -05:00
|
|
|
postFromISR((e_), (margin_), (pxHigherPrioTaskWoken_), (sender_))
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
#define TICK_X_FROM_ISR(tickRate_, pxHigherPrioTaskWoken_, sender_) \
|
2023-01-19 21:14:02 -05:00
|
|
|
tickFromISR((tickRate_), (pxHigherPrioTaskWoken_), (sender_))
|
2018-01-10 18:26:05 -05:00
|
|
|
#else
|
|
|
|
#define PUBLISH_FROM_ISR(e_, pxHigherPrioTaskWoken_, dummy) \
|
2023-01-19 21:14:02 -05:00
|
|
|
publishFromISR((e_), (pxHigherPrioTaskWoken_), nullptr)
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
#define POST_FROM_ISR(e_, pxHigherPrioTaskWoken_, dummy) \
|
2023-01-19 21:14:02 -05:00
|
|
|
postFromISR((e_), QP::QF::NO_MARGIN, (pxHigherPrioTaskWoken_), \
|
2022-08-11 15:36:19 -04:00
|
|
|
nullptr)
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
#define POST_X_FROM_ISR(e_, margin_, pxHigherPrioTaskWoken_, dummy) \
|
2023-01-19 21:14:02 -05:00
|
|
|
postFromISR((e_), (margin_), (pxHigherPrioTaskWoken_), nullptr)
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
#define TICK_X_FROM_ISR(tickRate_, pxHigherPrioTaskWoken_, dummy) \
|
2023-01-19 21:14:02 -05:00
|
|
|
tickFromISR((tickRate_), (pxHigherPrioTaskWoken_), nullptr)
|
2018-01-10 18:26:05 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TICK_FROM_ISR(pxHigherPrioTaskWoken_, sender_) \
|
2020-03-17 21:33:58 -04:00
|
|
|
TICK_X_FROM_ISR(0U, (pxHigherPrioTaskWoken_), (sender_))
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
#ifdef QEVT_DYN_CTOR
|
2018-01-10 18:26:05 -05:00
|
|
|
#define Q_NEW_FROM_ISR(evtT_, sig_, ...) \
|
2023-01-06 12:56:50 -05:00
|
|
|
(new(QP::QF::newXfromISR_(sizeof(evtT_), QP::QF::NO_MARGIN, (sig_))) \
|
2023-01-19 21:14:02 -05:00
|
|
|
evtT_(__VA_ARGS__))
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2020-03-17 21:33:58 -04:00
|
|
|
#define Q_NEW_X_FROM_ISR(e_, evtT_, margin_, sig_, ...) do { \
|
|
|
|
(e_) = static_cast<evtT_ *>( \
|
|
|
|
QP::QF::newXfromISR_(static_cast<std::uint_fast16_t>( \
|
2023-01-06 12:56:50 -05:00
|
|
|
sizeof(evtT_)), (margin_), (sig_))); \
|
2020-03-17 21:33:58 -04:00
|
|
|
if ((e_) != nullptr) { \
|
2023-01-19 21:14:02 -05:00
|
|
|
new((e_)) evtT_(__VA_ARGS__); \
|
2023-01-06 12:56:50 -05:00
|
|
|
} \
|
2019-12-31 15:56:23 -05:00
|
|
|
} while (false)
|
2018-01-10 18:26:05 -05:00
|
|
|
|
|
|
|
#else // QEvt is a POD (Plain Old Datatype)
|
2020-03-17 21:33:58 -04:00
|
|
|
#define Q_NEW_FROM_ISR(evtT_, sig_) \
|
|
|
|
(static_cast<evtT_ *>(QP::QF::newXfromISR_( \
|
|
|
|
static_cast<std::uint_fast16_t>(sizeof(evtT_)), \
|
2022-09-22 11:13:20 -04:00
|
|
|
QP::QF::NO_MARGIN, (sig_))))
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2020-03-17 21:33:58 -04:00
|
|
|
#define Q_NEW_X_FROM_ISR(e_, evtT_, margin_, sig_) \
|
|
|
|
((e_) = static_cast<evtT_ *>( \
|
|
|
|
QP::QF::newXfromISR_(sizeof(evtT_), (margin_), (sig_))))
|
2018-01-10 18:26:05 -05:00
|
|
|
#endif
|
|
|
|
|
2018-02-12 18:51:22 -05:00
|
|
|
namespace QP {
|
|
|
|
|
2018-01-10 18:26:05 -05:00
|
|
|
enum FreeRTOS_TaskAttrs {
|
|
|
|
TASK_NAME_ATTR
|
|
|
|
};
|
|
|
|
|
2018-02-12 18:51:22 -05:00
|
|
|
} // namespace QP
|
|
|
|
|
2018-01-10 18:26:05 -05:00
|
|
|
// FreeRTOS hooks prototypes (not provided by FreeRTOS)
|
|
|
|
extern "C" {
|
|
|
|
#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
|
|
|
|
} // extern "C"
|
|
|
|
|
2022-04-19 19:23:30 -04:00
|
|
|
//============================================================================
|
2018-01-10 18:26:05 -05:00
|
|
|
// interface used only inside QF, but not in applications
|
2022-08-28 22:12:27 -04:00
|
|
|
|
2018-01-10 18:26:05 -05:00
|
|
|
#ifdef QP_IMPL
|
2022-08-11 15:36:19 -04:00
|
|
|
#define FREERTOS_TASK_PRIO(qp_prio_) \
|
|
|
|
((UBaseType_t)((qp_prio_) + tskIDLE_PRIORITY))
|
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
// FreeRTOS scheduler locking for QF_publish_() (task context only)
|
|
|
|
#define QF_SCHED_STAT_
|
|
|
|
#define QF_SCHED_LOCK_(prio_) (vTaskSuspendAll())
|
|
|
|
#define QF_SCHED_UNLOCK_() ((void)xTaskResumeAll())
|
|
|
|
|
|
|
|
// native QF event pool customization
|
|
|
|
#define QF_EPOOL_TYPE_ QMPool
|
2018-01-10 18:26:05 -05:00
|
|
|
#define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \
|
|
|
|
(p_).init((poolSto_), (poolSize_), (evtSize_))
|
2020-10-01 12:50:17 -04:00
|
|
|
#define QF_EPOOL_EVENT_SIZE_(p_) ((p_).getBlockSize())
|
2024-01-17 07:50:09 -05:00
|
|
|
#define QF_EPOOL_GET_(p_, e_, m_, qsId_) \
|
|
|
|
((e_) = static_cast<QEvt *>((p_).get((m_), (qsId_))))
|
|
|
|
#define QF_EPOOL_PUT_(p_, e_, qsId_) ((p_).put((e_), (qsId_)))
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2024-10-15 13:15:28 -04:00
|
|
|
#endif // def QP_IMPL
|
2018-01-10 18:26:05 -05:00
|
|
|
|
2022-04-19 19:23:30 -04:00
|
|
|
//============================================================================
|
2018-01-10 18:26:05 -05:00
|
|
|
// 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.
|
|
|
|
|
2023-01-19 21:14:02 -05:00
|
|
|
#endif // QP_PORT_HPP_
|
2022-08-28 22:12:27 -04:00
|
|
|
|