📄 host2131.lst
字号:
C51 COMPILER V7.06 HOST2131 07/13/2004 18:08:14 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE HOST2131
OBJECT MODULE PLACED IN host2131.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE host2131.c OPTIMIZE(6,SPEED) INCDIR(c:\cypress\usb\target\inc) DEBUG OBJECT
-EXTEND
stmt level source
1 #pragma NOIV // Do not generate interrupt vectors
2 ////////////////////////////////////////////////////////////////////////////////
3 // File: host2131.c
4 // Purpose: 8051 firmware to master SL811 Embedded Host.
5 // Derived from periph.c frameworks file.
6 // Contains USB peripheral-related firmware.
7 // Contains PC host command interface.
8 // Based on SL811HST code written by cxn.
9 //
10 // $Header: /USB/ez811/firmware/Emb_Host/host2131.c 8 5/17/02 6:09p Tpm $
11 // Copyright (c) 2002 Cypress Semiconductor. May not be reproduced without permission.
12 // See the license agreement for more details.
13 ////////////////////////////////////////////////////////////////////////////////
14
15 #include "ezusb.h"
16 #include "ezregs.h"
17 #include "host_811.h"
18
19 extern BOOL GotSUD; // Received setup data flag
20 extern BOOL Sleep;
21 extern BOOL Rwuen;
22 extern BOOL Selfpwr;
23
24 extern BOOL SLAVE_ENUMERATED;
25 extern BOOL BULK_OUT_DONE;
26 extern BOOL DESC_XFER;
27 extern BOOL DATA_XFER;
28 extern xdata BYTE DataBufLen;
29 extern xdata BYTE DBUF[];
30 extern xdata BYTE HOSTCMD[];
31 extern xdata BYTE REGBUFF[];
32 extern xdata BYTE remainder;
33 extern void sl811h_init(void);
34 extern int slave_detect(void);
35 extern BOOL CONFIG_DONE;
36
37 extern BOOL DATA_XFER_OUT;
38 extern xdata BYTE DBUFOut[];
39 extern BOOL dsPoll;
40 extern BOOL bDataToggle;
41
42 extern xdata pDevDesc pDev; // Device descriptor struct
43 extern xdata pCfgDesc pCfg; // Config descriptor struct
44 extern xdata pStrDesc pStr; // String descriptor struct
45 extern xdata pHidDesc pHid; // HID class descriptor struct
46 extern xdata pHubDesc pHub; // HUD class descriptor struct
47 extern xdata pIntfDesc pIfc; // Interface descriptor struct
48 extern xdata pHUBDEV uHub; // Struct for downstream device on HUB
49 extern xdata pUSBDEV uDev[]; // Multiple USB devices attributes, Max 5 devices
50
51 void dsOut(void);
52 int DataRW(BYTE usbaddr, BYTE epaddr, WORD wPayload, WORD wLen, BYTE *pData);
53 WORD GetDevInfo(BYTE *DevInfo);
54
C51 COMPILER V7.06 HOST2131 07/13/2004 18:08:14 PAGE 2
55 int desc_next;
56 int data_next;
57 void TD_Poll(void);
58
59 BYTE Configuration; // Current configuration
60 BYTE AlternateSetting; // Alternate settings
61
62 //-----------------------------------------------------------------------------
63 // Task Dispatcher hooks
64 // The following hooks are called by the task dispatcher.
65 //-----------------------------------------------------------------------------
66 // IN2 => 1 bytes max, Refresh data update from ezusb to host
67 //-----------------------------------------------------------------------------
68 void TD_Init(void) // Called once at startup
69 {
70 1 Rwuen = TRUE; // Enable remote-wakeup
71 1 ISOCTL |= 0x01; // free up iso endpoints for external data space (1024)
72 1
73 1 IN07VAL |= bmEP1; // Enable endpoint 1 IN
74 1 IN07VAL |= bmEP2; // Enable endpoint 2 IN
75 1 IN07VAL |= bmEP3; // Enable endpoint 3 IN
76 1 OUT07VAL |= bmEP1; // Enable endpoint 1 OUT
77 1 OUT07IEN |= bmEP1; // Enable endpoint 1 OUT interrupt
78 1 OUT1BC = 0; // Arm Endpoint 1 OUT to recieve data
79 1 OUT07VAL |= bmEP3; // Enable endpoint 3 OUT
80 1 OUT07IEN |= bmEP3; // Enable endpoint 3 OUT interrupt
81 1 OUT3BC = 0; // Arm Endpoint 3 OUT to recieve data
82 1
83 1 BPADDR = (WORD)TD_Poll; // Setup breakpoint to trigger on TD_Poll()
84 1 USBBAV |= bmBPEN; // Enable the breakpoint
85 1 USBBAV &= ~bmBPPULSE;
86 1
87 1 sl811h_init(); // setup SL811H chip variables
88 1 desc_next = 0;
89 1 data_next = 0;
90 1
91 1 }
92
93 //*****************************************************************************************
94 // ENDPOINT FUNCTION :
95 // EP2-IN -> Return a byte of 0x01 to ezusb host to indicate a attach/detach for refresh
96 //*****************************************************************************************
97 void TD_Poll(void)
98 {
99 1 int i,count;
100 1 BYTE DescBufLen; // EZUSB's IN #1 descriptor buffer length
101 1
102 1 slave_detect(); // Poll for any slave USB device attached to "SL811HS" Embedded Host
103 1
104 1 if(BULK_OUT_DONE && !DESC_XFER)
105 1 {
106 2 BULK_OUT_DONE = FALSE;
107 2 switch(HOSTCMD[0]) // type of commands from EZUSB host
108 2 {
109 3 case SL_REFRESH:
110 3 DescBufLen = GetDevInfo(DBUF);
111 3 if(!DescBufLen)
112 3 { // there is nothing to transfer - keep the host app from pending
113 4 DBUF[0] = 0;
114 4 DescBufLen = 1; // arming the IN1 is done in the slave_detect loop
-
115 4 }
C51 COMPILER V7.06 HOST2131 07/13/2004 18:08:14 PAGE 3
116 3 DESC_XFER = TRUE; // set DESC_XFER to start transfer
117 3 break;
118 3
119 3 default: break; // default break;
120 3 }
121 2 }
122 1
123 1 if(DESC_XFER && !(IN1CS & bmEPBUSY))
124 1 { // ensure DESC_XFER & IN1 not busy
125 2 if(DescBufLen) // check for any data length
126 2 { //
127 3 count = (int)((DescBufLen>=64) ? 64:DescBufLen); // select data length, max allowed is 64 bytes
128 3 for(i=0; i<count; i++) // copy data into IN buffer
129 3 IN1BUF[i] = DBUF[i+desc_next]; //
130 3 IN1BC = count; // arm IN data transfer
131 3 DescBufLen -= count; // update remaining data len
132 3 desc_next += count;
133 3 if(!DescBufLen)
134 3 {
135 4 desc_next = 0;
136 4 DESC_XFER = FALSE; // reset DESC_XFER to stop transfer
137 4 }
138 3 }
139 2 }
140 1 }
141
142 //---------------------------------------
143 BOOL TD_Suspend(void) // Called before the device goes into suspend mode
144 {
145 1 return(TRUE);
146 1 }
147
148 BOOL TD_Resume(void) // Called after the device resumes
149 {
150 1 return(TRUE);
151 1 }
152
153 //-----------------------------------------------------------------------------
154 // Device Request hooks
155 // The following hooks are called by the end point 0 device request parser.
156 //-----------------------------------------------------------------------------
157
158 BOOL DR_GetDescriptor(void)
159 {
160 1 return(TRUE);
161 1 }
162
163 BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
164 {
165 1 Configuration = SETUPDAT[2];
166 1 CONFIG_DONE = TRUE;
167 1 return(TRUE); // Handled by user code
168 1 }
169
170 BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
171 {
172 1 IN0BUF[0] = Configuration;
173 1 EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
174 1 return(TRUE); // Handled by user code
175 1 }
176
177 BOOL DR_SetInterface(void) // Called when a Set Interface command is received
C51 COMPILER V7.06 HOST2131 07/13/2004 18:08:14 PAGE 4
178 {
179 1 AlternateSetting = SETUPDAT[2];
180 1 return(TRUE); // Handled by user code
181 1 }
182
183 BOOL DR_GetInterface(void) // Called when a Set Interface command is received
184 {
185 1 IN0BUF[0] = AlternateSetting;
186 1 EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
187 1 return(TRUE); // Handled by user code
188 1 }
189
190 BOOL DR_GetStatus(void)
191 {
192 1 return(TRUE);
193 1 }
194
195 BOOL DR_ClearFeature(void)
196 {
197 1 return(TRUE);
198 1 }
199
200 BOOL DR_SetFeature(void)
201 {
202 1 return(TRUE);
203 1 }
204
205 #define EP0BUFF_SIZE 0x40
206
207 BOOL DR_VendorCmnd(void)
208 {
209 1 WORD addr, len, bc;
210 1 BYTE EpAddr, EpIdx;
211 1 WORD i;
212 1 BYTE RegAddr;
213 1 xdata BYTE OUT_DATA[EP0BUFF_SIZE]; // OUT data buffer
214 1 int retDataRW = FALSE;
215 1 BYTE DescBufLen = 0;
216 1 WORD ReqLen = 0;
217 1
218 1 switch(SETUPDAT[1])
219 1 { // NOTE" 0xA0 is reserved: 0xA0 = Anchor Download (handled by core)
220 2 case SL_RESET:
221 2 {
222 3 sl811h_init(); // initialize SL811HST
223 3 *IN0BUF = SETUPDAT[1]; // return command type
224 3 IN0BC = 0x01; // arm endp, # bytes to xfr
225 3 EP0CS |= bmBIT1; // ack handshake phase of device request
226 3 break;
227 3 }
228 2 case SL_DEVICE_DESCP: // GetDevDesc
229 2 case SL_CONFIG_DESCP: // GetConfDesc
230 2 case SL_CLASS_DESCP: // GetClassDesc
231 2 case SL_STRING_DESCP: // GetStringDesc
232 2 {
233 3 EpAddr = SETUPDAT[2]; // Get address
234 3 ReqLen = SETUPDAT[6];
235 3 ReqLen |= SETUPDAT[7] << 8; // Get requested length
236 3
237 3 if(SETUPDAT[1] == SL_DEVICE_DESCP)
238 3 {
239 4 pDev =(pDevDesc)DBUF;
C51 COMPILER V7.06 HOST2131 07/13/2004 18:08:14 PAGE 5
240 4 if(GetDesc(EpAddr,DEVICE,0,18,DBUF)) // Device Descp - 18 bytes
241 4 DescBufLen = (WORD)pDev->bLength; // update buffer length
242 4 }
243 3 if(SETUPDAT[1] == SL_CONFIG_DESCP)
244 3 {
245 4 pCfg =(pCfgDesc)DBUF;
246 4 if (GetDesc(EpAddr,CONFIGURATION,0,255,DBUF))
247 4 DescBufLen = WordSwap(pCfg->wLength);
248 4 }
249 3 if(SETUPDAT[1] == SL_CLASS_DESCP)
250 3 {
251 4 if (GetDesc(EpAddr,CONFIGURATION,0,255,DBUF)) // Configuration Descp
252 4 {
253 5 pIfc = (pIntfDesc)(DBUF + 9); // point to Interface Descp
254 5 if(pIfc->iClass==HIDCLASS) // HID_CLASS
255 5 {
256 6 pHid = (pHidDesc)(DBUF + 9 + 9); // get HID's report descriptor
257 6 DescBufLen = (pHid->wItemLength <= 255) ? pHid->wItemLength : 255;
258 6 if(!GetHid_Desc(EpAddr,HID_REPORT,DescBufLen,DBUF))
259 6 DescBufLen = 0;
260 6 }
261 5 else if(pIfc->iClass==HUBCLASS) // HUB_CLASS
262 5 {
263 6 pHub =(pHubDesc)DBUF; // get HUB class descriptor
264 6 DescBufLen = (pHub->bLength <= 255) ? pHub->bLength : 255;
265 6 if(!GetHubDesc(EpAddr,0,9,DBUF))
266 6 DescBufLen = 0;
267 6 }
268 5 else
269 5 DescBufLen = 0; // Undefined Class
270 5 }
271 4 }
272 3 if(SETUPDAT[1] == SL_STRING_DESCP)
273 3 {
274 4 pStr = (pStrDesc)DBUF;
275 4 pStr->bLength = 0;
276 4 if(GetDesc(EpAddr,(WORD)(0x02<<8)|STRING,0x0904,4,DBUF))
277 4 { // get iManufacturer
278 5 DescBufLen = pStr->bLength; // set string length
279 5 if(!GetDesc(EpAddr,(WORD)(0x02<<8)|STRING,0x0904,pStr->bLength,DBUF))
280 5 DescBufLen = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -