C51 COMPILER V7.06 D13BUS 08/18/2005 15:30:27 PAGE 1 C51 COMPILER V7.06, COMPILATION OF MODULE D13BUS OBJECT MODULE PLACED IN D13BUS.OBJ COMPILER INVOKED BY: d:\Keil777\C51\BIN\C51.EXE D13BUS.C BROWSE DEBUG OBJECTEXTEND stmt level source 1 2 #include 3 #include 4 #include "BasicTyp.h" 5 #include "USB.h" 6 #include "Hal4D13.h" 7 #include "Chap_9.h" 8 #include "D13bus.h" 9 #include "usb_irq.h" 10 #include "mainloop.h" 11 12 13 // *************************************************************************** 14 15 #define SETUP_DMA_REQUEST 0x0471 16 #define GET_FIRMWARE_VERSION 0x0472 17 18 #define idata 19 extern IO_REQUEST idata ioRequest; 20 21 // **************************************************************************** 22 23 24 // ************************************************************************* 25 // Public Data 26 // ************************************************************************* 27 28 extern CONTROL_XFER ControlData; 29 extern D13FLAGS bD13flags; 30 31 // ************************************************************************* 32 // Subroutines 33 // ************************************************************************* 34 35 void D13Bus_ControlEntry(void) 36 { 37 1 // No support now, just stall it. 38 1 D13Bus_StallEP0(); 39 1 } 40 41 void reserved(void) 42 { 43 1 // Undefined commands, stall them 44 1 D13Bus_StallEP0(); 45 1 } 46 47 void read_write_register(void) 48 { 49 1 unsigned char i; 50 1 51 1 if(ControlData.DeviceRequest.bmRequestType & (unsigned char)USB_ENDPOINT_DIRECTION_MASK) 52 1 { 53 2 if(bD13flags.bits.verbose) 54 2 { 55 3 printf("Read Registers: Offset = 0x%x, Length = 0x%x, Index = 0x%x.\n", C51 COMPILER V7.06 D13BUS 08/18/2005 15:30:27 PAGE 2 56 3 ControlData.DeviceRequest.wValue, 57 3 ControlData.DeviceRequest.wLength, 58 3 ControlData.DeviceRequest.wIndex); 59 3 } 60 2 61 2 if(ControlData.DeviceRequest.wIndex == GET_FIRMWARE_VERSION && 62 2 ControlData.DeviceRequest.wValue == 0 && 63 2 ControlData.DeviceRequest.wLength == 1) 64 2 { 65 3 get_firmware_version(); 66 3 } 67 2 else 68 2 { 69 3 Chap9_StallEP0(); 70 3 printf("stall: get firmware version\n"); 71 3 } 72 2 73 2 } 74 1 else 75 1 { 76 2 if(bD13flags.bits.verbose) 77 2 { 78 3 79 3 printf("Write Registers: Offset = 0x%x, Length = 0x%x, Index = 0x%x.\n", 80 3 ControlData.DeviceRequest.wValue, 81 3 ControlData.DeviceRequest.wLength, 82 3 ControlData.DeviceRequest.wIndex); 83 3 84 3 printf("Data: "); 85 3 for(i = 0; i < ControlData.DeviceRequest.wLength; i ++) 86 3 printf("0x%x, ", *((ControlData.dataBuffer)+i)); 87 3 printf("\n"); 88 3 } 89 2 90 2 if(ControlData.DeviceRequest.wIndex == SETUP_DMA_REQUEST && 91 2 ControlData.DeviceRequest.wValue == 0 && 92 2 ControlData.DeviceRequest.wLength == 6) 93 2 { 94 3 RaiseIRQL(); 95 3 setup_dma_request(); 96 3 LowerIRQL(); 97 3 } 98 2 99 2 } 100 1 } 101 102 void setup_dma_request() 103 { 104 1 memcpy((unsigned char *)&ioRequest + ControlData.DeviceRequest.wValue, 105 1 ControlData.dataBuffer, 106 1 ControlData.DeviceRequest.wLength); 107 1 108 1 ioRequest.uSize = SWAP(ioRequest.uSize); 109 1 ioRequest.uAddressL = SWAP(ioRequest.uAddressL); 110 1 printf("Setup Data: addL, addH, uSize =%x, %x, %x \n", \ 111 1 ioRequest.uAddressL, ioRequest.bAddressH, ioRequest.uSize); 112 1 113 1 if(ioRequest.uSize > DMA_BUFFER_SIZE) // Unaccepted request 114 1 { 115 2 Chap9_StallEP0(); 116 2 printf("stall: ioRequest.uSize > DMA_BUFFER_SIZE.\n"); 117 2 } C51 COMPILER V7.06 D13BUS 08/18/2005 15:30:27 PAGE 3 118 1 else 119 1 { 120 2 RaiseIRQL(); 121 2 bD13flags.bits.setup_dma = 1; 122 2 LowerIRQL(); 123 2 } 124 1 } 125 126 void get_firmware_version() 127 { 128 1 unsigned char i; 129 1 130 1 i = 0x01; 131 1 D13Bus_SingleTransmitEP0(&i, 1); 132 1 } 133 134 // ************************************************************************* 135 // D13Bus support functions 136 // ************************************************************************* 137 138 void D13Bus_StallEP0(void) 139 { 140 1 Chap9_StallEP0(); 141 1 } 142 143 void D13Bus_SingleTransmitEP0(UCHAR * buf, UCHAR len) 144 { 145 1 Hal4D13_SingleTransmitEP0(buf, len); 146 1 147 1 RaiseIRQL(); 148 1 if(!ControlData.Abort) 149 1 { 150 2 ControlData.wLength = ControlData.wCount = len; 151 2 bD13flags.bits.DCP_state = USBFSM4DCP_HANDSHAKE; 152 2 } 153 1 LowerIRQL(); 154 1 155 1 } 156 157 void D13Bus_BurstTransmitEP0(UCHAR * pData, USHORT len) 158 { 159 1 ControlData.wCount = 0; 160 1 if(ControlData.wLength > len) 161 1 ControlData.wLength = len; 162 1 163 1 ControlData.Addr.pData = pData; 164 1 if( ControlData.wLength >= EP0_PACKET_SIZE) 165 1 { 166 2 Hal4D13_WriteEndpoint(EPINDEX4EP0_CONTROL_IN, ControlData.Addr.pData, EP0_PACKET_SIZE); 167 2 RaiseIRQL(); 168 2 if(!ControlData.Abort) 169 2 { 170 3 ControlData.wCount += EP0_PACKET_SIZE; 171 3 bD13flags.bits.DCP_state = USBFSM4DCP_DATAIN; 172 3 } 173 2 174 2 LowerIRQL(); 175 2 176 2 } 177 1 else 178 1 { 179 2 Hal4D13_WriteEndpoint(EPINDEX4EP0_CONTROL_IN, pData, ControlData.wLength); C51 COMPILER V7.06 D13BUS 08/18/2005 15:30:27 PAGE 4 180 2 RaiseIRQL(); 181 2 if(!ControlData.Abort) 182 2 { 183 3 ControlData.wCount += ControlData.wLength; 184 3 bD13flags.bits.DCP_state = USBFSM4DCP_DATAIN; 185 3 } 186 2 LowerIRQL(); 187 2 } 188 1 } MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 503 ---- CONSTANT SIZE = 255 ---- XDATA SIZE = ---- ---- PDATA SIZE = ---- ---- DATA SIZE = ---- 6 IDATA SIZE = ---- ---- BIT SIZE = ---- ---- END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)