]> git.sur5r.net Git - freertos/blob - Source/portable/GCC/ARM_CM3_MPU/portmacro.h
02c1adbd3787062aec2989a239ab98ee09d756b1
[freertos] / Source / portable / GCC / ARM_CM3_MPU / portmacro.h
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 \r
50 #ifndef PORTMACRO_H\r
51 #define PORTMACRO_H\r
52 \r
53 #ifdef __cplusplus\r
54 extern "C" {\r
55 #endif\r
56 \r
57 /*-----------------------------------------------------------\r
58  * Port specific definitions.\r
59  *\r
60  * The settings in this file configure FreeRTOS correctly for the\r
61  * given hardware and compiler.\r
62  *\r
63  * These settings should not be altered.\r
64  *-----------------------------------------------------------\r
65  */\r
66 \r
67 /* Type definitions. */\r
68 #define portCHAR                char\r
69 #define portFLOAT               float\r
70 #define portDOUBLE              double\r
71 #define portLONG                long\r
72 #define portSHORT               short\r
73 #define portSTACK_TYPE  unsigned portLONG\r
74 #define portBASE_TYPE   long\r
75 \r
76 #if( configUSE_16_BIT_TICKS == 1 )\r
77         typedef unsigned portSHORT portTickType;\r
78         #define portMAX_DELAY ( portTickType ) 0xffff\r
79 #else\r
80         typedef unsigned portLONG portTickType;\r
81         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
82 #endif\r
83 /*-----------------------------------------------------------*/\r
84 \r
85 /* MPU specific constants. */\r
86 #define portUSING_MPU_WRAPPERS          1\r
87 #define portPRIVILEGE_BIT                       ( 0x80000000UL )\r
88 \r
89 #define portMPU_REGION_READ_WRITE                               ( 0x03UL << 24UL )\r
90 #define portMPU_REGION_PRIVILEGED_READ_ONLY             ( 0x05UL << 24UL )\r
91 #define portMPU_REGION_READ_ONLY                                ( 0x06UL << 24UL )\r
92 #define portMPU_REGION_PRIVILEGED_READ_WRITE    ( 0x01UL << 24UL )\r
93 #define portMPU_REGION_CACHEABLE_BUFFERABLE             ( 0x07UL << 16UL )\r
94 #define portMPU_REGION_EXECUTE_NEVER                    ( 0x01UL << 28UL )\r
95 \r
96 #define portUNPRIVILEGED_FLASH_REGION           ( 0UL )\r
97 #define portPRIVILEGED_FLASH_REGION                     ( 1UL )\r
98 #define portPRIVILEGED_RAM_REGION                       ( 2UL )\r
99 #define portGENERAL_PERIPHERALS_REGION          ( 3UL )\r
100 #define portSTACK_REGION                                        ( 4UL )\r
101 #define portFIRST_CONFIGURABLE_REGION       ( 5UL )\r
102 #define portLAST_CONFIGURABLE_REGION            ( 7UL )\r
103 #define portNUM_CONFIGURABLE_REGIONS            ( ( portLAST_CONFIGURABLE_REGION - portFIRST_CONFIGURABLE_REGION ) + 1 )\r
104 #define portTOTAL_NUM_REGIONS                           ( portNUM_CONFIGURABLE_REGIONS + 1 ) /* Plus one to make space for the stack region. */\r
105 \r
106 #define portSWITCH_TO_USER_MODE() __asm volatile ( " mrs r0, control \n orr r0, #1 \n msr control, r0 " )\r
107 \r
108 typedef struct MPU_REGION_REGISTERS\r
109 {\r
110         unsigned portLONG ulRegionBaseAddress;\r
111         unsigned portLONG ulRegionAttribute;\r
112 } xMPU_REGION_REGISTERS;\r
113 \r
114 /* Plus 1 to create space for the stack region. */\r
115 typedef struct MPU_SETTINGS\r
116 {\r
117         xMPU_REGION_REGISTERS xRegion[ portTOTAL_NUM_REGIONS ];\r
118 } xMPU_SETTINGS;\r
119 \r
120 /* Architecture specifics. */\r
121 #define portSTACK_GROWTH                        ( -1 )\r
122 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )\r
123 #define portBYTE_ALIGNMENT                      8\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /* SVC numbers for various services. */\r
127 #define portSVC_START_SCHEDULER                         0\r
128 #define portSVC_YIELD                                           1\r
129 #define portSVC_prvRaisePrivilege                       2\r
130 \r
131 /* Scheduler utilities. */\r
132 \r
133 #define portYIELD()                             __asm volatile ( "      SVC     %0      \n" :: "i" (portSVC_YIELD) )\r
134 #define portYIELD_WITHIN_API()  *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET\r
135 \r
136 #define portNVIC_INT_CTRL                       ( ( volatile unsigned portLONG *) 0xe000ed04 )\r
137 #define portNVIC_PENDSVSET                      0x10000000\r
138 #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired ) *(portNVIC_INT_CTRL) = portNVIC_PENDSVSET\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 \r
142 /* Critical section management. */\r
143 \r
144 /*\r
145  * Set basepri to portMAX_SYSCALL_INTERRUPT_PRIORITY without effecting other\r
146  * registers.  r0 is clobbered.\r
147  */\r
148 #define portSET_INTERRUPT_MASK()                                                \\r
149         __asm volatile                                                                          \\r
150         (                                                                                                       \\r
151                 "       mov r0, %0                                                              \n"     \\r
152                 "       msr basepri, r0                                                 \n" \\r
153                 ::"i"(configMAX_SYSCALL_INTERRUPT_PRIORITY):"r0"        \\r
154         )\r
155 \r
156 /*\r
157  * Set basepri back to 0 without effective other registers.\r
158  * r0 is clobbered.\r
159  */\r
160 #define portCLEAR_INTERRUPT_MASK()                      \\r
161         __asm volatile                                                  \\r
162         (                                                                               \\r
163                 "       mov r0, #0                                      \n"     \\r
164                 "       msr basepri, r0                         \n"     \\r
165                 :::"r0"                                                         \\r
166         )\r
167 \r
168 #define portSET_INTERRUPT_MASK_FROM_ISR()               0;portSET_INTERRUPT_MASK()\r
169 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x)    portCLEAR_INTERRUPT_MASK();(void)x\r
170 \r
171 \r
172 extern void vPortEnterCritical( void );\r
173 extern void vPortExitCritical( void );\r
174 \r
175 #define portDISABLE_INTERRUPTS()        portSET_INTERRUPT_MASK()\r
176 #define portENABLE_INTERRUPTS()         portCLEAR_INTERRUPT_MASK()\r
177 #define portENTER_CRITICAL()            vPortEnterCritical()\r
178 #define portEXIT_CRITICAL()                     vPortExitCritical()\r
179 /*-----------------------------------------------------------*/\r
180 \r
181 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
182 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
183 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
184 \r
185 #define portNOP()\r
186 \r
187 \r
188 \r
189 #ifdef __cplusplus\r
190 }\r
191 #endif\r
192 \r
193 #endif /* PORTMACRO_H */\r
194 \r