📄 kchap9.lst
字号:
1 =2 void read_write_register(void);
2 =1 #define MAXIMUM_USB_STRING_LENGTH 255
3 =1
4 =1 // values for the bits returned by the USB GET_STATUS command
5 =1 #define USB_GETSTATUS_SELF_POWERED 0x01
6 =1 #define USB_GETSTATUS_REMOTE_WAKEUP_ENABLED 0x02
7 =1
8 =1
9 =1 #define USB_DEVICE_DESCRIPTOR_TYPE 0x01
10 =1 #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
11 =1 #define USB_STRING_DESCRIPTOR_TYPE 0x03
12 =1 #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
13 =1 #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
14 =1 #define USB_POWER_DESCRIPTOR_TYPE 0x06
15 =1
16 =1 #define USB_DESCRIPTOR_MAKE_TYPE_AND_INDEX(d, i) ((USHORT)((USHORT)d<<8 | i))
17 =1
18 =1 //
19 =1 // Values for bmAttributes field of an
20 =1 // endpoint descriptor
21 =1 //
22 =1
23 =1 #define USB_ENDPOINT_TYPE_MASK 0x03
24 =1
25 =1 #define USB_ENDPOINT_TYPE_CONTROL 0x00
26 =1 #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
27 =1 #define USB_ENDPOINT_TYPE_BULK 0x02
28 =1 #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
29 =1
30 =1
31 =1 //
32 =1 // definitions for bits in the bmAttributes field of a
33 =1 // configuration descriptor.
34 =1 //
35 =1 #define USB_CONFIG_POWERED_MASK 0xc0
36 =1
37 =1 #define USB_CONFIG_BUS_POWERED 0x80
38 =1 #define USB_CONFIG_SELF_POWERED 0x40
39 =1 #define USB_CONFIG_REMOTE_WAKEUP 0x20
40 =1
41 =1 //
42 =1 // Endpoint direction bit, stored in address
C51 COMPILER V6.20c KCHAP9 10/31/2002 21:55:45 PAGE 11
43 =1 //
44 =1
45 =1 #define USB_ENDPOINT_DIRECTION_MASK 0x80
46 =1
47 =1 // test direction bit in the bEndpointAddress field of
48 =1 // an endpoint descriptor.
49 =1 #define USB_ENDPOINT_DIRECTION_OUT(addr) (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
50 =1 #define USB_ENDPOINT_DIRECTION_IN(addr) ((addr) & USB_ENDPOINT_DIRECTION_MASK)
51 =1
52 =1 //
53 =1 // USB defined request codes
54 =1 // see chapter 9 of the USB 1.0 specifcation for
55 =1 // more information.
56 =1 //
57 =1
58 =1 // These are the correct values based on the USB 1.0
59 =1 // specification
60 =1
61 =1 #define USB_REQUEST_GET_STATUS 0x00
62 =1 #define USB_REQUEST_CLEAR_FEATURE 0x01
63 =1
64 =1 #define USB_REQUEST_SET_FEATURE 0x03
65 =1
66 =1 #define USB_REQUEST_SET_ADDRESS 0x05
67 =1 #define USB_REQUEST_GET_DESCRIPTOR 0x06
68 =1 #define USB_REQUEST_SET_DESCRIPTOR 0x07
69 =1 #define USB_REQUEST_GET_CONFIGURATION 0x08
70 =1 #define USB_REQUEST_SET_CONFIGURATION 0x09
71 =1 #define USB_REQUEST_GET_INTERFACE 0x0A
72 =1 #define USB_REQUEST_SET_INTERFACE 0x0B
73 =1 #define USB_REQUEST_SYNC_FRAME 0x0C
74 =1
75 =1
76 =1 //
77 =1 // defined USB device classes
78 =1 //
79 =1
80 =1
81 =1 #define USB_DEVICE_CLASS_RESERVED 0x00
82 =1 #define USB_DEVICE_CLASS_AUDIO 0x01
83 =1 #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02
84 =1 #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03
85 =1 #define USB_DEVICE_CLASS_MONITOR 0x04
86 =1 #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05
87 =1 #define USB_DEVICE_CLASS_POWER 0x06
88 =1 #define USB_DEVICE_CLASS_PRINTER 0x07
89 =1 #define USB_DEVICE_CLASS_STORAGE 0x08
90 =1 #define USB_DEVICE_CLASS_HUB 0x09
91 =1 #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF
92 =1
93 =1 //
94 =1 // USB defined Feature selectors
95 =1 //
96 =1
97 =1 #define USB_FEATURE_ENDPOINT_STALL 0x0000
98 =1 #define USB_FEATURE_REMOTE_WAKEUP 0x0001
99 =1 #define USB_FEATURE_POWER_D0 0x0002
100 =1 #define USB_FEATURE_POWER_D1 0x0003
101 =1 #define USB_FEATURE_POWER_D2 0x0004
102 =1 #define USB_FEATURE_POWER_D3 0x0005
103 =1
104 =1 typedef struct _USB_DEVICE_DESCRIPTOR {
C51 COMPILER V6.20c KCHAP9 10/31/2002 21:55:45 PAGE 12
105 =1 UCHAR bLength;
106 =1 UCHAR bDescriptorType;
107 =1 USHORT bcdUSB;
108 =1 UCHAR bDeviceClass;
109 =1 UCHAR bDeviceSubClass;
110 =1 UCHAR bDeviceProtocol;
111 =1 UCHAR bMaxPacketSize0;
112 =1 USHORT idVendor;
113 =1 USHORT idProduct;
114 =1 USHORT bcdDevice;
115 =1 UCHAR iManufacturer;
116 =1 UCHAR iProduct;
117 =1 UCHAR iSerialNumber;
118 =1 UCHAR bNumConfigurations;
119 =1 } USB_DEVICE_DESCRIPTOR, *PUSB_DEVICE_DESCRIPTOR;
120 =1
121 =1 typedef struct _USB_ENDPOINT_DESCRIPTOR {
122 =1 UCHAR bLength;
123 =1 UCHAR bDescriptorType;
124 =1 UCHAR bEndpointAddress;
125 =1 UCHAR bmAttributes;
126 =1 USHORT wMaxPacketSize;
127 =1 UCHAR bInterval;
128 =1 } USB_ENDPOINT_DESCRIPTOR, *PUSB_ENDPOINT_DESCRIPTOR;
129 =1
130 =1 //
131 =1 // values for bmAttributes Field in
132 =1 // USB_CONFIGURATION_DESCRIPTOR
133 =1 //
134 =1
135 =1 #define BUS_POWERED 0x80
136 =1 #define SELF_POWERED 0x40
137 =1 #define REMOTE_WAKEUP 0x20
138 =1
139 =1 typedef struct _USB_CONFIGURATION_DESCRIPTOR {
140 =1 UCHAR bLength;
141 =1 UCHAR bDescriptorType;
142 =1 USHORT wTotalLength;
143 =1 UCHAR bNumInterfaces;
144 =1 UCHAR bConfigurationValue;
145 =1 UCHAR iConfiguration;
146 =1 UCHAR bmAttributes;
147 =1 UCHAR MaxPower;
148 =1 } USB_CONFIGURATION_DESCRIPTOR, *PUSB_CONFIGURATION_DESCRIPTOR;
149 =1
150 =1 typedef struct _USB_INTERFACE_DESCRIPTOR {
151 =1 UCHAR bLength;
152 =1 UCHAR bDescriptorType;
153 =1 UCHAR bInterfaceNumber;
154 =1 UCHAR bAlternateSetting;
155 =1 UCHAR bNumEndpoints;
156 =1 UCHAR bInterfaceClass;
157 =1 UCHAR bInterfaceSubClass;
158 =1 UCHAR bInterfaceProtocol;
159 =1 UCHAR iInterface;
160 =1 } USB_INTERFACE_DESCRIPTOR, *PUSB_INTERFACE_DESCRIPTOR;
161 =1
162 =1 typedef struct _USB_STRING_DESCRIPTOR {
163 =1 UCHAR bLength;
164 =1 UCHAR bDescriptorType;
165 =1 UCHAR bString[1];
166 =1 } USB_STRING_DESCRIPTOR, *PUSB_STRING_DESCRIPTOR;
C51 COMPILER V6.20c KCHAP9 10/31/2002 21:55:45 PAGE 13
167 =1
168 =1 //
169 =1 // USB power descriptor added to core specification
170 =1 //
171 =1
172 =1 #define USB_SUPPORT_D0_COMMAND 0x01
173 =1 #define USB_SUPPORT_D1_COMMAND 0x02
174 =1 #define USB_SUPPORT_D2_COMMAND 0x04
175 =1 #define USB_SUPPORT_D3_COMMAND 0x08
176 =1
177 =1 #define USB_SUPPORT_D1_WAKEUP 0x10
178 =1 #define USB_SUPPORT_D2_WAKEUP 0x20
179 =1
180 =1
181 =1 typedef struct _USB_POWER_DESCRIPTOR {
182 =1 UCHAR bLength;
183 =1 UCHAR bDescriptorType;
184 =1 UCHAR bCapabilitiesFlags;
185 =1 USHORT EventNotification;
186 =1 USHORT D1LatencyTime;
187 =1 USHORT D2LatencyTime;
188 =1 USHORT D3LatencyTime;
189 =1 UCHAR PowerUnit;
190 =1 USHORT D0PowerConsumption;
191 =1 USHORT D1PowerConsumption;
192 =1 USHORT D2PowerConsumption;
193 =1 } USB_POWER_DESCRIPTOR, *PUSB_POWER_DESCRIPTOR;
194 =1
195 =1
196 =1 typedef struct _USB_COMMON_DESCRIPTOR {
197 =1 UCHAR bLength;
198 =1 UCHAR bDescriptorType;
199 =1 } USB_COMMON_DESCRIPTOR, *PUSB_COMMON_DESCRIPTOR;
200 =1
201 =1
202 =1 //
203 =1 // Standard USB HUB definitions
204 =1 //
205 =1 // See Chapter 11
206 =1 //
207 =1
208 =1 typedef struct _USB_HUB_DESCRIPTOR {
209 =1 UCHAR bDescriptorLength; // Length of this descriptor
210 =1 UCHAR bDescriptorType; // Hub configuration type
211 =1 UCHAR bNumberOfPorts; // number of ports on this hub
212 =1 USHORT wHubCharacteristics; // Hub Charateristics
213 =1 UCHAR bPowerOnToPowerGood; // port power on till power good in 2ms
214 =1 UCHAR bHubControlCurrent; // max current in mA
215 =1 //
216 =1 // room for 255 ports power control and removable bitmask
217 =1 UCHAR bRemoveAndPowerMask[64];
218 =1 } USB_HUB_DESCRIPTOR, *PUSB_HUB_DESCRIPTOR;
219 =1
12 #include "kchap9.h"
1 =1 /*
2 =1 //*************************************************************************
3 =1 // USB standard device requests
4 =1 //*************************************************************************
5 =1 */
6 =1 void get_status(void);
7 =1 void clear_feature(void);
8 =1 void set_feature(void);
C51 COMPILER V6.20c KCHAP9 10/31/2002 21:55:45 PAGE 14
9 =1 void set_address(void);
10 =1 void get_descriptor(void);
11 =1 void get_configuration(void);
12 =1 void set_configuration(void);
13 =1 void get_interface(void);
14 =1 void set_interface(void);
15 =1
16 =1 void reserved(void);
13
14 //---------------------------
15 extern void single_transmit(unsigned char * buf, unsigned char len);
16 extern void code_transmit(unsigned char code * pRomData, unsigned short len);
17 extern void stall_ep0(void);
18 extern void init_unconfig(void);
19 extern void init_config(void);
20
21 #define NUM_ENDPOINTS 4
22
23 #define CONFIG_DESCRIPTOR_LENGTH sizeof(USB_CONFIGURATION_DESCRIPTOR) \
24 + sizeof(USB_INTERFACE_DESCRIPTOR) \
25 + (NUM_ENDPOINTS * sizeof(USB_ENDPOINT_DESCRIPTOR))
26
27 extern CONTROL_XFER ControlData;
28 extern IO_REQUEST idata ioRequest;
29 extern EPPFLAGS bEPPflags;
30
31 code USB_DEVICE_DESCRIPTOR DeviceDescr =
32 {
33 sizeof(USB_DEVICE_DESCRIPTOR),
34 USB_DEVICE_DESCRIPTOR_TYPE,
35 SWAP(0x0100),
36 USB_CLASS_CODE_TEST_CLASS_DEVICE,
37 0,
38 0,
39 EP0_PACKET_SIZE,
40 SWAP(0x0471), //VID
41 SWAP(0x0666), //PID
42 SWAP(0x0100),
43 0, //Manufactory
44 0, //Product
45 0, //Serial Number
46 25 //Number of possible configurations
47 };
48
49 code USB_CONFIGURATION_DESCRIPTOR ConfigDescr =
50 {
51 sizeof(USB_CONFIGURATION_DESCRIPTOR),
52 USB_CONFIGURATION_DESCRIPTOR_TYPE,
53 SWAP(CONFIG_DESCRIPTOR_LENGTH),
54 1,
55 1,
56 0,
57 0x60,
58 0xf0
59 //0x1
60 };
61
62 code USB_INTERFACE_DESCRIPTOR InterfaceDescr =
63 {
64 sizeof(USB_INTERFACE_DESCRIPTOR),
65 USB_INTERFACE_DESCRIPTOR_TYPE,
66 0,
C51 COMPILER V6.20c KCHAP9 10/31/2002 21:55:45 PAGE 15
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -