sram.c 995 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2015-08-03 xiaonong The first version for STM32F7
  9. * 2017-08-25 LongfeiMa transplantation for stm32h7xx
  10. */
  11. #include "sram.h"
  12. #include "board.h"
  13. #include <rtthread.h>
  14. #ifdef RT_USING_EXT_SDRAM
  15. struct rt_memheap system_heap;
  16. void sram_init(void)
  17. {
  18. /* initialize the built-in SRAM as a memory heap */
  19. rt_memheap_init(&system_heap,
  20. "system",
  21. (void *)HEAP_BEGIN,
  22. (rt_uint32_t)HEAP_END - (rt_uint32_t)HEAP_BEGIN);
  23. }
  24. void *sram_malloc(unsigned long size)
  25. {
  26. return rt_memheap_alloc(&system_heap, size);
  27. }
  28. RTM_EXPORT(sram_malloc);
  29. void sram_free(void *ptr)
  30. {
  31. rt_memheap_free(ptr);
  32. }
  33. RTM_EXPORT(sram_free);
  34. void *sram_realloc(void *ptr, unsigned long size)
  35. {
  36. return rt_memheap_realloc(&system_heap, ptr, size);
  37. }
  38. RTM_EXPORT(sram_realloc);
  39. #endif