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