📄 sl811.lst
字号:
66 1 xferLen = usbstack.wPayload; // limit to wPayload size
67 1 else // else take < payload len
68 1 xferLen = usbstack.wLen; //
69 1
70 1 // For IN token
71 1 if (usbstack.pid==PID_IN) // for current IN tokens
72 1 { //
73 2 cmd = sDATA0_RD; // FS/FS on Hub, sync to sof
74 2 }
75 1 // For OUT token
76 1 else if(usbstack.pid==PID_OUT) // for OUT tokens
77 1 {
78 2 if(xferLen) // only when there are
79 2 {
80 3 //intr=usbstack.setup.wLength;
81 3 //usbstack.setup.wLength=WordSwap(usbstack.setup.wLength);
82 3 SL811BufWrite(data0,usbstack.buffer,xferLen); // data to transfer on USB
83 3 //usbstack.setup.wLength=intr;
84 3 }
85 2 cmd = sDATA0_WR; // FS/FS on Hub, sync to sof
86 2 // implement data toggle
87 2 bXXGFlags.bits.bData1 = uDev.bData1[usbstack.endpoint];
88 2 uDev.bData1[usbstack.endpoint] = (uDev.bData1[usbstack.endpoint] ? 0 : 1); // DataToggle
89 2
90 2 if(bXXGFlags.bits.bData1)
91 2 cmd |= 0x40; // Set Data1 bit in command
92 2 }
93 1 // For SETUP/OUT token
94 1 else // for current SETUP/OUT tokens
95 1 {
96 2 if(xferLen) // only when there are
97 2 {
98 3 intr=usbstack.setup.wLength;
99 3 usbstack.setup.wValue=WordSwap(usbstack.setup.wValue);
100 3 usbstack.setup.wIndex=WordSwap(usbstack.setup.wIndex);
101 3 usbstack.setup.wLength=WordSwap(usbstack.setup.wLength);
102 3 SL811BufWrite(data0,(unsigned char *)&usbstack.setup,xferLen); // data to transfer on USB
103 3 usbstack.setup.wLength=intr;
104 3 }
105 2 cmd = sDATA0_WR; // FS/FS on Hub, sync to sof
106 2 }
107 1 //------------------------------------------------
108 1 // For EP0's IN/OUT token data, start with DATA1
109 1 // Control Endpoint0's status stage.
110 1 // For data endpoint, IN/OUT data, start ????
111 1 //------------------------------------------------
112 1 if (usbstack.endpoint == 0 && usbstack.pid != PID_SETUP) // for Ep0's IN/OUT token
113 1 cmd |= 0x40; // always set DATA1
114 1 //------------------------------------------------
115 1 // Arming of USB data transfer for the first pkt
116 1 //------------------------------------------------
117 1 SL811Write(EP0Status,((usbstack.endpoint&0x0F)|usbstack.pid)); // PID + EP address
118 1 SL811Write(EP0Counter,usbstack.usbaddr); // USB address
119 1 SL811Write(EP0Address,data0); // buffer address, start with "data0"
120 1 SL811Write(EP0XferLen,xferLen); // data transfer length
121 1 SL811Write(IntStatus,INT_CLEAR); // clear interrupt status
122 1 SL811Write(EP0Control,cmd); // Enable ARM and USB transfer start here
123 1
124 1 //------------------------------------------------
125 1 // Main loop for completing a wLen data trasnfer
126 1 //------------------------------------------------
127 1 while(TRUE)
C51 COMPILER V7.20 SL811 12/13/2005 15:28:02 PAGE 5
128 1 {
129 2 //---------------Wait for done interrupt------------------
130 2 while(TRUE) // always ensure requested device is
131 2 { // inserted at all time, then you will
132 3 //intr=SL811Read(cSOFcnt);
133 3 //intr=SL811Read(IntEna);
134 3 intr = SL811Read(IntStatus);
135 3 // wait for interrupt to be done, and
136 3 if((intr & USB_RESET) || (intr & INSERT_REMOVE)) // proceed to parse result from slave
137 3 { // device.
138 4 bXXGFlags.bits.DATA_STOP = TRUE; // if device is removed, set DATA_STOP
139 4 return FALSE; // flag true, so that main loop will
140 4 } // know this condition and exit gracefully
141 3 if(intr & USB_A_DONE)
142 3 break; // interrupt done !!!
143 3 }
144 2
145 2 SL811Write(IntStatus,INT_CLEAR); // clear interrupt status
146 2 result = SL811Read(EP0Status); // read EP0status register
147 2 remainder = SL811Read(EP0Counter); // remainder value in last pkt xfer
148 2
149 2 //-------------------------ACK----------------------------
150 2 if (result & EP0_ACK) // Transmission ACK
151 2 {
152 3
153 3 // SETUP TOKEN
154 3 if(usbstack.pid == PID_SETUP) // do nothing for SETUP/OUT token
155 3 break; // exit while(1) immediately
156 3
157 3 // OUT TOKEN
158 3 else if(usbstack.pid == PID_OUT)
159 3 break;
160 3
161 3 // IN TOKEN
162 3 else if(usbstack.pid == PID_IN)
163 3 { // for IN token only
164 4 usbstack.wLen -= (WORD)xferLen; // update remainding wLen value
165 4 cmd ^= 0x40; // toggle DATA0/DATA1
166 4 dataX++; // point to next dataX
167 4
168 4 //------------------------------------------------
169 4 // If host requested for more data than the slave
170 4 // have, and if the slave's data len is a multiple
171 4 // of its endpoint payload size/last xferLen. Do
172 4 // not overwrite data in previous buffer.
173 4 //------------------------------------------------
174 4 if(remainder==xferLen) // empty data detected
175 4 bufLen = 0; // do not overwriten previous data
176 4 else // reset bufLen to zero
177 4 bufLen = xferLen; // update previous buffer length
178 4
179 4 //------------------------------------------------
180 4 // Arm for next data transfer when requested data
181 4 // length have not reach zero, i.e. wLen!=0, and
182 4 // last xferlen of data was completed, i.e.
183 4 // remainder is equal to zero, not a short pkt
184 4 //------------------------------------------------
185 4 if(!remainder && usbstack.wLen) // remainder==0 when last xferLen
186 4 { // was all completed or wLen!=0
187 5 addr = (dataX & 1) ? data1:data0; // select next address for data
188 5 xferLen = (BYTE)(usbstack.wLen>=usbstack.wPayload) ? usbstack.wPayload:usbstack.wLen; // get data len
-gth required
C51 COMPILER V7.20 SL811 12/13/2005 15:28:02 PAGE 6
189 5 //if (FULL_SPEED) // sync with SOF transfer
190 5 cmd |= 0x20; // always sync SOF when FS, regardless
191 5 SL811Write(EP0XferLen, xferLen); // select next xfer length
192 5 SL811Write(EP0Address, addr); // data buffer addr
193 5 SL811Write(IntStatus,INT_CLEAR); // is a LS is on Hub.
194 5 SL811Write(EP0Control,cmd); // Enable USB transfer and re-arm
195 5 }
196 4
197 4 //------------------------------------------------
198 4 // Copy last IN token data pkt from prev transfer
199 4 // Check if there was data available during the
200 4 // last data transfer
201 4 //------------------------------------------------
202 4 if(bufLen)
203 4 {
204 5 SL811BufRead(((dataX&1)?data0:data1), usbstack.buffer, bufLen);
205 5 usbstack.buffer += bufLen;
206 5 }
207 4
208 4 //------------------------------------------------
209 4 // Terminate on short packets, i.e. remainder!=0
210 4 // a short packet or empty data packet OR when
211 4 // requested data len have completed, i.e.wLen=0
212 4 // For a LOWSPEED device, the 1st device descp,
213 4 // wPayload is default to 64-byte, LS device will
214 4 // only send back a max of 8-byte device descp,
215 4 // and host detect this as a short packet, and
216 4 // terminate with OUT status stage
217 4 //------------------------------------------------
218 4 if(remainder || !usbstack.wLen)
219 4 break;
220 4 }// PID IN
221 3 }
222 2
223 2 //-------------------------NAK----------------------------
224 2 if (result & EP0_NAK) // NAK Detected
225 2 {
226 3 if(usbstack.endpoint==0) // on ep0 during enumeration of LS device
227 3 { // happen when slave is not fast enough,
228 4 SL811Write(IntStatus,INT_CLEAR); // clear interrupt status, need to
229 4 SL811Write(EP0Control,cmd); // re-arm and request for last cmd, IN token
230 4 result = 0; // respond to NAK status only
231 4 }
232 3 else // normal data endpoint, exit now !!! , non-zero ep
233 3 break; // main loop control the interval polling
234 3 }
235 2
236 2 //-----------------------TIMEOUT--------------------------
237 2 if (result & EP0_TIMEOUT) // TIMEOUT Detected
238 2 {
239 3 if(usbstack.endpoint==0) // happens when hub enumeration
240 3 {
241 4 if(++timeout >= TIMEOUT_RETRY)
242 4 {
243 5 timeout--;
244 5 break; // exit on the timeout detected
245 5 }
246 4 SL811Write(IntStatus,INT_CLEAR); // clear interrupt status, need to
247 4 SL811Write(EP0Control,cmd); // re-arm and request for last cmd again
248 4 }
249 3 else
250 3 { // all other data endpoint, data transfer
C51 COMPILER V7.20 SL811 12/13/2005 15:28:02 PAGE 7
251 4 bXXGFlags.bits.TIMEOUT_ERR = TRUE; // failed, set flag to terminate transfer
252 4 break; // happens when data transfer on a device
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -