2015-04-28 13:45:35 -04:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief QF/C port to Cortex-M, cooperative QV kernel, ARM-KEIL toolset
|
|
|
|
* @cond
|
|
|
|
******************************************************************************
|
2017-05-17 13:16:32 -04:00
|
|
|
* Last Updated for Version: 5.9.0
|
|
|
|
* Date of the Last Update: 2017-05-04
|
2013-09-23 14:34:35 -04:00
|
|
|
*
|
|
|
|
* Q u a n t u m L e a P s
|
|
|
|
* ---------------------------
|
|
|
|
* innovating embedded systems
|
|
|
|
*
|
2017-05-17 13:16:32 -04:00
|
|
|
* Copyright (C) 2005-2017 Quantum Leaps, LLC. All rights reserved.
|
2013-09-23 14:34:35 -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
|
2013-10-16 16:44:03 -04:00
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
2013-09-23 14:34:35 -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
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Contact information:
|
2017-05-17 13:16:32 -04:00
|
|
|
* https://state-machine.com
|
2015-12-31 14:55:40 -05:00
|
|
|
* mailto:info@state-machine.com
|
2015-04-28 13:45:35 -04:00
|
|
|
******************************************************************************
|
|
|
|
* @endcond
|
|
|
|
*/
|
2013-09-23 14:34:35 -04:00
|
|
|
#ifndef qf_port_h
|
|
|
|
#define qf_port_h
|
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
/* The maximum number of active objects in the application, see NOTE1 */
|
|
|
|
#define QF_MAX_ACTIVE 32
|
|
|
|
|
|
|
|
/* The maximum number of system clock tick rates */
|
|
|
|
#define QF_MAX_TICK_RATE 2
|
2013-09-23 14:34:35 -04:00
|
|
|
|
|
|
|
/* QF interrupt disable/enable and log2()... */
|
2017-02-08 20:25:14 -05:00
|
|
|
#if (__TARGET_ARCH_THUMB == 3) /* Cortex-M0/M0+/M1(v6-M, v6S-M)? */
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-02-08 20:25:14 -05:00
|
|
|
/* Cortex-M0/M0+/M1(v6-M, v6S-M) interrupt disabling policy, see NOTE2 */
|
2015-04-28 13:45:35 -04:00
|
|
|
#define QF_INT_DISABLE() __disable_irq()
|
|
|
|
#define QF_INT_ENABLE() __enable_irq()
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-05-17 13:16:32 -04:00
|
|
|
/* QF critical section entry/exit (save and restore interrupt status) */
|
|
|
|
#define QF_CRIT_STAT_TYPE unsigned
|
|
|
|
#define QF_CRIT_ENTRY(primask_) do { \
|
|
|
|
(primask_) = QF_get_PRIMASK(); \
|
|
|
|
QF_INT_DISABLE(); \
|
|
|
|
} while (0)
|
|
|
|
#define QF_CRIT_EXIT(primask_) QF_set_PRIMASK((primask_))
|
|
|
|
|
|
|
|
/* CMSIS threshold for "QF-aware" interrupts, see NOTE2 and NOTE5 */
|
2015-04-28 13:45:35 -04:00
|
|
|
#define QF_AWARE_ISR_CMSIS_PRI 0
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-05-17 13:16:32 -04:00
|
|
|
/* inline function for getting the PRIMASK register */
|
|
|
|
static __inline unsigned QF_get_PRIMASK(void) {
|
|
|
|
register unsigned __regPriMask __asm("primask");
|
|
|
|
return __regPriMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inline function for setting the PRIMASK register */
|
|
|
|
static __inline void QF_set_PRIMASK(unsigned primask) {
|
|
|
|
register unsigned __regPriMask __asm("primask");
|
|
|
|
__regPriMask = primask;
|
|
|
|
}
|
|
|
|
|
2017-02-08 20:25:14 -05:00
|
|
|
#else /* Cortex-M3/M4/M7 */
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-05-17 13:16:32 -04:00
|
|
|
/* Cortex-M3/M4/M7 alternative interrupt disabling with PRIMASK */
|
|
|
|
#define QF_PRIMASK_DISABLE() __disable_irq()
|
|
|
|
#define QF_PRIMASK_ENABLE() __enable_irq()
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-05-17 13:16:32 -04:00
|
|
|
/* Cortex-M3/M4/M7 interrupt disabling policy, see NOTE3 and NOTE4 */
|
|
|
|
#define QF_INT_DISABLE() do { \
|
|
|
|
QF_PRIMASK_DISABLE(); \
|
|
|
|
QF_set_BASEPRI(QF_BASEPRI); \
|
|
|
|
QF_PRIMASK_ENABLE(); \
|
|
|
|
} while (0)
|
|
|
|
#define QF_INT_ENABLE() QF_set_BASEPRI(0U)
|
|
|
|
|
|
|
|
/* QF critical section entry/exit (save and restore interrupt status) */
|
|
|
|
#define QF_CRIT_STAT_TYPE unsigned
|
|
|
|
#define QF_CRIT_ENTRY(basepri_) do {\
|
|
|
|
(basepri_) = QF_get_BASEPRI(); \
|
|
|
|
QF_INT_DISABLE(); \
|
|
|
|
} while (0)
|
|
|
|
#define QF_CRIT_EXIT(basepri_) QF_set_BASEPRI((basepri_))
|
|
|
|
|
|
|
|
/* BASEPRI threshold for "QF-aware" interrupts, see NOTE3.
|
|
|
|
* CAUTION: keep in synch with the value defined in "qk_port.s"
|
|
|
|
*/
|
2015-04-28 13:45:35 -04:00
|
|
|
#define QF_BASEPRI (0xFFU >> 2)
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-05-17 13:16:32 -04:00
|
|
|
/* CMSIS threshold for "QF-aware" interrupts, see NOTE5 */
|
2015-04-28 13:45:35 -04:00
|
|
|
#define QF_AWARE_ISR_CMSIS_PRI (QF_BASEPRI >> (8 - __NVIC_PRIO_BITS))
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-02-08 20:25:14 -05:00
|
|
|
/* Cortex-M3/M4/M7 provide the CLZ instruction for fast LOG2 */
|
2016-09-23 12:08:21 -04:00
|
|
|
#define QF_LOG2(n_) ((uint_fast8_t)(32U - __clz(n_)))
|
2013-09-23 14:34:35 -04:00
|
|
|
|
2017-05-17 13:16:32 -04:00
|
|
|
/* inline function for getting the BASEPRI register */
|
|
|
|
static __inline unsigned QF_get_BASEPRI(void) {
|
|
|
|
register unsigned volatile __regBasePri __asm("basepri");
|
|
|
|
return __regBasePri;
|
|
|
|
}
|
|
|
|
|
2013-12-30 17:37:40 -05:00
|
|
|
/* inline function for setting the BASEPRI register */
|
2014-04-06 11:43:13 -04:00
|
|
|
static __inline void QF_set_BASEPRI(unsigned basePri) {
|
|
|
|
register unsigned volatile __regBasePri __asm("basepri");
|
2013-12-30 17:37:40 -05:00
|
|
|
__regBasePri = basePri;
|
|
|
|
}
|
|
|
|
|
2013-09-23 14:34:35 -04:00
|
|
|
#endif
|
|
|
|
|
2015-12-31 14:55:40 -05:00
|
|
|
#define QF_CRIT_EXIT_NOP() __asm("isb")
|
2015-04-28 13:45:35 -04:00
|
|
|
|
|
|
|
#include "qep_port.h" /* QEP port */
|
2017-02-08 20:25:14 -05:00
|
|
|
#include "qv_port.h" /* QV cooperative kernel port */
|
2015-04-28 13:45:35 -04:00
|
|
|
#include "qf.h" /* QF platform-independent public interface */
|
2013-09-23 14:34:35 -04:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* NOTE1:
|
|
|
|
* The maximum number of active objects QF_MAX_ACTIVE can be increased
|
2017-02-08 20:25:14 -05:00
|
|
|
* up to 64, if necessary. Here it is set to a lower level to save some RAM.
|
2013-09-23 14:34:35 -04:00
|
|
|
*
|
|
|
|
* NOTE2:
|
|
|
|
* On Cortex-M0/M0+/M1 (architecture v6-M, v6S-M), the interrupt disabling
|
|
|
|
* policy uses the PRIMASK register to disable interrupts globally. The
|
|
|
|
* QF_AWARE_ISR_CMSIS_PRI level is zero, meaning that all interrupts are
|
2017-02-08 20:25:14 -05:00
|
|
|
* "QF-aware".
|
2013-09-23 14:34:35 -04:00
|
|
|
*
|
|
|
|
* NOTE3:
|
2017-02-08 20:25:14 -05:00
|
|
|
* On Cortex-M3/M4/M7, the interrupt disable/enable policy uses the BASEPRI
|
2013-09-23 14:34:35 -04:00
|
|
|
* register (which is not implemented in Cortex-M0/M0+/M1) to disable
|
2017-02-08 20:25:14 -05:00
|
|
|
* interrupts only with priority lower than the threshold specified by the
|
2013-09-23 14:34:35 -04:00
|
|
|
* QF_BASEPRI macro. The interrupts with priorities above QF_BASEPRI (i.e.,
|
2017-02-08 20:25:14 -05:00
|
|
|
* with numerical priority values lower than QF_BASEPRI) are NOT disabled in
|
|
|
|
* this method. These free-running interrupts have very low ("zero") latency,
|
|
|
|
* but they are not allowed to call any QF services, because QF is unaware
|
|
|
|
* of them ("QF-unaware" interrutps). Consequently, only interrupts with
|
|
|
|
* numerical values of priorities eqal to or higher than QF_BASEPRI
|
|
|
|
* ("QF-aware" interrupts ), can call QF services.
|
2013-09-23 14:34:35 -04:00
|
|
|
*
|
|
|
|
* NOTE4:
|
2017-05-17 13:16:32 -04:00
|
|
|
* The selective disabling of "QF-aware" interrupts with the BASEPRI register
|
|
|
|
* has a problem on ARM Cortex-M7 core r0p1 (see ARM-EPM-064408, errata
|
|
|
|
* 837070). The workaround recommended by ARM is to surround MSR BASEPRI with
|
|
|
|
* the CPSID i/CPSIE i pair, which is implemented in the QF_INT_DISABLE()
|
|
|
|
* macro. This workaround works also for Cortex-M3/M4 cores.
|
|
|
|
*
|
|
|
|
* NOTE5:
|
2013-09-23 14:34:35 -04:00
|
|
|
* The QF_AWARE_ISR_CMSIS_PRI macro is useful as an offset for enumerating
|
2017-02-08 20:25:14 -05:00
|
|
|
* the "QF-aware" interrupt priorities in the applications, whereas the
|
|
|
|
* numerical values of the "QF-aware" interrupts must be greater or equal to
|
|
|
|
* QF_AWARE_ISR_CMSIS_PRI. The values based on QF_AWARE_ISR_CMSIS_PRI can be
|
|
|
|
* passed directly to the CMSIS function NVIC_SetPriority(), which shifts
|
|
|
|
* them by (8 - __NVIC_PRIO_BITS) into the correct bit position, while
|
|
|
|
* __NVIC_PRIO_BITS is the CMSIS macro defining the number of implemented
|
|
|
|
* priority bits in the NVIC. Please note that the macro QF_AWARE_ISR_CMSIS_PRI
|
|
|
|
* is intended only for applications and is not used inside the QF port, which
|
|
|
|
* remains generic and not dependent on the number of implemented priority bits
|
|
|
|
* implemented in the NVIC.
|
2013-09-23 14:34:35 -04:00
|
|
|
*/
|
|
|
|
|
2015-04-28 13:45:35 -04:00
|
|
|
#endif /* qf_port_h */
|