S3C6410 Bare Metal DMA

Publisher:polkmmLatest update time:2017-02-26 Source: eefocusKeywords:S3C6410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  1. /************************************************************************************************************* 

  2.  * File name: dma.c 

  3.  * Function: S3C6410 DMA bottom-level driver function 

  4.  * Author: cp1300@139.com 

  5.  * Created: 2013-01-23 21:06 

  6.  * Last modified: January 23, 2013 

  7.  * Details: DMA controller underlying driver 

  8. *************************************************************************************************************/  

  9. #include "system.h"  

  10. #include "DMA.h"  

  11.   

  12.   

  13.   

  14. /************************************************************************************************************************* 

  15. *Function: void DMA_Init(void) 

  16. *Function: DMA initialization 

  17. *Parameters: None 

  18. *Return: None 

  19. *Depends on: underlying 

  20. *Author : cp1300@139.com 

  21. *Time: 20130131 

  22. *Last modified: 20130131 

  23. * Description: None 

  24. *************************************************************************************************************************/  

  25. void DMA_Init(void)  

  26. {  

  27.     Set_GateClk(HCLK_DMA0, ENABLE);  

  28.     Set_GateClk(HCLK_DMA1, ENABLE);  

  29.       

  30. }  

  31.   

  32.   

  33.   

  34. /************************************************************************************************************************* 

  35. *函数         :   void DMA_SetConfig(DMA_TypeDef *DMA, DMA_CHX ch, DMA_Config *config) 

  36. *Function: DMA configuration 

  37. *Parameters: DMA: DMA module selection, see DMA_TypeDef; ch: channel selection, see DMA_CHX; config: configuration, see DMA_Config 

  38. *Return: None 

  39. *Depends on: underlying 

  40. *Author : cp1300@139.com 

  41. *Time: 20130131 

  42. *Last modified: 20130131 

  43. *Description: Used to set DMA 

  44. *************************************************************************************************************************/  

  45. void DMA_SetConfig(DMA_TypeDef *DMA, DMA_CHX ch, DMA_Config *config)  

  46. {  

  47.     DMA_Enable(DMA); //Enable DMA module  

  48.     (DMA->CH[ch]).SrcAddr = config->SrcAddr; //Set source address  

  49.     (DMA->CH[ch]).DestAddr = config->DestAddr; //Set the destination address  

  50.     (DMA->CH[ch]).Control0 = 0x80000000 //1<<31 //Whether to generate an interrupt after the current transfer is completed  

  51.                                 | ((config->DestIncrement == ENABLE) ? (1 << 27) : 0) //Destination address increments  

  52.                                 | ((config->SrcIncrement == ENABLE) ? (1 << 26) : 0) // Source address auto-increment  

  53.                                 | ((config->DestPeripheral == DMA_MEM) ? AHB_M1 : AHB_M2) << 25 //Target AHB host selection  

  54.                                 | ((config->SrcPeripheral == DMA_MEM) ? AHB_M1 : AHB_M2) << 24 //Source AHB host selection  

  55.                                 | (config->FlowWidth & 0x7) << 21 // Target transfer width  

  56.                                 | (config->FlowWidth & 0x7) << 18 //Source transfer width  

  57.                                 | (config->BurstSize & 0x7) << 15 // Target transmission pulse size, number of single transmissions  

  58.                                 | (config->BurstSize & 0x7) << 12; //Source transmission pulse size, the number of single transmissions  

  59.     (DMA->CH[ch]).Control1 = config->DataSize & 0x1ffffff; //Number of data to be transferred  

  60.     (DMA->CH[ch]).Config     =     (0<<18)// enable DMA requests  

  61.                                 | (0<<16) // disables locked transfers  

  62.                                 | (1<<15) // Teminal count interrupt enable  

  63.                                 | (0<<14) // Interrupt error mask // Allow DMA request  

  64.                                 | (((config->SrcPeripheral == DMA_MEM) ? 0 : 1) << 12)  

  65.                                 | (((config->DestPeripheral == DMA_MEM) ? 0 : 1) << 11) //Transfer mode, such as memory to memory, etc.  

  66.                                 | (config->DestPeripheral & 0x0f) << 6 //Destination peripheral  

  67.                                 | (config->SrcPeripheral & 0x0f) << 1;     //源外设  

  68.     (DMA->CH[ch]).LLI = config->LLIArrd; //Next transfer LLI configuration location  

  69.     //(DMA->CH[ch]).ConfigExp =  7;  

  70. }  

  71.   

  72.   

  73.   

  74. /************************************************************************************************************************* 

  75. *函数         :   void DMA_Enable(DMA_TypeDef *DMA) 

  76. *Function: DMA enable 

  77. *Parameter: DMA: DMA module selection, see DMA_TypeDef; 

  78. *Return: None 

  79. *Depends on: underlying 

  80. *Author : cp1300@139.com 

  81. *Time: 20130131 

  82. *Last modified: 20130131 

  83. * Description: None 

  84. *************************************************************************************************************************/  

  85. void DMA_Enable(DMA_TypeDef *DMA)  

  86. {  

  87.     DMA->Config = 0x01; //AHB little-endian mode, start DMA controller    

  88. }  

  89.   

  90.   

  91.   

  92. /************************************************************************************************************************* 

  93. *函数         :   void DMA_Disable(DMA_TypeDef *DMA) 

  94. *Function: DMA off 

  95. *Parameter: DMA: DMA module selection, see DMA_TypeDef; 

  96. *Return: None 

  97. *Depends on: underlying 

  98. *Author : cp1300@139.com 

  99. *Time: 20130131 

  100. *Last modified: 20130131 

  101. * Description: None 

  102. *************************************************************************************************************************/  

  103. void DMA_Disable(DMA_TypeDef *DMA)  

  104. {  

  105.     DMA->Config = 0x00; //AHB little-endian mode, turn off DMA controller    

  106. }  

  107.   

  108.   

  109.   

  110. /************************************************************************************************************************* 

  111. *函数         :   void DMA_StartChannels(DMA_TypeDef *DMA, DMA_CHX ch) 

  112. *Function: DMA channel transfer starts 

  113. *Parameters: DMA: DMA module selection, see DMA_TypeDef; ch: channel selection, see DMA_CHX; 

  114. *Return: None 

  115. *Depends on: underlying 

  116. *Author : cp1300@139.com 

  117. *Time: 20130131 

  118. *Last modified: 20130131 

  119. * Description: None 

  120. *************************************************************************************************************************/  

  121. void DMA_StartChannels(DMA_TypeDef *DMA, DMA_CHX ch)  

  122. {  

  123.     DMA_ClearIntTCStatus(DMA0, ch);  

  124.     DMA_ClearIntErrorStatus(DMA0, ch);  

  125.       

  126.     (DMA->CH[ch]).Config |= 1 << 0; //Channel enable  

  127. }  

  128.   

  129.   

  130.   

  131. /************************************************************************************************************************* 

  132. *函数         :   void DMA_WaitComplete(DMA_TypeDef *DMA, DMA_CHX ch) 

  133. *Function: Wait for the transfer to complete 

  134. *Parameters: DMA: DMA module selection, see DMA_TypeDef; ch: channel selection, see DMA_CHX; 

  135. *Return: None 

  136. *Depends on: underlying 

  137. *Author : cp1300@139.com 

  138. *Time: 20130131 

  139. *Last modified: 20130131 

  140. * Description: None 

  141. *************************************************************************************************************************/  

  142. void DMA_WaitComplete(DMA_TypeDef *DMA, DMA_CHX ch)  

  143. {  

  144.     while(!(DMA->RawIntTCStatus & (1 << ch)));  

  145. }  

  146.   

  147.   

  148. /************************************************************************************************************************* 

  149. *函数         :   void DMA_ClearIntTCStatus(DMA_TypeDef *DMA, DMA_CHX ch) 

  150. *Function: DMA clears DMA transfer completion interrupt status 

  151. *Parameters: DMA: DMA module selection, see DMA_TypeDef; ch: channel selection, see DMA_CHX; 

  152. *Return: None 

  153. *Depends on: underlying 

  154. *Author : cp1300@139.com 

  155. *Time: 20130131 

  156. *Last modified: 20130131 

  157. * Description: None 

  158. *************************************************************************************************************************/  

  159. void DMA_ClearIntTCStatus(DMA_TypeDef *DMA, DMA_CHX ch)  

  160. {  

  161.     DMA->IntTcClear |= 1 << ch;  

  162. }  

  163.   

  164.   

  165. /************************************************************************************************************************* 

  166. *函数         :   void DMA_ClearIntErrorStatus(DMA_TypeDef *DMA, DMA_CHX ch) 

  167. *Function: Clear DMA transfer error interrupt status 

  168. *Parameters: DMA: DMA module selection, see DMA_TypeDef; ch: channel selection, see DMA_CHX; 

  169. *Return: None 

  170. *Depends on: underlying 

  171. *Author : cp1300@139.com 

  172. *Time: 20130131 

  173. *Last modified: 20130131 

  174. * Description: None 

  175. *************************************************************************************************************************/  

  176. void DMA_ClearIntErrorStatus(DMA_TypeDef *DMA, DMA_CHX ch)  

  177. {  

  178.     DMA->IntErrClear |= 1 << ch;  

  179. }  


  1. #ifndef DMA_H_  

  2. #define DMA_H_  

  3.   

  4.   

  5. //DMA channel definition  

  6. typedef enum   

  7. {  

  8.     DMA_CH0     =   0,  

  9.     DMA_CH1     =   1,  

  10.     DMA_CH2     =   2,  

  11.     DMA_CH3     =   3,  

  12.     DMA_CH4     =   4,  

  13.     DMA_CH5     =   5,  

  14.     DMA_CH6     =   6,  

  15.     DMA_CH7     =   7,  

  16. }DMA_CHX;  

  17.   

  18. //DMA single channel structure  

  19. typedef volatile struct  

  20. {  

  21.     vu32    SrcAddr;  

  22.     vu32 DestAddr;  

  23.     vu32    LLI;  

  24.     vu32    Control0;  

  25.     vu32    Control1;  

  26.     vu32    Config;  

  27.     vu32    ConfigExp;  

  28.     vu32    Reserved;  

  29. }DMA_CH_Config;  

  30.   

  31. //DMA register structure  

  32. typedef volatile struct  

  33. {  

  34.     vu32 IntStatus; //Interrupt status  

  35.     vu32 IntTcStatus; //Interrupt status during processing  

  36.     vu32 IntTcClear; //Interrupt clear  

  37.     vu32    IntErrorStatus;  

  38.     vu32    IntErrClear;  

  39.     vu32    RawIntTCStatus;  

  40.     vu32    RawIntErrorStatus;  

  41.     vu32    EnbldChns;  

  42.     vu32    SoftBReq;  

  43.     vu32    SoftSReq;  

  44.     vu32    SoftLBReq;  

  45.     vu32    SoftLSReq;  

  46.     vu32    Config;  

  47.     vu32    Sync;  

  48.     vu32 Reserved[50]; //Reserved  

  49.     DMA_CH_Config CH[8]; //8 independent channels  

  50. } DMA_TypeDef;  

  51.   

  52. //Base address of 4 DMA controllers  

  53. #define DMA0_BASE       0x75000000  

  54. #define DMA1_BASE       0x75100000  

  55. #define SDMA0_BASE      0x7DB00000  

  56. #define SDMA1_BASE      0x7DC00000  

  57.   

  58. //DMA register pointer  

  59. #define DMA0    ((DMA_TypeDef *)DMA0_BASE)  

  60. #define DMA1    ((DMA_TypeDef *)DMA1_BASE)  

  61. #define SDMA0   ((DMA_TypeDef *)SDMA0_BASE)  

  62. #define SDMA1   ((DMA_TypeDef *)SDMA1_BASE)  

  63.   

  64.   

  65. //DMA source definition  

  66. typedef enum  

  67. {  

  68.     //DMA0,SDMA0  

  69.     DMA_MEM         =   0,  

  70.     DMA_UART0_0     =   0,        

  71.     DMA_UART0_1     =   1,        

  72.     DMA_UART1_0     =   2,        

  73.     DMA_UART1_1     =   3,    

  74.     DMA_UART2_0     =   4,    

  75.     DMA_UART2_1     =   5,    

  76.     DMA_UART3_0     =   6,    

  77.     DMA_UART3_1     =   7,        

  78.     DMA_PCM0_TX     =   8,        

  79.     DMA_PCM0_RX     =   9,        

  80.     DMA_I2S0_TX     =   10,       

  81.     DMA_I2S0_RX     =   11,       

  82.     DMA_SPI0_TX     =   12,       

  83.     DMA_SPI0_RX     =   13,       

  84.     DMA_HSI_TX      =   14,       

  85.     DMA_HSI_RX      =   15,  

  86.     //DMA1,SDMA1  

  87.     DMA_PCM1_TX     =   16,  

  88.     DMA_PCM1_RX     =   17,  

  89.     DMA_I2S1_TX     =   18,  

  90.     DMA_I2S1_RX     =   19,  

  91.     DMA_SPI1_TX     =   20,  

  92.     DMA_SPI1_RX     =   21,  

  93.     DMA_AC_PCMout   =   22,  

  94.     DMA_AC_PCMin    =   23,  

  95.     DMA_AC_MICin    =   24,  

  96.     DMA_PWM         =   25,  

  97.     DMA_IrDA        =   26,  

  98.     DMA_SECU_RX     =   30,  

  99.     DMA_SECU_TX     =   31  

  100. }DMA_Sources_Type;  

  101.   

  102.   

  103. //DMA transfer type definition  

  104. /* 

  105. typedef enum 

  106.     MemToMem = 0, // memory to memory 

  107.     MemToPer = 1, // memory to peripherals 

  108.     PerToMem = 2, //peripheral to memory 

  109.     PerToPer = 3 //Peripheral to peripheral  

  110. }DMA_Transfer_Type; 

  111. */  

  112.   

  113. typedef enum  

  114. {  

  115.     NO_INT_PEND = 0x0,  

  116.     TC_INT_PEND = 0x1,  

  117.     ERR_INT_PEND = 0x2,  

  118.     TC_AND_ERR_INT_PEND = 0x3  

  119. } DMA_INT_STATUS;  

  120.   

  121.   

  122. //DMA AHB host selection definition  

  123. typedef enum  

  124. {  

  125.     AHB_M1 = 0, //AHB host 1  

  126.     AHB_M2 = 1, //AHB host 2  

  127. }DMA_AHB_Type;  

  128.   

  129. //DAM transmission width  

  130. typedef enum  

  131. {  

  132.     WIDTH_8BIT          =   0,  //8bit  

  133.     WIDTH_16BIT         =   1,  //16bit  

  134.     WIDTH_32BIT         =   2   //32bit  

  135. }DAM_Width_Type;  

  136.   

  137.   

  138. //Source or destination burst transfer size  

  139. typedef enum  

  140. {  

  141.     BURST1              =   0,  

  142.     BURST4              =   1,  

  143.     BURST8              =   2,  

  144.     BURST16             =   4,  

  145.     BURST32 = 5,  

  146.     BURST64             =   6,  

  147.     BURST128            =   7,  

  148.     BURST256            =   8  

  149. }DMA_BurstSize_Type;  

  150. /* 

  151.  *4-word FIFO per channel inside the DMAC. Therefore, the burst size and transfer width are limited by the FIFO 

  152. For example, if the data width is words, the available burst size is 4. If the data width is bytes, the available burst size is 

  153. Under 16 years of age. 

  154. */  

  155.   

  156. //DMA transfer configuration  

  157. typedef struct  

  158. {  

  159.     u32 SrcAddr; //DMA source address  

  160.     u32 DestAddr; //DAM target address  

  161.     DMA_Sources_Type    SrcPeripheral;  //源外设  

  162.     DMA_Sources_Type DestPeripheral; //Destination peripheral  

  163.     FunctionalState SrcIncrement; //Source address increment mode  

  164.     FunctionalState DestIncrement; //Destination address increment mode  

  165.     DAM_Width_Type FlowWidth; //Transmission width  

  166.     DMA_BurstSize_Type BurstSize; //Burst transfer size  

  167.     u32 DataSize; //Number of data to be transmitted, 32 bits  

  168.     u32 LLIArrd; //Next transmission configuration address  

  169. }DMA_Config;  

  170.   

  171.   

  172. //LLI address setting  

  173. typedef struct   

  174. {  

  175.     u32 SrcAddr; //The source address of the next transmission  

  176.     u32 DestAddr; //The destination address of the next transfer  

  177.     u32 LLIAddr; //LLI address of the next transmission  

  178.     u32 DMAControl0; //The next DMAControl0 data to be transferred  

  179.     u32 DMAControl1; //The next DMAControl1 data to be transferred  

  180. }DMA_LLI_Addr;  

  181.   

  182.   

  183.   

  184. // Function declaration  

  185. void DMA_Init(void);  

  186. void DMA_SetConfig(DMA_TypeDef *DMA, DMA_CHX ch, DMA_Config *config);  

  187. void DMA_Enable(DMA_TypeDef *DMA);  

  188. void DMA_Disable(DMA_TypeDef *DMA);  

  189. void DMA_WaitComplete(DMA_TypeDef *DMA, DMA_CHX ch);  

  190. void DMA_ClearIntTCStatus(DMA_TypeDef *DMA, DMA_CHX ch);  

  191. void DMA_ClearIntErrorStatus(DMA_TypeDef *DMA, DMA_CHX ch);  

  192. void DMA_StartChannels(DMA_TypeDef *DMA, DMA_CHX ch);  

  193.   

  194.   

  195.   

  196. #endif /*DMA_H_*/  


  197.   


  198.   

  199.   

  200.   

  201.   

  202.      

  203.  


Keywords:S3C6410 Reference address:S3C6410 Bare Metal DMA

Previous article:Mini2440 bare metal MMU experiment
Next article:OK6410 Assembly Program Exercise

Recommended ReadingLatest update time:2024-11-17 04:23

S3C6410 learning - Nand flash trap
When the system is started in Nand mode, the hardware copies the first 8KB of Nand Flash to Steppingstone, and then runs the program from address 0. In the code within 8KB, we need to complete the necessary hardware initialization. If the code exceeds 8K, we also need to move the remaining code to the link address, gen
[Microcontroller]
Design of wireless control system based on password recognition
0 Introduction     Speech is the most natural, convenient and effective way for humans to communicate information. Interacting with machines by voice is something that humans have always dreamed of. After more than ten years of development, speech recognition based on hidden Markov models has met the application requ
[Microcontroller]
Design of wireless control system based on password recognition
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号