1 /* 2 * FreeRTOS Kernel V10.2.1 3 * Copyright (C) 2019 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 * http://www.FreeRTOS.org 23 * http://aws.amazon.com/freertos 24 * 25 * 1 tab == 4 spaces! 26 */ 27 28 /*----------------------------------------------------------- 29 * Portable layer API. Each function must be defined for each port. 30 *----------------------------------------------------------*/ 31 32 #ifndef PORTABLE_H 33 #define PORTABLE_H 34 35 /* Each FreeRTOS port has a unique portmacro.h header file. Originally a 36 pre-processor definition was used to ensure the pre-processor found the correct 37 portmacro.h file for the port being used. That scheme was deprecated in favour 38 of setting the compiler's include path such that it found the correct 39 portmacro.h file - removing the need for the constant and allowing the 40 portmacro.h file to be located anywhere in relation to the port being used. 41 Purely for reasons of backward compatibility the old method is still valid, but 42 to make it clear that new projects should not use it, support for the port 43 specific constants has been moved into the deprecated_definitions.h header 44 file. */ 45 #include "deprecated_definitions.h" 46 47 /* If portENTER_CRITICAL is not defined then including deprecated_definitions.h 48 did not result in a portmacro.h header file being included - and it should be 49 included here. In this case the path to the correct portmacro.h header file 50 must be set in the compiler's include path. */ 51 #ifndef portENTER_CRITICAL 52 #include "esp_osal/portmacro.h" 53 #endif 54 55 #if portBYTE_ALIGNMENT == 32 56 #define portBYTE_ALIGNMENT_MASK ( 0x001f ) 57 #endif 58 59 #if portBYTE_ALIGNMENT == 16 60 #define portBYTE_ALIGNMENT_MASK ( 0x000f ) 61 #endif 62 63 #if portBYTE_ALIGNMENT == 8 64 #define portBYTE_ALIGNMENT_MASK ( 0x0007 ) 65 #endif 66 67 #if portBYTE_ALIGNMENT == 4 68 #define portBYTE_ALIGNMENT_MASK ( 0x0003 ) 69 #endif 70 71 #if portBYTE_ALIGNMENT == 2 72 #define portBYTE_ALIGNMENT_MASK ( 0x0001 ) 73 #endif 74 75 #if portBYTE_ALIGNMENT == 1 76 #define portBYTE_ALIGNMENT_MASK ( 0x0000 ) 77 #endif 78 79 #ifndef portBYTE_ALIGNMENT_MASK 80 #error "Invalid portBYTE_ALIGNMENT definition" 81 #endif 82 83 #ifndef portNUM_CONFIGURABLE_REGIONS 84 #define portNUM_CONFIGURABLE_REGIONS 1 85 #endif 86 87 #ifndef portHAS_STACK_OVERFLOW_CHECKING 88 #define portHAS_STACK_OVERFLOW_CHECKING 0 89 #endif 90 91 #ifndef portARCH_NAME 92 #define portARCH_NAME NULL 93 #endif 94 95 #ifdef __cplusplus 96 extern "C" { 97 #endif 98 99 #include "mpu_wrappers.h" 100 101 /* 102 * Setup the stack of a new task so it is ready to be placed under the 103 * scheduler control. The registers have to be placed on the stack in 104 * the order that the port expects to find them. 105 * 106 */ 107 #if( portUSING_MPU_WRAPPERS == 1 ) 108 #if( portHAS_STACK_OVERFLOW_CHECKING == 1 ) 109 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; 110 #else 111 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters, BaseType_t xRunPrivileged ) PRIVILEGED_FUNCTION; 112 #endif 113 #else 114 #if( portHAS_STACK_OVERFLOW_CHECKING == 1 ) 115 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, StackType_t *pxEndOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; 116 #else 117 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters ) PRIVILEGED_FUNCTION; 118 #endif 119 #endif 120 121 #ifdef configUSE_FREERTOS_PROVIDED_HEAP 122 123 /* Used by heap_5.c to define the start address and size of each memory region 124 that together comprise the total FreeRTOS heap space. */ 125 typedef struct HeapRegion 126 { 127 uint8_t *pucStartAddress; 128 size_t xSizeInBytes; 129 } HeapRegion_t; 130 131 /* Used to pass information about the heap out of vPortGetHeapStats(). */ 132 typedef struct xHeapStats 133 { 134 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. */ 135 size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ 136 size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */ 137 size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */ 138 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. */ 139 size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */ 140 size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */ 141 } HeapStats_t; 142 143 /* 144 * Used to define multiple heap regions for use by heap_5.c. This function 145 * must be called before any calls to pvPortMalloc() - not creating a task, 146 * queue, semaphore, mutex, software timer, event group, etc. will result in 147 * pvPortMalloc being called. 148 * 149 * pxHeapRegions passes in an array of HeapRegion_t structures - each of which 150 * defines a region of memory that can be used as the heap. The array is 151 * terminated by a HeapRegions_t structure that has a size of 0. The region 152 * with the lowest start address must appear first in the array. 153 */ 154 void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEGED_FUNCTION; 155 156 /* 157 * Returns a HeapStats_t structure filled with information about the current 158 * heap state. 159 */ 160 void vPortGetHeapStats( HeapStats_t *pxHeapStats ); 161 /* 162 * Map to the memory management routines required for the port. 163 */ 164 void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; 165 void vPortFree( void *pv ) PRIVILEGED_FUNCTION; 166 void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; 167 size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; 168 size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; 169 170 #else // configUSE_FREERTOS_PROVIDED_HEAP 171 172 /* 173 * Map to the memory management routines required for the port. 174 * 175 * Note that libc standard malloc/free are also available for 176 * non-FreeRTOS-specific code, and behave the same as 177 * pvPortMalloc()/vPortFree(). 178 */ 179 #define pvPortMalloc malloc 180 #define vPortFree free 181 #define xPortGetFreeHeapSize esp_get_free_heap_size 182 #define xPortGetMinimumEverFreeHeapSize esp_get_minimum_free_heap_size 183 184 #endif 185 186 /* 187 * Setup the hardware ready for the scheduler to take control. This generally 188 * sets up a tick interrupt and sets timers for the correct tick frequency. 189 */ 190 BaseType_t xPortStartScheduler( void ) PRIVILEGED_FUNCTION; 191 192 /* 193 * Undo any hardware/ISR setup that was performed by xPortStartScheduler() so 194 * the hardware is left in its original condition after the scheduler stops 195 * executing. 196 */ 197 void vPortEndScheduler( void ) PRIVILEGED_FUNCTION; 198 199 #ifdef __cplusplus 200 } 201 #endif 202 203 #endif /* PORTABLE_H */ 204