📄 protocol.lst
字号:
375 2 //SetConfiguration has no data phase,return zero length data packet to host
376 2
377 2 //if the value of SetConfiguration request is 0,device should enter address state
378 2 //and all endpoint should be disabled except for endpoint0
379 2 D12SetEndpointEnable(0);
380 2 sSysInformation.bD12ConfigurationValue = 0x00;
381 2 ControlOutComplete();
382 2 }
383 1 else if (sSysInformation.sUsbDeviceRequest.wValue == 1)
384 1 {
385 2 //SetConfiguration has no data phase,return zero length data packet to host
386 2 D12SetEndpointEnable(1);
387 2 sSysInformation.bD12ConfigurationValue = 0x01;
388 2 ControlOutComplete();
389 2 }
390 1 //Interface studio PDIUSBD12 USB1.1 Develop Board only support one configuration: 1.
391 1 else //illegal request
392 1 {
393 2 CONTROL_ENDPOINT_STALL //set control endpoint stall
394 2 }
395 1 }
396 //
397 //*************************************************************************
398 // Parameter:
399 // In : None
400 // Out: None
401 // Function:
402 // See USB specification 9.4.4
403 void GetInterface(void)
404 {
405 1 unsigned char data bAlternateSetting = 0;
406 1
407 1 if (sSysInformation.sUsbDeviceRequest.wIndex == 0)
408 1 {
409 2 //Our device only support one interface,so AlternateSetting only has one value:0
410 2 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN,0x01,&bAlternateSetting);
411 2 }
412 1 else
413 1 {
414 2 CONTROL_ENDPOINT_STALL //set control endpoint stall
415 2 }
416 1
417 1 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
418 1 }
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 8
419 //
420 //*************************************************************************
421 // Parameter:
422 // In : None
423 // Out: None
424 // Function:
425 // See USB specification 9.4.10
426 void SetInterface(void)
427 {
428 1 //PDIUSBD12 Develop Board only support one interface,so
429 1 //SetInterface request will be returned STALL
430 1 CONTROL_ENDPOINT_STALL //set control endpoint stall
431 1 }
432 //
433 //*************************************************************************
434 // Parameter:
435 // In : None
436 // Out: None
437 // Function:
438 // Althouth this firmware support SetDescriptor command, but receiced
439 // descriptor has no any interpretion by this firmware.It should be
440 // interpreted by user.Descriptor is save at mEp0OutBuffer, and next
441 // control-out will overlapp those data.
442 void SetDescriptor(void)
443 {
444 1 //Note: Actually, receive descriptor is implemented in Ep0Out() routine
445 1 //and ControlOutDealWith() routine.
446 1 ControlOutComplete();
447 1 }
448 //
449 //*************************************************************************
450 // Parameter:
451 // In : None
452 // Out: None
453 // Function:
454 // Although this firmware does not support isochronous transfer,
455 // synchronization frame request still is implementated.
456 void ReadSynFrameNumber(void)
457 {
458 1 D12ReadCurrentFrameNumber(&mEp0InBuffer);
459 1 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN, 0x02, &mEp0InBuffer);
460 1
461 1 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
462 1 }
463 ////////////////////////////////////////////////////////////////////////////
464 ////////////////////////////Vendor defined request//////////////////////////
465 //
466 //*************************************************************************
467 // Parameter:
468 // In : None
469 // Out: None
470 // Function:
471 void RamControl(void)
472 {
473 1 unsigned char xdata * data pRamBuffer ;
474 1 unsigned char data bDataLength;
475 1
476 1 sSysInformation.sRamControl.bRamCommand = sSysInformation.sUsbDeviceRequest.bRequest;
477 1
478 1 if (sSysInformation.sRamControl.bRamCommand != RAM_COMMAND_LOOPBACK)
479 1 {
480 2 sSysInformation.sRamControl.iRamStartAddress = sSysInformation.sUsbDeviceRequest.wIndex;
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 9
481 2 sSysInformation.sRamControl.iRamRwLength = sSysInformation.sUsbDeviceRequest.wValue;
482 2 sSysInformation.sRamControl.iRamRemaindLength = sSysInformation.sRamControl.iRamRwLength;
483 2 //if ram read
484 2 if (sSysInformation.sRamControl.iRamRemaindLength > RAM_BUFFER_SIZE)
485 2 {
486 3 //This firmware use P89C51RD2 internal RAM as ram buffer,it size is 512 bytes
487 3 //if data length of Host request is over 512 byte,stall this request
488 3 CONTROL_ENDPOINT_STALL //set control endpoint stall
489 3 }
490 2 else
491 2 {
492 3 if (sSysInformation.sRamControl.bRamCommand == RAM_COMMAND_READ)
493 3 {
494 4 pRamBuffer = &mRamBuffer + sSysInformation.sRamControl.iRamStartAddress;
495 4
496 4 //if iRamRemaindLength is longer than D12_EP2_MAX_PACKET_SIZE,the ram read
497 4 //must split several IN transaction
498 4 if (sSysInformation.sRamControl.iRamRemaindLength > D12_EP2_MAX_PACKET_SIZE)
499 4 {
500 5 sSysInformation.sRamControl.bRamRwStatus = TRANSMIT;
501 5 bDataLength = D12_EP2_MAX_PACKET_SIZE;
502 5 }
503 4 //if iRamRemaindLength is less than D12_EP2_MAX_PACKET_SIZE,only one IN transaction
504 4 //will complete ram read request
505 4 else
506 4 {
507 5 sSysInformation.sRamControl.bRamRwStatus = IDLE;
508 5 bDataLength = (unsigned char)(sSysInformation.sRamControl.iRamRemaindLength);
509 5 }
510 4 //if (bDataLength >0)
511 4 //{
512 4 D12WriteBuffer(D12_SELECT_ENDPOINT_ENDPOINT2_IN,bDataLength,pRamBuffer);
513 4 sSysInformation.sRamControl.iRamRemaindLength -= bDataLength;
514 4 //}
515 4 }
516 3 //if ram write
517 3 else
518 3 {
519 4 sSysInformation.sRamControl.bRamRwStatus = RECEIVE;
520 4 }
521 3 }
522 2 }
523 1
524 1 ControlOutComplete();
525 1 }
526 //
527 //*************************************************************************
528 // Parameter:
529 // In : None
530 // Out: None
531 // Function:
532 // Host software issue a GetFirmWareVersion request by vendor defined
533 // request.This function will return version number.
534 void GetFirmWareVersion(void)
535 {
536 1 //firmware version is one byte
537 1 unsigned char data bFirmWareVersion;
538 1 bFirmWareVersion = FIRMWARE_VERSION;
539 1
540 1 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN,0x01,&bFirmWareVersion);
541 1 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
542 1
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 10
543 1 }
544 //
545 //*************************************************************************
546 // Parameter:
547 // In : None
548 // Out: None
549 // Function:
550 // SetDeviceSerialNumber() is a vendor defined request to demonstrate
551 // how to implement control-out transfer with data stage.
552 void SetDeviceSerialNumber(void)
553 {
554 1 //Note: Actually, receive serial number is implemented in Ep0Out() routine
555 1 //and ControlOutDealWith() routine.
556 1 unsigned char data i;
557 1 //device serial number is 4 byte
558 1 for (i=0;i<4;i++)
559 1 {
560 2 //save serial number
561 2 mSerialNumber[i] = mEp0OutBuffer[i];
562 2 }
563 1
564 1 ControlOutComplete();
565 1 }
566
567 //
568 //*************************************************************************
569 // Parameter:
570 // In : None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -