portable.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. /*-----------------------------------------------------------
  29. * Portable layer API. Each function must be defined for each port.
  30. *----------------------------------------------------------*/
  31. #ifndef PORTABLE_H
  32. #define PORTABLE_H
  33. #ifdef ESP_PLATFORM
  34. #include "freertos/portmacro.h"
  35. #else
  36. #include "portmacro.h"
  37. #endif
  38. #if portBYTE_ALIGNMENT == 32
  39. #define portBYTE_ALIGNMENT_MASK ( 0x001f )
  40. #elif portBYTE_ALIGNMENT == 16
  41. #define portBYTE_ALIGNMENT_MASK ( 0x000f )
  42. #elif portBYTE_ALIGNMENT == 8
  43. #define portBYTE_ALIGNMENT_MASK ( 0x0007 )
  44. #elif portBYTE_ALIGNMENT == 4
  45. #define portBYTE_ALIGNMENT_MASK ( 0x0003 )
  46. #elif portBYTE_ALIGNMENT == 2
  47. #define portBYTE_ALIGNMENT_MASK ( 0x0001 )
  48. #elif portBYTE_ALIGNMENT == 1
  49. #define portBYTE_ALIGNMENT_MASK ( 0x0000 )
  50. #else /* if portBYTE_ALIGNMENT == 32 */
  51. #error "Invalid portBYTE_ALIGNMENT definition"
  52. #endif /* if portBYTE_ALIGNMENT == 32 */
  53. /* *INDENT-OFF* */
  54. #ifdef __cplusplus
  55. extern "C" {
  56. #endif
  57. /* *INDENT-ON* */
  58. #ifdef configUSE_FREERTOS_PROVIDED_HEAP
  59. /* Used by heap_5.c to define the start address and size of each memory region
  60. * that together comprise the total FreeRTOS heap space. */
  61. typedef struct HeapRegion
  62. {
  63. uint8_t * pucStartAddress;
  64. size_t xSizeInBytes;
  65. } HeapRegion_t;
  66. /* Used to pass information about the heap out of vPortGetHeapStats(). */
  67. typedef struct xHeapStats
  68. {
  69. 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. */
  70. size_t xSizeOfLargestFreeBlockInBytes; /* The maximum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
  71. size_t xSizeOfSmallestFreeBlockInBytes; /* The minimum size, in bytes, of all the free blocks within the heap at the time vPortGetHeapStats() is called. */
  72. size_t xNumberOfFreeBlocks; /* The number of free memory blocks within the heap at the time vPortGetHeapStats() is called. */
  73. 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. */
  74. size_t xNumberOfSuccessfulAllocations; /* The number of calls to pvPortMalloc() that have returned a valid memory block. */
  75. size_t xNumberOfSuccessfulFrees; /* The number of calls to vPortFree() that has successfully freed a block of memory. */
  76. } HeapStats_t;
  77. /*
  78. * Used to define multiple heap regions for use by heap_5.c. This function
  79. * must be called before any calls to pvPortMalloc() - not creating a task,
  80. * queue, semaphore, mutex, software timer, event group, etc. will result in
  81. * pvPortMalloc being called.
  82. *
  83. * pxHeapRegions passes in an array of HeapRegion_t structures - each of which
  84. * defines a region of memory that can be used as the heap. The array is
  85. * terminated by a HeapRegions_t structure that has a size of 0. The region
  86. * with the lowest start address must appear first in the array.
  87. */
  88. void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions );
  89. /*
  90. * Returns a HeapStats_t structure filled with information about the current
  91. * heap state.
  92. */
  93. void vPortGetHeapStats( HeapStats_t * pxHeapStats );
  94. /*
  95. * Map to the memory management routines required for the port.
  96. */
  97. void * pvPortMalloc( size_t xSize );
  98. void vPortFree( void * pv );
  99. void vPortInitialiseBlocks( void );
  100. size_t xPortGetFreeHeapSize( void );
  101. size_t xPortGetMinimumEverFreeHeapSize( void );
  102. #else // configUSE_FREERTOS_PROVIDED_HEAP
  103. /*
  104. * Map to the memory management routines required for the port.
  105. *
  106. * Note that libc standard malloc/free are also available for
  107. * non-FreeRTOS-specific code, and behave the same as
  108. * pvPortMalloc()/vPortFree().
  109. */
  110. #define pvPortMalloc rt_malloc
  111. #define vPortFree rt_free
  112. #define xPortGetFreeHeapSize esp_get_free_heap_size
  113. #define xPortGetMinimumEverFreeHeapSize esp_get_minimum_free_heap_size
  114. #endif
  115. void vPortEndScheduler( void );
  116. /* *INDENT-OFF* */
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120. /* *INDENT-ON* */
  121. #endif /* PORTABLE_H */