]> begriffs open source - freertos/blob - include/portable.h
Add suppport for ARM CM55 (#494)
[freertos] / include / portable.h
1 /*\r
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 /*-----------------------------------------------------------\r
30 * Portable layer API.  Each function must be defined for each port.\r
31 *----------------------------------------------------------*/\r
32 \r
33 #ifndef PORTABLE_H\r
34 #define PORTABLE_H\r
35 \r
36 /* Each FreeRTOS port has a unique portmacro.h header file.  Originally a\r
37  * pre-processor definition was used to ensure the pre-processor found the correct\r
38  * portmacro.h file for the port being used.  That scheme was deprecated in favour\r
39  * of setting the compiler's include path such that it found the correct\r
40  * portmacro.h file - removing the need for the constant and allowing the\r
41  * portmacro.h file to be located anywhere in relation to the port being used.\r
42  * Purely for reasons of backward compatibility the old method is still valid, but\r
43  * to make it clear that new projects should not use it, support for the port\r
44  * specific constants has been moved into the deprecated_definitions.h header\r
45  * file. */\r
46 #include "deprecated_definitions.h"\r
47 \r
48 /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h\r
49  * did not result in a portmacro.h header file being included - and it should be\r
50  * included here.  In this case the path to the correct portmacro.h header file\r
51  * must be set in the compiler's include path. */\r
52 #ifndef portENTER_CRITICAL\r
53     #include "portmacro.h"\r
54 #endif\r
55 \r
56 #if portBYTE_ALIGNMENT == 32\r
57     #define portBYTE_ALIGNMENT_MASK    ( 0x001f )\r
58 #elif portBYTE_ALIGNMENT == 16\r
59     #define portBYTE_ALIGNMENT_MASK    ( 0x000f )\r
60 #elif portBYTE_ALIGNMENT == 8\r
61     #define portBYTE_ALIGNMENT_MASK    ( 0x0007 )\r
62 #elif portBYTE_ALIGNMENT == 4\r
63     #define portBYTE_ALIGNMENT_MASK    ( 0x0003 )\r
64 #elif portBYTE_ALIGNMENT == 2\r
65     #define portBYTE_ALIGNMENT_MASK    ( 0x0001 )\r
66 #elif portBYTE_ALIGNMENT == 1\r
67     #define portBYTE_ALIGNMENT_MASK    ( 0x0000 )\r
68 #else /* if portBYTE_ALIGNMENT == 32 */\r
69     #error "Invalid portBYTE_ALIGNMENT definition"\r
70 #endif /* if portBYTE_ALIGNMENT == 32 */\r
71 \r
72 #ifndef portUSING_MPU_WRAPPERS\r
73     #define portUSING_MPU_WRAPPERS    0\r
74 #endif\r
75 \r
76 #ifndef portNUM_CONFIGURABLE_REGIONS\r
77     #define portNUM_CONFIGURABLE_REGIONS    1\r
78 #endif\r
79 \r
80 #ifndef portHAS_STACK_OVERFLOW_CHECKING\r
81     #define portHAS_STACK_OVERFLOW_CHECKING    0\r
82 #endif\r
83 \r
84 #ifndef portARCH_NAME\r
85     #define portARCH_NAME    NULL\r
86 #endif\r
87 \r
88 #ifndef configSTACK_ALLOCATION_FROM_SEPARATE_HEAP\r
89     /* Defaults to 0 for backward compatibility. */\r
90     #define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP    0\r
91 #endif\r
92 \r
93 /* *INDENT-OFF* */\r
94 #ifdef __cplusplus\r
95     extern "C" {\r
96 #endif\r
97 /* *INDENT-ON* */\r
98 \r
99 #include "mpu_wrappers.h"\r
100 \r
101 /*\r
102  * Setup the stack of a new task so it is ready to be placed under the\r
103  * scheduler control.  The registers have to be placed on the stack in\r
104  * the order that the port expects to find them.\r
105  *\r
106  */\r
107 #if ( portUSING_MPU_WRAPPERS == 1 )\r
108     #if ( portHAS_STACK_OVERFLOW_CHECKING == 1 )\r
109         StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,\r
110                                              StackType_t * pxEndOfStack,\r
111                                              TaskFunction_t pxCode,\r
112                                              void * pvParameters,\r
113                                              BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION;\r
114     #else\r
115         StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,\r
116                                              TaskFunction_t pxCode,\r
117                                              void * pvParameters,\r
118                                              BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION;\r
119     #endif\r
120 #else /* if ( portUSING_MPU_WRAPPERS == 1 ) */\r
121     #if ( portHAS_STACK_OVERFLOW_CHECKING == 1 )\r
122         StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,\r
123                                              StackType_t * pxEndOfStack,\r
124                                              TaskFunction_t pxCode,\r
125                                              void * pvParameters ) PRIVILEGED_FUNCTION;\r
126     #else\r
127         StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,\r
128                                              TaskFunction_t pxCode,\r
129                                              void * pvParameters ) PRIVILEGED_FUNCTION;\r
130     #endif\r
131 #endif /* if ( portUSING_MPU_WRAPPERS == 1 ) */\r
132 \r
133 /* Used by heap_5.c to define the start address and size of each memory region\r
134  * that together comprise the total FreeRTOS heap space. */\r
135 typedef struct HeapRegion\r
136 {\r
137     uint8_t * pucStartAddress;\r
138     size_t xSizeInBytes;\r
139 } HeapRegion_t;\r
140 \r
141 /* Used to pass information about the heap out of vPortGetHeapStats(). */\r
142 typedef struct xHeapStats\r
143 {\r
144     size_t xAvailableHeapSpaceInBytes;      /* The total heap size currently available - this is the sum of all the free blocks, not the largest block that can be allocated. */\r
145     size_t xSizeOfLargestFreeBlockInBytes;  /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */\r
146     size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */\r
147     size_t xNumberOfFreeBlocks;             /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */\r
148     size_t xMinimumEverFreeBytesRemaining;  /* The minimum amount of total free memory (sum of all free blocks) there has been in the heap since the system booted. */\r
149     size_t xNumberOfSuccessfulAllocations;  /* The number of calls to pvPortMalloc() that have returned a valid memory block. */\r
150     size_t xNumberOfSuccessfulFrees;        /* The number of calls to vPortFree() that has successfully freed a block of memory. */\r
151 } HeapStats_t;\r
152 \r
153 /*\r
154  * Used to define multiple heap regions for use by heap_5.c.  This function\r
155  * must be called before any calls to pvPortMalloc() - not creating a task,\r
156  * queue, semaphore, mutex, software timer, event group, etc. will result in\r
157  * pvPortMalloc being called.\r
158  *\r
159  * pxHeapRegions passes in an array of HeapRegion_t structures - each of which\r
160  * defines a region of memory that can be used as the heap.  The array is\r
161  * terminated by a HeapRegions_t structure that has a size of 0.  The region\r
162  * with the lowest start address must appear first in the array.\r
163  */\r
164 void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION;\r
165 \r
166 /*\r
167  * Returns a HeapStats_t structure filled with information about the current\r
168  * heap state.\r
169  */\r
170 void vPortGetHeapStats( HeapStats_t * pxHeapStats );\r
171 \r
172 /*\r
173  * Map to the memory management routines required for the port.\r
174  */\r
175 void * pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;\r
176 void * pvPortCalloc( size_t xNum,\r
177                      size_t xSize ) PRIVILEGED_FUNCTION;\r
178 void vPortFree( void * pv ) PRIVILEGED_FUNCTION;\r
179 void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;\r
180 size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;\r
181 size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION;\r
182 \r
183 #if ( configSTACK_ALLOCATION_FROM_SEPARATE_HEAP == 1 )\r
184     void * pvPortMallocStack( size_t xSize ) PRIVILEGED_FUNCTION;\r
185     void vPortFreeStack( void * pv ) PRIVILEGED_FUNCTION;\r
186 #else\r
187     #define pvPortMallocStack    pvPortMalloc\r
188     #define vPortFreeStack       vPortFree\r
189 #endif\r
190 \r
191 #if ( configUSE_MALLOC_FAILED_HOOK == 1 )\r
192 \r
193 /**\r
194  * task.h\r
195  * @code{c}\r
196  * void vApplicationMallocFailedHook( void )\r
197  * @endcode\r
198  *\r
199  * This hook function is called when allocation failed.\r
200  */\r
201     void vApplicationMallocFailedHook( void ); /*lint !e526 Symbol not defined as it is an application callback. */\r
202 #endif\r
203 \r
204 /*\r
205  * Setup the hardware ready for the scheduler to take control.  This generally\r
206  * sets up a tick interrupt and sets timers for the correct tick frequency.\r
207  */\r
208 BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION;\r
209 \r
210 /*\r
211  * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so\r
212  * the hardware is left in its original condition after the scheduler stops\r
213  * executing.\r
214  */\r
215 void vPortEndScheduler( void ) PRIVILEGED_FUNCTION;\r
216 \r
217 /*\r
218  * The structures and methods of manipulating the MPU are contained within the\r
219  * port layer.\r
220  *\r
221  * Fills the xMPUSettings structure with the memory region information\r
222  * contained in xRegions.\r
223  */\r
224 #if ( portUSING_MPU_WRAPPERS == 1 )\r
225     struct xMEMORY_REGION;\r
226     void vPortStoreTaskMPUSettings( xMPU_SETTINGS * xMPUSettings,\r
227                                     const struct xMEMORY_REGION * const xRegions,\r
228                                     StackType_t * pxBottomOfStack,\r
229                                     uint32_t ulStackDepth ) PRIVILEGED_FUNCTION;\r
230 #endif\r
231 \r
232 /* *INDENT-OFF* */\r
233 #ifdef __cplusplus\r
234     }\r
235 #endif\r
236 /* *INDENT-ON* */\r
237 \r
238 #endif /* PORTABLE_H */\r