?? host_811.lst
字號:
C51 COMPILER V6.10 HOST_811 09/04/2002 22:22:07 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE HOST_811
OBJECT MODULE PLACED IN .\host_811.OBJ
COMPILER INVOKED BY: f:\Keil\C51\BIN\C51.EXE .\host_811.c OPTIMIZE(6,SPEED) INCDIR(c:\cypress\usb\target\inc) DEBUG OBJE
-CTEXTEND
stmt level source
1 ////////////////////////////////////////////////////////////////////////////////
2 // Cypress Semiconductor - Customer Design Center
3 ////////////////////////////////////////////////////////////////////////////////
4 // File: host_811.c
5 // Purpose: 8051 firmware to master SL811 Embedded Host.
6 // Contains SL811-related control firmware.
7 // Based on SL811HST code written by cxn.
8 // H/W Target: SL811HST(Rev 1.5) + EZUSB DEV KIT
9 // IMPORTANT : Turn ON SW4 of S6-DIP-SWITCH
10 // to enable upper 32K memory on EZUSB Dev Kit
11 //
12 // $Header: /USB/ez811/firmware/Emb_Host/host_811.c 8 5/14/02 8:30p Tpm $
13 // Copyright (c) 2002 Cypress Semiconductor. May not be reproduced without permission.
14 // See the license agreement for more details.
15 ////////////////////////////////////////////////////////////////////////////////
16
17 #include "ezusb.h"
*** ERROR 318 IN LINE 17 OF .\host_811.c: can't open file 'ezusb.h'
18 #include "ezregs.h"
*** ERROR 318 IN LINE 18 OF .\host_811.c: can't open file 'ezregs.h'
19 #include "host_811.h"
*** ERROR 318 IN LINE 9 OF host_811.h: can't open file 'ezusb.h'
*** ERROR 318 IN LINE 10 OF host_811.h: can't open file 'ezregs.h'
*** ERROR C141 IN LINE 55 OF HOST_811.H: syntax error near 'WORD'
*** ERROR C129 IN LINE 55 OF HOST_811.H: missing ';' before 'wVID'
20
21 ////////////////////////////////////////////////////////////////////////////////
22 // Code and Xdata Memory Space
23 ////////////////////////////////////////////////////////////////////////////////
24 //
25 // ** Upper 32K external memory **
26 // (PROGRAM'S CODE/XDATA MEMORY ALLOCATION)
27 // Program xdata Space : 0x2000 ~ 0x23FF -> ALL XDATA (size:0x0400,1K)(ISO unused data mem)
28 // Program Code Space1 : 0x8000 ~ 0x9EFF -> ?FW, ?EZ811 (size:0x1F00,7K) (ext. code memory)
29 // Program Code Space2 : 0xA000 ~ 0xDFFF -> ?SL811H (size:0x4000,16K)(ext. code memory)
30 // (MONITOR'S CODE/XDATA MEMORY ALLOCATION) (SHOULD NEVER BE USED)
31 // Monitor xdata Space : 0x9F00 ~ 0x9FFF (size:0x0100,256)(ext. code memory)
32 // Monitor Code Space : 0xE000 ~ 0xFFFF (size:0x2000,8K) (ext. code memory)
33 //
34 // ** Lower 32K external memory **
35 // SL811H_ADDR address : 0x4000
36 // SL811H_DATA address : 0x4001
37 //
38 // ** Internal 8K EZUSB code/xdata memory **
39 // Both USBJmpTb.a51 and Dscr.a51 code are located to EZUSB internal 8K memory
40 //
41 // (See Project -> Options for Target 'Target 1' for detail settings)
42 //
43 //*****************************************************************************************
44 // SL811H Modules (major routines only):
45 //*****************************************************************************************
46 // 1) usbXfer() : handles usd data transfer, SETUP,IN, OUT
47 // 2) ep0Xfer() : handles endpoint zero control pipe
48 // 3) DataRW() : handles data endpoint transfer pipe
C51 COMPILER V6.10 HOST_811 09/04/2002 22:22:07 PAGE 2
49 // 4) EnumUsbDev() : device enum(HID/HUB), excl. multi-interface
50 // 5) HubPortEnum() : hub port device enum, incl. dynamic USB address
51 // 6) speed_detect(): SL811H slave device attach/speed detect
52 // 7) slave_detect(): Main loop control between SL811H & EZUSB & GUI
53 // 8) host_811.c : Entire code size
54
55 //*****************************************************************************************
56 // SL811HST+EZUSB Hardware Resources :
57 //*****************************************************************************************
58 // SL811HST <--> AN2131QC <--> FUNCTIONS (looking from SL811H side)
59 // A0 <--> A0 <--> (I) Address entry for SL811H, '0'-addr, '1'-data
60 // D0 ~ D7 <--> D0 ~ D7 <--> (B) 8-bit Data Bus
61 // nCS <--> A15 <--> (I) Enable lower 32K memory(where SL811H is mapped)
62 // nRD <--> nRD (PC7) <--> (I) Read (active low)
63 // nWR <--> nWR (PC6) <--> (I) Write (active low)
64 // nRST <--> PB0 <--> (I) SL811HST's reset (active low)
65 // MS_SEL <--> PB1 <--> (I) SL811HST's master/slave select, '0'-host
66 // INTR <--> INT4 (PB4) <--> (O) SL811HST's interrupt (active high) not used
67 // ACTIVE_LED <--> PB6 <--> Blink - waiting for enum, On - enumerated
68 //
69 // For Downstream Port LEDs on Hub (not present on Demo Board):
70 // DOWNSTREAM PORT1 LED 0x80 // PA bit 7
71 // DOWNSTREAM PORT2 LED 0x40 // PA bit 6
72 // DOWNSTREAM PORT3 LED 0x20 // PA bit 5
73 // DOWNSTREAM PORT4 LED 0x10 // PA bit 4
74 //
75 //*****************************************************************************************
76 // Monitor (Serial Port 1) Hardware Resources :
77 //*****************************************************************************************
78 // PB2 - (I) RxD1 (looking from EZUSB side)
79 // PB2 - (0) TxD1
80 // PC6 - (O) nWR
81 // PC7 - (O) nRD
82
83 //*****************************************************************************************
84 // xdata variables
85 //*****************************************************************************************
86 xdata BYTE SL811H_ADDR _at_ 0x4000; // A0 = '0' to external memory
87 xdata BYTE SL811H_DATA _at_ 0x4001; // A0 = '1' (EZ-USB Dev Kit - SW4 ON)
88
89 xdata BYTE DBUF[256]; // at 0x2000 for general descriptors data
90 xdata BYTE STATUS[8]; // for status data buffer
91 xdata BYTE REGBUFF[16]; // Buffer for Register Data
92 xdata BYTE HOSTCMD[8]; // EZUSB's OUT1 host command data
93 xdata BYTE pHOSTCMD[8]; // previous data transfer info, during data transfer
94 xdata BYTE HubChange[1]; // Hub port endpoint 1 data status
95 xdata BYTE DataBufLen; // EZUSB's IN #3 data transfer buffer length
96 xdata BYTE pNumPort; // Number of downstream ports on hub
97 xdata BYTE remainder; // Remaining byte in a USB transfer
98 xdata pUSBDEV uDev[MAX_DEV]; // Multiple USB devices attributes, Max 5 devices
99 xdata pHUBDEV uHub; // Struct for downstream device on HUB
100 xdata pDevDesc pDev; // Device descriptor struct
101 xdata pCfgDesc pCfg; // Configuration descriptor struct
102 xdata pIntfDesc pIfc; // Interface descriptor struct
103 xdata pEPDesc pEnp; // Endpoint descriptor struct
104 xdata pStrDesc pStr; // String descriptor struct
105 xdata pHidDesc pHid; // HID class descriptor struct
106 xdata pHubDesc pHub; // HUD class descriptor struct
107 xdata pPortStatus pStat; // HID ports status
108
109 //*****************************************************************************************
110 // Boolean Logic Defines
C51 COMPILER V6.10 HOST_811 09/04/2002 22:22:07 PAGE 3
111 //*****************************************************************************************
112 BOOL SLAVE_FOUND; // Slave USB device found
113 BOOL SLAVE_ENUMERATED; // slave USB device enumeration done
114 BOOL FULL_SPEED; // Full-Speed = TRUE, Low-Speed = FALSE
115 BOOL HUB_DEVICE; // HUB device = TRUE
116 BOOL BULK_OUT_DONE; // Set when EZUSB's OUT1 hostcmd xfer is done
117 BOOL DESC_XFER; // Set when there is data for EZUSB's IN1 desc xfer
118 BOOL DATA_XFER; // Set when there is data for EZUSB's IN3 data xfer
119 BOOL DATA_XFER_OUT; // Set when there is data for EZUSB's OUT3 data xfer
120 BOOL CONFIG_DONE; // Set when EZUSB completes its enumeration process.
121 BOOL TIMEOUT_ERR; // timeout error during data endpoint transfer
122 BOOL DATA_STOP; // device unplugged during data transfer
123 BOOL DATA_INPROCESS; // set when we are in a data pipe transfer
124 BOOL pLS_HUB; // indicate previous command is a LS device on hub
125
126 BOOL dsPoll; // poll downstream port conections
127
128 BOOL bData1;
129
130 //*****************************************************************************************
131 // Byte Read from SL811H
132 // a = register address
133 // return = data in register
134 //*****************************************************************************************
135 BYTE SL811Read(BYTE a)
136 {
137 SL811H_ADDR = a;
138 return (SL811H_DATA);
139 }
140
141 //*****************************************************************************************
142 // Byte Write to SL811H
143 // a = register address
144 // d = data to be written to this register address
145 //*****************************************************************************************
146 void SL811Write(BYTE a, BYTE d)
147 {
148 SL811H_ADDR = a;
149 SL811H_DATA = d;
150 }
151
152 //*****************************************************************************************
153 // Buffer Read from SL811H
154 // addr = buffer start address
155 // s = return buffer address where data are to be save/read
156 // c = buffer data length
157 //*****************************************************************************************
158 void SL811BufRead(BYTE addr, BYTE *s, BYTE c)
159 {
160 SL811H_ADDR = addr;
161 while (c--)
162 *s++ = SL811H_DATA;
163 }
164
165 //*****************************************************************************************
166 // Buffer Write to SL811H
167 // addr = buffer start address
168 // s = buffer address where data are to be written
169 // c = buffer data length
170 //*****************************************************************************************
171 void SL811BufWrite(BYTE addr, BYTE *s, BYTE c)
172 {
C51 COMPILER V6.10 HOST_811 09/04/2002 22:22:07 PAGE 4
173 SL811H_ADDR = addr;
174 while (c--)
175 SL811H_DATA = *s++;
176 }
177
178 //*****************************************************************************************
179 // Swap high and low byte
180 //*****************************************************************************************
181 WORD WordSwap(WORD input)
182 {
183 return(((input&0x00FF)<<8)|((input&0xFF00)>>8));
184 }
185
186 //*****************************************************************************************
187 // UsbReset during enumeration of device attached directly to SL811HS
188 //*****************************************************************************************
189 void USBReset()
190 {
191 BYTE tmp;
192 tmp = SL811Read(CtrlReg);
193 SL811Write(CtrlReg,tmp|0x08);
194 EZUSB_Delay(25);
195 SL811Write(CtrlReg,tmp);
196 }
197
198 //*****************************************************************************************
199 // usbXfer:
200 // successful transfer = return TRUE
201 // fail transfer = return FALSE
202 //*****************************************************************************************
203 int usbXfer(BYTE usbaddr, BYTE endpoint, BYTE pid, BYTE iso, WORD wPayload, WORD wLen, BYTE *buffer)
204 {
205 xdata BYTE cmd, result, timeout, intr;
206 xdata BYTE xferLen, bufLen, data0, data1, dataX, addr;
207
208 //------------------------------------------------
209 // Default setting for usb trasnfer
210 //------------------------------------------------
211 bufLen = dataX = timeout = 0; //reset all
212 data0 = EP0_Buf; // DATA0 buffer address
213 data1 = data0 + (BYTE)wPayload; // DATA1 buffer address
214 DATA_STOP = TIMEOUT_ERR = FALSE; // set default conditions
215
216 //------------------------------------------------
217 // Define data transfer payload
218 //------------------------------------------------
219 if (wLen >= wPayload) // select proper data payload
220 xferLen = wPayload; // limit to wPayload size
221 else // else take < payload len
222 xferLen = wLen; //
223
224 //------------------------------------------------
225 // For IN token
226 //------------------------------------------------
227 if (pid==PID_IN) // for current IN tokens
228 { //
229 if(FULL_SPEED) //
230 cmd = sDATA0_RD; // FS/FS on Hub, sync to sof
231 else // LS, no sync to sof for IN
232 cmd = DATA0_RD; //
233 //-------------------------------------------- response to OUT can propagate to SL811HS
234 // handling LS device on HUB
C51 COMPILER V6.10 HOST_811 09/04/2002 22:22:07 PAGE 5
235 //--------------------------------------------
236 if(HUB_DEVICE && usbaddr!=HUB_ADDR) // Transfer on Hub, USB addr #0, #2..#5 only
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -