qpc/ports/ucos-ii/qf_port.h

140 lines
5.4 KiB
C
Raw Normal View History

2015-04-28 13:45:35 -04:00
/**
* @file
2020-07-18 17:56:40 -04:00
* @brief QF/C generic port to uC/OS-II
2015-04-28 13:45:35 -04:00
* @cond
******************************************************************************
2020-10-01 12:48:48 -04:00
* Last updated for version 6.9.1
* Last updated on 2020-09-08
2012-08-14 18:07:04 -04:00
*
2020-03-17 21:33:20 -04:00
* Q u a n t u m L e a P s
* ------------------------
* Modern Embedded Software
2012-08-14 18:07:04 -04:00
*
2020-03-17 21:33:20 -04:00
* Copyright (C) 2005-2020 Quantum Leaps, LLC. All rights reserved.
2012-08-14 18:07:04 -04:00
*
* This program is open source software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
2012-08-14 18:07:04 -04:00
* (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>.
2012-08-14 18:07:04 -04:00
*
* 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
2012-08-14 18:07:04 -04:00
/* uC/OS-II event queue and thread types */
2015-04-28 13:45:35 -04:00
#define QF_EQUEUE_TYPE OS_EVENT *
#define QF_THREAD_TYPE uint32_t
2012-08-14 18:07:04 -04:00
/* The maximum number of active objects in the application */
2020-07-18 17:56:40 -04:00
#define QF_MAX_ACTIVE ((OS_LOWEST_PRIO - 2 < 64) ? (OS_LOWEST_PRIO - 2) : 64U)
2012-08-14 18:07:04 -04:00
2020-07-18 17:56:40 -04:00
#include "ucos_ii.h" /* uC/OS-II API, port and compile-time configuration */
2020-07-18 17:56:40 -04:00
/* uC/OS-II crtitical section, NOTE1 */
#if (OS_CRITICAL_METHOD == 1u)
/* QF_CRIT_STAT_TYPE not defined */
#define QF_CRIT_ENTRY(dummy) OS_ENTER_CRITICAL()
#define QF_CRIT_EXIT(dummy) OS_EXIT_CRITICAL()
#elif (OS_CRITICAL_METHOD == 3u)
#define QF_CRIT_STAT_TYPE OS_CPU_SR
#define QF_CRIT_ENTRY(dummy) OS_ENTER_CRITICAL()
#define QF_CRIT_EXIT(dummy) OS_EXIT_CRITICAL()
#else
#error Unsupported uC/OS-II critical section type
#endif /* OS_CRITICAL_METHOD */
2016-10-08 12:05:08 -04:00
#include "qep_port.h" /* QEP port */
#include "qequeue.h" /* native QF event queue for deferring events */
2020-07-18 17:56:40 -04:00
#include "qmpool.h" /* native QF event pool */
#include "qf.h" /* QF platform-independent public interface */
2012-08-14 18:07:04 -04:00
2018-02-12 18:53:40 -05:00
2012-08-14 18:07:04 -04:00
/*****************************************************************************
* interface used only inside QF, but not in applications
*/
2014-04-06 11:43:13 -04:00
#ifdef QP_IMPL
2012-08-14 18:07:04 -04:00
2020-07-18 17:56:40 -04:00
/* uC/OS-II crtitical section, NOTE1 */
#if (OS_CRITICAL_METHOD == 3u)
/* internal uC/OS-II critical section operations, NOTE1 */
#define QF_CRIT_STAT_ OS_CPU_SR cpu_sr;
2020-10-01 12:48:48 -04:00
#define QF_CRIT_E_() OS_ENTER_CRITICAL()
#define QF_CRIT_X_() OS_EXIT_CRITICAL()
2020-07-18 17:56:40 -04:00
#endif /* OS_CRITICAL_METHOD */
2016-09-29 18:08:33 -04:00
/* uC/OS-II-specific scheduler locking, see NOTE2 */
#define QF_SCHED_STAT_
2020-07-18 17:56:40 -04:00
#define QF_SCHED_LOCK_(dummy) do { \
if (OSIntNesting == 0) { \
OSSchedLock(); \
} \
2019-12-31 15:55:08 -05:00
} while (false)
2020-03-17 21:33:20 -04:00
2020-07-18 17:56:40 -04:00
#define QF_SCHED_UNLOCK_() do { \
if (OSIntNesting == 0) { \
OSSchedUnlock(); \
2016-09-29 18:08:33 -04:00
} \
2019-12-31 15:55:08 -05:00
} while (false)
2016-03-30 18:50:33 -04:00
2016-09-29 18:08:33 -04:00
/* uC/OS-II event pool operations... */
2015-04-28 13:45:35 -04:00
#define QF_EPOOL_TYPE_ OS_MEM*
2020-03-17 21:33:20 -04:00
#define QF_EPOOL_INIT_(pool_, poolSto_, poolSize_, evtSize_) do { \
INT8U err; \
(pool_) = OSMemCreate((poolSto_), (INT32U)((poolSize_)/(evtSize_)), \
2020-03-17 21:33:20 -04:00
(INT32U)(evtSize_), &err); \
2020-07-18 17:56:40 -04:00
Q_ASSERT_ID(105, err == OS_ERR_NONE); \
2019-12-31 15:55:08 -05:00
} while (false)
2012-08-14 18:07:04 -04:00
#define QF_EPOOL_EVENT_SIZE_(pool_) ((pool_)->OSMemBlkSize)
2020-10-01 12:48:48 -04:00
#define QF_EPOOL_GET_(pool_, e_, m_, qs_id_) do { \
QF_CRIT_STAT_ \
QF_CRIT_E_(); \
if ((pool_)->OSMemNFree > (m_)) { \
INT8U err; \
(e_) = (QEvt *)OSMemGet((pool_), &err); \
Q_ASSERT_ID(205, err == OS_ERR_NONE); \
} \
else { \
(e_) = (QEvt *)0; \
} \
QF_CRIT_X_(); \
2019-12-31 15:55:08 -05:00
} while (false)
2012-08-14 18:07:04 -04:00
2020-10-01 12:48:48 -04:00
#define QF_EPOOL_PUT_(pool_, e_, qs_id_) \
2020-07-18 17:56:40 -04:00
Q_ALLEGE_ID(305, OSMemPut((pool_), (void *)(e_)) == OS_ERR_NONE)
#endif /* ifdef QP_IMPL */
2012-08-14 18:07:04 -04:00
2013-09-23 14:34:35 -04:00
/*****************************************************************************
* NOTE1:
2020-07-18 17:56:40 -04:00
* This QP port to uC/OS-II re-uses the exact same crtical section mechanism
* as uC/OS-II. The goal is to make this port independent on the CPU or the
* toolchain by employing only the official uC/OS-II API. That way, all CPU
* and toolchain dependencies are handled internally by uC/OS-II.
2016-03-30 18:50:33 -04:00
*
* NOTE2:
* uC/OS-II provides only global scheduler locking for all thread priorities
* by means of OSSchedLock() and OSSchedUnlock(). Therefore, locking the
* scheduler only up to the specified lock priority is not supported.
2013-09-23 14:34:35 -04:00
*/
2020-07-18 17:56:40 -04:00
#endif /* QF_PORT_H */