vendor.c
上传用户:ids068
上传日期:2013-04-04
资源大小:639k
文件大小:7k
源码类别:

USB编程

开发平台:

C/C++

  1. //***********************************************************************
  2. //                         *
  3. //                P H I L I P S   P R O P R I E T A R Y              *    
  4. //                                                                      *
  5. //          COPYRIGHT (c)   1999 BY PHILIPS SINGAPORE (APIC).        *
  6. //                    --  ALL RIGHTS RESERVED  --                  *
  7. //                                                                      *
  8. //  File Name :       DMADebug.c                                    *
  9. //  Author :       Albert Goh         *
  10. //  Created :       3 March 2000                                *
  11. //                                                                      *
  12. //***********************************************************************
  13. //***********************************************************************
  14. //                                                                      *
  15. // GDMADebug.c is the file that contain the routine for the GDMA debug  *
  16. // It will be able to configured as master for slave for the debugging *
  17. //                                                                      *
  18. //***********************************************************************
  19. //***********************************************************************
  20. //                                                                      *
  21. //  Module History             *
  22. //  **************             *
  23. //                   *
  24. //  Date    Version Author Changes       *
  25. //  ====    ======= ====== =======       *
  26. //  030300   0.1  Albert Created           *
  27. //                                                                      *
  28. //                                                                      *
  29. //***********************************************************************
  30. //***********************************************************************
  31. //*                *
  32. //*                      Include Files Definition    *
  33. //*                *
  34. //***********************************************************************
  35. #include "standard.h"
  36. #include "Kernel.h"
  37. #include "D14.h"
  38. //***********************************************************************
  39. //*                *
  40. //*                  External Variable Definition        *
  41. //*                *
  42. //***********************************************************************
  43. extern USB_DEVICE USB_Device;
  44. extern DMA_INT_FLAG DMA_Int_Flag;
  45. extern USB_INT_FLAG USB_Int_Flag;
  46. extern volatile D14_CNTRL_REG xdata D14_Cntrl_Reg;
  47. extern void Start_mSEC_Timer(Data);
  48. extern UC Data;
  49. extern UI Temp,PIO_Count;
  50. extern KERNEL Kernel_Flag;
  51. extern ULI  bytecount;
  52. extern FILESIZE FileSize;
  53. extern UI count;
  54. extern UC idata Endpt_FIFO[MAX_BUF];
  55. extern UC Type;
  56. //***********************************************************************
  57. //*                *
  58. //*                      Variable Definition        *
  59. //*                *
  60. //***********************************************************************
  61. UI Count_PIO;
  62. //***********************************************************************
  63. //*                *
  64. //*                      Prototype Definition     *
  65. //*                *
  66. //***********************************************************************
  67. void DMA_Debug_Mode(void);
  68. void DMA_Init(void);
  69. void DMA_Mode(Data);
  70. //***********************************************************************
  71. //*                *
  72. //*                      Routine Definition    *
  73. //*                *
  74. //***********************************************************************
  75. //***********************************************************************
  76. //*                     *
  77. //* Routine  : DMA Debug Mode                                     *
  78. //* Input : None                          *
  79. //* Output : None                                      *
  80. //* Function : Generic DMA mode routine                       *
  81. //*                *
  82. //***********************************************************************
  83. void DMA_Debug_Mode(void)
  84. {
  85. if(Kernel_Flag.BITS.Transfer_Start)
  86. {
  87. if(FileSize.Size.Address[0] == 0 &&
  88. FileSize.Size.Address[1] == 0 &&
  89. FileSize.Size.Address[2] == 0)
  90. {
  91. Kernel_Flag.BITS.Out_Reset_Done = 0;
  92. Kernel_Flag.BITS.In_Reset_Done = 0;
  93. }
  94. if(FileSize.Size.DIR == 0x00 || FileSize.Size.DIR == 0x80)
  95. DMA_Mode(Write);
  96. else
  97. DMA_Mode(Read);
  98. }
  99. }
  100. //***********************************************************************
  101. //*                     *
  102. //* Routine  : DMA Mode                                           *
  103. //* Input : DMA Controller setting                      *
  104. //* Output : None                                      *
  105. //* Function : to do GDMA data transfer                       *
  106. //*                *
  107. //***********************************************************************
  108. void DMA_Mode(Data)
  109. {
  110. UI Datcount;
  111. if(Data)
  112. {
  113. //read
  114. do
  115. {
  116. //Check for Out Token ACK interrupt
  117. while(!USB_Int_Flag.BITS.EP2RX)
  118. {
  119. if(USB_Int_Flag.BITS.SUSP || Kernel_Flag.BITS.Bus_Reset || USB_Int_Flag.BITS.EP0SETUP)
  120. break;
  121. }
  122. EA_DISABLE;
  123. USB_Int_Flag.BITS.EP2RX = 0;
  124. EA_ENABLE;
  125. D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
  126. D14_Cntrl_Reg.D14_DMA_ENDPOINT = 2;
  127. //Read in FIFO data
  128. if (bytecount > PIO_Count)
  129. {
  130. Datcount = PIO_Count;
  131. }
  132. else
  133. {
  134. Datcount = bytecount;
  135. }
  136. if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
  137. {
  138. for(Count_PIO = 0 ; Count_PIO < Datcount ; Count_PIO++)
  139. Endpt_FIFO[Count_PIO] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
  140. }
  141. else
  142. {
  143. for(Count_PIO = 0 ; Count_PIO < Datcount; Count_PIO++)
  144. Temp = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
  145. }
  146. bytecount -= Datcount;
  147. }while(bytecount);
  148. }
  149. else
  150. {
  151. //write
  152. do
  153. {
  154. //initialize endpoint index
  155. D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
  156. D14_Cntrl_Reg.D14_DMA_ENDPOINT = 2;
  157. //Write data to FIFO
  158. if (bytecount>PIO_Count)
  159. {
  160. D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB =( unsigned char ) PIO_Count;
  161. D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = ( unsigned char ) (PIO_Count>>8);
  162. Datcount = PIO_Count;
  163. }
  164. else
  165. {
  166. D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB =( unsigned char ) bytecount;
  167. D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = ( unsigned char ) (bytecount>>8);
  168. Datcount = bytecount;
  169. }
  170. if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
  171. {
  172. for(Count_PIO = 0 ; Count_PIO < Datcount ; Count_PIO++)
  173. D14_Cntrl_Reg.D14_DATA_PORT_LSB = Endpt_FIFO[Count_PIO];
  174. }
  175. else
  176. {
  177. for(Count_PIO = 0 ; Count_PIO < Datcount ; Count_PIO++)
  178. D14_Cntrl_Reg.D14_DATA_PORT_LSB = Count_PIO % 256;
  179. }
  180. //Check for In Token ACK
  181. while(!USB_Int_Flag.BITS.EP2TX)
  182. {    
  183. if(USB_Int_Flag.BITS.SUSP || Kernel_Flag.BITS.Bus_Reset || USB_Int_Flag.BITS.EP0SETUP)
  184. break;
  185. }    
  186. EA_DISABLE;
  187. USB_Int_Flag.BITS.EP2TX = 0;
  188. EA_ENABLE;
  189. bytecount -= Datcount; 
  190. }while(bytecount);
  191. //stop DMA controller
  192. DMA_Start = GDMA_Stop;
  193. //transfewr done,reset internal variables
  194. DMA_Int_Flag.BITS.DMA_DONE = 0;
  195. Count_PIO = 0;
  196. }
  197. Kernel_Flag.BITS.Transfer_Start = 0;  
  198. }