📄 main.lst
字号:
204 1 #ifdef _Debug_
205 1 j = FIRMWARE_VERSION;
206 1 printf("Interface Studio PDIUSBD12 USB1.1 Develop Board FirmWare V%x.\n,",j);
207 1 #endif
208 1
209 1 if (sSysInformation.bRamError == FALSE)
210 1 {
211 2 #ifdef _Debug_
212 2 printf("On Chip XRAM tested,and no error.\n");
213 2 #endif
214 2 }
215 1 else
216 1 {
217 2 #ifdef _Debug_
218 2 printf("On Chip XRAM error.\n");
219 2 #endif
220 2 while(1); //if on chip XRAM error,data transfer of bulk transfer will
221 2 //be error,so here is a dead cycle;
222 2 }
223 1
224 1 D12_SUSPEND = 0; //pull down D12_SUSPEND pin for access it
225 1 D12SetAddressEnable(USB_DEFAULT_DEVICE_ADDRESS,TRUE); //after reset D12,use default address,namely endpo
-int0,address 0
226 1
227 1 D12SetMode(0x00, 0x4B);
228 1 D12SetDMA(0xC0);
229 1 #ifdef _Debug_
230 1 printf("Connecting to USB...");
231 1 #else
//we found that if here has no delay,PDIUSBD12 can not setup USB connection correctly!!
for (j=0;j<1000;j++) _nop_ ();
#endif
235 1
236 1 D12SetMode(0x10,0x4B); //enable soft connect
237 1 #ifdef _Debug_
238 1 printf("Connection finished!\n");
239 1 #endif
240 1
C51 COMPILER V7.01 MAIN 02/17/2006 15:09:23 PAGE 5
241 1 for (j=0;j<10000;j++) _nop_ ();
242 1
243 1
244 1 mEp1InBuffer[0] = SWITCH_ADDRESS;
245 1
246 1 EA = 1; //MCU global interrupt is enabled
247 1
248 1 //Main program loop
249 1 while(1)
250 1 {
251 2
252 2 #ifndef _INT_MODE_
if (U_INT!=1)
{
UsbIsr(); //USB interrupt service routine
}
#endif
258 2
259 2 if (sSysInformation.bTimer0)
260 2 {
261 3 //if Host driver has successfully configed our device
262 3 if (sSysInformation.bD12ConfigurationValue != 0x00)
263 3 {
264 4 i = SWITCH_ADDRESS;
265 4 if (mEp1InBuffer[0] != i)
266 4 {
267 5 //Here we will write switch status to endpoint1-in buffer if switch status changed.
268 5 //When interrupt IN token is received,this switch status will be transmit to Host
269 5 //automatically by PDIUSBD12.Host software should transmit IN token periodly according
270 5 //to the interval describled by endpoint descriptor.If no switch status change,
271 5 //endpoint1-in buffer has no valid data and when Host transmit IN token,PDIUSBD12
272 5 //will return NAK automatically.
273 5 mEp1InBuffer[0] = i;
274 5 D12WriteBuffer(D12_SELECT_ENDPOINT_ENDPOINT1_IN,0x01,&mEp1InBuffer[0]);
275 5
276 5 }
277 4 //refresh led status,always be executed periodly
278 4
279 4 LED_ADDRESS = mEp1OutBuffer[0];
280 4 sSysInformation.bTimer0 = FALSE;
281 4 }
282 3 }
283 2
284 2
285 2 if (sSysInformation.bSuspendChange)
286 2 {
287 3 //According to USB specification,when Host request device enter suspend state,
288 3 //device should draw no more than 500uA current.This requirement is very strict.
289 3 //Interface studio USB1.1 develop board is self powered,so we can ignore this
290 3 //requirement.We just set bInSuspend flag,but run our firmware as usual.
291 3
292 3 #ifdef _Debug_
293 3 printf("Suspend change.\n");
294 3 #endif
295 3
296 3 D12_SUSPEND = 1; //release SUSPEND pin,if D12 enter SUSPEND state,
297 3 //this pin will be drive high by D12;
298 3 //else if D12 exit SUSPEND,this pin will be drive low by D12
299 3 for (i=0;i<10;i++); //delay for suspend pin is stable driven by PDIUSBD12
300 3 if(D12_SUSPEND == 1)
301 3 {
302 4 D12_SUSPEND = 0; //pull low to access D12
C51 COMPILER V7.01 MAIN 02/17/2006 15:09:23 PAGE 6
303 4 LED_ADDRESS = 0xFF; //close all led for save power
304 4 sSysInformation.bSuspendChange = FALSE; //clear suspend flag
305 4 sSysInformation.bInSuspend = TRUE; //set suspend flag,used for MCU is exit powrdown mode
306 4 D12_SUSPEND = 1;
307 4 #ifdef _Debug_
308 4 printf("Enter suspend.\n");
309 4 #endif
310 4
311 4 }
312 3 else
313 3 {
314 4 sSysInformation.bInSuspend = FALSE; //set suspend flag,used for MCU is exit powrdown mode
315 4 sSysInformation.bSuspendChange = FALSE; //clear suspend flag
316 4 #ifdef _Debug_
317 4 printf("Exit suspend.\n");
318 4 #endif
319 4 }
320 3
321 3 }
322 2
323 2 if (sSysInformation.bBusReset)
324 2 {
325 3 UsbBusReset();
326 3 #ifdef _Debug_
327 3 printf("Bus reset.\n");
328 3 #endif
329 3 }
330 2
331 2 //if received a setup packet
332 2 if (sSysInformation.bSetup)
333 2 {
334 3 EA = 0;
335 3 #ifdef _Debug_
336 3 printf("--------------------------------------------\n");
337 3 printf("SetUp: bRequest code is :");
338 3 printf("%x,%x,%x,%x,%x,\n", (unsigned int)(sSysInformation.sUsbDeviceRequest.bmRequestType),
339 3 (unsigned int)(sSysInformation.sUsbDeviceRequest.bRequest),
340 3 (sSysInformation.sUsbDeviceRequest.wValue),
341 3 (sSysInformation.sUsbDeviceRequest.wIndex),
342 3 (sSysInformation.sUsbDeviceRequest.wLength));
343 3 #endif
344 3 UsbSetUpDeal();
345 3 sSysInformation.bSetup = FALSE;
346 3 EA = 1;
347 3 }
348 2 //if there is a uncompleted control-out transfer
349 2 if (sSysInformation.sUsbSetUpDealwith.bControOutCommandIsPending)
350 2 {
351 3 ControlOutDealWith();
352 3 }
353 2
354 2 } // Main Loop end
355 1
356 1 }
357
358
359 void UsbBusReset(void)
360 {
361 1 //When first connect to Host, Host will always issue a bus reset command.
362 1 //And if USB communication has error,host may issue bus reset command also.
363 1
364 1 //When no USB cable connect between Host and PDIUSBD12,D+ and D- wire will be
C51 COMPILER V7.01 MAIN 02/17/2006 15:09:23 PAGE 7
365 1 //high impedance,and no USB event should be produced by PDIUSBD12;but unfortunately,
366 1 //unsure state of D+/D- will make PDIUSBD12 produce error USB bus event to MCU.
367 1 //To avoid this case,we can attach a 1Mohm pullup resistor to D-,and a 1Mohm
368 1 //pulldown resistor to D+,thus when there has no USB connection,PDIUSBD12 will
369 1 //report a bus reset state to MCU.but this has no trouble to our application.
370 1
371 1
372 1 //If Host transmit bus reset signal
373 1 sSysInformation.bBusReset = FALSE;
374 1 sSysInformation.bRemoteWakeUpEnable = FALSE;
375 1 sSysInformation.bD12ConfigurationValue = 0x00;
376 1 sSysInformation.bSetup = FALSE;
377 1 sSysInformation.bUsbStatus = IDLE;
378 1
379 1 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
380 1 sSysInformation.sUsbSetUpDealwith.bControlOutDataComplete = TRUE;
381 1 sSysInformation.sUsbSetUpDealwith.bControOutCommandIsPending = FALSE;
382 1
383 1 sSysInformation.sRamControl.bRamCommand = RAM_COMMAND_LOOPBACK;
384 1 sSysInformation.sRamControl.bRamRwStatus = IDLE;
385 1 sSysInformation.sRamControl.iRamStartAddress = &mRamBuffer;
386 1 sSysInformation.sRamControl.iRamRwLength = 0;
387 1 sSysInformation.sRamControl.iRamRemaindLength = 0;
388 1
389 1 D12SetAddressEnable(USB_DEFAULT_DEVICE_ADDRESS,TRUE); //after reset D12,use default address,namely endpoi
-nt0,address 0
390 1 D12SetEndpointEnable(0x00); //disable generic/isochronous endpoint
391 1
392 1
393 1 }
394
395 //
396 //*************************************************************************
397
398
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 794 ----
CONSTANT SIZE = 312 ----
XDATA SIZE = 644 ----
PDATA SIZE = ---- ----
DATA SIZE = 43 5
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -