ChibiOS/RT
2.6.0
chcore.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
00003                  2011,2012,2013 Giovanni Di Sirio.
00004 
00005     This file is part of ChibiOS/RT.
00006 
00007     ChibiOS/RT is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ChibiOS/RT is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020                                       ---
00021 
00022     A special exception to the GPL can be applied should you wish to distribute
00023     a combined work that includes ChibiOS/RT, without being obliged to provide
00024     the source code for any proprietary components. See the file exception.txt
00025     for full details of how and when the exception can be applied.
00026 */
00027 
00028 /**
00029  * @file    RVCT/ARMCMx/chcore.h
00030  * @brief   ARM Cortex-Mx port macros and structures.
00031  *
00032  * @addtogroup RVCT_ARMCMx_CORE
00033  * @{
00034  */
00035 
00036 #ifndef _CHCORE_H_
00037 #define _CHCORE_H_
00038 
00039 /*===========================================================================*/
00040 /* Port constants (common).                                                  */
00041 /*===========================================================================*/
00042 
00043 /* Added to make the header stand-alone when included from asm.*/
00044 #ifndef FALSE
00045 #define FALSE       0
00046 #endif
00047 #ifndef TRUE
00048 #define TRUE        (!FALSE)
00049 #endif
00050 
00051 #define CORTEX_M0                       0   /**< @brief Cortex-M0 variant.  */
00052 #define CORTEX_M1                       1   /**< @brief Cortex-M1 variant.  */
00053 #define CORTEX_M3                       3   /**< @brief Cortex-M3 variant.  */
00054 #define CORTEX_M4                       4   /**< @brief Cortex-M4 variant.  */
00055 
00056 /* Inclusion of the Cortex-Mx implementation specific parameters.*/
00057 #include "cmparams.h"
00058 
00059 /* Cortex model check, only M0 and M3 supported right now.*/
00060 #if (CORTEX_MODEL == CORTEX_M0) || (CORTEX_MODEL == CORTEX_M3) ||           \
00061     (CORTEX_MODEL == CORTEX_M4)
00062 #elif (CORTEX_MODEL == CORTEX_M1)
00063 #error "untested Cortex-M model"
00064 #else
00065 #error "unknown or unsupported Cortex-M model"
00066 #endif
00067 
00068 /**
00069  * @brief   Total priority levels.
00070  */
00071 #define CORTEX_PRIORITY_LEVELS          (1 << CORTEX_PRIORITY_BITS)
00072 
00073 /**
00074  * @brief   Minimum priority level.
00075  * @details This minimum priority level is calculated from the number of
00076  *          priority bits supported by the specific Cortex-Mx implementation.
00077  */
00078 #define CORTEX_MINIMUM_PRIORITY         (CORTEX_PRIORITY_LEVELS - 1)
00079 
00080 /**
00081  * @brief   Maximum priority level.
00082  * @details The maximum allowed priority level is always zero.
00083  */
00084 #define CORTEX_MAXIMUM_PRIORITY         0
00085 
00086 /*===========================================================================*/
00087 /* Port macros (common).                                                     */
00088 /*===========================================================================*/
00089 
00090 /**
00091  * @brief   Priority level verification macro.
00092  */
00093 #define CORTEX_IS_VALID_PRIORITY(n)                                         \
00094   (((n) >= 0) && ((n) < CORTEX_PRIORITY_LEVELS))
00095 
00096 /**
00097  * @brief   Priority level verification macro.
00098  */
00099 #define CORTEX_IS_VALID_KERNEL_PRIORITY(n)                                  \
00100   (((n) >= CORTEX_MAX_KERNEL_PRIORITY) && ((n) < CORTEX_PRIORITY_LEVELS))
00101 
00102 /**
00103  * @brief   Priority level to priority mask conversion macro.
00104  */
00105 #define CORTEX_PRIORITY_MASK(n)                                             \
00106   ((n) << (8 - CORTEX_PRIORITY_BITS))
00107 
00108 /*===========================================================================*/
00109 /* Port configurable parameters (common).                                    */
00110 /*===========================================================================*/
00111 
00112 /*===========================================================================*/
00113 /* Port derived parameters (common).                                         */
00114 /*===========================================================================*/
00115 
00116 /*===========================================================================*/
00117 /* Port exported info (common).                                              */
00118 /*===========================================================================*/
00119 
00120 /**
00121  * @brief   Macro defining a generic ARM architecture.
00122  */
00123 #define CH_ARCHITECTURE_ARM
00124 
00125 /**
00126  * @brief   Name of the compiler supported by this port.
00127  */
00128 #define CH_COMPILER_NAME                "RVCT"
00129 
00130 /*===========================================================================*/
00131 /* Port implementation part (common).                                        */
00132 /*===========================================================================*/
00133 
00134 /* Includes the sub-architecture-specific part.*/
00135 #if (CORTEX_MODEL == CORTEX_M0) || (CORTEX_MODEL == CORTEX_M1)
00136 #include "chcore_v6m.h"
00137 #elif (CORTEX_MODEL == CORTEX_M3) || (CORTEX_MODEL == CORTEX_M4)
00138 #include "chcore_v7m.h"
00139 #endif
00140 
00141 #if !defined(_FROM_ASM_)
00142 
00143 #include "nvic.h"
00144 
00145 /* The following declarations are there just for Doxygen documentation, the
00146    real declarations are inside the sub-headers.*/
00147 #if defined(__DOXYGEN__)
00148 
00149 /**
00150  * @brief   Stack and memory alignment enforcement.
00151  * @note    In this architecture the stack alignment is enforced to 64 bits,
00152  *          32 bits alignment is supported by hardware but deprecated by ARM,
00153  *          the implementation choice is to not offer the option.
00154  */
00155 typedef uint64_t stkalign_t;
00156 
00157 /**
00158  * @brief   Interrupt saved context.
00159  * @details This structure represents the stack frame saved during a
00160  *          preemption-capable interrupt handler.
00161  * @note    It is implemented to match the Cortex-Mx exception context.
00162  */
00163 struct extctx {};
00164 
00165 /**
00166  * @brief   System saved context.
00167  * @details This structure represents the inner stack frame during a context
00168  *          switching.
00169  */
00170 struct intctx {};
00171 
00172 #endif /* defined(__DOXYGEN__) */
00173 
00174 /**
00175  * @brief   Excludes the default @p chSchIsPreemptionRequired()implementation.
00176  */
00177 #define PORT_OPTIMIZED_ISPREEMPTIONREQUIRED
00178 
00179 #if (CH_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
00180 /**
00181  * @brief   Inline-able version of this kernel function.
00182  */
00183 #define chSchIsPreemptionRequired()                                         \
00184   (currp->p_preempt ? firstprio(&rlist.r_queue) > currp->p_prio :           \
00185                       firstprio(&rlist.r_queue) >= currp->p_prio)
00186 #else /* CH_TIME_QUANTUM == 0 */
00187 #define chSchIsPreemptionRequired()                                         \
00188   (firstprio(&rlist.r_queue) > currp->p_prio)
00189 #endif /* CH_TIME_QUANTUM == 0 */
00190 
00191 #endif /* _FROM_ASM_ */
00192 
00193 #endif /* _CHCORE_H_ */
00194 
00195 /** @} */