KERNEL.H
上传用户:ids068
上传日期:2013-04-04
资源大小:639k
文件大小:12k
源码类别:

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 :       Kernel.h                                        *
  9. //  Author :       Albert Goh   *
  10. //  Created :       3 March 2000                                *
  11. //                                                                   *
  12. //***********************************************************************
  13. //***********************************************************************
  14. //                                                                      *
  15. // Kernel.h has the various external defintion and structure defintion  *
  16. //                                                                      *
  17. //***********************************************************************
  18. //***********************************************************************
  19. //                                                                      *
  20. //  Module History *
  21. //  ************** *
  22. // *
  23. //  Date    Version Author Changes *
  24. //  ==== ======= ====== ======= *
  25. //  030300   0.1  Albert Created     *
  26. //                                                                      *
  27. //                                                                      *
  28. //***********************************************************************
  29. //***********************************************************************
  30. //* *
  31. //*                       Variable Definition   *
  32. //* *
  33. //***********************************************************************
  34. sfr AUXR = 0x8e;
  35. sfr CKCON = 0x8f;
  36. #define MAX_BUF 64
  37. //#define                  CHAP9_COMPLIANT   15                //use for chapter 9 and 8 test
  38.                                                                //max packet size is 512
  39. //#define USB_ENABLED 3     //to test FIFO must disable DMA_ENABLED and PIO_ENABLED
  40. //USAGE FOR ATA AND ATAPI DEVICE
  41. //#define PIO_ENABLED 1   // to test PIO mode must disable DMA_ENABLED
  42. //#define MDMA_TRANSFER 5 //ATA MDMA Transfer Mode
  43. //#define UDMA_TRANSFER 6 //ATA UDMA Transfer Mode
  44. //#define PIO_TRANSFER 7 //ATA PIO Transfer Mode
  45. //#define DEVICE_ENABLED  8
  46. #define ATAPI_DEVICE 9
  47. //USAGE FOR THE GENERIC DMA MODE
  48. //#define DMA_ENABLED 2 //Select DMA Mode
  49. //#define GDMA_MODE 10 //GDMA Slave Mode 
  50. //#define MDMA_MODE 11 //MDMA Master Mode
  51. //#define MPIO_MODE 17 //Manual PIO Mode
  52. //#define PING_PONG 15 //set the descriptor to PID 1582
  53. #define           SBUS_RESET                  0         
  54. #define           SSUSPEND                    1
  55. #define           SPOWER                      2
  56. #define           SWAKEUP                     3
  57. #define           SCMD                        4
  58. #define           SREAD                       5
  59. #define           SWRITE                      6
  60. #define           SSTATUS                     7
  61. #define Crystal_Freq 24
  62. #define DEVICE_RESET 0x0C
  63. #define ENABLE_INTRQ 0x08
  64. #define DISABLE_INTRQ 0x0A
  65. #define SETUP_DMA_REQUEST     0x7104
  66. #define GET_FIRMWARE_VERSION    0x7204
  67. #define GET_SET_TWAIN_REQUEST   0x7304
  68. #define MASTER_DRIVE 0xA0
  69. #define ATA_MASTER 0
  70. #define ID_ATAPI_DEVICE 0xA1
  71. #define ID_ATA_DEVICE 0xEC
  72. #define ATAPI_SOFTRESET 0x08
  73. #define SET_FEATURE 0xEF
  74. #define INIT_DRIVE 0x91
  75. #define Transfer_Mode 0x03
  76. #define Read 0
  77. #define Write 1
  78. #define GDMA_Read 1
  79. #define GDMA_Write 0
  80. #define GDMA_Start 1
  81. #define GDMA_Stop 0
  82. #define OUT 0
  83. #define IN 1
  84. #define OFF 0
  85. #define ON 1
  86. #define Endpt_Zero 0
  87. #define Endpt_One 1
  88. #define Endpt_Two 2
  89. #define Endpt_Three 3
  90. #define Endpt_Four 4
  91. #define Endpt_Five 5
  92. #define Endpt_Six 6
  93. #define Endpt_Seven 7
  94. #define Control_Type 0
  95. #define Iso_Type 1
  96. #define Bulk_Type 2
  97. #define Int_Type 3
  98. /*
  99. #define Control_Type 0
  100. #define Iso_Type 3
  101. #define Bulk_Type 1
  102. #define Int_Type 2
  103. */
  104. /*
  105. #define Get_Status 0x00
  106. #define Clear_Feature 0x01
  107. #define Set_Feature 0x03
  108. #define Set_Address 0x05
  109. #define Get_Descriptor 0x06
  110. #define Set_Descriptor 0x07
  111. #define Get_Config 0x08
  112. #define Set_Config 0x09
  113. #define Get_Interface 0x0A
  114. #define Set_Interface 0x0B
  115. #define Synch_Frame 0x0C
  116. */
  117. #define USB_Default 0
  118. #define USB_Addressed 1
  119. #define USB_Configured 2
  120. #define ATAPI_Cmd_Packet_Phase          0x09
  121. #define ATAPI_Message_Phase 0x0B
  122. #define ATAPI_Read_Phase    0x0A
  123. #define ATAPI_Write_Phase   0x08
  124. #define ATAPI_Read_Phase_NODRQ    0x02
  125. #define ATAPI_Write_Phase_NODRQ   0x00
  126. #define ATAPI_Status_Phase 0x03
  127. #define Error_Phase   0xAA
  128. #define No_Data_Phase   0x55
  129. #define Data_Host2Device 0x00
  130. #define Data_Device2Host 0x80
  131. #define TransferData2Host 0x01
  132. #define TransferData2Device 0x02
  133. #define TransferNoData 0x00
  134. #define ATAPI_PACKET_COMMAND 0xA0
  135. #define GDMA_Read_Command 0x00
  136. #define GDMA_Write_Command 0x01
  137. #define UDMA_Read_Command 0x02
  138. #define UDMA_Write_Command 0x03
  139. #define PIO_Read_Command 0x04
  140. #define PIO_Write_Command 0x05
  141. #define MDMA_Read_Command 0x06
  142. #define MDMA_Write_Command 0x07
  143. #define PIO_Write_Complete 0x08
  144. #define PIO_Read_Complete  0x09
  145. #define READ_1F0 0x0A
  146. #define POLL_BUSY 0x0B
  147. #define UPDATE_TASKFILE 0x0C
  148. #define  DMA_VALIDATE_BUFFER        0x0E
  149. #define  DMA_CLEAR_BUFFER           0x0F
  150. #define  DMA_BUFFER_RESTART         0x10
  151. #define  DMA_RESET                  0x11
  152. #define  DMA_FLUSH                  0x12
  153. //for FPGA and old board
  154. /*
  155. #define DMA_Start  P16
  156. #define DMA_Wr_Rd P17
  157. #define DMA_Reset P14
  158. #define ISP1581_CS P15
  159. #define  ISP1581_RESET              P27
  160. #define  RESET_IDE                  P26
  161. #define HS_FS_LED P35
  162. */
  163. // for new Evalkit
  164. /*
  165. #define DMA_Start  P10
  166. #define DMA_Reset P11
  167. #define DMA_Wr_Rd P12
  168. #define  VBus_Sense     P21
  169. #define ISP1581_CS P15
  170. #define  ISP1581_RESET  P16
  171. #define  RESET_IDE      P17
  172. #define HS_FS_LED P20
  173. */
  174. sbit DMA_Start = P1^4;
  175. sbit DMA_Reset = P1^4;
  176. sbit DMA_Wr_Rd = P1^4;
  177. sbit   VBus_Sense =    P1^2;
  178. sbit RESET_IDE =     P1^4;
  179. sbit HS_FS_LED = P1^0;
  180. //sbit ISP1581_CS = P1^2;
  181. sbit ISP1581_RESET = P3^4;
  182. #define EA_DISABLE EA=0
  183. #define EA_ENABLE EA=1
  184. // for old Evalkit
  185. /*
  186. #define DMA_Start  P34
  187. #define DMA_Wr_Rd P10
  188. #define DMA_Reset P35
  189. #define ISP1581_CS P26
  190. #define  ISP1581_RESET              P25
  191. #define  RESET_IDE                  P24
  192. #define HS_FS_LED P23
  193. */
  194. #define GDMA_Test 1
  195. #define UDMA_Test 2
  196. #define MDMA_Test 3
  197. #define PIO_Test    4
  198. #define HIGH_SPEED 0
  199. #define FULL_SPEED 1
  200. #define HIGH_SPEED_LED          1
  201. #define FULL_SPEED_LED 0
  202. #define  TEST_MODE            0x0200
  203. #define  ENDPOINT_HALT        0
  204. #define  DEVICE_REMOTE_WAKEUP 1
  205. #define  TEST_J            1
  206. #define  TEST_K            2
  207. #define  TEST_SE0_NAK      3
  208. #define  TEST_PACKET       4
  209. #define  TEST_FORCE_ENABLE 5
  210. //***********************************************************************
  211. //* *
  212. //*                  Structure Variable Definition   *
  213. //* *
  214. //***********************************************************************
  215. typedef union KERNEL 
  216. {
  217. struct KERNEL_BITS
  218. {
  219. UC TIMER_ONOFF  :  1, // 8051 timer running state
  220. STATE :   3, //kernel current state
  221. MASTER_ATAPI_DRIVE :  1,
  222. MASTER_ATA_DRIVE :  1,
  223. MASTER_PRESENT :  1,
  224. SLAVE_PRESENT :  1;
  225. UC Manual_PIO : 1,
  226. Auto_PIO : 1,
  227. UDMA_Mode : 1,
  228. MDMA_Mode : 1,
  229. GDMA_Mode : 1,
  230. Timer_Expired : 1,
  231. Bus_Reset : 1;
  232. UC Error_Occur : 2,
  233. Init_Done : 1,
  234. In_Reset_Done : 1,
  235. Out_Reset_Done : 1,
  236. Tx_Done : 1,
  237. Dummy_Byte : 1,
  238. Endpt_Stall : 1;
  239. UC HS_FS_State : 1,
  240. MPIO_Out_Reset_Done           : 1,
  241. MPIO_In_Reset_Done  : 1,
  242. Register_Test : 1,
  243.                            Transfer_Error                      :        1,
  244.                            Transfer_Start                      :        1,
  245.                            ATAPI_DMA_END                       :        1;
  246. }BITS;
  247. ULI VALUE;
  248. }KERNEL;
  249. typedef struct DRIVE_CONFIG
  250. {
  251.     UI General_Config; //word 0
  252. UI PIO_Mode; //word 51
  253. UI MDMA_Mode; //word 63
  254. UI Advanced_PIO; //word 64
  255. UI UDMA_Mode; //word 88
  256. }DRIVE_CONFIG;
  257. typedef struct TIMER
  258. {
  259. UI mSEC_Scale;
  260. UI Hundred_mSEC_Scale;
  261. }TIMER;
  262. typedef struct FEATURE
  263. {
  264. UC SubCommand_Count;
  265. UC SubCommand_Number;
  266. UC SubCommand_Low;
  267. UC SubCommand_High;
  268. }FEATURE;
  269. typedef union DMA_INT_FLAG
  270. {
  271. struct DMA_FLAG_BITS
  272. {
  273. UC CMD_AUTO_COMPLETE : 1;
  274. UC CMD_INTRQ_OK : 1;
  275. UC TASKFILE_READ_COMPLETE : 1;
  276. UC BSY_DRQ_POLL_DONE : 1;
  277. UC START_READ_1F0_RD_FIFO : 1;
  278. UC RD_1F0_FIFO_EMPTY : 1;
  279. UC WR_1F0_FIFO_FULL : 1;
  280. UC WR_1F0_FIFO_EMPTY : 1;
  281. UC DMA_DONE : 1;
  282. UC INTRQ_SEEN : 1;
  283.          UC       INT_EOT                             :        1;
  284.          UC       EXT_EOT                             :        1;
  285. UC RES1 : 4;
  286. }BITS;
  287. UI VALUE;
  288. }DMA_INT_FLAG;
  289. typedef union DATA_SWAP 
  290. {
  291. UC byte[2];
  292. UI word;
  293. }DATA_SWAP;
  294. typedef union ATAPI_BYTECOUNT 
  295. {
  296. UC Byte[4];
  297. ULI VALUE;
  298. }ATAPI_BYTECOUNT;
  299. typedef union BYTECOUNT 
  300. {
  301. UC Byte[2];
  302. ULI VALUE;
  303. }BYTECOUNT;
  304. /*
  305. typedef union USB_ELEMENT
  306. {
  307. struct USB_ELEMENT_BITS
  308. {
  309. UI SOF_Count : 11,
  310.    uSOF_Count : 3;
  311. }BITS;
  312. // UI  Value;
  313. }USB_ELEMENT;
  314. */
  315. typedef union USB_INT_FLAG
  316. {
  317. struct USB_FLAG_BITS
  318. {
  319. UC RESET :  1;
  320. UC SOF : 1;
  321. UC PSOF : 1;
  322. UC SUSP : 1;
  323. UC RESUME : 1;
  324. UC HS_STAT : 1;
  325. UC DMA : 1;
  326. UC RESERVED3 : 1;
  327. UC EP0SETUP : 1;
  328. UC RESERVED2 :  1;
  329. UC EP0RX : 1;
  330. UC EP0TX : 1;
  331. UC EP1RX : 1;
  332. UC EP1TX : 1;
  333. UC EP2RX : 1;
  334. UC EP2TX : 1;
  335. UC EP3RX : 1;
  336. UC EP3TX : 1;
  337. UC EP4RX : 1;
  338. UC EP4TX : 1;
  339. UC EP5RX : 1;
  340. UC EP5TX : 1;
  341. UC EP6RX : 1;
  342. UC EP6TX : 1;
  343. UC EP7RX : 1;
  344. UC EP7TX : 1;
  345. UC RESERVED1 : 6;
  346. }BITS;
  347. UL VALUE;
  348. }USB_INT_FLAG;
  349. typedef struct USB_DEVICE_REQ
  350. {
  351. UC bmRequestType;
  352. UC bRequest;
  353. UI wValue;
  354. UI wIndex;
  355. UI wLength;
  356. }USB_DEVICE_REQ;
  357. typedef struct USB_DEVICE
  358. {
  359. struct USB_DEVICE_BITS
  360. {
  361. UC Remote_Wakeup : 1,
  362.    Halt : 1,
  363.    Self_Powered : 1,
  364.    Endpt_Halt : 1,
  365.    Test_Mode : 1,
  366.    State : 3;
  367. UC CBI_Detected : 1;
  368. UC DMA_Test_Mode : 8;
  369. UC Alter_Interface : 1,
  370. CBW_Rx : 1,
  371. CBW_Data : 1,
  372. DMA_State : 3,
  373. Big_Endian : 1;
  374. }BITS;
  375. }USB_DEVICE;
  376. typedef struct USBCBW
  377. {
  378.          union Signature
  379.          {
  380.          UC dCBWSignature[4];
  381.                   ULI VALUE;
  382.          
  383.          }Signature;
  384.                     
  385. UC  dCBWTag[4];
  386.          union Length
  387.          {
  388.          
  389.                   UC dCBWDataTransferLength[4];
  390.                   ULI VALUE;
  391.          
  392.          }Length;
  393.          
  394. UC  dCBWFlags;
  395. UC  bCBWLUN;
  396. UC  bCDBLength;
  397.          UC  CBWCDB[0x10];
  398. } USBCBW;
  399. typedef struct USB_CSW
  400. {
  401.          union Residue
  402.          {
  403.          UC dCSWDataResidue[4];
  404.                   ULI VALUE;
  405.          
  406.          }Residue;
  407.                     
  408. UC bCSWStatus;
  409. }USBCSW;
  410. typedef union FILESIZE
  411. {
  412.          struct filesize
  413.          {
  414.             UC       Address[3];
  415.             UC       FileSize[4];
  416.             UC       DIR;
  417.          
  418.          }Size; 
  419.          
  420.          UDI      Value;
  421. }FILESIZE;