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