ChibiOS/RT
2.5.1
chcore.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
00003                  2011,2012 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  * @file    GCC/ARMCMx/chcore.h
00023  * @brief   ARM Cortex-Mx port macros and structures.
00024  *
00025  * @addtogroup ARMCMx_CORE
00026  * @{
00027  */
00028 
00029 #ifndef _CHCORE_H_
00030 #define _CHCORE_H_
00031 
00032 /*===========================================================================*/
00033 /* Port constants (common).                                                  */
00034 /*===========================================================================*/
00035 
00036 /* Added to make the header stand-alone when included from asm.*/
00037 #ifndef FALSE
00038 #define FALSE       0
00039 #endif
00040 #ifndef TRUE
00041 #define TRUE        (!FALSE)
00042 #endif
00043 
00044 #define CORTEX_M0                       0   /**< @brief Cortex-M0 variant.  */
00045 #define CORTEX_M1                       1   /**< @brief Cortex-M1 variant.  */
00046 #define CORTEX_M3                       3   /**< @brief Cortex-M3 variant.  */
00047 #define CORTEX_M4                       4   /**< @brief Cortex-M4 variant.  */
00048 
00049 /* Inclusion of the Cortex-Mx implementation specific parameters.*/
00050 #include "cmparams.h"
00051 
00052 /* Cortex model check, only M0 and M3 supported right now.*/
00053 #if (CORTEX_MODEL == CORTEX_M0) || (CORTEX_MODEL == CORTEX_M3) ||           \
00054     (CORTEX_MODEL == CORTEX_M4)
00055 #elif (CORTEX_MODEL == CORTEX_M1)
00056 #warning "untested Cortex-M model"
00057 #else
00058 #error "unknown or unsupported Cortex-M model"
00059 #endif
00060 
00061 /**
00062  * @brief   Total priority levels.
00063  */
00064 #define CORTEX_PRIORITY_LEVELS          (1 << CORTEX_PRIORITY_BITS)
00065 
00066 /**
00067  * @brief   Minimum priority level.
00068  * @details This minimum priority level is calculated from the number of
00069  *          priority bits supported by the specific Cortex-Mx implementation.
00070  */
00071 #define CORTEX_MINIMUM_PRIORITY         (CORTEX_PRIORITY_LEVELS - 1)
00072 
00073 /**
00074  * @brief   Maximum priority level.
00075  * @details The maximum allowed priority level is always zero.
00076  */
00077 #define CORTEX_MAXIMUM_PRIORITY         0
00078 
00079 /*===========================================================================*/
00080 /* Port macros (common).                                                     */
00081 /*===========================================================================*/
00082 
00083 /**
00084  * @brief   Priority level verification macro.
00085  */
00086 #define CORTEX_IS_VALID_PRIORITY(n)                                         \
00087   (((n) >= 0) && ((n) < CORTEX_PRIORITY_LEVELS))
00088 
00089 /**
00090  * @brief   Priority level verification macro.
00091  */
00092 #define CORTEX_IS_VALID_KERNEL_PRIORITY(n)                                  \
00093   (((n) >= CORTEX_MAX_KERNEL_PRIORITY) && ((n) < CORTEX_PRIORITY_LEVELS))
00094 
00095 /**
00096  * @brief   Priority level to priority mask conversion macro.
00097  */
00098 #define CORTEX_PRIORITY_MASK(n)                                             \
00099   ((n) << (8 - CORTEX_PRIORITY_BITS))
00100 
00101 /*===========================================================================*/
00102 /* Port configurable parameters (common).                                    */
00103 /*===========================================================================*/
00104 
00105 /*===========================================================================*/
00106 /* Port derived parameters (common).                                         */
00107 /*===========================================================================*/
00108 
00109 /*===========================================================================*/
00110 /* Port exported info (common).                                              */
00111 /*===========================================================================*/
00112 
00113 /**
00114  * @brief   Macro defining a generic ARM architecture.
00115  */
00116 #define CH_ARCHITECTURE_ARM
00117 
00118 /**
00119  * @brief   Name of the compiler supported by this port.
00120  */
00121 #define CH_COMPILER_NAME                "GCC " __VERSION__
00122 
00123 /*===========================================================================*/
00124 /* Port implementation part (common).                                        */
00125 /*===========================================================================*/
00126 
00127 /* Includes the sub-architecture-specific part.*/
00128 #if (CORTEX_MODEL == CORTEX_M0) || (CORTEX_MODEL == CORTEX_M1)
00129 #include "chcore_v6m.h"
00130 #elif (CORTEX_MODEL == CORTEX_M3) || (CORTEX_MODEL == CORTEX_M4)
00131 #include "chcore_v7m.h"
00132 #endif
00133 
00134 #if !defined(_FROM_ASM_)
00135 
00136 #include "nvic.h"
00137 
00138 /* The following declarations are there just for Doxygen documentation, the
00139    real declarations are inside the sub-headers.*/
00140 #if defined(__DOXYGEN__)
00141 
00142 /**
00143  * @brief   Stack and memory alignment enforcement.
00144  * @note    In this architecture the stack alignment is enforced to 64 bits,
00145  *          32 bits alignment is supported by hardware but deprecated by ARM,
00146  *          the implementation choice is to not offer the option.
00147  */
00148 typedef uint64_t stkalign_t;
00149 
00150 /**
00151  * @brief   Interrupt saved context.
00152  * @details This structure represents the stack frame saved during a
00153  *          preemption-capable interrupt handler.
00154  * @note    It is implemented to match the Cortex-Mx exception context.
00155  */
00156 struct extctx {};
00157 
00158 /**
00159  * @brief   System saved context.
00160  * @details This structure represents the inner stack frame during a context
00161  *          switching.
00162  */
00163 struct intctx {};
00164 
00165 #endif /* defined(__DOXYGEN__) */
00166 
00167 /**
00168  * @brief   Excludes the default @p chSchIsPreemptionRequired()implementation.
00169  */
00170 #define PORT_OPTIMIZED_ISPREEMPTIONREQUIRED
00171 
00172 #if (CH_TIME_QUANTUM > 0) || defined(__DOXYGEN__)
00173 /**
00174  * @brief   Inline-able version of this kernel function.
00175  */
00176 #define chSchIsPreemptionRequired()                                         \
00177   (currp->p_preempt ? firstprio(&rlist.r_queue) > currp->p_prio :           \
00178                       firstprio(&rlist.r_queue) >= currp->p_prio)
00179 #else /* CH_TIME_QUANTUM == 0 */
00180 #define chSchIsPreemptionRequired()                                         \
00181   (firstprio(&rlist.r_queue) > currp->p_prio)
00182 #endif /* CH_TIME_QUANTUM == 0 */
00183 
00184 #endif /* _FROM_ASM_ */
00185 
00186 #endif /* _CHCORE_H_ */
00187 
00188 /** @} */