dma_mem.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. /*****************************************************************************
  27. * Include Section
  28. * add all #include here
  29. *****************************************************************************/
  30. #include "dma_mem.h"
  31. #ifdef RT_USING_DMA_MEM
  32. /*****************************************************************************
  33. * Define section
  34. * add all #define here
  35. *****************************************************************************/
  36. //#define FH_TEST_DMA_MEM
  37. /****************************************************************************
  38. * ADT section
  39. * add definition of user defined Data Type that only be used in this file here
  40. ***************************************************************************/
  41. /******************************************************************************
  42. * Function prototype section
  43. * add prototypes for all functions called by this file,execepting those
  44. * declared in header file
  45. *****************************************************************************/
  46. /*****************************************************************************
  47. * Global variables section - Exported
  48. * add declaration of global variables that will be exported here
  49. * e.g.
  50. * int8_t foo;
  51. ****************************************************************************/
  52. /*****************************************************************************
  53. * static fun;
  54. *****************************************************************************/
  55. /*****************************************************************************
  56. * Global variables section - Local
  57. * define global variables(will be refered only in this file) here,
  58. * static keyword should be used to limit scope of local variable to this file
  59. * e.g.
  60. * static uint8_t ufoo;
  61. *****************************************************************************/
  62. static struct rt_memheap dma_heap = {0};
  63. /* function body */
  64. /*****************************************************************************
  65. * Description:
  66. * add funtion description here
  67. * Parameters:
  68. * description for each argument, new argument starts at new line
  69. * Return:
  70. * what does this function returned?
  71. *****************************************************************************/
  72. rt_err_t fh_dma_mem_init(rt_uint32_t *mem_start,rt_uint32_t size){
  73. return rt_memheap_init(&dma_heap,"dma_heap",mem_start,size);
  74. }
  75. void *fh_dma_mem_malloc(rt_uint32_t size){
  76. return rt_memheap_alloc(&dma_heap, size);
  77. }
  78. void fh_dma_mem_free(void *ptr){
  79. rt_memheap_free(ptr);
  80. }
  81. #ifdef FH_TEST_DMA_MEM
  82. int dma_mem_debug(void *ptr){
  83. //rt_memheap_free(ptr);
  84. rt_kprintf("dma mem start 0x%08x\n",(rt_uint32_t)dma_heap.start_addr);
  85. rt_kprintf("dma mem total size 0x%08x\n",dma_heap.pool_size);
  86. rt_kprintf("dma mem left size 0x%08x\n",dma_heap.available_size);
  87. rt_kprintf("dma mem max use size 0x%08x\n",dma_heap.max_used_size);
  88. return 0;
  89. }
  90. #endif
  91. #ifdef RT_USING_FINSH
  92. #include <finsh.h>
  93. #ifdef FH_TEST_DMA_MEM
  94. FINSH_FUNCTION_EXPORT(dma_mem_debug, dma_start & left size & max_use);
  95. #endif
  96. #endif
  97. #endif