qpc/ports/threadx/qf_port.h

154 lines
6.2 KiB
C
Raw Normal View History

2015-04-28 13:45:35 -04:00
/**
* @file
* @brief QF/C, port to ThreadX
* @cond
******************************************************************************
2020-10-01 12:48:48 -04:00
* Last updated for version 6.9.1
* Last updated on 2020-09-08
*
2020-03-17 21:33:20 -04:00
* Q u a n t u m L e a P s
* ------------------------
* Modern Embedded Software
*
2020-03-17 21:33:20 -04:00
* Copyright (C) 2005-2020 Quantum Leaps, LLC. All rights reserved.
*
* This program is open source software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alternatively, this program may be distributed and modified under the
* terms of Quantum Leaps commercial licenses, which expressly supersede
* the GNU General Public License and are specifically designed for
* licensees interested in retaining the proprietary status of their code.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2020-03-17 21:33:20 -04:00
* along with this program. If not, see <www.gnu.org/licenses>.
*
* Contact information:
2019-12-31 15:55:08 -05:00
* <www.state-machine.com/licensing>
* <info@state-machine.com>
2015-04-28 13:45:35 -04:00
******************************************************************************
* @endcond
*/
2019-10-27 11:57:33 -04:00
#ifndef QF_PORT_H
#define QF_PORT_H
/* ThreadX event queue and thread types */
#define QF_EQUEUE_TYPE TX_QUEUE
#define QF_THREAD_TYPE TX_THREAD
#define QF_OS_OBJECT_TYPE uint8_t
/* QF priority offset within ThreadX priority numbering scheme, see NOTE1 */
2020-03-17 21:33:20 -04:00
#define QF_TX_PRIO_OFFSET 8U
/* The maximum number of active objects in the application, see NOTE2 */
2020-03-17 21:33:20 -04:00
#define QF_MAX_ACTIVE (31U - QF_TX_PRIO_OFFSET)
/* QF critical section for ThreadX, see NOTE3 */
#define QF_CRIT_STAT_TYPE UINT
#define QF_CRIT_ENTRY(stat_) ((stat_) = tx_interrupt_control(TX_INT_DISABLE))
#define QF_CRIT_EXIT(stat_) ((void)tx_interrupt_control(stat_))
#include "tx_api.h" /* ThreadX API */
#include "qep_port.h" /* QEP port */
#include "qequeue.h" /* used for event deferral */
#include "qf.h" /* QF platform-independent public interface */
2020-10-01 12:48:48 -04:00
#ifdef Q_SPY
#include "qmpool.h" /* needed only for QS-RX */
#endif
/*****************************************************************************
* interface used only inside QF, but not in applications
*/
#ifdef QP_IMPL
2018-01-10 18:27:33 -05:00
/*! ThreadX-specific scheduler locking (implemented in qf_port.c) */
2016-03-30 18:50:33 -04:00
typedef struct {
uint_fast8_t lockPrio; /*!< lock prio [QF numbering scheme] */
UINT prevThre; /*!< previoius preemption threshold */
TX_THREAD *lockHolder; /*!< the thread holding the lock */
} QFSchedLock;
2016-09-29 18:08:33 -04:00
#define QF_SCHED_STAT_ QFSchedLock lockStat_;
2020-03-17 21:33:20 -04:00
#define QF_SCHED_LOCK_(prio_) do { \
if (_tx_thread_system_state != 0U) { \
lockStat_.lockPrio = 0U; \
} else { \
2016-09-29 18:08:33 -04:00
QFSchedLock_(&lockStat_, (prio_)); \
2020-03-17 21:33:20 -04:00
} \
2019-12-31 15:55:08 -05:00
} while (false)
2020-03-17 21:33:20 -04:00
#define QF_SCHED_UNLOCK_() do { \
if (lockStat_.lockPrio != 0U) { \
2016-09-29 18:08:33 -04:00
QFSchedUnlock_(&lockStat_); \
2020-03-17 21:33:20 -04:00
} \
2019-12-31 15:55:08 -05:00
} while (false)
2016-03-30 18:50:33 -04:00
/* internal implementation of scheduler locking/unlocking */
2016-04-01 10:02:43 -04:00
void QFSchedLock_(QFSchedLock * const lockStat, uint_fast8_t prio);
2016-03-30 18:50:33 -04:00
void QFSchedUnlock_(QFSchedLock const * const lockStat);
extern UINT _tx_thread_system_state; /* internal TX interrupt counter */
2016-09-29 18:08:33 -04:00
/* TreadX block pool operations... */
#define QF_EPOOL_TYPE_ TX_BLOCK_POOL
2020-03-17 21:33:20 -04:00
#define QF_EPOOL_INIT_(pool_, poolSto_, poolSize_, evtSize_) \
2018-01-10 18:27:33 -05:00
Q_ALLEGE(tx_block_pool_create(&(pool_), (CHAR *)"QP", (evtSize_), \
(poolSto_), (poolSize_)) == TX_SUCCESS)
#define QF_EPOOL_EVENT_SIZE_(pool_) \
((uint_fast16_t)(pool_).tx_block_pool_block_size)
2020-10-01 12:48:48 -04:00
#define QF_EPOOL_GET_(pool_, e_, margin_, qs_id_) do { \
2020-03-17 21:33:20 -04:00
QF_CRIT_STAT_ \
2020-10-01 12:48:48 -04:00
QF_CRIT_E_(); \
2020-03-17 21:33:20 -04:00
if ((pool_).tx_block_pool_available > (margin_)) { \
Q_ALLEGE(tx_block_allocate(&(pool_), (VOID **)&(e_), TX_NO_WAIT) \
2020-03-17 21:33:20 -04:00
== TX_SUCCESS); \
} \
else { \
(e_) = (QEvt *)0; \
} \
2020-10-01 12:48:48 -04:00
QF_CRIT_X_(); \
2019-12-31 15:55:08 -05:00
} while (false)
2020-10-01 12:48:48 -04:00
#define QF_EPOOL_PUT_(dummy, e_, qs_id_) \
Q_ALLEGE(tx_block_release((VOID *)(e_)) == TX_SUCCESS)
#endif /* ifdef QP_IMPL */
/*****************************************************************************
* NOTE1:
* QF_TX_PRIO_OFFSET specifies the number of highest-urgency ThreadX
* priorities not available to QP active objects. These highest-urgency
* priorities might be used by ThreadX threads that run "above" QP active
* objects.
*
* Because the ThreadX priority numbering is "upside down" compared
* to the QP priority numbering, the ThreadX priority for an active object
* thread is calculated as follows:
* tx_prio = QF_TX_PRIO_OFFSET + QF_MAX_ACTIVE - qp_prio
*
* NOTE2:
* The maximum number of active objects in QP can be increased to 63,
* inclusive, but it can be reduced to save some memory. Also, the number of
* active objects cannot exceed the number of TreadX thread priorities
* TX_MAX_PRIORITIES, because each QP active object requires a unique
* priority level. Due to the artificial limitations of the ThreadX demo
* for Windows, QF_MAX_ACTIVE is set here lower to not exceed the total
* available priority levels.
*
* NOTE3:
* The ThreadX critical section must be able to nest, which is the case with
* the tx_interrupt_control() API.
*/
2019-10-27 11:57:33 -04:00
#endif /* QF_PORT_H */
2020-03-17 21:33:20 -04:00