driver_sddac.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #include "driver_sddac.h"
  2. #include "driver_clk.h"
  3. /**
  4. * @brief Kick Start SDDAC DMA function.
  5. * @param buf: DMA start address.
  6. * @param size: DMA transmit len.
  7. * @retval None
  8. */
  9. AT(.com_periph.sddac.kick)
  10. void sddac_dma_kick_start(uint8_t *buf, uint16_t size)
  11. {
  12. SDDAC->dma_addr = (s32)buf;
  13. SDDAC->dma_size = size - 1;
  14. }
  15. /**
  16. * @brief Initializes the sddac peripheral according to the specified
  17. * parameters in the config
  18. * @param config: pointer to a sddac_init_typedef structure that
  19. * contains the configuration information for the specified SDDAC peripheral.
  20. * @retval None
  21. */
  22. void sddac_init(sddac_init_typedef *config)
  23. {
  24. if(config){
  25. if(config->sample_rate > SDDAC_NORMAL_SPR_8k){
  26. SDDAC->con |= SDDAC_OSR_MODE;
  27. config->sample_rate -= (SDDAC_NORMAL_SPR_8k + 1);
  28. }else{
  29. SDDAC->con &= ~SDDAC_OSR_MODE;
  30. }
  31. SDDAC->con &= ~SDDAC_FSIN_SEL;
  32. SDDAC->con |= ((config->sample_rate * SDDAC_FSIN_SEL_0) & SDDAC_FSIN_SEL);
  33. SDDAC->dma_addr = (s32)config->dma_buf;
  34. SDDAC->dma_size = config->dma_size - 1;
  35. SDDAC->dma_con |= SDDAC_DMA_EN; //dma_en
  36. }
  37. }
  38. /**
  39. * @brief De-initialize the specified SDDAC peripheral.
  40. * @retval None
  41. */
  42. void sddac_deinit(void)
  43. {
  44. SDDAC->dma_con &= ~SDDAC_DMA_EN; //dma disable
  45. SDDAC->con &= ~SDDAC_DAC_EN; //dac disable
  46. clk_gate0_cmd(CLK_GATE0_DAC, CLK_DIS); //dac clk gate disable
  47. }
  48. /**
  49. * @brief Enable or disable the specified SDDAC interrupt.
  50. * @param isr: Function to be executed for service interruption.
  51. * @param pr: Priority of service interruption.
  52. * @param interrupt_type: specifies the SDDAC interrupt sources to be enable or disable.
  53. * this parameter can be one of the following values:
  54. * @arg SDDAC_IT_ALL_DONE: DMA full-transfer interrupt.
  55. * @arg SDDAC_IT_HALF_DONE: DMA half-transfer interrupt.
  56. * @param state: the state of the SDDAC peripheral's interrupt.
  57. * this parameter can be: ENABLE or DISABLE.
  58. * @retval None
  59. */
  60. void sddac_pic_config(isr_t isr, int pr, SDDAC_IT_TYPEDEF interrupt_type, FUNCTIONAL_STATE state)
  61. {
  62. if(state == ENABLE){
  63. if(interrupt_type & SDDAC_IT_ALL_DONE){
  64. SDDAC->dma_con |= SDDAC_DMA_APEND_IE;
  65. }
  66. if(interrupt_type & SDDAC_IT_HALF_DONE){
  67. SDDAC->dma_con |= SDDAC_DMA_HPEND_IE;
  68. }
  69. sys_irq_init(IRQn_DAC_DMAIN, pr, isr);
  70. }else{
  71. SDDAC->dma_con &= ~(SDDAC_DMA_APEND_IE | SDDAC_DMA_HPEND_IE);
  72. }
  73. }
  74. /**
  75. * @brief Enable or disable the specified SDDAC peripheral.
  76. * @param state: the state of the SDDAC peripheral.
  77. * this parameter can be: ENABLE or DISABLE.
  78. * @retval None
  79. */
  80. AT(.com_periph.sddac.cmd)
  81. void sddac_cmd(FUNCTIONAL_STATE state)
  82. {
  83. if(state == ENABLE){
  84. SDDAC->con |= SDDAC_DMA_EN;
  85. }else{
  86. SDDAC->con &= ~SDDAC_DMA_EN;
  87. }
  88. }
  89. /**
  90. * @brief Check the specified SDDAC flag is set or not.
  91. * @param interrupt_type: specifies the flag to check.
  92. * the parameter can be one of the following values:
  93. * @arg SDDAC_IT_ALL_DONE: DMA full-transfer interrupt.
  94. * @arg SDDAC_IT_HALF_DONE: DMA half-transfer interrupt.
  95. * @retval the state of interrupt_type (SET or RESET).
  96. */
  97. AT(.com_periph.sddac.get)
  98. FLAG_STATE sddac_get_flag(SDDAC_IT_TYPEDEF interrupt_type)
  99. {
  100. if((interrupt_type == SDDAC_IT_ALL_DONE) && (SDDAC->dma_pend & SDDAC_DMA_ALLPEND)){
  101. return SET;
  102. }else if((interrupt_type == SDDAC_IT_HALF_DONE) && (SDDAC->dma_pend & SDDAC_DMA_HALFPEND)){
  103. return SET;
  104. }
  105. return RESET;
  106. }
  107. /**
  108. * @brief Clear the SDDAC pending.
  109. * @param interrupt_type: specifies flag to clear.
  110. * the parameter can be one of the following values:
  111. * @arg SDDAC_IT_ALL_DONE: DMA full-transfer interrupt.
  112. * @arg SDDAC_IT_HALF_DONE: DMA half-transfer interrupt.
  113. * @retval None
  114. */
  115. AT(.com_periph.sddac.clear)
  116. void sddac_clear_flag(SDDAC_IT_TYPEDEF interrupt_type)
  117. {
  118. if(interrupt_type == SDDAC_IT_ALL_DONE){
  119. SDDAC->dma_cpnd = SDDAC_DMA_ALLPEND_CLR;
  120. }else if (interrupt_type == SDDAC_IT_HALF_DONE){
  121. SDDAC->dma_cpnd = SDDAC_DMA_HALFPEND_CLR;
  122. }
  123. }