heap_3.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * FreeRTOS Kernel V10.3.1
  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. * http://www.FreeRTOS.org
  23. * http://aws.amazon.com/freertos
  24. *
  25. * 1 tab == 4 spaces!
  26. */
  27. /*
  28. * Implementation of pvPortMalloc() and vPortFree() that relies on the
  29. * compilers own malloc() and free() implementations.
  30. *
  31. * This file can only be used if the linker is configured to to generate
  32. * a heap memory area.
  33. *
  34. * See heap_1.c, heap_2.c and heap_4.c for alternative implementations, and the
  35. * memory management pages of http://www.FreeRTOS.org for more information.
  36. */
  37. #include <stdlib.h>
  38. /* Defining MPU_WRAPPERS_INCLUDED_FROM_API_FILE prevents task.h from redefining
  39. all the API functions to use the MPU wrappers. That should only be done when
  40. task.h is included from an application file. */
  41. #define MPU_WRAPPERS_INCLUDED_FROM_API_FILE
  42. #include "FreeRTOS.h"
  43. #include "task.h"
  44. #undef MPU_WRAPPERS_INCLUDED_FROM_API_FILE
  45. #if( configSUPPORT_DYNAMIC_ALLOCATION == 0 )
  46. #error This file must not be used if configSUPPORT_DYNAMIC_ALLOCATION is 0
  47. #endif
  48. /*-----------------------------------------------------------*/
  49. void *pvPortMalloc( size_t xWantedSize )
  50. {
  51. void *pvReturn;
  52. vTaskSuspendAll();
  53. {
  54. pvReturn = malloc( xWantedSize );
  55. traceMALLOC( pvReturn, xWantedSize );
  56. }
  57. ( void ) xTaskResumeAll();
  58. #if( configUSE_MALLOC_FAILED_HOOK == 1 )
  59. {
  60. if( pvReturn == NULL )
  61. {
  62. extern void vApplicationMallocFailedHook( void );
  63. vApplicationMallocFailedHook();
  64. }
  65. }
  66. #endif
  67. return pvReturn;
  68. }
  69. /*-----------------------------------------------------------*/
  70. void vPortFree( void *pv )
  71. {
  72. if( pv )
  73. {
  74. vTaskSuspendAll();
  75. {
  76. free( pv );
  77. traceFREE( pv, 0 );
  78. }
  79. ( void ) xTaskResumeAll();
  80. }
  81. }