portable.h 8.8 KB

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