├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSES ├── GPL-3.0-or-later.txt ├── License.txt ├── LicenseRef-QL-commercial.txt ├── LicenseRef-QL-dual.qlc ├── QP-Arduino_GPL_Exception.txt ├── QP-RasPi_GPL_Exception.txt └── QP-mbed_GPL_Exception.txt ├── README.md ├── cmakeSupport.md ├── include ├── README.md ├── qequeue.h ├── qk.h ├── qmpool.h ├── qp.h ├── qp_pkg.h ├── qpc.h ├── qs_dummy.h ├── qsafe.h ├── qstamp.h └── qv.h ├── ports ├── CMakeLists.txt ├── README.md ├── arm-cm │ ├── CMakeLists.txt │ ├── README.md │ ├── config │ │ └── qp_config.h │ ├── qk │ │ ├── armclang │ │ │ ├── qk_port.c │ │ │ ├── qp_port.h │ │ │ └── qs_port.h │ │ ├── gnu │ │ │ ├── qk_port.c │ │ │ ├── qp_port.h │ │ │ ├── qs_port.h │ │ │ └── syscalls.c │ │ └── iar │ │ │ ├── qk_port.c │ │ │ ├── qp_port.h │ │ │ └── qs_port.h │ └── qv │ │ ├── armclang │ │ ├── qp_port.h │ │ ├── qs_port.h │ │ └── qv_port.c │ │ ├── gnu │ │ ├── qp_port.h │ │ ├── qs_port.h │ │ ├── qv_port.c │ │ └── syscalls.c │ │ └── iar │ │ ├── qp_port.h │ │ ├── qs_port.h │ │ └── qv_port.c ├── arm-cr │ ├── CMakeLists.txt │ ├── config │ │ └── qp_config.h │ ├── qk │ │ ├── gnu │ │ │ ├── qp_port.h │ │ │ └── qs_port.h │ │ ├── iar │ │ │ ├── qp_port.h │ │ │ └── qs_port.h │ │ └── ti │ │ │ ├── qp_port.h │ │ │ └── qs_port.h │ └── qv │ │ ├── gnu │ │ ├── qp_port.h │ │ └── qs_port.h │ │ ├── iar │ │ ├── qp_port.h │ │ └── qs_port.h │ │ └── ti │ │ ├── qp_port.h │ │ └── qs_port.h ├── config │ └── qp_config.h ├── embos │ ├── CMakeLists.txt │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.h │ └── syscalls.c ├── freertos │ ├── CMakeLists.txt │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.h │ └── syscalls.c ├── msp430 │ ├── CMakeLists.txt │ ├── README.md │ ├── qk │ │ ├── qp_port.h │ │ └── qs_port.h │ ├── qutest │ │ ├── qp_port.h │ │ └── qs_port.h │ └── qv │ │ ├── qp_port.h │ │ └── qs_port.h ├── posix-qv │ ├── CMakeLists.txt │ ├── README.md │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.c │ ├── qs_port.h │ └── safe_std.h ├── posix │ ├── CMakeLists.txt │ ├── README.md │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.c │ ├── qs_port.h │ └── safe_std.h ├── qep-only │ ├── CMakeLists.txt │ ├── qp_port.h │ └── safe_std.h ├── qube │ ├── README.txt │ ├── qp_port.h │ ├── qs_port.h │ ├── qube.c │ └── safe_std.h ├── risc-v │ ├── CMakeLists.txt │ └── qv │ │ ├── README.md │ │ └── gnu │ │ ├── qp_port.h │ │ └── qs_port.h ├── threadx │ ├── CMakeLists.txt │ ├── README.md │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.h │ └── syscalls.c ├── uc-os2 │ ├── CMakeLists.txt │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.h │ └── syscalls.c ├── win32-qv │ ├── CMakeLists.txt │ ├── README.md │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.c │ ├── qs_port.h │ ├── qwin_gui.c │ ├── qwin_gui.h │ └── safe_std.h ├── win32 │ ├── CMakeLists.txt │ ├── README.md │ ├── qf_port.c │ ├── qp_port.h │ ├── qs_port.c │ ├── qs_port.h │ ├── qwin_gui.c │ ├── qwin_gui.h │ └── safe_std.h └── zephyr │ └── README.md ├── qpc_8.0.4.sha1 ├── qpc_sdk_init.cmake ├── sha1.bat ├── src ├── CMakeLists.txt ├── README.md ├── qf │ ├── CMakeLists.txt │ ├── qep_hsm.c │ ├── qep_msm.c │ ├── qf_act.c │ ├── qf_actq.c │ ├── qf_defer.c │ ├── qf_dyn.c │ ├── qf_mem.c │ ├── qf_ps.c │ ├── qf_qact.c │ ├── qf_qeq.c │ ├── qf_qmact.c │ └── qf_time.c ├── qk │ ├── CMakeLists.txt │ └── qk.c ├── qs │ ├── CMakeLists.txt │ └── qstamp.c └── qv │ ├── CMakeLists.txt │ └── qv.c └── zephyr ├── CMakeLists.txt ├── Kconfig ├── README.md ├── module.yml ├── qf_port.c ├── qp-zephyr.jpg ├── qp_port.h └── qs_port.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.qms 2 | *.obj 3 | *.o 4 | *.d 5 | *.lib 6 | *.a 7 | *.bin 8 | *.elf 9 | *.err 10 | *.hex 11 | *.exe 12 | *.EXE 13 | *.map 14 | *.dep 15 | *.pdf 16 | *.PDF 17 | *.Hbp 18 | *.nav 19 | *.tps 20 | *.tws 21 | *.tmp 22 | *.log 23 | *.chm 24 | *.zip 25 | *.pdb 26 | *.ncb 27 | *.suo 28 | *.sdf 29 | *.chw 30 | *.sfr 31 | *.ewt 32 | *.user 33 | *.avrsuo 34 | *.Debug 35 | *.Release 36 | *.bak 37 | version-* 38 | JLink*.* 39 | 40 | include/qs.h 41 | include/qs_pkg.h 42 | include/qxk.h 43 | src/qs/qs.c 44 | src/qs/qs_64bit.c 45 | src/qs/qs_fp.c 46 | src/qs/qs_rx.c 47 | src/qs/qutest.c 48 | src/qxk/qxk.c 49 | src/qxk/qxk_mutex.c 50 | src/qxk/qxk_sema.c 51 | src/qxk/qxk_xthr.c 52 | 53 | ports/arm-cm/qxk/ 54 | ports/arm-cm/qutest/ 55 | ports/posix-qutest/ 56 | ports/win32-qutest/ 57 | 58 | priv/ 59 | html/ 60 | latex/ 61 | dbg/ 62 | rel/ 63 | spy/ 64 | build*/ 65 | settings/ 66 | .settings/ 67 | targetConfigs/ 68 | 69 | Debug/ 70 | Release/ 71 | Spy/ 72 | QSpy/ 73 | 74 | lib/ 75 | obj/ 76 | output/ 77 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rd_party"] 2 | path = 3rd_party 3 | url = https://github.com/QuantumLeaps/3rd_party.git 4 | [submodule "examples"] 5 | path = examples 6 | url = https://github.com/QuantumLeaps/qpc-examples 7 | -------------------------------------------------------------------------------- /LICENSES/License.txt: -------------------------------------------------------------------------------- 1 | Quantum Leaps Dual-Licensing: 2 | 3 | The QP/C Real-Time Embedded Framework is dually-licensed under 4 | the following two alternatives: 5 | 6 | 1. Open source GNU General Public License (GPL) version 3, 7 | or alternatively, 8 | 9 | 2. One of the closed source Quantum Leaps commercial licenses. 10 | 11 | The terms of the open source GNU General Public License version 3 12 | can be found at: https://www.gnu.org/licenses/gpl-3.0 13 | 14 | The terms of the closed source Quantum Leaps commercial licenses 15 | can be found at: https://www.state-machine.com/licensing 16 | 17 | Redistributions in source code must retain the top-level comment blocks 18 | in all files. Plagiarizing this software to sidestep the license 19 | obligations is illegal. 20 | -------------------------------------------------------------------------------- /LICENSES/LicenseRef-QL-commercial.txt: -------------------------------------------------------------------------------- 1 | Quantum Leaps Commercial Licenses 2 | 3 | Copyright (C) 2005 Quantum Leaps, LLC 4 | 5 | Quantum Leaps commercial licenses are traditional closed-source, paid-for 6 | licenses designed for licensees interested in retaining the proprietary 7 | status of their code. 8 | 9 | The Quantum Leaps commercial licenses expressly supersede the GPL open source 10 | license. This means that when you license the QP/C or QP/C++ Real-Time 11 | Event Frameworks under a Quantum Leaps commercial license, you specifically 12 | do not use the software under the open source license and therefore you are 13 | not subject to any of its terms. 14 | 15 | Quantum Leaps commercial licensing options are described below: 16 | 17 | 18 | SPDX-License-Identifier: LicenseRef-QL-Single-Product 19 | ----------------------------------------------------- 20 | Single Product License allows a given company ("Licensee") to embed the 21 | specified type(s) of the QP Real-Time Event Framework(s) into one end- 22 | product of the Licensee (Single Product). Licensee can distribute/sell an 23 | unlimited number of units of the Single Product (royalty-free licensing), 24 | for the life of the Single Product. A different Single Product license is 25 | required for each different end product (i.e. model) even if the end-product 26 | is in the same family as a previously licensed end product. This license 27 | is specific to the Licensee and the name and model of the Single Product, 28 | which needs to be defined in the license. The general rule we apply is: 29 | 30 | If you consider it a separate product... so do we! 31 | 32 | Volume discounts are offered if several Single Products are licensed at once 33 | with one license agreement. 34 | 35 | 36 | SPDX-License-Identifier: LicenseRef-QL-Product-Line 37 | --------------------------------------------------- 38 | Product Line License allows a given company ("Licensee") to embed the 39 | specified type(s) of the QP Real-Time Event Framework(s) into any number 40 | of end-products within a family of related products (Product Line). Licensee 41 | can distribute/sell an unlimited number of units of each of those products 42 | (royalty-free licensing), for the life of the end-products within the 43 | Product Line. Product Line License applies to all end-products that do 44 | similar functions within the same Product Line. 45 | 46 | 47 | SPDX-License-Identifier: LicenseRef-QL-Any-Product 48 | -------------------------------------------------- 49 | Any-Product License allows a given company ("Licensee") to embed the 50 | specified type(s) of the QP Real-Time Event Framework(s) into any end- 51 | product of that company. The Licensee can distribute/sell an unlimited number 52 | of the products containing the licensed QP framework type(s) (royalty-free 53 | licensing). 54 | 55 | 56 | SPDX-License-Identifier: LicenseRef-QL-Site 57 | ------------------------------------------- 58 | Site-License allows a given company ("Licensee") to embed the specified 59 | type(s) of the QP Real-Time Event Framework(s) into any end-customer 60 | product, as long as the products are designed at a given physical location 61 | (Site), which must be defined in the license. This license gives the 62 | Licensee also limited sublicensing rights for its clients and is specifically 63 | designed for development contractors and consultants, who develop embedded 64 | software for other companies. 65 | 66 | 67 | SPDX-License-Identifier: LicenseRef-QL-OEM 68 | ------------------------------------------ 69 | OEM License allows a given company ("Licensee") to embed the specified 70 | type(s) of the QP Real-Time Event Framework(s) in any product of that 71 | company (Original Equipment Manufacturer) and gives limited sublicensing 72 | rights to system integrators, subsystem vendors, subcontractors, and other 73 | affiliates. OEM licenses are customizable to match exactly the specific 74 | licensing needs of a given Licensee. 75 | 76 | 77 | SPDX-License-Identifier: LicenseRef-QL-Eval 78 | ------------------------------------------- 79 | Evaluation License allows a specific company ("Licensee") to temporarily 80 | use the specified type(s) of the QP Real-Time Event Framework(s) for 81 | in-house evaluation. This license expressly prohibits any distribution 82 | of the licensed QP software. 83 | 84 | 85 | **** 86 | NOTE: Please use the contact information below to find the current prices 87 | of the Quantum Leaps commercial licenses and to request the license 88 | agreements and price quotes. 89 | **** 90 | 91 | Contact Information: 92 | ==================== 93 | - https://www.state-machine.com/licensing 94 | - mailto:info@state-machine.com 95 | -------------------------------------------------------------------------------- /LICENSES/LicenseRef-QL-dual.qlc: -------------------------------------------------------------------------------- 1 | public 2 | qpc 3 | 2025-12-31 4 | 5 | Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 6 | 7 | Q u a n t u m L e a P s 8 | ------------------------ 9 | Modern Embedded Software 10 | 11 | SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 12 | 13 | This software is dual-licensed under the terms of the open-source GNU 14 | General Public License (GPL) or, alternatively under the terms of one of 15 | the closed-source Quantum Leaps commercial licenses. 16 | 17 | Redistributions in source code must retain this top-level comment block. 18 | Plagiarizing this software to sidestep the license obligations is illegal. 19 | 20 | NOTE: 21 | The GPL does NOT permit the incorporation of this code into proprietary 22 | programs. Please contact Quantum Leaps for commercial licensing options, 23 | which expressly supersede the GPL and are designed explicitly for 24 | closed-source distribution. 25 | 26 | Quantum Leaps contact information: 27 | 28 | 29 | #1671FF5623AF7CA93973FA6EC044A008F7F65702 -------------------------------------------------------------------------------- /LICENSES/QP-Arduino_GPL_Exception.txt: -------------------------------------------------------------------------------- 1 | QP/C++ and QP-nano FRAMEWORK EXCEPTION FOR ARDUINO 2 | 3 | Version 3.0, December 22, 2021 4 | 5 | Copyright (c) 2005-2021 Quantum Leaps, LLC. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this 8 | license document, but changing it is not allowed. 9 | 10 | This QP/C++ and QP-nano Framework Exception for Arduino ("Exception") 11 | is an additional permission under section 7 of the GNU General Public 12 | License, version 3 ("GPLv3"). It applies to the QP/C++ and QP-nano 13 | source code (the "QP Frameworks") that is distributed as part of the 14 | QP-Arduino Support Package. 15 | 16 | When you use QP/C++ or QP-nano Frameworks inside your program, the frameworks' 17 | code is combined with your code of the program. The purpose of this Exception 18 | is to allow non-GPL (including proprietary) programs to use, in this way, the 19 | QP Frameworks' code covered by this Exception. 20 | 21 | 0. Definitions. 22 | "QP Frameworks" are lightweight real-time event frameworks (RTEFs) 23 | as well as all supporting ports and examples, as distributed from: 24 | and 25 | 26 | 27 | "Arduino-Certified Board" means any board with an Arduino-supported 28 | CPU that bears an official Arduino logo and/or is officially certified 29 | under the Arduino Certified Program 30 | (see ). 31 | 32 | "Target Code" refers to output from any compiler and linker in 33 | executable form suitable for execution by an embedded microcontroller. 34 | 35 | 36 | 1. Grant of Additional Permission 37 | As a special Exception, the copyright holder of QP Frameworks gives you 38 | permission to propagate a work of Target Code formed by combining 39 | the QP Frameworks with your own source code without the requirement 40 | to expose your proprietary source code, provided that all Target Code 41 | will execute on Arduino-Certified Board(s). 42 | 43 | 2. No Weakening of GPL 44 | The availability of this Exception does not imply any general 45 | presumption that third-party software linking to the QP Framework is 46 | unaffected by the copyleft requirements of the GPLv3 license. 47 | -------------------------------------------------------------------------------- /LICENSES/QP-RasPi_GPL_Exception.txt: -------------------------------------------------------------------------------- 1 | QP/C and QP/C++ FRAMEWORKS EXCEPTION FOR RASPBERRY PI 2 | 3 | Version 2.0, 2 August 2022 4 | 5 | Copyright (c) 2005-2021 Quantum Leaps, LLC. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this 8 | license document, but changing it is not allowed. 9 | 10 | This QP/C and QP/C++ Framework Exception for Raspberry Pi ("Exception") 11 | is an additional permission under section 7 of the GNU General Public 12 | License, version 3 ("GPLv3"). It applies to the QP/C and QP/C++ source 13 | code (the "QP Frameworks"). 14 | 15 | When you use QP Frameworks inside your program, the QP Frameworks' code 16 | is combined with your code of the program. The purpose of this Exception 17 | is to allow non-GPL (including proprietary) programs to use, in this way, 18 | the QP Frameworks' code covered by this Exception. 19 | 20 | 0. Definitions. 21 | "QP Frameworks" are lightweight real-time event frameworks (RTEFs) 22 | as well as all supporting ports and examples, as distributed from: 23 | and 24 | 25 | 26 | "Raspberry Pi" is a low cost, credit-card sized computer that is designed 27 | by the Raspberry Pi Foundation based in the UK and registered as UK 28 | educational charity under the number 1129409. For the purpose of this 29 | license, Raspberry Pi means only genuine Raspberry Pi computer bearing 30 | the Raspberry Pi logo, as described at: 31 | . 32 | 33 | "Target Code" refers to output from any compiler and linker in executable 34 | form suitable for execution by Raspberry Pi. 35 | 36 | 37 | 1. Grant of Additional Permission 38 | As a special Exception, the copyright holder of QP Frameworks gives you 39 | permission to propagate a work of Target Code formed by combining the 40 | QP/C or QP/C++ Frameworks with your own source code without the requirement 41 | to expose your propriatory source code, provided that all Target Code will 42 | execute on a genuine Raspberry Pi computer(s). 43 | 44 | 2. No Weakening of GPL 45 | The availability of this Exception does not imply any general 46 | presumption that third-party software linking to the QP Framework is 47 | unaffected by the copyleft requirements of the GPLv3 license. 48 | -------------------------------------------------------------------------------- /LICENSES/QP-mbed_GPL_Exception.txt: -------------------------------------------------------------------------------- 1 | QP/C and QP/C++ FRAMEWORKS EXCEPTION FOR ARM mbed 2 | 3 | Version 2.0, August 2022 4 | 5 | Copyright (c) 2005-2014 Quantum Leaps, LLC. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this 8 | license document, but changing it is not allowed. 9 | 10 | This QP/C and QP/C++ Framework Exception for ARM mbed ("Exception") 11 | is an additional permission under section 7 of the GNU General Public 12 | License, version 3 ("GPLv3"). It applies to the QP/C and QP/C++ source 13 | code (the "QP Frameworks"). 14 | 15 | When you use QP Frameworks inside your program, the QP Frameworks' code 16 | is combined with your code of the program. The purpose of this Exception 17 | is to allow non-GPL (including proprietary) programs to use, in this way, 18 | the QP Frameworks' code covered by this Exception. 19 | 20 | 0. Definitions. 21 | "QP Frameworks" are lightweight real-time event frameworks (RTEFs) 22 | as well as all supporting ports and examples, as distributed from: 23 | and 24 | 25 | 26 | "mbed-Enabled Board" means any board with an ARM Cortex-M CPU that is listed 27 | on the official "mbed platforms" website . 28 | 29 | 30 | 1. Grant of Additional Permission 31 | As a special Exception, the copyright holder of QP Frameworks gives you 32 | permission to propagate a work of Target Code formed by combining the 33 | QP/C or QP/C++ Frameworks with your own source code without the requirement 34 | to expose your propriatory source code, provided that all Target Code will 35 | execute on an "mbed-Enabled Board". 36 | 37 | 2. No Weakening of GPL 38 | The availability of this Exception does not imply any general 39 | presumption that third-party software linking to the QP Framework is 40 | unaffected by the copyleft requirements of the GPLv3 license. 41 | -------------------------------------------------------------------------------- /include/README.md: -------------------------------------------------------------------------------- 1 | # Files Missing from the QP/C GPL Distribution 2 | Due to the widespread non-compliance with the GPL, as well as infringement 3 | on the [dual-licensing model of QP frameworks][Lic], the following files 4 | have been **removed from the open-source GPL distribution**: 5 | 6 | ``` 7 | qpc 8 | | 9 | +---include 10 | | qs.h 11 | | qs_pkg.h 12 | | qxk.h 13 | | 14 | \---src 15 | | 16 | +---qs 17 | | qs.c 18 | | qs_64bit.c 19 | | qs_fp.c 20 | | qs_rx.c 21 | | qutest.c 22 | | 23 | \---qxk 24 | qxk.c 25 | qxk_mutex.c 26 | qxk_sema.c 27 | qxk_xthr.c 28 | ``` 29 | 30 | > NOTE: These files are available to the [commercial licensees][Cust] with 31 | the active Support Term. Please contact [Quantum Leaps technical support][Sup] 32 | to get the complete QP/C framework distribution. 33 | 34 | # QP/C Framework Evaluation 35 | To request **evaluation** of the complete QP/C framework, please contact 36 | Quantum Leaps at: 37 | - https://www.state-machine.com/contact 38 | 39 | # Quantum Leaps Licensing: 40 | To learn more about the open source and commercial licensing options: 41 | - https://www.state-machine.com/licensing 42 | 43 | [Lic]: 44 | [Cust]: 45 | [Sup]: 46 | -------------------------------------------------------------------------------- /include/qequeue.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QEQUEUE_H_ 30 | #define QEQUEUE_H_ 31 | 32 | #ifndef QF_EQUEUE_CTR_SIZE 33 | #define QF_EQUEUE_CTR_SIZE 1U 34 | #endif 35 | 36 | #if (QF_EQUEUE_CTR_SIZE == 1U) 37 | typedef uint8_t QEQueueCtr; 38 | #elif (QF_EQUEUE_CTR_SIZE == 2U) 39 | typedef uint16_t QEQueueCtr; 40 | #else 41 | #error QF_EQUEUE_CTR_SIZE defined incorrectly, expected 1U or 2U 42 | #endif 43 | 44 | struct QEvt; // forward declaration 45 | 46 | //============================================================================ 47 | //! @class QEQueue 48 | typedef struct QEQueue { 49 | struct QEvt const * volatile frontEvt; //!< @private @memberof QEQueue 50 | struct QEvt const * * ring; //!< @private @memberof QEQueue 51 | QEQueueCtr end; //!< @private @memberof QEQueue 52 | QEQueueCtr volatile head; //!< @private @memberof QEQueue 53 | QEQueueCtr volatile tail; //!< @private @memberof QEQueue 54 | QEQueueCtr volatile nFree; //!< @private @memberof QEQueue 55 | QEQueueCtr nMin; //!< @private @memberof QEQueue 56 | } QEQueue; 57 | 58 | //! @public @memberof QEQueue 59 | void QEQueue_init(QEQueue * const me, 60 | struct QEvt const * * const qSto, 61 | uint_fast16_t const qLen); 62 | 63 | //! @public @memberof QEQueue 64 | bool QEQueue_post(QEQueue * const me, 65 | struct QEvt const * const e, 66 | uint_fast16_t const margin, 67 | uint_fast8_t const qsId); 68 | 69 | //! @public @memberof QEQueue 70 | void QEQueue_postLIFO(QEQueue * const me, 71 | struct QEvt const * const e, 72 | uint_fast8_t const qsId); 73 | 74 | //! @public @memberof QEQueue 75 | struct QEvt const * QEQueue_get(QEQueue * const me, 76 | uint_fast8_t const qsId); 77 | 78 | //! @public @memberof QEQueue 79 | static inline QEQueueCtr QEQueue_getNFree(QEQueue const * const me) { 80 | return me->nFree; 81 | } 82 | 83 | //! @public @memberof QEQueue 84 | static inline QEQueueCtr QEQueue_getNMin(QEQueue const * const me) { 85 | return me->nMin; 86 | } 87 | 88 | //! @public @memberof QEQueue 89 | static inline bool QEQueue_isEmpty(QEQueue const * const me) { 90 | return me->frontEvt == (struct QEvt *)0; 91 | } 92 | 93 | #endif // QEQUEUE_H_ 94 | -------------------------------------------------------------------------------- /include/qk.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QK_H_ 30 | #define QK_H_ 31 | 32 | //============================================================================ 33 | //! @class QK 34 | typedef struct QK { 35 | //! @cond INTERNAL 36 | uint8_t dummy; 37 | //! @endcond 38 | } QK; 39 | 40 | typedef uint_fast8_t QSchedStatus; 41 | 42 | //============================================================================ 43 | //! @class QK_Attr 44 | typedef struct { 45 | QPSet readySet; //!< @memberof QK_Attr 46 | uint_fast8_t actPrio; //!< @memberof QK_Attr 47 | uint_fast8_t nextPrio; //!< @memberof QK_Attr 48 | uint_fast8_t actThre; //!< @memberof QK_Attr 49 | uint_fast8_t lockCeil; //!< @memberof QK_Attr 50 | uint_fast8_t intNest; //!< @memberof QK_Attr 51 | } QK_Attr; 52 | 53 | //! @static @private @memberof QK 54 | extern QK_Attr QK_priv_; 55 | 56 | //! @static @private @memberof QK 57 | uint_fast8_t QK_sched_(void); 58 | 59 | //! @static @private @memberof QK 60 | uint_fast8_t QK_sched_act_( 61 | QActive const * const act, 62 | uint_fast8_t const pthre_in); 63 | 64 | //! @static @private @memberof QK 65 | void QK_activate_(void); 66 | 67 | //! @static @public @memberof QK 68 | QSchedStatus QK_schedLock(uint_fast8_t const ceiling); 69 | 70 | //! @static @public @memberof QK 71 | void QK_schedUnlock(QSchedStatus const prevCeil); 72 | 73 | //! @static @public @memberof QK 74 | void QK_onIdle(void); 75 | 76 | //============================================================================ 77 | // interface used only for internal implementation, but not in applications 78 | #ifdef QP_IMPL 79 | 80 | // scheduler locking for QK... 81 | #define QF_SCHED_STAT_ QSchedStatus lockStat_; 82 | #define QF_SCHED_LOCK_(ceil_) do { \ 83 | if (QK_ISR_CONTEXT_()) { \ 84 | lockStat_ = 0xFFU; \ 85 | } else { \ 86 | lockStat_ = QK_schedLock((ceil_)); \ 87 | } \ 88 | } while (false) 89 | 90 | #define QF_SCHED_UNLOCK_() do { \ 91 | if (lockStat_ != 0xFFU) { \ 92 | QK_schedUnlock(lockStat_); \ 93 | } \ 94 | } while (false) 95 | 96 | // QActive event queue customization for QK... 97 | #define QACTIVE_EQUEUE_WAIT_(me_) ((void)0) 98 | #define QACTIVE_EQUEUE_SIGNAL_(me_) do { \ 99 | QPSet_insert(&QK_priv_.readySet, (uint_fast8_t)(me_)->prio); \ 100 | if (!QK_ISR_CONTEXT_()) { \ 101 | if (QK_sched_() != 0U) { \ 102 | QK_activate_(); \ 103 | } \ 104 | } \ 105 | } while (false) 106 | 107 | // QF event pool customization for QK... 108 | #define QF_EPOOL_TYPE_ QMPool 109 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 110 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 111 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 112 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 113 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 114 | #define QF_EPOOL_PUT_(p_, e_, qsId_) \ 115 | (QMPool_put(&(p_), (e_), (qsId_))) 116 | 117 | #endif // QP_IMPL 118 | 119 | #endif // QK_H_ 120 | -------------------------------------------------------------------------------- /include/qmpool.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QMPOOL_H_ 30 | #define QMPOOL_H_ 31 | 32 | #ifndef QF_MPOOL_SIZ_SIZE 33 | #define QF_MPOOL_SIZ_SIZE 2U 34 | #endif 35 | #ifndef QF_MPOOL_CTR_SIZE 36 | #define QF_MPOOL_CTR_SIZE 2U 37 | #endif 38 | 39 | #define QF_MPOOL_EL(evType_) struct { \ 40 | void * sto_[((sizeof(evType_) - 1U) / sizeof(void *)) + \ 41 | (sizeof(evType_) < (2U * sizeof(void *)) ? 2U : 1U)]; \ 42 | } 43 | 44 | #if (QF_MPOOL_SIZ_SIZE == 1U) 45 | typedef uint8_t QMPoolSize; 46 | #elif (QF_MPOOL_SIZ_SIZE == 2U) 47 | typedef uint16_t QMPoolSize; 48 | #elif (QF_MPOOL_SIZ_SIZE == 4U) 49 | typedef uint32_t QMPoolSize; 50 | #else 51 | #error QF_MPOOL_SIZ_SIZE defined incorrectly, expected 1U, 2U, or 4U 52 | #endif 53 | 54 | #if (QF_MPOOL_CTR_SIZE == 1U) 55 | typedef uint8_t QMPoolCtr; 56 | #elif (QF_MPOOL_CTR_SIZE == 2U) 57 | typedef uint16_t QMPoolCtr; 58 | #elif (QF_MPOOL_CTR_SIZE == 4U) 59 | typedef uint32_t QMPoolCtr; 60 | #else 61 | #error QF_MPOOL_CTR_SIZE defined incorrectly, expected 1U, 2U, or 4U 62 | #endif 63 | 64 | //============================================================================ 65 | //! @class QMPool 66 | typedef struct { 67 | void * * start; //!< @private @memberof QMPool 68 | void * * end; //!< @private @memberof QMPool 69 | void * * volatile freeHead; //!< @private @memberof QMPool 70 | QMPoolSize blockSize; //!< @private @memberof QMPool 71 | QMPoolCtr nTot; //!< @private @memberof QMPool 72 | QMPoolCtr volatile nFree; //!< @private @memberof QMPool 73 | QMPoolCtr nMin; //!< @private @memberof QMPool 74 | } QMPool; 75 | 76 | //! @public @memberof QMPool 77 | void QMPool_init(QMPool * const me, 78 | void * const poolSto, 79 | uint_fast32_t const poolSize, 80 | uint_fast16_t const blockSize); 81 | 82 | //! @public @memberof QMPool 83 | void * QMPool_get(QMPool * const me, 84 | uint_fast16_t const margin, 85 | uint_fast8_t const qsId); 86 | 87 | //! @public @memberof QMPool 88 | void QMPool_put(QMPool * const me, 89 | void * const block, 90 | uint_fast8_t const qsId); 91 | 92 | #endif // QMPOOL_H_ 93 | -------------------------------------------------------------------------------- /include/qp_pkg.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PKG_H_ 30 | #define QP_PKG_H_ 31 | 32 | //============================================================================ 33 | #define QACTIVE_CAST_(ptr_) ((QActive *)(ptr_)) 34 | #define Q_PTR2UINT_CAST_(ptr_) ((uintptr_t)(ptr_)) 35 | 36 | //============================================================================ 37 | typedef struct { 38 | #if (QF_MAX_EPOOL > 0U) 39 | QF_EPOOL_TYPE_ ePool_[QF_MAX_EPOOL]; //!< @private @memberof QF_Attr 40 | uint_fast8_t maxPool_; //!< @private @memberof QF_Attr 41 | #else 42 | uint8_t dummy; //!< @private @memberof QF_Attr 43 | #endif // (QF_MAX_EPOOL == 0U) 44 | } QF_Attr; 45 | 46 | extern QF_Attr QF_priv_; //!< @static @private @memberof QF 47 | 48 | //! @static @private @memberof QF 49 | void QF_bzero_( 50 | void * const start, 51 | uint_fast16_t const len); 52 | 53 | //============================================================================ 54 | // Bitmasks are for the QTimeEvt::flags attribute 55 | #define QTE_FLAG_IS_LINKED (1U << 7U) 56 | #define QTE_FLAG_WAS_DISARMED (1U << 6U) 57 | 58 | //============================================================================ 59 | //! @private @memberof QEvt 60 | static inline void QEvt_refCtr_inc_(QEvt const * const me) { 61 | // NOTE: this function must be called inside a critical section 62 | uint8_t const rc = me->refCtr_ + 1U; 63 | ((QEvt *)me)->refCtr_ = rc; // cast away 'const' 64 | } 65 | 66 | //! @private @memberof QEvt 67 | static inline void QEvt_refCtr_dec_(QEvt const * const me) { 68 | // NOTE: this function must be called inside a critical section 69 | uint8_t const rc = me->refCtr_ - 1U; 70 | ((QEvt *)me)->refCtr_ = rc; // cast away 'const' 71 | } 72 | 73 | #endif // QP_PKG_H_ 74 | -------------------------------------------------------------------------------- /include/qs_dummy.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QS_DUMMY_H_ 30 | #define QS_DUMMY_H_ 31 | 32 | #ifdef Q_SPY 33 | #error Q_SPY must NOT be defined to include qs_dummy.h 34 | #endif 35 | 36 | #ifdef Q_UTEST 37 | #error Q_UTEST must NOT be defined to include qs_dummy.h 38 | #endif 39 | 40 | #define QS_INIT(arg_) ((uint8_t)1U) 41 | #define QS_EXIT() ((void)0) 42 | #define QS_DUMP() ((void)0) 43 | #define QS_GLB_FILTER(rec_) ((void)0) 44 | #define QS_LOC_FILTER(qsId_) ((void)0) 45 | 46 | #define QS_BEGIN_ID(rec_, qsId_) if (false) { 47 | #define QS_END() } 48 | #define QS_BEGIN_INCRIT(rec_, qsId_) if (false) { 49 | #define QS_END_INCRIT() } 50 | 51 | #define QS_I8(width_, data_) ((void)0) 52 | #define QS_U8(width_, data_) ((void)0) 53 | #define QS_I16(width_, data_) ((void)0) 54 | #define QS_U16(width_, data_) ((void)0) 55 | #define QS_I32(width_, data_) ((void)0) 56 | #define QS_U32(width_, data_) ((void)0) 57 | #define QS_F32(width_, data_) ((void)0) 58 | #define QS_F64(width_, data_) ((void)0) 59 | #define QS_I64(width_, data_) ((void)0) 60 | #define QS_U64(width_, data_) ((void)0) 61 | #define QS_ENUM(group_, value_) ((void)0) 62 | #define QS_STR(str_) ((void)0) 63 | #define QS_MEM(mem_, size_) ((void)0) 64 | #define QS_SIG(sig_, obj_) ((void)0) 65 | #define QS_OBJ(obj_) ((void)0) 66 | #define QS_FUN(fun_) ((void)0) 67 | 68 | #define QS_SIG_DICTIONARY(sig_, obj_) ((void)0) 69 | #define QS_OBJ_DICTIONARY(obj_) ((void)0) 70 | #define QS_OBJ_ARR_DICTIONARY(obj_, idx_) ((void)0) 71 | #define QS_FUN_DICTIONARY(fun_) ((void)0) 72 | #define QS_USR_DICTIONARY(rec_) ((void)0) 73 | #define QS_ENUM_DICTIONARY(value_, group_) ((void)0) 74 | #define QS_ASSERTION(module_, loc_, delay_) ((void)0) 75 | #define QS_FLUSH() ((void)0) 76 | 77 | #define QS_TEST_PROBE_DEF(fun_) 78 | #define QS_TEST_PROBE(code_) 79 | #define QS_TEST_PROBE_ID(id_, code_) 80 | #define QS_TEST_PAUSE() ((void)0) 81 | 82 | #define QS_OUTPUT() ((void)0) 83 | #define QS_RX_INPUT() ((void)0) 84 | #define QS_RX_PUT(b_) ((void)0) 85 | #define QS_ONLY(code_) ((void)0) 86 | 87 | //============================================================================ 88 | // interface used only for internal implementation, but not in applications 89 | #ifdef QP_IMPL 90 | // predefined QS trace records 91 | #define QS_BEGIN_PRE(rec_, qsId_) if (false) { 92 | #define QS_END_PRE() } 93 | #define QS_U8_PRE(data_) ((void)0) 94 | #define QS_2U8_PRE(data1_, data2_) ((void)0) 95 | #define QS_U16_PRE(data_) ((void)0) 96 | #define QS_U32_PRE(data_) ((void)0) 97 | #define QS_TIME_PRE() ((void)0) 98 | #define QS_SIG_PRE(sig_) ((void)0) 99 | #define QS_EVS_PRE(size_) ((void)0) 100 | #define QS_OBJ_PRE(obj_) ((void)0) 101 | #define QS_FUN_PRE(fun_) ((void)0) 102 | #define QS_EQC_PRE(ctr_) ((void)0) 103 | #define QS_MPC_PRE(ctr_) ((void)0) 104 | #define QS_MPS_PRE(size_) ((void)0) 105 | #define QS_TEC_PRE(ctr_) ((void)0) 106 | 107 | #define QS_CRIT_STAT 108 | #define QS_CRIT_ENTRY() ((void)0) 109 | #define QS_CRIT_EXIT() ((void)0) 110 | 111 | #define QS_TR_CRIT_ENTRY() ((void)0) 112 | #define QS_TR_CRIT_EXIT() ((void)0) 113 | #define QS_TR_ISR_ENTRY(isrnest_, prio_) ((void)0) 114 | #define QS_TR_ISR_EXIT(isrnest_, prio_) ((void)0) 115 | #endif // QP_IMPL 116 | 117 | #endif // QS_DUMMY_H_ 118 | -------------------------------------------------------------------------------- /include/qsafe.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C/C++ Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QSAFE_H_ 30 | #define QSAFE_H_ 31 | 32 | // QF-FuSa enabled =========================================================== 33 | #ifndef Q_UNSAFE 34 | 35 | #ifndef QF_CRIT_STAT 36 | #define QF_CRIT_STAT 37 | #endif 38 | 39 | #ifndef QF_CRIT_ENTRY 40 | #define QF_CRIT_ENTRY() ((void)0) 41 | #endif 42 | 43 | #ifndef QF_CRIT_EXIT 44 | #define QF_CRIT_EXIT() ((void)0) 45 | #endif 46 | 47 | #ifndef QF_CRIT_EST 48 | #define QF_CRIT_EST() ((void)0) 49 | #endif 50 | 51 | #define Q_DEFINE_THIS_MODULE(name_) \ 52 | static char const Q_this_module_[] = name_; 53 | 54 | #define Q_ASSERT_INCRIT(id_, expr_) \ 55 | ((expr_) ? ((void)0) : Q_onError(&Q_this_module_[0], (id_))) 56 | 57 | #define Q_ERROR_INCRIT(id_) \ 58 | (Q_onError(&Q_this_module_[0], (id_))) 59 | 60 | #define Q_ASSERT_ID(id_, expr_) do { \ 61 | QF_CRIT_STAT \ 62 | QF_CRIT_ENTRY(); \ 63 | if (!(expr_)) Q_onError(&Q_this_module_[0], (id_)); \ 64 | QF_CRIT_EXIT(); \ 65 | } while (false) 66 | 67 | #define Q_ERROR_ID(id_) do { \ 68 | QF_CRIT_EST(); \ 69 | Q_onError(&Q_this_module_[0], (id_)); \ 70 | } while (false) 71 | 72 | #define Q_ASSERT_LOCAL(id_, expr_) do { \ 73 | if (!(expr_)) { \ 74 | QF_CRIT_EST(); \ 75 | Q_onError(&Q_this_module_[0], (id_)); \ 76 | } \ 77 | } while (false) 78 | 79 | // QF-FuSa disabled ========================================================== 80 | #else 81 | 82 | #define Q_DEFINE_THIS_MODULE(name_) 83 | #define Q_ASSERT_INCRIT(id_, expr_) ((void)0) 84 | #define Q_ERROR_INCRIT(id_) ((void)0) 85 | #define Q_ASSERT_ID(id_, expr_) ((void)0) 86 | #define Q_ERROR_ID(id_) ((void)0) 87 | #define Q_ASSERT_LOCAL(id_, expr_) ((void)0) 88 | 89 | #endif // QF-FuSa disabled 90 | 91 | //============================================================================ 92 | #define Q_DEFINE_THIS_FILE Q_DEFINE_THIS_MODULE(__FILE__) 93 | #define Q_ASSERT(expr_) Q_ASSERT_ID(__LINE__, (expr_)) 94 | #define Q_ERROR() Q_ERROR_ID(__LINE__) 95 | 96 | #define Q_REQUIRE(expr_) Q_ASSERT(expr_) 97 | #define Q_REQUIRE_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) 98 | #define Q_REQUIRE_INCRIT(id_, expr_) Q_ASSERT_INCRIT((id_), (expr_)) 99 | #define Q_REQUIRE_LOCAL(id_, expr_) Q_ASSERT_LOCAL((id_), (expr_)) 100 | 101 | #define Q_ENSURE(expr_) Q_ASSERT(expr_) 102 | #define Q_ENSURE_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) 103 | #define Q_ENSURE_INCRIT(id_, expr_) Q_ASSERT_INCRIT((id_), (expr_)) 104 | #define Q_ENSURE_LOCAL(id_, expr_) Q_ASSERT_LOCAL((id_), (expr_)) 105 | 106 | #define Q_INVARIANT(expr_) Q_ASSERT(expr_) 107 | #define Q_INVARIANT_ID(id_, expr_) Q_ASSERT_ID((id_), (expr_)) 108 | #define Q_INVARIANT_INCRIT(id_, expr_) Q_ASSERT_INCRIT((id_), (expr_)) 109 | #define Q_INVARIANT_LOCAL(id_, expr_) Q_ASSERT_LOCAL((id_), (expr_)) 110 | 111 | #define Q_ERROR_LOCAL(id_) Q_ERROR_ID(id_) 112 | 113 | #ifndef Q_ASSERT_STATIC 114 | #define Q_ASSERT_STATIC(expr_) extern char Q_static_assert_[(expr_) ? 1 : -1] 115 | #endif // ndef Q_ASSERT_STATIC 116 | 117 | #ifndef Q_NORETURN 118 | #define Q_NORETURN _Noreturn void 119 | #endif // ndef Q_NORETURN 120 | 121 | // Is this header file used outside QP? 122 | #ifndef QP_VERSION 123 | #define Q_DIM(array_) (sizeof(array_) / sizeof((array_)[0U])) 124 | #endif // ndef QP_VERSION 125 | 126 | //============================================================================ 127 | #ifdef __cplusplus 128 | extern "C" { 129 | #endif 130 | 131 | #ifndef QP_VERSION 132 | typedef int int_t; 133 | #endif // ndef QP_VERSION 134 | 135 | Q_NORETURN Q_onError( 136 | char const * const module, 137 | int_t const id); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif // QSAFE_H_ 144 | -------------------------------------------------------------------------------- /include/qstamp.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QSTAMP_H_ 30 | #define QSTAMP_H_ 31 | 32 | extern char const Q_BUILD_DATE[12]; 33 | extern char const Q_BUILD_TIME[9]; 34 | 35 | #endif // QSTAMP_H_ 36 | -------------------------------------------------------------------------------- /include/qv.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QV_H_ 30 | #define QV_H_ 31 | 32 | //============================================================================ 33 | //! @class QV 34 | typedef struct QV { 35 | //! @cond INTERNAL 36 | uint8_t dummy; 37 | //! @endcond 38 | } QV; 39 | 40 | //============================================================================ 41 | //! @class QV_Attr 42 | typedef struct { 43 | QPSet readySet; //!< @private @memberof QV_Attr 44 | uint_fast8_t schedCeil; //!< @private @memberof QV_Attr 45 | } QV_Attr; 46 | 47 | //! @static @private @memberof QV 48 | extern QV_Attr QV_priv_; 49 | 50 | //! @static @public @memberof QV 51 | void QV_schedDisable(uint_fast8_t const ceiling); 52 | 53 | //! @static @public @memberof QV 54 | void QV_schedEnable(void); 55 | 56 | //! @static @public @memberof QV 57 | void QV_onIdle(void); 58 | 59 | //============================================================================ 60 | // interface used only for internal implementation, but not in applications 61 | #ifdef QP_IMPL 62 | 63 | // scheduler locking for QV (not needed)... 64 | #define QF_SCHED_STAT_ 65 | #define QF_SCHED_LOCK_(dummy) ((void)0) 66 | #define QF_SCHED_UNLOCK_() ((void)0) 67 | 68 | // QActive event queue customization for QV... 69 | #define QACTIVE_EQUEUE_WAIT_(me_) ((void)0) 70 | #define QACTIVE_EQUEUE_SIGNAL_(me_) \ 71 | QPSet_insert(&QV_priv_.readySet, (uint_fast8_t)(me_)->prio) 72 | 73 | // QF event pool customization for QV... 74 | #define QF_EPOOL_TYPE_ QMPool 75 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 76 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 77 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 78 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 79 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 80 | #define QF_EPOOL_PUT_(p_, e_, qsId_) (QMPool_put(&(p_), (e_), (qsId_))) 81 | 82 | #endif // QP_IMPL 83 | 84 | #endif // QV_H_ 85 | -------------------------------------------------------------------------------- /ports/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # CMake the qpc libraries for different targets 2 | set(PORT_DIR ${PORT}) 3 | if((PORT STREQUAL win32) OR (PORT STREQUAL posix)) 4 | if(QPC_CFG_UNIT_TEST) 5 | set(PORT_DIR ${PORT_DIR}-qutest) 6 | elseif(KERNEL STREQUAL qv) 7 | set(PORT_DIR ${PORT_DIR}-qv) 8 | endif() 9 | endif() 10 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PORT_DIR}) 11 | message(STATUS "Found port dir - './${PORT_DIR}' for port ${PORT}, KERNEL ${KERNEL}") 12 | else() 13 | message(FATAL_ERROR "Target port dir '${CMAKE_CURRENT_SOURCE_DIR}/${PORT_DIR}' not found!") 14 | endif() 15 | 16 | add_subdirectory(${PORT_DIR}) 17 | if(NOT QPC_CFG_QPCONFIG_H_INCLUDE_PATH) 18 | set(QPC_CFG_QPCONFIG_H_INCLUDE_PATH config) 19 | endif() 20 | target_include_directories(qpc PUBLIC ${QPC_CFG_QPCONFIG_H_INCLUDE_PATH}) 21 | -------------------------------------------------------------------------------- /ports/README.md: -------------------------------------------------------------------------------- 1 | # Files Missing from the QP/C GPL Distribution 2 | Due to the growing non-compliance with the GPL as well as infringement 3 | on the dual-licensing model of QP frameworks, the following files have 4 | been **removed from the open-source GPL distribution**: 5 | 6 | ``` 7 | qpc 8 | | 9 | \---ports 10 | +---arm-cm 11 | | +---qxk 12 | | | +---armclang 13 | | | | qxk_port.c 14 | | | | qp_port.h 15 | | | | qs_port.h 16 | | | | 17 | | | +---config 18 | | | | qp_config.h 19 | | | | 20 | | | +---gnu 21 | | | | qxk_port.c 22 | | | | qp_port.h 23 | | | | qs_port.h 24 | | | | 25 | | | \---iar 26 | | | qxk_port.c 27 | | | qp_port.h 28 | | | qs_port.h 29 | | | 30 | | \---qutest 31 | | qp_port.h 32 | | qs_port.h 33 | | 34 | +---posix-qutest 35 | | qp_port.h 36 | | qs_port.h 37 | | qutest_port.c 38 | | safe_std.h 39 | | 40 | \---win32-qutest 41 | qp_port.h 42 | qs_port.h 43 | qutest_port.c 44 | safe_std.h 45 | ``` 46 | 47 | > NOTE: These files are available to the [commercial licensees][com] with 48 | current Support Term. Please contact [Quantum Leaps technical support][sup] 49 | to get the complete QP/C framework distribution. 50 | 51 | # QP/C Framework Evaluation 52 | To request **evaluation** of the complete QP/C framework, please contact 53 | Quantum Leaps at: 54 | 55 | - https://www.state-machine.com/contact 56 | - mailto:info@state-machine.com 57 | 58 | # Quantum Leaps Licensing: 59 | To learn more about the open source and commercial licensing options: 60 | - https://www.state-machine.com/licensing 61 | 62 | [com]: 63 | [sup]: 64 | -------------------------------------------------------------------------------- /ports/arm-cm/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/arm-cm 2 | string(TOLOWER ${CMAKE_C_COMPILER_ID} _compiler_) 3 | list (APPEND compList gnu iar armclang) 4 | if(NOT (${_compiler_} IN_LIST compList)) 5 | message(WARNING "no support for compiler '${_compiler_}'. Falling back to GNU. Just give it a try :)") 6 | set(_compiler_ gnu) 7 | endif() 8 | unset(compList) 9 | 10 | set(qx_port_c ${KERNEL}_port.c) 11 | 12 | if(QPC_CFG_UNIT_TEST) 13 | target_include_directories(qpc PUBLIC qutest) 14 | else() 15 | target_include_directories(qpc PUBLIC ${KERNEL}/${_compiler_}) 16 | endif() 17 | 18 | target_sources(qpc PRIVATE ${KERNEL}/${_compiler_}/${qx_port_c}) 19 | 20 | -------------------------------------------------------------------------------- /ports/arm-cm/README.md: -------------------------------------------------------------------------------- 1 | # Native QP/C Ports to ARM Cortex-M 2 | 3 | ## Supported ARM Cortex-M Architectures: 4 | 5 | - ARMv6-M (**ARM Cortex-M0/M0+**) 6 | - ARMv7-M (**ARM Cortex-M3/M4/M7**) 7 | - ARMv8-M (**ARM Cortex-M23/M33**) 8 | 9 | ## Supported QP/C Kernels and Toolchains: 10 | - [Cooperative QV kernel](https://www.state-machine.com/qpc/group__qv.html) 11 | + ARM/KEIL MDK, ARM Compiler 6 (ARM-CLANG) 12 | + IAR-ARM 13 | + GNU-ARM 14 | - [Preemptive, non-locking QK kernel](https://www.state-machine.com/qpc/group__qk.html) 15 | + ARM/KEIL MDK, ARM Compiler 6 (ARM-CLANG) 16 | + IAR-ARM 17 | + GNU-ARM 18 | - [Dual-mode (blocking/non-blocking) QXK kernel](https://www.state-machine.com/qpc/group__qxk.html) 19 | + ARM/KEIL MDK, ARM Compiler 6 (ARM-CLANG) 20 | + IAR-ARM 21 | + GNU-ARM 22 | 23 | ## Documentation: 24 | 25 | Detailed documentation for these ports is available in the QP/C Manual at: 26 | 27 | - https://www.state-machine.com/qpc/arm-cm.html 28 | -------------------------------------------------------------------------------- /ports/arm-cm/qk/armclang/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cm/qk/gnu/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cm/qk/gnu/syscalls.c: -------------------------------------------------------------------------------- 1 | // dummy system calls to eliminate the following GNU linker warning: 2 | // "warning: xxxx is not implemented and will always fail" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern int __io_putchar(int ch) __attribute__((weak)); 14 | extern int __io_getchar(void) __attribute__((weak)); 15 | 16 | char *__env[1] = { 0 }; 17 | char **environ = __env; 18 | 19 | void initialise_monitor_handles() { 20 | } 21 | int _getpid(void) { 22 | return 1; 23 | } 24 | int _kill(int pid, int sig) { 25 | (void)pid; 26 | (void)sig; 27 | errno = EINVAL; 28 | return -1; 29 | } 30 | void _exit (int status) { 31 | _kill(status, -1); 32 | while (1) { // do not return 33 | } 34 | } 35 | __attribute__((weak)) int _read(int file, char *ptr, int len) { 36 | (void)file; 37 | for (int i = len; i != 0; --i) { 38 | *ptr++ = __io_getchar(); 39 | } 40 | return len; 41 | } 42 | __attribute__((weak)) int _write(int file, char *ptr, int len) { 43 | (void)file; 44 | for (int i = len; i != 0; --i) { 45 | __io_putchar(*ptr++); 46 | } 47 | return len; 48 | } 49 | int _close(int file) { 50 | (void)file; 51 | return -1; 52 | } 53 | int _fstat(int file, struct stat *st) { 54 | (void)file; 55 | st->st_mode = S_IFCHR; 56 | return 0; 57 | } 58 | int _isatty(int file) { 59 | (void)file; 60 | return 1; 61 | } 62 | int _lseek(int file, int ptr, int dir) { 63 | (void)file; 64 | (void)ptr; 65 | (void)dir; 66 | return 0; 67 | } 68 | int _open(char *path, int flags, ...) { 69 | (void)path; 70 | (void)flags; 71 | return -1; 72 | } 73 | int _wait(int *status) { 74 | (void)status; 75 | errno = ECHILD; 76 | return -1; 77 | } 78 | int _unlink(char *name) { 79 | (void)name; 80 | errno = ENOENT; 81 | return -1; 82 | } 83 | int _times(struct tms *buf) { 84 | (void)buf; 85 | return -1; 86 | } 87 | int _stat(char *file, struct stat *st) { 88 | (void)file; 89 | st->st_mode = S_IFCHR; 90 | return 0; 91 | } 92 | int _link(char *old, char *new) { 93 | (void)old; 94 | (void)new; 95 | errno = EMLINK; 96 | return -1; 97 | } 98 | int _fork(void) { 99 | errno = EAGAIN; 100 | return -1; 101 | } 102 | int _execve(char *name, char **argv, char **env) { 103 | (void)name; 104 | (void)argv; 105 | (void)env; 106 | errno = ENOMEM; 107 | return -1; 108 | } 109 | -------------------------------------------------------------------------------- /ports/arm-cm/qk/iar/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cm/qv/armclang/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cm/qv/gnu/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cm/qv/gnu/syscalls.c: -------------------------------------------------------------------------------- 1 | // dummy system calls to eliminate the following GNU linker warning: 2 | // "warning: xxxx is not implemented and will always fail" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern int __io_putchar(int ch) __attribute__((weak)); 14 | extern int __io_getchar(void) __attribute__((weak)); 15 | 16 | char *__env[1] = { 0 }; 17 | char **environ = __env; 18 | 19 | void initialise_monitor_handles() { 20 | } 21 | int _getpid(void) { 22 | return 1; 23 | } 24 | int _kill(int pid, int sig) { 25 | (void)pid; 26 | (void)sig; 27 | errno = EINVAL; 28 | return -1; 29 | } 30 | void _exit (int status) { 31 | _kill(status, -1); 32 | while (1) { // do not return 33 | } 34 | } 35 | __attribute__((weak)) int _read(int file, char *ptr, int len) { 36 | (void)file; 37 | for (int i = len; i != 0; --i) { 38 | *ptr++ = __io_getchar(); 39 | } 40 | return len; 41 | } 42 | __attribute__((weak)) int _write(int file, char *ptr, int len) { 43 | (void)file; 44 | for (int i = len; i != 0; --i) { 45 | __io_putchar(*ptr++); 46 | } 47 | return len; 48 | } 49 | int _close(int file) { 50 | (void)file; 51 | return -1; 52 | } 53 | int _fstat(int file, struct stat *st) { 54 | (void)file; 55 | st->st_mode = S_IFCHR; 56 | return 0; 57 | } 58 | int _isatty(int file) { 59 | (void)file; 60 | return 1; 61 | } 62 | int _lseek(int file, int ptr, int dir) { 63 | (void)file; 64 | (void)ptr; 65 | (void)dir; 66 | return 0; 67 | } 68 | int _open(char *path, int flags, ...) { 69 | (void)path; 70 | (void)flags; 71 | return -1; 72 | } 73 | int _wait(int *status) { 74 | (void)status; 75 | errno = ECHILD; 76 | return -1; 77 | } 78 | int _unlink(char *name) { 79 | (void)name; 80 | errno = ENOENT; 81 | return -1; 82 | } 83 | int _times(struct tms *buf) { 84 | (void)buf; 85 | return -1; 86 | } 87 | int _stat(char *file, struct stat *st) { 88 | (void)file; 89 | st->st_mode = S_IFCHR; 90 | return 0; 91 | } 92 | int _link(char *old, char *new) { 93 | (void)old; 94 | (void)new; 95 | errno = EMLINK; 96 | return -1; 97 | } 98 | int _fork(void) { 99 | errno = EAGAIN; 100 | return -1; 101 | } 102 | int _execve(char *name, char **argv, char **env) { 103 | (void)name; 104 | (void)argv; 105 | (void)env; 106 | errno = ENOMEM; 107 | return -1; 108 | } 109 | -------------------------------------------------------------------------------- /ports/arm-cm/qv/iar/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/arm-cr 2 | string(TOLOWER ${CMAKE_C_COMPILER_ID} _compiler_) 3 | list (APPEND compList gnu iar ti) 4 | if(NOT (${_compiler_} IN_LIST compList)) 5 | message(WARNING "no support for compiler '${_compiler_}'. Falling back to GNU. Just give it a try :)") 6 | set(_compiler_ gnu) 7 | endif() 8 | unset(compList) 9 | 10 | if(NOT KERNEL MATCHES "q[vk]") 11 | message(WARNING "Kernel ${KERNEL} is not supported! Falling back to QV kernel") 12 | set(KERNEL qv) 13 | endif() 14 | target_include_directories(qpc PUBLIC ${KERNEL}/${_compiler_}) 15 | -------------------------------------------------------------------------------- /ports/arm-cr/qk/gnu/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cr/qk/iar/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cr/qk/ti/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cr/qv/gnu/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | // no-return function specifier (C11 Standard) 37 | #define Q_NORETURN _Noreturn void 38 | 39 | // QF configuration for QV -- data members of the QActive class... 40 | 41 | // QV event-queue used for AOs 42 | #define QACTIVE_EQUEUE_TYPE QEQueue 43 | 44 | // QF interrupt disable/enable, see NOTE2 45 | #ifdef __thumb__ // THUMB mode? 46 | 47 | #define QF_INT_DISABLE() __asm volatile ("cpsid i") 48 | #define QF_INT_ENABLE() __asm volatile ("cpsie i") 49 | #define QF_INT_ENABLE_ALL() __asm volatile ("cpsie if") 50 | 51 | #elif (defined __arm__) // ARM mode? 52 | 53 | #define QF_INT_DISABLE() \ 54 | __asm volatile ("MSR cpsr_c,#(0x1F | 0x80)" ::: "cc") 55 | #define QF_INT_ENABLE() \ 56 | __asm volatile ("MSR cpsr_c,#(0x1F)" ::: "cc") 57 | #define QF_INT_ENABLE_ALL() \ 58 | __asm volatile ("MSR cpsr_c,#(0x1F)" ::: "cc") 59 | #else 60 | #error Incorrect CPU mode. Must be either __arm__ or __thumb__. 61 | #endif 62 | 63 | // Cortex-R provide the CLZ instruction for fast LOG2 64 | #define QF_LOG2(n_) ((uint8_t)(32U - __builtin_clz(n_))) 65 | 66 | // QF critical section entry/exit, see NOTE3 67 | #define QF_CRIT_STAT uint32_t cpsr_; 68 | #define QF_CRIT_ENTRY() do { \ 69 | __asm volatile ("MRS %0,cpsr" : "=r" (cpsr_) :: "cc"); \ 70 | QF_INT_DISABLE(); \ 71 | } while (false) 72 | 73 | #define QF_CRIT_EXIT() \ 74 | __asm volatile ("MSR cpsr_c,%0" :: "r" (cpsr_) : "cc") 75 | 76 | #define QF_CRIT_EST() QF_INT_DISABLE() 77 | #define QF_CRIT_EXIT_NOP() __asm volatile ("ISB") 78 | 79 | // macro to put the CPU to sleep inside QV_onIdle() 80 | #define QV_CPU_SLEEP() do { \ 81 | __asm volatile ("WFI"); \ 82 | QF_INT_ENABLE(); \ 83 | } while (false) 84 | 85 | // include files ------------------------------------------------------------- 86 | #include "qequeue.h" // QV kernel uses the native QP event queue 87 | #include "qmpool.h" // QV kernel uses the native QP memory pool 88 | #include "qp.h" // QP framework 89 | #include "qv.h" // QV kernel 90 | 91 | //============================================================================ 92 | // NOTE2: 93 | // The FIQ-type interrupts are NEVER disabled in this port, so the FIQ is 94 | // a "kernel-unaware" interrupt. If the FIQ is ever used in the application, 95 | // it must be an "ARM FIQ"-type function. For this to work, the FIQ 96 | // stack needs to be initialized. 97 | // 98 | // NOTE3: 99 | // This port implements the "save and restore" interrupt status policy, 100 | // which again never disables the FIQ-type interrupts. This policy allows 101 | // for nesting critical sections, which is necessary inside IRQ-type 102 | // interrupts that run with interrupts (IRQ) disabled. 103 | // 104 | 105 | #endif // QP_PORT_H_ 106 | 107 | -------------------------------------------------------------------------------- /ports/arm-cr/qv/gnu/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cr/qv/iar/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include // IAR intrinsic functions 35 | #include "qp_config.h" // QP configuration from the application 36 | 37 | // no-return function specifier (C11 Standard) 38 | #define Q_NORETURN _Noreturn void 39 | 40 | // QF configuration for QV -- data members of the QActive class... 41 | 42 | // QV event-queue used for AOs 43 | #define QACTIVE_EQUEUE_TYPE QEQueue 44 | 45 | // QF interrupt disable/enable, see NOTE2 46 | #define QF_INT_DISABLE() __disable_irq() 47 | #define QF_INT_ENABLE() __enable_irq() 48 | #define QF_INT_ENABLE_ALL() __enable_interrupt() 49 | 50 | // Cortex-R provide the CLZ instruction for fast LOG2 51 | #define QF_LOG2(n_) ((uint8_t)(32U - __CLZ(n_))) 52 | 53 | // QF critical section entry/exit, see NOTE3 54 | #define QF_CRIT_STAT uint32_t cpsr_; 55 | #define QF_CRIT_ENTRY() do { \ 56 | cpsr_ = __get_CPSR(); \ 57 | QF_INT_DISABLE(); \ 58 | } while (false) 59 | #define QF_CRIT_EXIT() __set_CPSR(cpsr_) 60 | #define QF_CRIT_EST() QF_INT_DISABLE() 61 | #define QF_CRIT_EXIT_NOP() __ISB() 62 | 63 | // macro to put the CPU to sleep inside QV_onIdle() 64 | #define QV_CPU_SLEEP() do { \ 65 | __WFI(); \ 66 | QF_INT_ENABLE(); \ 67 | } while (false) 68 | 69 | // include files ------------------------------------------------------------- 70 | #include "qequeue.h" // QV kernel uses the native QP event queue 71 | #include "qmpool.h" // QV kernel uses the native QP memory pool 72 | #include "qp.h" // QP framework 73 | #include "qv.h" // QV kernel 74 | 75 | //============================================================================ 76 | // NOTE2: 77 | // The FIQ-type interrupts are NEVER disabled in this port, so the FIQ is 78 | // a "kernel-unaware" interrupt. If the FIQ is ever used in the application, 79 | // it must be an "__arm __fiq"-type function. For this to work, the FIQ 80 | // stack needs to be initialized. 81 | // 82 | // NOTE3: 83 | // This port implements the "save and restore" interrupt status policy, 84 | // which again never disables the FIQ-type interrupts. This policy allows 85 | // for nesting critical sections, which is necessary inside IRQ-type 86 | // interrupts that run with interrupts (IRQ) disabled. 87 | // 88 | 89 | #endif // QP_PORT_H_ 90 | 91 | -------------------------------------------------------------------------------- /ports/arm-cr/qv/iar/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/arm-cr/qv/ti/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | // no-return function specifier (C11 Standard) 37 | #define Q_NORETURN _Noreturn void 38 | 39 | // QF configuration for QV -- data members of the QActive class... 40 | 41 | // QV event-queue used for AOs 42 | #define QACTIVE_EQUEUE_TYPE QEQueue 43 | 44 | // QF interrupt disable/enable, see NOTE2 45 | #ifdef __16bis__ 46 | #define QF_INT_DISABLE() __asm(" CPSID i") 47 | #define QF_INT_ENABLE() __asm(" CPSIE i") 48 | #define QF_INT_ENABLE_ALL() __asm(" CPSIE if") 49 | #else 50 | #define QF_INT_DISABLE() _disable_IRQ() 51 | #define QF_INT_ENABLE() _enable_IRQ() 52 | #define QF_INT_ENABLE_ALL() _enable_interrupts() 53 | #endif 54 | 55 | // Cortex-R provide the CLZ instruction for fast LOG2 56 | #define QF_LOG2(n_) ((uint8_t)(32U - __clz(n_))) 57 | 58 | // QF critical section entry/exit, see NOTE3 59 | #define QF_CRIT_STAT uint32_t cpsr_; 60 | #define QF_CRIT_ENTRY() do { \ 61 | cpsr_ = _get_CPSR(); \ 62 | QF_INT_DISABLE(); \ 63 | } while (false) 64 | #define QF_CRIT_EXIT() do { \ 65 | if ((cpsr_ & (1U << 7U)) == 0U) { \ 66 | QF_INT_ENABLE(); \ 67 | } \ 68 | } while (false) 69 | 70 | #define QF_CRIT_EST() QF_INT_DISABLE() 71 | #define QF_CRIT_EXIT_NOP() __asm(" ISB") 72 | 73 | // macro to put the CPU to sleep inside QV_onIdle() 74 | #define QV_CPU_SLEEP() do { \ 75 | __wfi(); \ 76 | QF_INT_ENABLE(); \ 77 | } while (false) 78 | 79 | // include files ------------------------------------------------------------- 80 | #include "qequeue.h" // QV kernel uses the native QP event queue 81 | #include "qmpool.h" // QV kernel uses the native QP memory pool 82 | #include "qp.h" // QP framework 83 | #include "qv.h" // QV kernel 84 | 85 | //============================================================================ 86 | // NOTE2: 87 | // The FIQ-type interrupts are NEVER disabled in this port, so the FIQ is 88 | // a "kernel-unaware" interrupt. If the FIQ is ever used in the application, 89 | // it must be an "ARM FIQ"-type function. For this to work, the FIQ 90 | // stack needs to be initialized. 91 | // 92 | // NOTE3: 93 | // This port implements the "save and restore" interrupt status policy, 94 | // which again never disables the FIQ-type interrupts. This policy allows 95 | // for nesting critical sections, which is necessary inside IRQ-type 96 | // interrupts that run with interrupts (IRQ) disabled. 97 | // 98 | 99 | #endif // QP_PORT_H_ 100 | 101 | -------------------------------------------------------------------------------- /ports/arm-cr/qv/ti/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/embos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/embos 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE qf_port.c) 4 | -------------------------------------------------------------------------------- /ports/embos/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | // no-return function specifier (C11 Standard) 37 | #define Q_NORETURN _Noreturn void 38 | 39 | // embOS message mailbox and thread types 40 | #define QACTIVE_EQUEUE_TYPE OS_MAILBOX 41 | #define QACTIVE_THREAD_TYPE OS_TASK 42 | #define QACTIVE_OS_OBJ_TYPE uint32_t 43 | 44 | // QF interrupt disable/enable 45 | #define QF_INT_DISABLE() OS_INT_IncDI() 46 | #define QF_INT_ENABLE() OS_INT_DecRI() 47 | 48 | // QF critical section for embOS, see NOTE2 49 | #define QF_CRIT_STAT 50 | #define QF_CRIT_ENTRY() QF_INT_DISABLE() 51 | #define QF_CRIT_EXIT() QF_INT_ENABLE() 52 | #define QF_CRIT_EST() QF_INT_DISABLE() 53 | 54 | // include files ------------------------------------------------------------- 55 | #include "RTOS.h" // embOS API 56 | 57 | #include "qequeue.h" // QP event queue (for deferring events) 58 | #include "qmpool.h" // QP memory pool (for event pools) 59 | #include "qp.h" // QP platform-independent public interface 60 | 61 | 62 | enum EmbOS_TaskAttrs { 63 | TASK_NAME_ATTR, 64 | TASK_USES_FPU 65 | }; 66 | 67 | 68 | //============================================================================ 69 | // interface used only inside QF, but not in applications 70 | 71 | #ifdef QP_IMPL 72 | 73 | // embOS-specific scheduler locking, see NOTE3 74 | #define QF_SCHED_STAT_ 75 | #define QF_SCHED_LOCK_(dummy) do { \ 76 | if (OS_INT_InInterrupt() == (OS_BOOL)0) { \ 77 | OS_TASK_EnterRegion(); \ 78 | } \ 79 | } while (false) 80 | 81 | #define QF_SCHED_UNLOCK_() do { \ 82 | if (OS_INT_InInterrupt() == (OS_BOOL)0) { \ 83 | OS_TASK_LeaveRegion(); \ 84 | } \ 85 | } while (false) 86 | 87 | // native QF event pool customization 88 | #define QF_EPOOL_TYPE_ QMPool 89 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 90 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 91 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 92 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 93 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 94 | #define QF_EPOOL_PUT_(p_, e_, qsId_) \ 95 | (QMPool_put(&(p_), (e_), (qsId_))) 96 | 97 | #endif // QP_IMPL 98 | 99 | //============================================================================ 100 | // NOTE2: 101 | // The embOS critical section does not use the status variable, because the 102 | // implementation uses a global up-down counter, which allows the embOS 103 | // critical section to nest. Nesting of critical sections is needed in this 104 | // QP-embOS port. 105 | // 106 | // NOTE3: 107 | // embOS provides only global scheduler locking for all thread priorities 108 | // by means of OS_EnterRegion() and OS_LeaveRegion(). Therefore, locking the 109 | // scheduler only up to the specified lock priority is not supported. 110 | // 111 | 112 | #endif // QP_PORT_H_ 113 | 114 | -------------------------------------------------------------------------------- /ports/embos/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/embos/syscalls.c: -------------------------------------------------------------------------------- 1 | // dummy system calls to eliminate the following GNU linker warning: 2 | // "warning: xxxx is not implemented and will always fail" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern int __io_putchar(int ch) __attribute__((weak)); 14 | extern int __io_getchar(void) __attribute__((weak)); 15 | 16 | char *__env[1] = { 0 }; 17 | char **environ = __env; 18 | 19 | void initialise_monitor_handles() { 20 | } 21 | int _getpid(void) { 22 | return 1; 23 | } 24 | int _kill(int pid, int sig) { 25 | (void)pid; 26 | (void)sig; 27 | errno = EINVAL; 28 | return -1; 29 | } 30 | void _exit (int status) { 31 | _kill(status, -1); 32 | while (1) { // do not return 33 | } 34 | } 35 | __attribute__((weak)) int _read(int file, char *ptr, int len) { 36 | (void)file; 37 | for (int i = len; i != 0; --i) { 38 | *ptr++ = __io_getchar(); 39 | } 40 | return len; 41 | } 42 | __attribute__((weak)) int _write(int file, char *ptr, int len) { 43 | (void)file; 44 | for (int i = len; i != 0; --i) { 45 | __io_putchar(*ptr++); 46 | } 47 | return len; 48 | } 49 | int _close(int file) { 50 | (void)file; 51 | return -1; 52 | } 53 | int _fstat(int file, struct stat *st) { 54 | (void)file; 55 | st->st_mode = S_IFCHR; 56 | return 0; 57 | } 58 | int _isatty(int file) { 59 | (void)file; 60 | return 1; 61 | } 62 | int _lseek(int file, int ptr, int dir) { 63 | (void)file; 64 | (void)ptr; 65 | (void)dir; 66 | return 0; 67 | } 68 | int _open(char *path, int flags, ...) { 69 | (void)path; 70 | (void)flags; 71 | return -1; 72 | } 73 | int _wait(int *status) { 74 | (void)status; 75 | errno = ECHILD; 76 | return -1; 77 | } 78 | int _unlink(char *name) { 79 | (void)name; 80 | errno = ENOENT; 81 | return -1; 82 | } 83 | int _times(struct tms *buf) { 84 | (void)buf; 85 | return -1; 86 | } 87 | int _stat(char *file, struct stat *st) { 88 | (void)file; 89 | st->st_mode = S_IFCHR; 90 | return 0; 91 | } 92 | int _link(char *old, char *new) { 93 | (void)old; 94 | (void)new; 95 | errno = EMLINK; 96 | return -1; 97 | } 98 | int _fork(void) { 99 | errno = EAGAIN; 100 | return -1; 101 | } 102 | int _execve(char *name, char **argv, char **env) { 103 | (void)name; 104 | (void)argv; 105 | (void)env; 106 | errno = ENOMEM; 107 | return -1; 108 | } 109 | -------------------------------------------------------------------------------- /ports/freertos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/freertos 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE qf_port.c) 4 | -------------------------------------------------------------------------------- /ports/freertos/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/freertos/syscalls.c: -------------------------------------------------------------------------------- 1 | // dummy system calls to eliminate the following GNU linker warning: 2 | // "warning: xxxx is not implemented and will always fail" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern int __io_putchar(int ch) __attribute__((weak)); 14 | extern int __io_getchar(void) __attribute__((weak)); 15 | 16 | char *__env[1] = { 0 }; 17 | char **environ = __env; 18 | 19 | void initialise_monitor_handles() { 20 | } 21 | int _getpid(void) { 22 | return 1; 23 | } 24 | int _kill(int pid, int sig) { 25 | (void)pid; 26 | (void)sig; 27 | errno = EINVAL; 28 | return -1; 29 | } 30 | void _exit (int status) { 31 | _kill(status, -1); 32 | while (1) { // do not return 33 | } 34 | } 35 | __attribute__((weak)) int _read(int file, char *ptr, int len) { 36 | (void)file; 37 | for (int i = len; i != 0; --i) { 38 | *ptr++ = __io_getchar(); 39 | } 40 | return len; 41 | } 42 | __attribute__((weak)) int _write(int file, char *ptr, int len) { 43 | (void)file; 44 | for (int i = len; i != 0; --i) { 45 | __io_putchar(*ptr++); 46 | } 47 | return len; 48 | } 49 | int _close(int file) { 50 | (void)file; 51 | return -1; 52 | } 53 | int _fstat(int file, struct stat *st) { 54 | (void)file; 55 | st->st_mode = S_IFCHR; 56 | return 0; 57 | } 58 | int _isatty(int file) { 59 | (void)file; 60 | return 1; 61 | } 62 | int _lseek(int file, int ptr, int dir) { 63 | (void)file; 64 | (void)ptr; 65 | (void)dir; 66 | return 0; 67 | } 68 | int _open(char *path, int flags, ...) { 69 | (void)path; 70 | (void)flags; 71 | return -1; 72 | } 73 | int _wait(int *status) { 74 | (void)status; 75 | errno = ECHILD; 76 | return -1; 77 | } 78 | int _unlink(char *name) { 79 | (void)name; 80 | errno = ENOENT; 81 | return -1; 82 | } 83 | int _times(struct tms *buf) { 84 | (void)buf; 85 | return -1; 86 | } 87 | int _stat(char *file, struct stat *st) { 88 | (void)file; 89 | st->st_mode = S_IFCHR; 90 | return 0; 91 | } 92 | int _link(char *old, char *new) { 93 | (void)old; 94 | (void)new; 95 | errno = EMLINK; 96 | return -1; 97 | } 98 | int _fork(void) { 99 | errno = EAGAIN; 100 | return -1; 101 | } 102 | int _execve(char *name, char **argv, char **env) { 103 | (void)name; 104 | (void)argv; 105 | (void)env; 106 | errno = ENOMEM; 107 | return -1; 108 | } 109 | -------------------------------------------------------------------------------- /ports/msp430/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/msp430 2 | if(QPC_CFG_UNIT_TEST) 3 | target_include_directories(qpc PUBLIC qutest) 4 | else() 5 | if(NOT KERNEL MATCHES "q[vk]") 6 | message(WARNING "Kernel ${KERNEL} is not supported! Falling back to QV kernel") 7 | set(KERNEL qv) 8 | endif() 9 | target_include_directories(qpc PUBLIC ${KERNEL}) 10 | endif() 11 | -------------------------------------------------------------------------------- /ports/msp430/README.md: -------------------------------------------------------------------------------- 1 | # MSP430 Port 2 | 3 | Documentation for this port is available in the QP/C Manual at: 4 | 5 | - https://www.state-machine.com/qpc/msp430.html 6 | -------------------------------------------------------------------------------- /ports/msp430/qk/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | #if defined(__TI_COMPILER_VERSION__) || defined(__GNUC__) 37 | // no-return function specifier (C11 Standard) 38 | #define Q_NORETURN _Noreturn void 39 | #elif defined(__IAR_SYSTEMS_ICC__) 40 | #define Q_NORETURN __noreturn void 41 | #endif 42 | 43 | // QF configuration for QK -- data members of the QActive class... 44 | 45 | // QActive event queue type 46 | #define QACTIVE_EQUEUE_TYPE QEQueue 47 | // QACTIVE_OS_OBJ_TYPE not used in this port 48 | // QACTIVE_THREAD_TYPE not used in this port 49 | 50 | // QF interrupt disable/enable... 51 | #define QF_INT_DISABLE() __disable_interrupt() 52 | #define QF_INT_ENABLE() __enable_interrupt() 53 | 54 | // QF critical section entry/exit... 55 | #define QF_CRIT_STAT unsigned short int_state_; 56 | #define QF_CRIT_ENTRY() do { \ 57 | int_state_ = __get_interrupt_state(); \ 58 | __disable_interrupt(); \ 59 | } while (false) 60 | 61 | #define QF_CRIT_EST() __disable_interrupt() 62 | #define QF_CRIT_EXIT() __set_interrupt_state(int_state_) 63 | 64 | // Check if the code executes in the ISR context 65 | #define QK_ISR_CONTEXT_() (QK_priv_.intNest != 0U) 66 | 67 | // QK interrupt entry and exit... 68 | #define QK_ISR_ENTRY() (++QK_priv_.intNest) 69 | 70 | #define QK_ISR_EXIT() do { \ 71 | --QK_priv_.intNest; \ 72 | if (QK_priv_.intNest == 0U) { \ 73 | if (QK_sched_() != 0U) { \ 74 | QK_activate_(); \ 75 | } \ 76 | } \ 77 | } while (false) 78 | 79 | // include files ------------------------------------------------------------- 80 | #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) 81 | #include 82 | #elif defined(__GNUC__) 83 | #include 84 | #include "in430.h" 85 | #endif 86 | 87 | #include "qequeue.h" // QK kernel uses the native QP event queue 88 | #include "qmpool.h" // QK kernel uses the native QP memory pool 89 | #include "qp.h" // QP framework 90 | #include "qk.h" // QK kernel 91 | 92 | #endif // QP_PORT_H_ 93 | 94 | -------------------------------------------------------------------------------- /ports/msp430/qk/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 2U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 2U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/msp430/qutest/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QP_PORT_H_ 29 | #define QP_PORT_H_ 30 | 31 | #include // Exact-width types. WG14/N843 C99 Standard 32 | #include // Boolean type. WG14/N843 C99 Standard 33 | #include "qp_config.h" // QP configuration from the application 34 | 35 | #if defined(__TI_COMPILER_VERSION__) || defined(__GNUC__) 36 | // no-return function specifier (C11 Standard) 37 | #define Q_NORETURN _Noreturn void 38 | #elif defined(__IAR_SYSTEMS_ICC__) 39 | #define Q_NORETURN __noreturn void 40 | #endif 41 | 42 | // QF configuration for QK -- data members of the QActive class... 43 | 44 | // QActive event queue type 45 | #define QACTIVE_EQUEUE_TYPE QEQueue 46 | // QACTIVE_OS_OBJ_TYPE not used in this port 47 | // QACTIVE_THREAD_TYPE not used in this port 48 | 49 | // QF critical section 50 | #define QF_CRIT_STAT QCritStatus critStat_; 51 | #define QF_CRIT_ENTRY() (critStat_ = QF_critEntry()) 52 | #define QF_CRIT_EXIT() (QF_critExit(critStat_)) 53 | #define QF_CRIT_EST() ((void)QF_critEntry()) 54 | 55 | // QF_LOG2 not defined -- use the internal LOG2() implementation 56 | 57 | // include files ------------------------------------------------------------- 58 | #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) 59 | #include 60 | #elif defined(__GNUC__) 61 | #include 62 | #include "in430.h" 63 | #endif 64 | 65 | #include "qequeue.h" // QUTest port uses QEQueue event-queue 66 | #include "qmpool.h" // QUTest port uses QMPool memory-pool 67 | #include "qp.h" // QP platform-independent public interface 68 | 69 | //============================================================================ 70 | // interface used only inside QF implementation, but not in applications 71 | 72 | #ifdef QP_IMPL 73 | 74 | // QUTest scheduler locking 75 | #define QF_SCHED_STAT_ QSchedStatus lockStat_; 76 | #define QF_SCHED_LOCK_(ceil_) (lockStat_ = QF_schedLock((ceil_))) 77 | #define QF_SCHED_UNLOCK_() (QF_schedUnlock(lockStat_)) 78 | 79 | // native QEQueue operations 80 | #define QACTIVE_EQUEUE_WAIT_(me_) ((void)0) 81 | #define QACTIVE_EQUEUE_SIGNAL_(me_) \ 82 | QPSet_insert(&QS_tstPriv_.readySet, (uint_fast8_t)(me_)->prio) 83 | 84 | // native QMPool operations 85 | #define QF_EPOOL_TYPE_ QMPool 86 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 87 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 88 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 89 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 90 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 91 | #define QF_EPOOL_PUT_(p_, e_, qsId_) \ 92 | (QMPool_put(&(p_), (e_), (qsId_))) 93 | 94 | #endif // QP_IMPL 95 | 96 | #endif // QP_PORT_H_ 97 | 98 | -------------------------------------------------------------------------------- /ports/msp430/qutest/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 2U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 2U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/msp430/qv/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | #if defined(__TI_COMPILER_VERSION__) || defined(__GNUC__) 37 | // no-return function specifier (C11 Standard) 38 | #define Q_NORETURN _Noreturn void 39 | #elif defined(__IAR_SYSTEMS_ICC__) 40 | #define Q_NORETURN __noreturn void 41 | #endif 42 | 43 | // QF configuration for QV -- data members of the QActive class... 44 | 45 | // QActive event queue type 46 | #define QACTIVE_EQUEUE_TYPE QEQueue 47 | // QACTIVE_OS_OBJ_TYPE not used in this port 48 | // QACTIVE_THREAD_TYPE not used in this port 49 | 50 | // QF interrupt disable/enable... 51 | #define QF_INT_DISABLE() __disable_interrupt() 52 | #define QF_INT_ENABLE() __enable_interrupt() 53 | 54 | // QF critical section entry/exit... 55 | #define QF_CRIT_STAT unsigned short int_state_; 56 | #define QF_CRIT_ENTRY() do { \ 57 | int_state_ = __get_interrupt_state(); \ 58 | __disable_interrupt(); \ 59 | } while (false) 60 | 61 | #define QF_CRIT_EST() __disable_interrupt() 62 | #define QF_CRIT_EXIT() __set_interrupt_state(int_state_) 63 | 64 | // include files ------------------------------------------------------------- 65 | #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__) 66 | #include 67 | #elif defined(__GNUC__) 68 | #include 69 | #include "in430.h" 70 | #endif 71 | 72 | #include "qequeue.h" // QV kernel uses the native QP event queue 73 | #include "qmpool.h" // QV kernel uses the native QP memory pool 74 | #include "qp.h" // QP framework 75 | #include "qv.h" // QV kernel 76 | 77 | #endif // QP_PORT_H_ 78 | 79 | -------------------------------------------------------------------------------- /ports/msp430/qv/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 2U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 2U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/posix-qv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/posix-qv 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE 4 | qf_port.c 5 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_port.c> 6 | ) -------------------------------------------------------------------------------- /ports/posix-qv/README.md: -------------------------------------------------------------------------------- 1 | # POSIX (single-threaded) 2 | 3 | Documentation for this port is available in the QP/C Manual at: 4 | 5 | - https://www.state-machine.com/qpc/posix-qv.html 6 | -------------------------------------------------------------------------------- /ports/posix-qv/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | #if defined(__LP64__) || defined(_LP64) // 64-bit architecture? 32 | #define QS_OBJ_PTR_SIZE 8U 33 | #define QS_FUN_PTR_SIZE 8U 34 | #else // 32-bit architecture 35 | #define QS_OBJ_PTR_SIZE 4U 36 | #define QS_FUN_PTR_SIZE 4U 37 | #endif 38 | 39 | void QS_output(void); // handle the QS output 40 | void QS_rx_input(void); // handle the QS-RX input 41 | 42 | //============================================================================ 43 | // NOTE: QS might be used with or without other QP components, in which 44 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 45 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 46 | // with the other QP component, by simply including "qp_port.h" 47 | // *before* "qs.h". 48 | #ifndef QP_PORT_H_ 49 | #include "qp_port.h" // use QS with QP 50 | #endif 51 | 52 | #include "qs.h" // QS platform-independent public interface 53 | 54 | #endif // QS_PORT_H_ 55 | -------------------------------------------------------------------------------- /ports/posix-qv/safe_std.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef SAFE_STD_H_ 30 | #define SAFE_STD_H_ 31 | 32 | #include 33 | #include 34 | 35 | // portable "safe" facilities from and ................ 36 | #ifdef _WIN32 // Windows OS? 37 | 38 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 39 | memmove_s(dest_, num_, src_, count_) 40 | 41 | #define STRNCPY_S(dest_, destsiz_, src_) \ 42 | strncpy_s(dest_, destsiz_, src_, _TRUNCATE) 43 | 44 | #define STRCAT_S(dest_, destsiz_, src_) \ 45 | strcat_s(dest_, destsiz_, src_) 46 | 47 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 48 | _snprintf_s(buf_, bufsiz_, _TRUNCATE, format_, __VA_ARGS__) 49 | 50 | #define PRINTF_S(format_, ...) \ 51 | printf_s(format_, __VA_ARGS__) 52 | 53 | #define FPRINTF_S(fp_, format_, ...) \ 54 | fprintf_s(fp_, format_, __VA_ARGS__) 55 | 56 | #ifdef _MSC_VER 57 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 58 | fread_s(buf_, bufsiz_, elsiz_, count_, fp_) 59 | #else 60 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 61 | fread(buf_, elsiz_, count_, fp_) 62 | #endif // _MSC_VER 63 | 64 | #define FOPEN_S(fp_, fName_, mode_) \ 65 | if (fopen_s(&fp_, fName_, mode_) != 0) { \ 66 | fp_ = (FILE *)0; \ 67 | } else (void)0 68 | 69 | #define LOCALTIME_S(tm_, time_) \ 70 | localtime_s(tm_, time_) 71 | 72 | #else // other OS (Linux, MacOS, etc.) ..................................... 73 | 74 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 75 | memmove(dest_, src_, count_) 76 | 77 | #define STRNCPY_S(dest_, destsiz_, src_) do { \ 78 | strncpy(dest_, src_, destsiz_); \ 79 | dest_[(destsiz_) - 1] = '\0'; \ 80 | } while (false) 81 | 82 | #define STRCAT_S(dest_, destsiz_, src_) \ 83 | strcat(dest_, src_) 84 | 85 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 86 | snprintf(buf_, bufsiz_, format_, __VA_ARGS__) 87 | 88 | #define PRINTF_S(format_, ...) \ 89 | printf(format_, __VA_ARGS__) 90 | 91 | #define FPRINTF_S(fp_, format_, ...) \ 92 | fprintf(fp_, format_, __VA_ARGS__) 93 | 94 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 95 | fread(buf_, elsiz_, count_, fp_) 96 | 97 | #define FOPEN_S(fp_, fName_, mode_) \ 98 | (fp_ = fopen(fName_, mode_)) 99 | 100 | #define LOCALTIME_S(tm_, time_) \ 101 | memcpy(tm_, localtime(time_), sizeof(struct tm)) 102 | 103 | #endif // _WIN32 104 | 105 | #endif // SAFE_STD_H_ 106 | -------------------------------------------------------------------------------- /ports/posix/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/posix 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE 4 | qf_port.c 5 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_port.c> 6 | ) -------------------------------------------------------------------------------- /ports/posix/README.md: -------------------------------------------------------------------------------- 1 | # POSIX (multi-threaded with p-threads) 2 | 3 | Documentation for this port is available in the QP/C Manual at: 4 | 5 | - https://www.state-machine.com/qpc/posix.html 6 | -------------------------------------------------------------------------------- /ports/posix/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | #if defined(__LP64__) || defined(_LP64) // 64-bit architecture? 32 | #define QS_OBJ_PTR_SIZE 8U 33 | #define QS_FUN_PTR_SIZE 8U 34 | #else // 32-bit architecture 35 | #define QS_OBJ_PTR_SIZE 4U 36 | #define QS_FUN_PTR_SIZE 4U 37 | #endif 38 | 39 | void QS_output(void); // handle the QS output 40 | void QS_rx_input(void); // handle the QS-RX input 41 | 42 | //============================================================================ 43 | // NOTE: QS might be used with or without other QP components, in which 44 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 45 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 46 | // with the other QP component, by simply including "qp_port.h" 47 | // *before* "qs.h". 48 | #ifndef QP_PORT_H_ 49 | #include "qp_port.h" // use QS with QP 50 | #endif 51 | 52 | #include "qs.h" // QS platform-independent public interface 53 | 54 | #endif // QS_PORT_H_ 55 | -------------------------------------------------------------------------------- /ports/posix/safe_std.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef SAFE_STD_H_ 30 | #define SAFE_STD_H_ 31 | 32 | #include 33 | #include 34 | 35 | // portable "safe" facilities from and ................ 36 | #ifdef _WIN32 // Windows OS? 37 | 38 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 39 | memmove_s(dest_, num_, src_, count_) 40 | 41 | #define STRNCPY_S(dest_, destsiz_, src_) \ 42 | strncpy_s(dest_, destsiz_, src_, _TRUNCATE) 43 | 44 | #define STRCAT_S(dest_, destsiz_, src_) \ 45 | strcat_s(dest_, destsiz_, src_) 46 | 47 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 48 | _snprintf_s(buf_, bufsiz_, _TRUNCATE, format_, __VA_ARGS__) 49 | 50 | #define PRINTF_S(format_, ...) \ 51 | printf_s(format_, __VA_ARGS__) 52 | 53 | #define FPRINTF_S(fp_, format_, ...) \ 54 | fprintf_s(fp_, format_, __VA_ARGS__) 55 | 56 | #ifdef _MSC_VER 57 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 58 | fread_s(buf_, bufsiz_, elsiz_, count_, fp_) 59 | #else 60 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 61 | fread(buf_, elsiz_, count_, fp_) 62 | #endif // _MSC_VER 63 | 64 | #define FOPEN_S(fp_, fName_, mode_) \ 65 | if (fopen_s(&fp_, fName_, mode_) != 0) { \ 66 | fp_ = (FILE *)0; \ 67 | } else (void)0 68 | 69 | #define LOCALTIME_S(tm_, time_) \ 70 | localtime_s(tm_, time_) 71 | 72 | #else // other OS (Linux, MacOS, etc.) ..................................... 73 | 74 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 75 | memmove(dest_, src_, count_) 76 | 77 | #define STRNCPY_S(dest_, destsiz_, src_) do { \ 78 | strncpy(dest_, src_, destsiz_); \ 79 | dest_[(destsiz_) - 1] = '\0'; \ 80 | } while (false) 81 | 82 | #define STRCAT_S(dest_, destsiz_, src_) \ 83 | strcat(dest_, src_) 84 | 85 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 86 | snprintf(buf_, bufsiz_, format_, __VA_ARGS__) 87 | 88 | #define PRINTF_S(format_, ...) \ 89 | printf(format_, __VA_ARGS__) 90 | 91 | #define FPRINTF_S(fp_, format_, ...) \ 92 | fprintf(fp_, format_, __VA_ARGS__) 93 | 94 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 95 | fread(buf_, elsiz_, count_, fp_) 96 | 97 | #define FOPEN_S(fp_, fName_, mode_) \ 98 | (fp_ = fopen(fName_, mode_)) 99 | 100 | #define LOCALTIME_S(tm_, time_) \ 101 | memcpy(tm_, localtime(time_), sizeof(struct tm)) 102 | 103 | #endif // _WIN32 104 | 105 | #endif // SAFE_STD_H_ 106 | -------------------------------------------------------------------------------- /ports/qep-only/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/qep-only 2 | target_include_directories(qpc PUBLIC .) 3 | -------------------------------------------------------------------------------- /ports/qep-only/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | // no-return function specifier (C11 Standard) 33 | #define Q_NORETURN _Noreturn void 34 | 35 | // include files ------------------------------------------------------------- 36 | #include // Exact-width types. WG14/N843 C99 Standard 37 | #include // Boolean type. WG14/N843 C99 Standard 38 | #include "qp_config.h" // QP configuration from the application 39 | #include "qp.h" // QP platform-independent public interface 40 | 41 | #endif // QP_PORT_H_ 42 | -------------------------------------------------------------------------------- /ports/qep-only/safe_std.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef SAFE_STD_H_ 30 | #define SAFE_STD_H_ 31 | 32 | #include 33 | #include 34 | 35 | // portable "safe" facilities from and ................ 36 | #ifdef _WIN32 // Windows OS? 37 | 38 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 39 | memmove_s(dest_, num_, src_, count_) 40 | 41 | #define STRNCPY_S(dest_, destsiz_, src_) \ 42 | strncpy_s(dest_, destsiz_, src_, _TRUNCATE) 43 | 44 | #define STRCAT_S(dest_, destsiz_, src_) \ 45 | strcat_s(dest_, destsiz_, src_) 46 | 47 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 48 | _snprintf_s(buf_, bufsiz_, _TRUNCATE, format_, __VA_ARGS__) 49 | 50 | #define PRINTF_S(format_, ...) \ 51 | printf_s(format_, __VA_ARGS__) 52 | 53 | #define FPRINTF_S(fp_, format_, ...) \ 54 | fprintf_s(fp_, format_, __VA_ARGS__) 55 | 56 | #ifdef _MSC_VER 57 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 58 | fread_s(buf_, bufsiz_, elsiz_, count_, fp_) 59 | #else 60 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 61 | fread(buf_, elsiz_, count_, fp_) 62 | #endif // _MSC_VER 63 | 64 | #define FOPEN_S(fp_, fName_, mode_) \ 65 | if (fopen_s(&fp_, fName_, mode_) != 0) { \ 66 | fp_ = (FILE *)0; \ 67 | } else (void)0 68 | 69 | #define LOCALTIME_S(tm_, time_) \ 70 | localtime_s(tm_, time_) 71 | 72 | #else // other OS (Linux, MacOS, etc.) ..................................... 73 | 74 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 75 | memmove(dest_, src_, count_) 76 | 77 | #define STRNCPY_S(dest_, destsiz_, src_) do { \ 78 | strncpy(dest_, src_, destsiz_); \ 79 | dest_[(destsiz_) - 1] = '\0'; \ 80 | } while (false) 81 | 82 | #define STRCAT_S(dest_, destsiz_, src_) \ 83 | strcat(dest_, src_) 84 | 85 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 86 | snprintf(buf_, bufsiz_, format_, __VA_ARGS__) 87 | 88 | #define PRINTF_S(format_, ...) \ 89 | printf(format_, __VA_ARGS__) 90 | 91 | #define FPRINTF_S(fp_, format_, ...) \ 92 | fprintf(fp_, format_, __VA_ARGS__) 93 | 94 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 95 | fread(buf_, elsiz_, count_, fp_) 96 | 97 | #define FOPEN_S(fp_, fName_, mode_) \ 98 | (fp_ = fopen(fName_, mode_)) 99 | 100 | #define LOCALTIME_S(tm_, time_) \ 101 | memcpy(tm_, localtime(time_), sizeof(struct tm)) 102 | 103 | #endif // _WIN32 104 | 105 | #endif // SAFE_STD_H_ 106 | -------------------------------------------------------------------------------- /ports/qube/README.txt: -------------------------------------------------------------------------------- 1 | "Qube" is an environment to exercise QP active object components. 2 | "Qube" is a simple console-based application that allows developers 3 | to post/publish events to active objects under development. 4 | -------------------------------------------------------------------------------- /ports/qube/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // SafeQP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QP_PORT_H_ 29 | #define QP_PORT_H_ 30 | 31 | #include // Exact-width types. WG14/N843 C99 Standard 32 | #include // Boolean type. WG14/N843 C99 Standard 33 | #include "qp_config.h" // QP configuration from the application 34 | 35 | // no-return function specifier (C11 Standard) 36 | #define Q_NORETURN _Noreturn void 37 | 38 | // Qube event queue and thread types 39 | #define QACTIVE_EQUEUE_TYPE QEQueue 40 | #define QACTIVE_OS_OBJ_TYPE void * 41 | #define QACTIVE_THREAD_TYPE void const * 42 | 43 | // QF interrupt disable/enable 44 | //#define QF_INT_DISABLE() (++QF_intLock_) 45 | //#define QF_INT_ENABLE() (--QF_intLock_) 46 | 47 | // Qube critical section 48 | #define QF_CRIT_STAT uint_fast8_t crit_stat_; 49 | #define QF_CRIT_ENTRY() (crit_stat_ = QF_intLock_++) 50 | #define QF_CRIT_EXIT() (QF_intLock_ = crit_stat_) 51 | #define QF_CRIT_EST() (++QF_intLock_) 52 | 53 | // QF_LOG2 not defined -- use the internal LOG2() implementation 54 | 55 | // include files ------------------------------------------------------------- 56 | #include "qequeue.h" // Qube port uses QEQueue event-queue 57 | #include "qmpool.h" // Qube port uses QMPool memory-pool 58 | #include "qp.h" // QP platform-independent public interface 59 | 60 | void Qube_setAO(QActive *ao); 61 | QEvt const *Qube_onGenEvt(QSignal sig, char const *params); 62 | extern uint_fast8_t QF_intLock_; 63 | 64 | //========================================================================== 65 | // interface used only inside QF implementation, but not in applications 66 | #ifdef QP_IMPL 67 | 68 | extern QPSet QF_readySet_; 69 | extern QPSet QF_readySet_dis_; 70 | 71 | // Qube scheduler locking (not used) 72 | #define QF_SCHED_STAT_ 73 | #define QF_SCHED_LOCK_(dummy) ((void)0) 74 | #define QF_SCHED_UNLOCK_() ((void)0) 75 | 76 | // native event queue operations 77 | #define QACTIVE_EQUEUE_WAIT_(me_) ((void)0) 78 | #define QACTIVE_EQUEUE_SIGNAL_(me_) \ 79 | QPSet_insert(&QF_readySet_, (uint_fast8_t)(me_)->prio) 80 | 81 | // native QF event pool operations 82 | #define QF_EPOOL_TYPE_ QMPool 83 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 84 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 85 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 86 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 87 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 88 | #define QF_EPOOL_PUT_(p_, e_, qsId_) \ 89 | (QMPool_put(&(p_), (e_), (qsId_))) 90 | 91 | #include "qp_pkg.h" // internal QP interface 92 | 93 | #endif // QP_IMPL 94 | 95 | #endif // QP_PORT_H_ 96 | -------------------------------------------------------------------------------- /ports/qube/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // SafeQP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | #if defined(__LP64__) || defined(_LP64) || defined(_WIN64) // 64-bit? 32 | #define QS_OBJ_PTR_SIZE 8U 33 | #define QS_FUN_PTR_SIZE 8U 34 | #else // 32-bit architecture 35 | #define QS_OBJ_PTR_SIZE 4U 36 | #define QS_FUN_PTR_SIZE 4U 37 | #endif 38 | 39 | // flush the QS output buffer after each QS record 40 | #define QS_REC_DONE() QS_onFlush() 41 | 42 | //============================================================================ 43 | // NOTE: QS might be used with or without other QP components, in which 44 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 45 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 46 | // with the other QP component, by simply including "qp_port.h" 47 | // *before* "qs.h". 48 | #ifndef QP_PORT_H_ 49 | #include "qp_port.h" // use QS with QP 50 | #endif 51 | 52 | #include "qs.h" // QS platform-independent public interface 53 | 54 | #endif // QS_PORT_H_ 55 | -------------------------------------------------------------------------------- /ports/qube/safe_std.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // SafeQP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef SAFE_STD_H_ 29 | #define SAFE_STD_H_ 30 | 31 | #include 32 | #include 33 | 34 | // portable "safe" facilities from and ................ 35 | #ifdef _WIN32 // Windows OS? 36 | 37 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 38 | memmove_s(dest_, num_, src_, count_) 39 | 40 | #define STRNCPY_S(dest_, destsiz_, src_) \ 41 | strncpy_s(dest_, destsiz_, src_, _TRUNCATE) 42 | 43 | #define STRCAT_S(dest_, destsiz_, src_) \ 44 | strcat_s(dest_, destsiz_, src_) 45 | 46 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 47 | _snprintf_s(buf_, bufsiz_, _TRUNCATE, format_, __VA_ARGS__) 48 | 49 | #define PRINTF_S(format_, ...) \ 50 | printf_s(format_, __VA_ARGS__) 51 | 52 | #define FPRINTF_S(fp_, format_, ...) \ 53 | fprintf_s(fp_, format_, __VA_ARGS__) 54 | 55 | #ifdef _MSC_VER 56 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 57 | fread_s(buf_, bufsiz_, elsiz_, count_, fp_) 58 | #else 59 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 60 | fread(buf_, elsiz_, count_, fp_) 61 | #endif // _MSC_VER 62 | 63 | #define FOPEN_S(fp_, fName_, mode_) \ 64 | if (fopen_s(&fp_, fName_, mode_) != 0) { \ 65 | fp_ = (FILE *)0; \ 66 | } else (void)0 67 | 68 | #define LOCALTIME_S(tm_, time_) \ 69 | localtime_s(tm_, time_) 70 | 71 | #else // other OS (Linux, MacOS, etc.) ..................................... 72 | 73 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 74 | memmove(dest_, src_, count_) 75 | 76 | #define STRNCPY_S(dest_, destsiz_, src_) do { \ 77 | strncpy(dest_, src_, destsiz_); \ 78 | dest_[(destsiz_) - 1] = '\0'; \ 79 | } while (false) 80 | 81 | #define STRCAT_S(dest_, destsiz_, src_) \ 82 | strcat(dest_, src_) 83 | 84 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 85 | snprintf(buf_, bufsiz_, format_, __VA_ARGS__) 86 | 87 | #define PRINTF_S(format_, ...) \ 88 | printf(format_, __VA_ARGS__) 89 | 90 | #define FPRINTF_S(fp_, format_, ...) \ 91 | fprintf(fp_, format_, __VA_ARGS__) 92 | 93 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 94 | fread(buf_, elsiz_, count_, fp_) 95 | 96 | #define FOPEN_S(fp_, fName_, mode_) \ 97 | (fp_ = fopen(fName_, mode_)) 98 | 99 | #define LOCALTIME_S(tm_, time_) \ 100 | memcpy(tm_, localtime(time_), sizeof(struct tm)) 101 | 102 | #endif // _WIN32 103 | 104 | #endif // SAFE_STD_H_ 105 | -------------------------------------------------------------------------------- /ports/risc-v/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/threadx 2 | string(TOLOWER ${CMAKE_C_COMPILER_ID} _compiler_) 3 | 4 | if((KERNEL STREQUAL qv) AND (${_compiler_} STREQUAL gnu)) 5 | target_include_directories(qpc PUBLIC qv/gnu) 6 | else() 7 | message(FATAL_ERROR "Only the QV kernel in combination with the GNU compiler are supported!") 8 | endif() 9 | 10 | -------------------------------------------------------------------------------- /ports/risc-v/qv/README.md: -------------------------------------------------------------------------------- 1 | # QP/C Port to RISC-V 2 | This document describes the QP/C framework port to RISC-V with the cooperative QV kernel. The port is located in the `qpc/ports/risc-v/qv/gnu` directory. 3 | 4 | ``` 5 | qpc/ - QP/C installation directory 6 | +-ports/ - QP/C ports directory 7 | | +-risc-v/ - QP/C port to RISC-V 8 | | | +-qv/ - QP/C port to RISV-V with the QV kernel 9 | | | | +-gnu/ - QP/C port to RISV-V with the QV kernel and GNU compiler 10 | | | | | +-qep_port.h - QEP/C (hierarchical event processor) port 11 | | | | | +-qf_port.h - QF/C (event-driven framework) port 12 | | | | | +-qs_port.h - QS/C (QP/Spy software tracing) port 13 | | | | | +-qv_port.h - QV/C (cooperative QV kernel) port 14 | ``` 15 | > NOTE: 16 | The `qpc/ports/risc-v/qv/qv/gnu` directory needs to be provided to the compiler's include path. 17 | 18 | ## Cooperative QV Kernel for RISC-V 19 | The most important aspects of the QP/C port to RISC-V with the cooperative QV kernel are provided as macro definitions in the files `qf_port.h` and `qv_port.h` in the `qpc/ports/risc-v/qv/qv/gnu` directory. The port strives to be generic in that it's designed to support all currently available RISC-V (RV32) chips. 20 | 21 | ``` 22 | file: qf_port.h 23 | ~ ~ ~ 24 | 25 | /* The maximum number of active objects in the application, see NOTE1 */ 26 | #define QF_MAX_ACTIVE 32U 27 | 28 | /* interrupt disabling policy, see NOTE2 */ 29 | #define QF_INT_DISABLE() __asm__ volatile("csrc mstatus,8") 30 | #define QF_INT_ENABLE() __asm__ volatile("csrs mstatus,8") 31 | 32 | /* QF critical section entry/exit, see NOTE3 */ 33 | #define QF_CRIT_STAT_TYPE unsigned int 34 | #define QF_CRIT_ENTRY(status_) do { \ 35 | __asm__ volatile("csrr %0, mstatus" : "=r"(status_)); \ 36 | QF_INT_DISABLE(); \ 37 | } while (false) 38 | #define QF_CRIT_EXIT(status_) \ 39 | __asm__ volatile ("csrw mstatus, %0" :: "rK"(status_)) 40 | 41 | /* support for fast LOG2, see NOTE4 */ 42 | #define QF_LOG2(n_) ((uint_fast8_t)(32U - __builtin_clz((n_)))) 43 | 44 | /* NOP instruction for RISC-V, NOTE5 */ 45 | #define QF_CRIT_EXIT_NOP() __asm__ volatile ("nop") 46 | 47 | 48 | ~ ~ ` 49 | ``` 50 | 51 | **[1]** the maximum number of active objects `QF_MAX_ACTIVE` can be increased up to 64, if necessary. Here it is set to a lower level of 32 to slightly improve performance and save some RAM. 52 | 53 | **[2]** the port disables interrupts by clearing `mstatus` bit-3 (MIE == Machine Interrupt Enable) and enables interrupts setting `mstatus` bit-3 (MIE). 54 | 55 | **[3]** the port uses the "save and restore interrupt status" policy. This policy is appropriate for CPUs that disable interrupts inside ISRs, which is the case with RISC-V. Also, this policy allows *nesting* of critical sections. 56 | 57 | **[4]** The port takes advantage of the built-in function `__builtin_clz()` for fast computation of log-base-2, which is used in the QV scheduler. 58 | 59 | **[5]** The port uses `NOP` instruction to prevent potential merging of back-to-back critical sections inside the QP/C implementation. This precaution is to reduce interrupt latency. 60 | 61 | ``` 62 | file: qv_port.h 63 | ~ ~ ~ 64 | 65 | /*! macro to put the CPU to sleep inside QV_onIdle() callback */ 66 | /* The following QV_CPU_SLEEP() executes the WFI instruction with 67 | * interrupts still DISABLED. Interrupts are enabled only after 68 | * the RISC-V CPU wakes up. 69 | * NOTE: this approach needs to be tested for each specific RISC-V SoC. 70 | */ 71 | #define QV_CPU_SLEEP() do { \ 72 | __asm volatile("wfi"); \ 73 | QF_INT_ENABLE(); \ 74 | } while (false) 75 | 76 | ~ ~ ` 77 | ``` 78 | 79 | **[6]** The QV port can detect the idle condition of the system, which can be utilized to put the system (CPU and peripherals) in a low-power sleep mode. However, the specifics of the QV kernel require the CPU to transition to the sleep mode with interrupts **DISABLED**. 80 | 81 | > **NOTE:** 82 | According to the "The RISC-V Instruction Set Manual", the `WFI` instruction can be executed when interrupts are **disabled**. 83 | -------------------------------------------------------------------------------- /ports/risc-v/qv/gnu/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | // no-return function specifier (C11 Standard) 37 | #define Q_NORETURN _Noreturn void 38 | 39 | // interrupt disabling policy, see NOTE2 40 | #define QF_INT_DISABLE() __asm__ volatile("csrc mstatus,8") 41 | #define QF_INT_ENABLE() __asm__ volatile("csrs mstatus,8") 42 | 43 | // QF critical section entry/exit, see NOTE3 44 | #define QF_CRIT_STAT unsigned int mstatus_; 45 | #define QF_CRIT_ENTRY() do { \ 46 | __asm__ volatile("csrr %0, mstatus" : "=r"(mstatus_)); \ 47 | QF_INT_DISABLE(); \ 48 | } while (false) 49 | 50 | #define QF_CRIT_EST() QF_INT_DISABLE() 51 | #define QF_CRIT_EXIT() \ 52 | __asm__ volatile ("csrw mstatus, %0" :: "rK"(mstatus_)) 53 | 54 | // support for fast LOG2, see NOTE4 55 | #define QF_LOG2(n_) ((uint_fast8_t)(32U - __builtin_clz((n_)))) 56 | 57 | // NOP instruction for RISC-V, NOTE5 58 | #define QF_CRIT_EXIT_NOP() __asm__ volatile ("nop") 59 | 60 | // include files ------------------------------------------------------------- 61 | #include "qequeue.h" // QV kernel uses the native QP event queue 62 | #include "qmpool.h" // QV kernel uses the native QP memory pool 63 | #include "qp.h" // QP framework 64 | #include "qv.h" // QV kernel 65 | 66 | //============================================================================ 67 | // NOTE2: 68 | // Interrupts are disabled by clearing the MIE (bit-3) in the mstatus register. 69 | // Interrupts are enabled by setting the MIE (bit-3) in the mstatus register. 70 | // 71 | // NOTE3: 72 | // QP critical section uses the "save and restore interrupt status" policy. 73 | // This policy is appropriate for CPUs that disable interrupts inside ISRs, 74 | // which is the case with RISC-V. Also, this policy allows *nesting* of 75 | // critical sections. 76 | // 77 | // NOTE4: 78 | // The __builtin_clz() function is used for the integer log-base-2 79 | // implementation, which is used in the QV scheduler. 80 | // 81 | // NOTE5: 82 | // The NOP instruction is used to prevent merging of back-to-back critical 83 | // sections. 84 | // 85 | 86 | #endif // QP_PORT_H_ 87 | 88 | -------------------------------------------------------------------------------- /ports/risc-v/qv/gnu/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/threadx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/os_xxx 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE qf_port.c) 4 | -------------------------------------------------------------------------------- /ports/threadx/README.md: -------------------------------------------------------------------------------- 1 | # ThreadX Port 2 | 3 | Documentation for this port is available in the QP/C Manual at: 4 | 5 | - https://www.state-machine.com/qpc/threadx.html 6 | -------------------------------------------------------------------------------- /ports/threadx/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/threadx/syscalls.c: -------------------------------------------------------------------------------- 1 | // dummy system calls to eliminate the following GNU linker warning: 2 | // "warning: xxxx is not implemented and will always fail" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern int __io_putchar(int ch) __attribute__((weak)); 14 | extern int __io_getchar(void) __attribute__((weak)); 15 | 16 | char *__env[1] = { 0 }; 17 | char **environ = __env; 18 | 19 | void initialise_monitor_handles() { 20 | } 21 | int _getpid(void) { 22 | return 1; 23 | } 24 | int _kill(int pid, int sig) { 25 | (void)pid; 26 | (void)sig; 27 | errno = EINVAL; 28 | return -1; 29 | } 30 | void _exit (int status) { 31 | _kill(status, -1); 32 | while (1) { // do not return 33 | } 34 | } 35 | __attribute__((weak)) int _read(int file, char *ptr, int len) { 36 | (void)file; 37 | for (int i = len; i != 0; --i) { 38 | *ptr++ = __io_getchar(); 39 | } 40 | return len; 41 | } 42 | __attribute__((weak)) int _write(int file, char *ptr, int len) { 43 | (void)file; 44 | for (int i = len; i != 0; --i) { 45 | __io_putchar(*ptr++); 46 | } 47 | return len; 48 | } 49 | int _close(int file) { 50 | (void)file; 51 | return -1; 52 | } 53 | int _fstat(int file, struct stat *st) { 54 | (void)file; 55 | st->st_mode = S_IFCHR; 56 | return 0; 57 | } 58 | int _isatty(int file) { 59 | (void)file; 60 | return 1; 61 | } 62 | int _lseek(int file, int ptr, int dir) { 63 | (void)file; 64 | (void)ptr; 65 | (void)dir; 66 | return 0; 67 | } 68 | int _open(char *path, int flags, ...) { 69 | (void)path; 70 | (void)flags; 71 | return -1; 72 | } 73 | int _wait(int *status) { 74 | (void)status; 75 | errno = ECHILD; 76 | return -1; 77 | } 78 | int _unlink(char *name) { 79 | (void)name; 80 | errno = ENOENT; 81 | return -1; 82 | } 83 | int _times(struct tms *buf) { 84 | (void)buf; 85 | return -1; 86 | } 87 | int _stat(char *file, struct stat *st) { 88 | (void)file; 89 | st->st_mode = S_IFCHR; 90 | return 0; 91 | } 92 | int _link(char *old, char *new) { 93 | (void)old; 94 | (void)new; 95 | errno = EMLINK; 96 | return -1; 97 | } 98 | int _fork(void) { 99 | errno = EAGAIN; 100 | return -1; 101 | } 102 | int _execve(char *name, char **argv, char **env) { 103 | (void)name; 104 | (void)argv; 105 | (void)env; 106 | errno = ENOMEM; 107 | return -1; 108 | } 109 | -------------------------------------------------------------------------------- /ports/uc-os2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/uc-os2 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE qf_port.c) 4 | -------------------------------------------------------------------------------- /ports/uc-os2/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | 36 | // no-return function specifier (C11 Standard) 37 | #define Q_NORETURN _Noreturn void 38 | 39 | // uC-OS2 event queue and thread types 40 | #define QACTIVE_EQUEUE_TYPE OS_EVENT * 41 | #define QACTIVE_THREAD_TYPE uint32_t 42 | 43 | // include files ------------------------------------------------------------- 44 | #include "ucos_ii.h" // uC-OS2 API, port and compile-time configuration 45 | 46 | #include "qequeue.h" // QP event queue (for deferring events) 47 | #include "qmpool.h" // QP memory pool (for event pools) 48 | #include "qp.h" // QP platform-independent public interface 49 | 50 | // uC-OS2 critical section, NOTE1 51 | #if (OS_CRITICAL_METHOD == 1U) 52 | #define QF_CRIT_STAT 53 | #define QF_CRIT_ENTRY() OS_ENTER_CRITICAL() 54 | #define QF_CRIT_EXIT() OS_EXIT_CRITICAL() 55 | #define QF_CRIT_EST() OS_ENTER_CRITICAL() 56 | #elif (OS_CRITICAL_METHOD == 3U) 57 | #define QF_CRIT_STAT OS_CPU_SR cpu_sr; 58 | #define QF_CRIT_ENTRY() OS_ENTER_CRITICAL() 59 | #define QF_CRIT_EXIT() OS_EXIT_CRITICAL() 60 | #define QF_CRIT_EST() do { \ 61 | OS_CPU_SR cpu_sr; \ 62 | OS_ENTER_CRITICAL(); \ 63 | (void)cpu_sr; \ 64 | } while (false) 65 | #else 66 | #error Unsupported uC-OS2 critical section type 67 | #endif // OS_CRITICAL_METHOD 68 | 69 | 70 | enum UCOS2_TaskAttrs { 71 | TASK_NAME_ATTR 72 | }; 73 | 74 | //============================================================================ 75 | // interface used only inside QF implementation, but not in applications 76 | #ifdef QP_IMPL 77 | 78 | // uC-OS2-specific scheduler locking, see NOTE2 79 | #define QF_SCHED_STAT_ 80 | #define QF_SCHED_LOCK_(dummy) do { \ 81 | if (OSIntNesting == 0U) { \ 82 | OSSchedLock(); \ 83 | } \ 84 | } while (false) 85 | 86 | #define QF_SCHED_UNLOCK_() do { \ 87 | if (OSIntNesting == 0U) { \ 88 | OSSchedUnlock(); \ 89 | } \ 90 | } while (false) 91 | 92 | // native QF event pool customization 93 | #define QF_EPOOL_TYPE_ QMPool 94 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 95 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 96 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 97 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 98 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 99 | #define QF_EPOOL_PUT_(p_, e_, qsId_) \ 100 | (QMPool_put(&(p_), (e_), (qsId_))) 101 | 102 | #endif // QP_IMPL 103 | 104 | //============================================================================ 105 | // NOTE1: 106 | // This QP port to uC-OS2 re-uses the exact same critical section mechanism 107 | // as uC-OS2. The goal is to make this port independent on the CPU or the 108 | // toolchain by employing only the official uC-OS2 API. That way, all CPU 109 | // and toolchain dependencies are handled internally by uC-OS2. 110 | // 111 | // NOTE2: 112 | // uC-OS2 provides only global scheduler locking for all thread priorities 113 | // by means of OSSchedLock() and OSSchedUnlock(). Therefore, locking the 114 | // scheduler only up to the specified lock priority is not supported. 115 | // 116 | 117 | #endif // QP_PORT_H_ 118 | 119 | -------------------------------------------------------------------------------- /ports/uc-os2/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | -------------------------------------------------------------------------------- /ports/uc-os2/syscalls.c: -------------------------------------------------------------------------------- 1 | // dummy system calls to eliminate the following GNU linker warning: 2 | // "warning: xxxx is not implemented and will always fail" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | extern int __io_putchar(int ch) __attribute__((weak)); 14 | extern int __io_getchar(void) __attribute__((weak)); 15 | 16 | char *__env[1] = { 0 }; 17 | char **environ = __env; 18 | 19 | void initialise_monitor_handles() { 20 | } 21 | int _getpid(void) { 22 | return 1; 23 | } 24 | int _kill(int pid, int sig) { 25 | (void)pid; 26 | (void)sig; 27 | errno = EINVAL; 28 | return -1; 29 | } 30 | void _exit (int status) { 31 | _kill(status, -1); 32 | while (1) { // do not return 33 | } 34 | } 35 | __attribute__((weak)) int _read(int file, char *ptr, int len) { 36 | (void)file; 37 | for (int i = len; i != 0; --i) { 38 | *ptr++ = __io_getchar(); 39 | } 40 | return len; 41 | } 42 | __attribute__((weak)) int _write(int file, char *ptr, int len) { 43 | (void)file; 44 | for (int i = len; i != 0; --i) { 45 | __io_putchar(*ptr++); 46 | } 47 | return len; 48 | } 49 | int _close(int file) { 50 | (void)file; 51 | return -1; 52 | } 53 | int _fstat(int file, struct stat *st) { 54 | (void)file; 55 | st->st_mode = S_IFCHR; 56 | return 0; 57 | } 58 | int _isatty(int file) { 59 | (void)file; 60 | return 1; 61 | } 62 | int _lseek(int file, int ptr, int dir) { 63 | (void)file; 64 | (void)ptr; 65 | (void)dir; 66 | return 0; 67 | } 68 | int _open(char *path, int flags, ...) { 69 | (void)path; 70 | (void)flags; 71 | return -1; 72 | } 73 | int _wait(int *status) { 74 | (void)status; 75 | errno = ECHILD; 76 | return -1; 77 | } 78 | int _unlink(char *name) { 79 | (void)name; 80 | errno = ENOENT; 81 | return -1; 82 | } 83 | int _times(struct tms *buf) { 84 | (void)buf; 85 | return -1; 86 | } 87 | int _stat(char *file, struct stat *st) { 88 | (void)file; 89 | st->st_mode = S_IFCHR; 90 | return 0; 91 | } 92 | int _link(char *old, char *new) { 93 | (void)old; 94 | (void)new; 95 | errno = EMLINK; 96 | return -1; 97 | } 98 | int _fork(void) { 99 | errno = EAGAIN; 100 | return -1; 101 | } 102 | int _execve(char *name, char **argv, char **env) { 103 | (void)name; 104 | (void)argv; 105 | (void)env; 106 | errno = ENOMEM; 107 | return -1; 108 | } 109 | -------------------------------------------------------------------------------- /ports/win32-qv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/win32-qv 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE 4 | qf_port.c 5 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/qwin_gui.c> 6 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_port.c> 7 | ) 8 | -------------------------------------------------------------------------------- /ports/win32-qv/README.md: -------------------------------------------------------------------------------- 1 | # Win32-API (Windows single-threaded) 2 | 3 | Documentation for this port is available in the QP/C Manual at: 4 | 5 | - https://www.state-machine.com/qpc/win32-qv.html 6 | -------------------------------------------------------------------------------- /ports/win32-qv/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | #ifdef _WIN64 // 64-bit architecture? 32 | #define QS_OBJ_PTR_SIZE 8U 33 | #define QS_FUN_PTR_SIZE 8U 34 | #else // 32-bit architecture 35 | #define QS_OBJ_PTR_SIZE 4U 36 | #define QS_FUN_PTR_SIZE 4U 37 | #endif 38 | 39 | void QS_output(void); // handle the QS output 40 | void QS_rx_input(void); // handle the QS-RX input 41 | 42 | //============================================================================ 43 | // NOTE: QS might be used with or without other QP components, in which 44 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 45 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 46 | // with the other QP component, by simply including "qp_port.h" 47 | // *before* "qs.h". 48 | #ifndef QP_PORT_H_ 49 | #include "qp_port.h" // use QS with QP 50 | #endif 51 | 52 | #include "qs.h" // QS platform-independent public interface 53 | 54 | #endif // QS_PORT_H_ 55 | -------------------------------------------------------------------------------- /ports/win32-qv/safe_std.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef SAFE_STD_H_ 30 | #define SAFE_STD_H_ 31 | 32 | #include 33 | #include 34 | 35 | // portable "safe" facilities from and ................ 36 | #ifdef _WIN32 // Windows OS? 37 | 38 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 39 | memmove_s(dest_, num_, src_, count_) 40 | 41 | #define STRNCPY_S(dest_, destsiz_, src_) \ 42 | strncpy_s(dest_, destsiz_, src_, _TRUNCATE) 43 | 44 | #define STRCAT_S(dest_, destsiz_, src_) \ 45 | strcat_s(dest_, destsiz_, src_) 46 | 47 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 48 | _snprintf_s(buf_, bufsiz_, _TRUNCATE, format_, __VA_ARGS__) 49 | 50 | #define PRINTF_S(format_, ...) \ 51 | printf_s(format_, __VA_ARGS__) 52 | 53 | #define FPRINTF_S(fp_, format_, ...) \ 54 | fprintf_s(fp_, format_, __VA_ARGS__) 55 | 56 | #ifdef _MSC_VER 57 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 58 | fread_s(buf_, bufsiz_, elsiz_, count_, fp_) 59 | #else 60 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 61 | fread(buf_, elsiz_, count_, fp_) 62 | #endif // _MSC_VER 63 | 64 | #define FOPEN_S(fp_, fName_, mode_) \ 65 | if (fopen_s(&fp_, fName_, mode_) != 0) { \ 66 | fp_ = (FILE *)0; \ 67 | } else (void)0 68 | 69 | #define LOCALTIME_S(tm_, time_) \ 70 | localtime_s(tm_, time_) 71 | 72 | #else // other OS (Linux, MacOS, etc.) ..................................... 73 | 74 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 75 | memmove(dest_, src_, count_) 76 | 77 | #define STRNCPY_S(dest_, destsiz_, src_) do { \ 78 | strncpy(dest_, src_, destsiz_); \ 79 | dest_[(destsiz_) - 1] = '\0'; \ 80 | } while (false) 81 | 82 | #define STRCAT_S(dest_, destsiz_, src_) \ 83 | strcat(dest_, src_) 84 | 85 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 86 | snprintf(buf_, bufsiz_, format_, __VA_ARGS__) 87 | 88 | #define PRINTF_S(format_, ...) \ 89 | printf(format_, __VA_ARGS__) 90 | 91 | #define FPRINTF_S(fp_, format_, ...) \ 92 | fprintf(fp_, format_, __VA_ARGS__) 93 | 94 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 95 | fread(buf_, elsiz_, count_, fp_) 96 | 97 | #define FOPEN_S(fp_, fName_, mode_) \ 98 | (fp_ = fopen(fName_, mode_)) 99 | 100 | #define LOCALTIME_S(tm_, time_) \ 101 | memcpy(tm_, localtime(time_), sizeof(struct tm)) 102 | 103 | #endif // _WIN32 104 | 105 | #endif // SAFE_STD_H_ 106 | -------------------------------------------------------------------------------- /ports/win32/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ports/win32 2 | target_include_directories(qpc PUBLIC .) 3 | target_sources(qpc PRIVATE 4 | qf_port.c 5 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/qwin_gui.c> 6 | $<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_port.c> 7 | ) 8 | -------------------------------------------------------------------------------- /ports/win32/README.md: -------------------------------------------------------------------------------- 1 | # Win32-API (Windows multi-threaded with Win32-threads) 2 | 3 | Documentation for this port is available in the QP/C Manual at: 4 | 5 | - https://www.state-machine.com/qpc/win32.html 6 | -------------------------------------------------------------------------------- /ports/win32/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | #ifdef _WIN64 // 64-bit architecture? 32 | #define QS_OBJ_PTR_SIZE 8U 33 | #define QS_FUN_PTR_SIZE 8U 34 | #else // 32-bit architecture 35 | #define QS_OBJ_PTR_SIZE 4U 36 | #define QS_FUN_PTR_SIZE 4U 37 | #endif 38 | 39 | void QS_output(void); // handle the QS output 40 | void QS_rx_input(void); // handle the QS-RX input 41 | 42 | //============================================================================ 43 | // NOTE: QS might be used with or without other QP components, in which 44 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 45 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 46 | // with the other QP component, by simply including "qp_port.h" 47 | // *before* "qs.h". 48 | #ifndef QP_PORT_H_ 49 | #include "qp_port.h" // use QS with QP 50 | #endif 51 | 52 | #include "qs.h" // QS platform-independent public interface 53 | 54 | #endif // QS_PORT_H_ 55 | -------------------------------------------------------------------------------- /ports/win32/safe_std.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef SAFE_STD_H_ 30 | #define SAFE_STD_H_ 31 | 32 | #include 33 | #include 34 | 35 | // portable "safe" facilities from and ................ 36 | #ifdef _WIN32 // Windows OS? 37 | 38 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 39 | memmove_s(dest_, num_, src_, count_) 40 | 41 | #define STRNCPY_S(dest_, destsiz_, src_) \ 42 | strncpy_s(dest_, destsiz_, src_, _TRUNCATE) 43 | 44 | #define STRCAT_S(dest_, destsiz_, src_) \ 45 | strcat_s(dest_, destsiz_, src_) 46 | 47 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 48 | _snprintf_s(buf_, bufsiz_, _TRUNCATE, format_, __VA_ARGS__) 49 | 50 | #define PRINTF_S(format_, ...) \ 51 | printf_s(format_, __VA_ARGS__) 52 | 53 | #define FPRINTF_S(fp_, format_, ...) \ 54 | fprintf_s(fp_, format_, __VA_ARGS__) 55 | 56 | #ifdef _MSC_VER 57 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 58 | fread_s(buf_, bufsiz_, elsiz_, count_, fp_) 59 | #else 60 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 61 | fread(buf_, elsiz_, count_, fp_) 62 | #endif // _MSC_VER 63 | 64 | #define FOPEN_S(fp_, fName_, mode_) \ 65 | if (fopen_s(&fp_, fName_, mode_) != 0) { \ 66 | fp_ = (FILE *)0; \ 67 | } else (void)0 68 | 69 | #define LOCALTIME_S(tm_, time_) \ 70 | localtime_s(tm_, time_) 71 | 72 | #else // other OS (Linux, MacOS, etc.) ..................................... 73 | 74 | #define MEMMOVE_S(dest_, num_, src_, count_) \ 75 | memmove(dest_, src_, count_) 76 | 77 | #define STRNCPY_S(dest_, destsiz_, src_) do { \ 78 | strncpy(dest_, src_, destsiz_); \ 79 | dest_[(destsiz_) - 1] = '\0'; \ 80 | } while (false) 81 | 82 | #define STRCAT_S(dest_, destsiz_, src_) \ 83 | strcat(dest_, src_) 84 | 85 | #define SNPRINTF_S(buf_, bufsiz_, format_, ...) \ 86 | snprintf(buf_, bufsiz_, format_, __VA_ARGS__) 87 | 88 | #define PRINTF_S(format_, ...) \ 89 | printf(format_, __VA_ARGS__) 90 | 91 | #define FPRINTF_S(fp_, format_, ...) \ 92 | fprintf(fp_, format_, __VA_ARGS__) 93 | 94 | #define FREAD_S(buf_, bufsiz_, elsiz_, count_, fp_) \ 95 | fread(buf_, elsiz_, count_, fp_) 96 | 97 | #define FOPEN_S(fp_, fName_, mode_) \ 98 | (fp_ = fopen(fName_, mode_)) 99 | 100 | #define LOCALTIME_S(tm_, time_) \ 101 | memcpy(tm_, localtime(time_), sizeof(struct tm)) 102 | 103 | #endif // _WIN32 104 | 105 | #endif // SAFE_STD_H_ 106 | -------------------------------------------------------------------------------- /ports/zephyr/README.md: -------------------------------------------------------------------------------- 1 | The QP/C port to Zephyr is located in the `qpc/zephyr` directory 2 | to follow the conventions established for 3 | [Zephyr modules](https://docs.zephyrproject.org/latest/develop/modules.html) 4 | -------------------------------------------------------------------------------- /qpc_sdk_init.cmake: -------------------------------------------------------------------------------- 1 | # Pre-initialize the QPC SDK 2 | # This file must be included prior to the project() call 3 | 4 | # Note: this file is perhaps named badly, as it provides a method qpc_sdk_init which 5 | # the enclosing project calls LATER to actually "initialize" the SDK (by including the CMakeLists.txt from this 6 | # same directory) 7 | 8 | if (NOT TARGET _qpc_sdk_pre_init_marker) 9 | add_library(_qpc_sdk_pre_init_marker INTERFACE) 10 | 11 | function(qpc_is_top_level_project VAR) 12 | string(TOLOWER ${CMAKE_CURRENT_LIST_DIR} __list_dir) 13 | string(TOLOWER ${CMAKE_SOURCE_DIR} __source_dir) 14 | if (__source_dir STREQUAL __list_dir) 15 | set(${VAR} 1 PARENT_SCOPE) 16 | else() 17 | set(${VAR} 0 PARENT_SCOPE) 18 | endif() 19 | endfunction() 20 | 21 | function(qpc_message_debug MESSAGE) 22 | # The log-level system was added in CMake 3.15. 23 | if(${CMAKE_VERSION} VERSION_LESS "3.15.0") 24 | message(${MESSAGE}) 25 | else() 26 | message(DEBUG ${MESSAGE}) 27 | endif() 28 | endfunction() 29 | 30 | if (NOT QPC_SDK_PATH) 31 | set(QPC_SDK_PATH ${CMAKE_CURRENT_LIST_DIR}) 32 | endif () 33 | 34 | file(REAL_PATH "${QPC_SDK_PATH}" QPC_SDK_PATH BASE_DIRECTORY "${CMAKE_BINARY_DIR}") 35 | 36 | set(QPC_SDK_PATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to the QP/C SDK" FORCE) 37 | 38 | list(APPEND CMAKE_MODULE_PATH ${QPC_SDK_PATH}/cmake) 39 | 40 | message("QPC_SDK_PATH is ${CMAKE_CURRENT_LIST_DIR}") 41 | 42 | function(qpc_sdk_init) 43 | if (NOT CMAKE_PROJECT_NAME) 44 | message(WARNING "qpc_sdk_init() should be called after the project is created (and languages added)") 45 | endif() 46 | 47 | add_subdirectory(${QPC_SDK_PATH} qpc-sdk) 48 | endfunction() 49 | endif() 50 | -------------------------------------------------------------------------------- /sha1.bat: -------------------------------------------------------------------------------- 1 | @setlocal 2 | 3 | set VERSION=8.0.4 4 | 5 | :: usage 6 | @echo Usage: qpc_sha1 [gen] 7 | @echo examples of use: 8 | @echo qpc_sha1 : check the sha1 sums in the file qpc_%VERSION%.sha1 9 | @echo qpc_sha1 gen : generate the sha1 file qpc_%VERSION%.sha1 10 | @echo. 11 | 12 | @if NOT "%1"=="gen" ( 13 | sha1sum --check --warn qpc_%VERSION%.sha1 14 | goto end 15 | ) 16 | 17 | @echo generating qpc_%VERSION%.sha1... 18 | @sha1sum ^ 19 | include/* ^ 20 | src/qf/* src/qk/* src/qs/* src/qv/* src/qxk/* ^ 21 | ports/arm-cm/config/* ^ 22 | ports/arm-cm/qk/armclang/* ports/arm-cm/qk/gnu/* ports/arm-cm/qk/iar/* ^ 23 | ports/arm-cm/qv/armclang/* ports/arm-cm/qv/gnu/* ports/arm-cm/qv/iar/* ^ 24 | ports/arm-cm/qxk/armclang/* ports/arm-cm/qxk/gnu/* ports/arm-cm/qxk/iar/* ^ 25 | ports/arm-cm/qutest/* ^ 26 | ports/arm-cr/config/* ^ 27 | ports/arm-cr/qk/gnu/* ports/arm-cr/qk/iar/* ports/arm-cr/qk/ti/* ^ 28 | ports/arm-cr/qv/gnu/* ports/arm-cr/qv/iar/* ports/arm-cr/qv/ti/* ^ 29 | ports/msp430/qk/* ports/msp430/qv/* ports/msp430/qutest/* ^ 30 | ports/config/* ^ 31 | ports/embos/* ^ 32 | ports/freertos/* ^ 33 | ports/threadx/* ^ 34 | ports/uc-os2/* ^ 35 | ports/qep-only/* ^ 36 | ports/posix/* ports/posix-qv/* ports/posix-qutest/* ^ 37 | ports/win32/* ports/win32-qv/* ports/win32-qutest/* ^ 38 | zephyr/* ^ 39 | > qpc_%VERSION%.sha1 40 | qclean 41 | @echo done 42 | 43 | :end 44 | @endlocal 45 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # qpc/src 2 | add_subdirectory(qf) 3 | add_subdirectory(qs) 4 | if(${PORT} IN_LIST QPC_BAREMETAL_PORTS) 5 | message(STATUS "adding subdir '${KERNEL}' for port '${PORT}'") 6 | add_subdirectory(${KERNEL}) 7 | endif() 8 | -------------------------------------------------------------------------------- /src/README.md: -------------------------------------------------------------------------------- 1 | # Files Missing from the QP/C GPL Distribution 2 | Due to the widespread non-compliance with the GPL, as well as infringement 3 | on the [dual-licensing model of QP frameworks][Lic], the following files 4 | have been **removed from the open-source GPL distribution**: 5 | 6 | ``` 7 | qpc 8 | | 9 | +---include 10 | | qs.h 11 | | qs_pkg.h 12 | | qxk.h 13 | | 14 | \---src 15 | | 16 | +---qs 17 | | qs.c 18 | | qs_64bit.c 19 | | qs_fp.c 20 | | qs_rx.c 21 | | qutest.c 22 | | 23 | \---qxk 24 | qxk.c 25 | qxk_mutex.c 26 | qxk_sema.c 27 | qxk_xthr.c 28 | ``` 29 | 30 | > NOTE: These files are available to the [commercial licensees][Cust] with 31 | the active Support Term. Please contact [Quantum Leaps technical support][Sup] 32 | to get the complete QP/C framework distribution. 33 | 34 | # QP/C Framework Evaluation 35 | To request **evaluation** of the complete QP/C framework, please contact 36 | Quantum Leaps at: 37 | - https://www.state-machine.com/contact 38 | 39 | # Quantum Leaps Licensing: 40 | To learn more about the open source and commercial licensing options: 41 | - https://www.state-machine.com/licensing 42 | 43 | [Lic]: 44 | [Cust]: 45 | [Sup]: 46 | -------------------------------------------------------------------------------- /src/qf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./src/qf 2 | target_sources(qpc PRIVATE 3 | qep_hsm.c 4 | qep_msm.c 5 | qf_act.c 6 | # qf_actq.c - see below 7 | qf_defer.c 8 | qf_dyn.c 9 | # qf_mem.c - see below 10 | qf_ps.c 11 | qf_qact.c 12 | qf_qeq.c 13 | qf_qmact.c 14 | qf_time.c 15 | ) 16 | if(NOT (${QPC_CFG_PORT} IN_LIST QPC_RTOS_PORTS)) 17 | target_sources(qpc PRIVATE 18 | qf_actq.c 19 | ) 20 | endif() 21 | if(NOT (${QPC_CFG_PORT} STREQUAL uc-os2)) 22 | target_sources(qpc PRIVATE 23 | qf_mem.c 24 | ) 25 | endif() -------------------------------------------------------------------------------- /src/qf/qf_act.c: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #define QP_IMPL // this is QP implementation 30 | #include "qp_port.h" // QP port 31 | #include "qp_pkg.h" // QP package-scope interface 32 | #include "qsafe.h" // QP Functional Safety (FuSa) Subsystem 33 | #ifdef Q_SPY // QS software tracing enabled? 34 | #include "qs_port.h" // QS port 35 | #include "qs_pkg.h" // QS facilities for pre-defined trace records 36 | #else 37 | #include "qs_dummy.h" // disable the QS software tracing 38 | #endif // Q_SPY 39 | 40 | //Q_DEFINE_THIS_MODULE("qf_act") 41 | 42 | // QP version string embedded in the binary image 43 | char const QP_versionStr[24] = "QP/C " QP_VERSION_STR; 44 | 45 | QF_Attr QF_priv_; 46 | 47 | //! @static @private @memberof QActive 48 | QActive * QActive_registry_[QF_MAX_ACTIVE + 1U]; 49 | 50 | //............................................................................ 51 | //! @static @private @memberof QF 52 | void QF_bzero_( 53 | void * const start, 54 | uint_fast16_t const len) 55 | { 56 | uint8_t *ptr = (uint8_t *)start; 57 | for (uint_fast16_t n = len; n > 0U; --n) { 58 | *ptr = 0U; 59 | ++ptr; 60 | } 61 | } 62 | 63 | //............................................................................ 64 | #ifndef QF_LOG2 65 | uint_fast8_t QF_LOG2(QPSetBits const bitmask) { 66 | static uint8_t const log2LUT[16] = { 67 | 0U, 1U, 2U, 2U, 3U, 3U, 3U, 3U, 68 | 4U, 4U, 4U, 4U, 4U, 4U, 4U, 4U 69 | }; 70 | uint_fast8_t n = 0U; 71 | QPSetBits x = bitmask; 72 | QPSetBits tmp; 73 | 74 | #if (QF_MAX_ACTIVE > 16U) 75 | tmp = (x >> 16U); 76 | if (tmp != 0U) { 77 | n += 16U; 78 | x = tmp; 79 | } 80 | #endif 81 | #if (QF_MAX_ACTIVE > 8U) 82 | tmp = (x >> 8U); 83 | if (tmp != 0U) { 84 | n += 8U; 85 | x = tmp; 86 | } 87 | #endif 88 | tmp = (x >> 4U); 89 | if (tmp != 0U) { 90 | n += 4U; 91 | x = tmp; 92 | } 93 | return n + log2LUT[x]; 94 | } 95 | #endif // ndef QF_LOG2 96 | -------------------------------------------------------------------------------- /src/qf/qf_qact.c: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #define QP_IMPL // this is QP implementation 30 | #include "qp_port.h" // QP port 31 | #include "qp_pkg.h" // QP package-scope interface 32 | #include "qsafe.h" // QP Functional Safety (FuSa) Subsystem 33 | #ifdef Q_SPY // QS software tracing enabled? 34 | #include "qs_port.h" // QS port 35 | #include "qs_pkg.h" // QS facilities for pre-defined trace records 36 | #else 37 | #include "qs_dummy.h" // disable the QS software tracing 38 | #endif // Q_SPY 39 | 40 | Q_DEFINE_THIS_MODULE("qf_qact") 41 | 42 | //............................................................................ 43 | //! @protected @memberof QActive 44 | void QActive_ctor(QActive * const me, 45 | QStateHandler const initial) 46 | { 47 | // clear the whole QActive object, so that the framework can start 48 | // correctly even if the startup code fails to clear the uninitialized 49 | // data (as is required by the C Standard). 50 | QF_bzero_(me, sizeof(*me)); 51 | 52 | // NOTE: QActive inherits the abstract QAsm class, but it calls the 53 | // constructor of the QHsm subclass. This is because QActive inherits 54 | // the behavior from the QHsm subclass. 55 | QHsm_ctor((QHsm *)(me), initial); 56 | 57 | // NOTE: this vtable is identical as QHsm, but is provided 58 | // for the QActive subclass to provide a UNIQUE vptr to distinguish 59 | // subclasses of QActive (e.g., in the debugger). 60 | static struct QAsmVtable const vtable = { // QActive virtual table 61 | &QHsm_init_, 62 | &QHsm_dispatch_, 63 | &QHsm_isIn_ 64 | #ifdef Q_SPY 65 | ,&QHsm_getStateHandler_ 66 | #endif 67 | }; 68 | me->super.vptr = &vtable; // hook vptr to QActive vtable 69 | } 70 | 71 | //............................................................................ 72 | //! @private @memberof QActive 73 | void QActive_register_(QActive * const me) { 74 | QF_CRIT_STAT 75 | QF_CRIT_ENTRY(); 76 | 77 | if (me->pthre == 0U) { // preemption-threshold not defined? 78 | me->pthre = me->prio; // apply the default 79 | } 80 | 81 | #ifndef Q_UNSAFE 82 | Q_REQUIRE_INCRIT(100, 83 | (0U < me->prio) && (me->prio <= QF_MAX_ACTIVE)); 84 | Q_REQUIRE_INCRIT(110, QActive_registry_[me->prio] == (QActive *)0); 85 | Q_REQUIRE_INCRIT(120, me->prio <= me->pthre); 86 | 87 | uint8_t prev_thre = me->pthre; 88 | uint8_t next_thre = me->pthre; 89 | 90 | for (uint_fast8_t p = (uint_fast8_t)me->prio - 1U; 91 | p > 0U; 92 | --p) 93 | { 94 | if (QActive_registry_[p] != (QActive *)0) { 95 | prev_thre = QActive_registry_[p]->pthre; 96 | break; 97 | } 98 | } 99 | for (uint_fast8_t p = (uint_fast8_t)me->prio + 1U; 100 | p <= QF_MAX_ACTIVE; 101 | ++p) 102 | { 103 | if (QActive_registry_[p] != (QActive *)0) { 104 | next_thre = QActive_registry_[p]->pthre; 105 | break; 106 | } 107 | } 108 | 109 | Q_ASSERT_INCRIT(160, 110 | (prev_thre <= me->pthre) && (me->pthre <= next_thre)); 111 | 112 | #endif // Q_UNSAFE 113 | 114 | // register the AO at the QF-prio. 115 | QActive_registry_[me->prio] = me; 116 | 117 | QF_CRIT_EXIT(); 118 | } 119 | 120 | //............................................................................ 121 | //! @private @memberof QActive 122 | void QActive_unregister_(QActive * const me) { 123 | uint_fast8_t const p = (uint_fast8_t)me->prio; 124 | 125 | QF_CRIT_STAT 126 | QF_CRIT_ENTRY(); 127 | 128 | Q_REQUIRE_INCRIT(200, (0U < p) && (p <= QF_MAX_ACTIVE)); 129 | Q_REQUIRE_INCRIT(210, QActive_registry_[p] == me); 130 | 131 | me->super.state.fun = Q_STATE_CAST(0); // invalidate the state 132 | 133 | QActive_registry_[p] = (QActive *)0; // free-up the prio. level 134 | QF_CRIT_EXIT(); 135 | } 136 | -------------------------------------------------------------------------------- /src/qf/qf_qmact.c: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #define QP_IMPL // this is QP implementation 30 | #include "qp_port.h" // QP port 31 | #include "qp_pkg.h" // QP package-scope interface 32 | #include "qsafe.h" // QP Functional Safety (FuSa) Subsystem 33 | #ifdef Q_SPY // QS software tracing enabled? 34 | #include "qs_port.h" // QS port 35 | #include "qs_pkg.h" // QS facilities for pre-defined trace records 36 | #else 37 | #include "qs_dummy.h" // disable the QS software tracing 38 | #endif // Q_SPY 39 | 40 | //Q_DEFINE_THIS_MODULE("qf_qmact") 41 | 42 | //............................................................................ 43 | //! @protected @memberof QMActive 44 | void QMActive_ctor(QMActive * const me, 45 | QStateHandler const initial) 46 | { 47 | // clear the whole QMActive object, so that the framework can start 48 | // correctly even if the startup code fails to clear the uninitialized 49 | // data (as is required by the C Standard). 50 | QF_bzero_(me, sizeof(*me)); 51 | 52 | // NOTE: QActive inherits the QActvie class, but it calls the 53 | // constructor of the QMsm subclass. This is because QMActive inherits 54 | // the behavior from the QMsm subclass. 55 | QMsm_ctor((QMsm *)(me), initial); 56 | 57 | // NOTE: this vtable is identical as QMsm, but is provided 58 | // for the QMActive subclass to provide a UNIQUE vptr to distinguish 59 | // subclasses of QActive (e.g., in the debugger). 60 | static struct QAsmVtable const vtable = { // QMActive virtual table 61 | &QMsm_init_, 62 | &QMsm_dispatch_, 63 | &QMsm_isIn_ 64 | #ifdef Q_SPY 65 | ,&QMsm_getStateHandler_ 66 | #endif 67 | }; 68 | me->super.super.vptr = &vtable; // hook vptr to QMActive vtable 69 | } 70 | -------------------------------------------------------------------------------- /src/qk/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./src/qf 2 | target_sources(qpc PRIVATE 3 | qk.c 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /src/qs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./src/qs 2 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/qs.c) 3 | target_sources(qpc PRIVATE 4 | "$<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_64bit.c>" 5 | "$<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_fp.c>" 6 | "$<$:${CMAKE_CURRENT_SOURCE_DIR}/qs_rx.c>" 7 | "$<$:${CMAKE_CURRENT_SOURCE_DIR}/qstamp.c>" 8 | "$<$:${CMAKE_CURRENT_SOURCE_DIR}/qs.c>" 9 | "$<$,$>:${CMAKE_CURRENT_SOURCE_DIR}/qutest.c>" 10 | ) 11 | else() 12 | target_sources(qpc PRIVATE 13 | "$<$:${CMAKE_CURRENT_SOURCE_DIR}/qstamp.c>" 14 | ) 15 | endif() 16 | -------------------------------------------------------------------------------- /src/qs/qstamp.c: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #include "qstamp.h" 29 | 30 | char const Q_BUILD_DATE[12] = __DATE__; 31 | char const Q_BUILD_TIME[9] = __TIME__; 32 | -------------------------------------------------------------------------------- /src/qv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ./src/qf 2 | target_sources(qpc PRIVATE 3 | qv.c 4 | ) 5 | -------------------------------------------------------------------------------- /zephyr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # QPC Zephyr module 2 | # SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 3 | 4 | zephyr_library_named(qpc) 5 | 6 | if(CONFIG_QPC) 7 | 8 | set(QPC_DIR ..) 9 | 10 | zephyr_include_directories( 11 | ${QPC_DIR}/include 12 | ${QPC_DIR}/zephyr 13 | ) 14 | 15 | target_include_directories(app PUBLIC 16 | ${QPC_DIR}/include 17 | ${QPC_DIR}/zephyr 18 | ) 19 | 20 | zephyr_library_sources( 21 | ${QPC_DIR}/src/qf/qep_hsm.c 22 | ${QPC_DIR}/src/qf/qep_msm.c 23 | ${QPC_DIR}/src/qf/qf_act.c 24 | ${QPC_DIR}/src/qf/qf_defer.c 25 | ${QPC_DIR}/src/qf/qf_dyn.c 26 | ${QPC_DIR}/src/qf/qf_mem.c 27 | ${QPC_DIR}/src/qf/qf_ps.c 28 | ${QPC_DIR}/src/qf/qf_qact.c 29 | ${QPC_DIR}/src/qf/qf_qeq.c 30 | ${QPC_DIR}/src/qf/qf_qmact.c 31 | ${QPC_DIR}/src/qf/qf_time.c 32 | ${QPC_DIR}/zephyr/qf_port.c 33 | ) 34 | 35 | # QSPY option... 36 | if(QSPY) 37 | 38 | target_compile_definitions(app PUBLIC Q_SPY) 39 | zephyr_library_compile_definitions(Q_SPY) 40 | 41 | zephyr_library_sources( 42 | ${QPC_DIR}/src/qs/qs.c 43 | ${QPC_DIR}/src/qs/qs_rx.c 44 | ${QPC_DIR}/src/qs/qs_fp.c 45 | ${QPC_DIR}/src/qs/qutest.c 46 | ${QPC_DIR}/src/qs/qs_64bit.c 47 | ${QPC_DIR}/src/qs/qstamp.c 48 | ) 49 | 50 | endif() # QSPY 51 | 52 | endif() # CONFIG_QPC 53 | -------------------------------------------------------------------------------- /zephyr/Kconfig: -------------------------------------------------------------------------------- 1 | # QPC Zephyr module 2 | # SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 3 | 4 | menuconfig QPC 5 | bool "QPC" 6 | default n 7 | help 8 | Enables the QPC Module 9 | 10 | if QPC 11 | 12 | module = QPC 13 | module-str = QPC 14 | 15 | endif 16 | -------------------------------------------------------------------------------- /zephyr/README.md: -------------------------------------------------------------------------------- 1 | [![QP Zephyr Module](./qp-zephyr.jpg)](https://www.state-machine.com/qpc/zephyr.html) 2 | 3 | # About the QPC Zephyr Module 4 | This directory defines the 5 | [QP/C Real-Time Embedded Framework](https://github.com/QuantumLeaps/qpc) 6 | as a [Zephyr module](https://docs.zephyrproject.org/latest/develop/modules.html). 7 | 8 | # How to use 9 | Example of use is provided in the related repository 10 | [qpc-zephyr-app](https://github.com/QuantumLeaps/qpc-zephyr-app) 11 | 12 | To create your own QP-Zephyr project, you can clone that repository 13 | and customize it to your needs: 14 | 15 | ```bash 16 | git clone https://github.com/QuantumLeaps/qpc-zephyr-app --recurse-submodules --depth 1 17 | ``` 18 | where `` is the name of your project. 19 | 20 | 21 | ## Configuring the QPC Zephyr Module 22 | The `Kconfig` file provides configuration `CONFIG_QPC` to activate the QPC module 23 | in Zephyr. To do so, you need to add the following line to your `prj.conf`: 24 | 25 | ```ini 26 | CONFIG_QPC=y 27 | ``` 28 | 29 | ## Option for Activating QSPY Software Tracing 30 | The QP/C Zephyr Module supports the 31 | [QSPY Software Tracing](https://www.state-machine.com/qtools/qpspy.html) 32 | option and will add the appropriate macros and files to build the "QSPY" 33 | configuration. 34 | 35 | If you wish to enable "QSPY" you can provide the option "QSPY" 36 | in the command-line for the build. For example: 37 | 38 | ```bash 39 | west build -b nucleo_h743zi -- -DQSPY=ON 40 | ``` 41 | -------------------------------------------------------------------------------- /zephyr/module.yml: -------------------------------------------------------------------------------- 1 | build: 2 | cmake: zephyr 3 | kconfig: zephyr/Kconfig 4 | -------------------------------------------------------------------------------- /zephyr/qp-zephyr.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QuantumLeaps/qpc/c3c9a0522d4149f5d9bded5a47806bdba6d64cd8/zephyr/qp-zephyr.jpg -------------------------------------------------------------------------------- /zephyr/qp_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-QL-commercial 11 | // 12 | // This software is dual-licensed under the terms of the open-source GNU 13 | // General Public License (GPL) or under the terms of one of the closed- 14 | // source Quantum Leaps commercial licenses. 15 | // 16 | // Redistributions in source code must retain this top-level comment block. 17 | // Plagiarizing this software to sidestep the license obligations is illegal. 18 | // 19 | // NOTE: 20 | // The GPL does NOT permit the incorporation of this code into proprietary 21 | // programs. Please contact Quantum Leaps for commercial licensing options, 22 | // which expressly supersede the GPL and are designed explicitly for 23 | // closed-source distribution. 24 | // 25 | // Quantum Leaps contact information: 26 | // 27 | // 28 | //============================================================================ 29 | #ifndef QP_PORT_H_ 30 | #define QP_PORT_H_ 31 | 32 | #include // Exact-width types. WG14/N843 C99 Standard 33 | #include // Boolean type. WG14/N843 C99 Standard 34 | #include "qp_config.h" // QP configuration from the application 35 | #include // Zephyr kernel API 36 | 37 | // no-return function specifier (C11 Standard) 38 | #define Q_NORETURN _Noreturn void 39 | 40 | // event queue and thread types 41 | #define QACTIVE_EQUEUE_TYPE struct k_msgq 42 | #define QACTIVE_THREAD_TYPE struct k_thread 43 | 44 | // QF critical section entry/exit for Zephyr, see NOTE1 45 | #define QF_CRIT_STAT k_spinlock_key_t key_; 46 | #define QF_CRIT_ENTRY() ((key_) = k_spin_lock(&QF_spinlock)) 47 | #define QF_CRIT_EXIT() k_spin_unlock(&QF_spinlock, key_) 48 | #define QF_CRIT_EST() ((void)k_spin_lock(&QF_spinlock)) 49 | 50 | // Q_PRINTK() macro to avoid conflicts with Zephyr's printk() 51 | // when Q_SPY configuration is used 52 | #ifndef Q_SPY 53 | #define Q_PRINTK(fmt_, ...) printk(fmt_, ##__VA_ARGS__) 54 | #else 55 | #define Q_PRINTK(dummy, ...) ((void)0) 56 | #endif 57 | 58 | // include files ------------------------------------------------------------- 59 | #include "qequeue.h" // used for event deferral 60 | #include "qmpool.h" // this QP port uses the native QF memory pool 61 | #include "qp.h" // QP platform-independent public interface 62 | 63 | // Zephyr spinlock for QF critical section 64 | extern struct k_spinlock QF_spinlock; 65 | 66 | //============================================================================ 67 | // interface used only inside QF implementation, but not in applications 68 | #ifdef QP_IMPL 69 | 70 | // scheduler locking, see NOTE2 71 | #define QF_SCHED_STAT_ 72 | #define QF_SCHED_LOCK_(dummy) do { \ 73 | if (!k_is_in_isr()) { \ 74 | k_sched_lock(); \ 75 | } \ 76 | } while (false) 77 | 78 | #define QF_SCHED_UNLOCK_() do { \ 79 | if (!k_is_in_isr()) { \ 80 | k_sched_unlock(); \ 81 | } \ 82 | } while (false) 83 | 84 | // native QF event pool customization 85 | #define QF_EPOOL_TYPE_ QMPool 86 | #define QF_EPOOL_INIT_(p_, poolSto_, poolSize_, evtSize_) \ 87 | (QMPool_init(&(p_), (poolSto_), (poolSize_), (evtSize_))) 88 | #define QF_EPOOL_EVENT_SIZE_(p_) ((uint_fast16_t)(p_).blockSize) 89 | #define QF_EPOOL_GET_(p_, e_, m_, qsId_) \ 90 | ((e_) = (QEvt *)QMPool_get(&(p_), (m_), (qsId_))) 91 | #define QF_EPOOL_PUT_(p_, e_, qsId_) \ 92 | (QMPool_put(&(p_), (e_), (qsId_))) 93 | 94 | #endif // QP_IMPL 95 | 96 | //============================================================================ 97 | // NOTE1: 98 | // This QP port to Zephyr assumes that Active Objects will use only the 99 | // preemptive Zephyr priorities [0..(CONFIG_NUM_PREEMPT_PRIORITIES - 1U)]. 100 | // In this priority numbering, the QP AO priority QF_MAX_ACTIVE (highest) 101 | // maps to Zephyr priority 0 (highest). The QP AO priority 1 (lowest) maps 102 | // to Zephyr priority (CONFIG_NUM_PREEMPT_PRIORITIES - 2U). 103 | // 104 | // NOTE2: 105 | // Zephyr does not support selective scheduler locking up to a given 106 | // priority ceiling. Therefore, this port uses global Zephyr scheduler lock. 107 | // 108 | 109 | #endif // QP_PORT_H_ 110 | 111 | -------------------------------------------------------------------------------- /zephyr/qs_port.h: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // QP/C Real-Time Event Framework (RTEF) 3 | // 4 | // Copyright (C) 2005 Quantum Leaps, LLC. All rights reserved. 5 | // 6 | // Q u a n t u m L e a P s 7 | // ------------------------ 8 | // Modern Embedded Software 9 | // 10 | // SPDX-License-Identifier: LicenseRef-QL-commercial 11 | // 12 | // This software is licensed under the terms of the Quantum Leaps commercial 13 | // licenses. Please contact Quantum Leaps for more information about the 14 | // available licensing options. 15 | // 16 | // RESTRICTIONS 17 | // You may NOT : 18 | // (a) redistribute, encumber, sell, rent, lease, sublicense, or otherwise 19 | // transfer rights in this software, 20 | // (b) remove or alter any trademark, logo, copyright or other proprietary 21 | // notices, legends, symbols or labels present in this software, 22 | // (c) plagiarize this software to sidestep the licensing obligations. 23 | // 24 | // Quantum Leaps contact information: 25 | // 26 | // 27 | //============================================================================ 28 | #ifndef QS_PORT_H_ 29 | #define QS_PORT_H_ 30 | 31 | // object pointer size in bytes 32 | #define QS_OBJ_PTR_SIZE 4U 33 | 34 | // function pointer size in bytes 35 | #define QS_FUN_PTR_SIZE 4U 36 | 37 | //============================================================================ 38 | // NOTE: QS might be used with or without other QP components, in which 39 | // case the separate definitions of the macros QF_CRIT_STAT, QF_CRIT_ENTRY(), 40 | // and QF_CRIT_EXIT() are needed. In this port QS is configured to be used 41 | // with the other QP component, by simply including "qp_port.h" 42 | // *before* "qs.h". 43 | #ifndef QP_PORT_H_ 44 | #include "qp_port.h" // use QS with QP 45 | #endif 46 | 47 | #include "qs.h" // QS platform-independent public interface 48 | 49 | #endif // QS_PORT_H_ 50 | --------------------------------------------------------------------------------