sram.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * File : sram.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-08-03 xiaonong The first version for STM32F7
  23. */
  24. #include "sram.h"
  25. #include "board.h"
  26. #include <rtthread.h>
  27. #ifdef RT_USING_EXT_SDRAM
  28. struct rt_memheap system_heap;
  29. void sram_init(void)
  30. {
  31. /* initialize the built-in SRAM as a memory heap */
  32. rt_memheap_init(&system_heap,
  33. "system",
  34. (void *)HEAP_BEGIN,
  35. (rt_uint32_t)HEAP_END - (rt_uint32_t)HEAP_BEGIN);
  36. }
  37. void *sram_malloc(unsigned long size)
  38. {
  39. return rt_memheap_alloc(&system_heap, size);
  40. }
  41. RTM_EXPORT(sram_malloc);
  42. void sram_free(void *ptr)
  43. {
  44. rt_memheap_free(ptr);
  45. }
  46. RTM_EXPORT(sram_free);
  47. void *sram_realloc(void *ptr, unsigned long size)
  48. {
  49. return rt_memheap_realloc(&system_heap, ptr, size);
  50. }
  51. RTM_EXPORT(sram_realloc);
  52. #endif