dma.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 "drivers/dma.h"
  31. /*****************************************************************************
  32. * Define section
  33. * add all #define here
  34. *****************************************************************************/
  35. /****************************************************************************
  36. * ADT section
  37. * add definition of user defined Data Type that only be used in this file here
  38. ***************************************************************************/
  39. /******************************************************************************
  40. * Function prototype section
  41. * add prototypes for all functions called by this file,execepting those
  42. * declared in header file
  43. *****************************************************************************/
  44. /*****************************************************************************
  45. * Global variables section - Exported
  46. * add declaration of global variables that will be exported here
  47. * e.g.
  48. * int8_t foo;
  49. ****************************************************************************/
  50. /*****************************************************************************
  51. * static fun;
  52. *****************************************************************************/
  53. static rt_err_t rt_dma_init(struct rt_device *dev);
  54. static rt_err_t rt_dma_open(struct rt_device *dev, rt_uint16_t oflag);
  55. static rt_err_t rt_dma_close(struct rt_device *dev);
  56. static rt_err_t rt_dma_control(struct rt_device *dev,
  57. rt_uint8_t cmd,
  58. void *args);
  59. /*****************************************************************************
  60. * Global variables section - Local
  61. * define global variables(will be refered only in this file) here,
  62. * static keyword should be used to limit scope of local variable to this file
  63. * e.g.
  64. * static uint8_t ufoo;
  65. *****************************************************************************/
  66. /* function body */
  67. /*****************************************************************************
  68. * Description:
  69. * add funtion description here
  70. * Parameters:
  71. * description for each argument, new argument starts at new line
  72. * Return:
  73. * what does this function returned?
  74. *****************************************************************************/
  75. static rt_err_t rt_dma_init(struct rt_device *dev)
  76. {
  77. struct rt_dma_device *dma;
  78. RT_ASSERT(dev != RT_NULL);
  79. dma = (struct rt_dma_device *)dev;
  80. if (dma->ops->init)
  81. {
  82. return (dma->ops->init(dma));
  83. }
  84. return (-RT_ENOSYS);
  85. }
  86. static rt_err_t rt_dma_open(struct rt_device *dev, rt_uint16_t oflag)
  87. {
  88. return (RT_EOK);
  89. }
  90. static rt_err_t rt_dma_close(struct rt_device *dev)
  91. {
  92. struct rt_dma_device *dma;
  93. RT_ASSERT(dev != RT_NULL);
  94. dma = (struct rt_dma_device *)dev;
  95. if (dma->ops->control(dma, RT_DEVICE_CTRL_DMA_CLOSE, RT_NULL) != RT_EOK)
  96. {
  97. return (-RT_ERROR);
  98. }
  99. return (RT_EOK);
  100. }
  101. static rt_err_t rt_dma_control(struct rt_device *dev,
  102. rt_uint8_t cmd,
  103. void *args)
  104. {
  105. struct rt_dma_device *dma;
  106. RT_ASSERT(dev != RT_NULL);
  107. dma = (struct rt_dma_device *)dev;
  108. //args is the private data for the soc!!
  109. return (dma->ops->control(dma, cmd, args));
  110. }
  111. /**
  112. * This function register a dma device
  113. */
  114. rt_err_t rt_hw_dma_register(struct rt_dma_device *dma,
  115. const char *name,
  116. rt_uint32_t flag,
  117. void *data)
  118. {
  119. rt_uint32_t ret;
  120. struct rt_device *device;
  121. RT_ASSERT(dma != RT_NULL);
  122. device = &(dma->parent);
  123. device->type = RT_Device_Class_Miscellaneous;
  124. device->rx_indicate = RT_NULL;
  125. device->tx_complete = RT_NULL;
  126. device->init = rt_dma_init;
  127. device->open = rt_dma_open;
  128. device->close = rt_dma_close;
  129. device->read = RT_NULL;
  130. device->write = RT_NULL;
  131. device->control = rt_dma_control;
  132. device->user_data = data;
  133. /* register a character device */
  134. ret = rt_device_register(device, name, flag);
  135. rt_kprintf("dma ret is :%x\n",ret);
  136. return ret;
  137. }