州周立功单片机发展有限公司Te:(020)3873097638730977Fax:38730925htpr/w bEPPflags bits control state= USB IDLE; short i= ControlData. wLength -ControlData w Count D12 Read LastTransaction Status( 1); /Clear interrupt flag if (bEPPflags bits control state I= USB TRANSMIT return if(i>=EPO PACKET SIZE)4 DI2_ WriteEndpoint(l, ControlData pData+ ControlData wCount, EPO PACKET_ SIZE); ControlData wCount += EPO PACKET SIZE bEPPflags bits control state USB TRANSMIT else if( il=0)i ControlData w Count + bEPPflags. bits control state USB IDLE else if (i=0) DI2 Write Endpoint(1, 0, 0); // Send zero packet at the end??? bEPPflags bits control state= USB IDLE, if(bEPPflags bits dma state= DMA PENDING) bEPPflags bits setup dma= 1 else bEPPflags bits dma state= DMA IDLE. D12 ReadLastTransaction Status(3); /*Clear interrupt flag"/
广州周立功单片机发展有限公司 Tel: (020)38730976 38730977 Fax: 38730925 http://www.zlgmcu.com 16 else { bEPPflags.bits.control_state = USB_IDLE; } } void ep0_txdone(void) { short i = ControlData.wLength - ControlData.wCount; D12_ReadLastTransactionStatus(1); // Clear interrupt flag if (bEPPflags.bits.control_state != USB_TRANSMIT) return; if( i >= EP0_PACKET_SIZE) { D12_WriteEndpoint(1, ControlData.pData + ControlData.wCount, EP0_PACKET_SIZE); ControlData.wCount += EP0_PACKET_SIZE; bEPPflags.bits.control_state = USB_TRANSMIT; } else if( i != 0) { D12_WriteEndpoint(1, ControlData.pData + ControlData.wCount, i); ControlData.wCount += i; bEPPflags.bits.control_state = USB_IDLE; } else if (i == 0){ D12_WriteEndpoint(1, 0, 0); // Send zero packet at the end ??? bEPPflags.bits.control_state = USB_IDLE; } } void dma_eot(void) { if(bEPPflags.bits.dma_state == DMA_PENDING) bEPPflags.bits.setup_dma = 1; else bEPPflags.bits.dma_state = DMA_IDLE; } void ep1_txdone(void) { D12_ReadLastTransactionStatus(3); /* Clear interrupt flag */
州周立功单片机发展有限公司Te:(020)3873097638730977Fax:38730925htpr/w unsigned char len: D12 ReadLast TransactionStatus(2); /*Clear interrupt flag"/ len= D12 ReadEndpoint(2, GenEpBuf, sizeof( Gen Ep Buf); if(len I=0) bEPPflags bits epl void main txdone( void) #ifndef C51 unsigned short len unsigned char far *fp D12_ ReadLastTransaction Status(5); /*Clear interrupt flag "/ #ifndef C51 seg=(ioBuffer io Count)>>4 off=(ioBuffer io Count)&Oxf. fp= MK FP(seg, off) ount if(bEPPflags bits dma state DMA PENDING) bEPPflags bits setup dma= 1 bEPPflags bits dma state DMA IDLE, else i f(len >64) len=DI2 Write Endpoint(5, fp, len), io Count += len
广州周立功单片机发展有限公司 Tel: (020)38730976 38730977 Fax: 38730925 http://www.zlgmcu.com 17 } void ep1_rxdone(void) { unsigned char len; D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */ len = D12_ReadEndpoint(2, GenEpBuf, sizeof(GenEpBuf)); if(len != 0) bEPPflags.bits.ep1_rxdone = 1; } void main_txdone(void) { #ifndef __C51__ unsigned short len; unsigned char far *fp; unsigned short seg, off; #endif D12_ReadLastTransactionStatus(5); /* Clear interrupt flag */ #ifndef __C51__ seg = (ioBuffer + ioCount)>>4; off = (ioBuffer + ioCount)&0xf; fp = MK_FP(seg, off); len = ioSize - ioCount; if(len == 0) { if(bEPPflags.bits.dma_state == DMA_PENDING) bEPPflags.bits.setup_dma = 1; else bEPPflags.bits.dma_state = DMA_IDLE; } else { if(len > 64) len = 64; len = D12_WriteEndpoint(5, fp, len); ioCount += len; } #endif }
州周立功单片机发展有限公司Te:(020)3873097638730977Fax:38730925htpr/w unsigned char far "fp unsigned short seg, off, DI2 ReadLast Transaction Status(4); /Clear interrupt flag*/ #ifndef C51 seg=(ioBuffer ioCount fp= MK FP(seg, off); len= D12 ReadMain Endpoint( fp ) io Count + len if( Count >=ioNize)i if(bEPPflags bits dma state DMA PENDING) bEPPflags bits setup dma=1; els bEPPflags bits dma state DMA IDLE, 主循环一MANL00P.c 主循环检査事件标志并进入对应的子程序进行进一步的处理。它还包含人机接口的代码,例如LED 和键盘扫描。 本本本市本春本市本春本本享春本春市本本本本本本本本市本 ∥98/11/25 Added 1/O access support on Main endpoints (WK) #include <stdio. h> #ifdef C51 #include <dos h> #include <malloc. h>
广州周立功单片机发展有限公司 Tel: (020)38730976 38730977 Fax: 38730925 http://www.zlgmcu.com 18 void main_rxdone(void) { #ifndef __C51__ unsigned char len; unsigned char far *fp; unsigned short seg, off; #endif D12_ReadLastTransactionStatus(4); /* Clear interrupt flag */ #ifndef __C51__ seg = (ioBuffer + ioCount)>>4; off = (ioBuffer + ioCount)&0xf; fp = MK_FP(seg, off); len = D12_ReadMainEndpoint( fp ); ioCount += len; if(ioCount >= ioSize) { if(bEPPflags.bits.dma_state == DMA_PENDING) bEPPflags.bits.setup_dma = 1; else bEPPflags.bits.dma_state = DMA_IDLE; } #endif } 主循环 MAINLOOP.C 主循环检查事件标志并进入对应的子程序进行进一步的处理 它还包含人机接口的代码 例如 LED 和键盘扫描 /* //************************************************************************* // File Name: MainLoop.C // 98/11/25 Added I/O access support on Main endpoints. (WK) //************************************************************************* */ #include <stdio.h> #include <string.h> #ifdef __C51__ #include <reg51.h> /* special function register declarations */ #else #include <bios.h> #include <dos.h> #include <malloc.h> #endif
州周立功单片机发展有限公司Te:(020)3873097638730977Fax:38730925htpr/w #include"epphal h #include d12cih" #include"mainloop h #include"protodmah /USB protocol function pointer arrays /布市率事布率亭事率事布率本事布布本亭事水摩布布市春事市摩布布事摩布事布水事事事率*布事事布布 e void(Standard DeviceRequest)(void get status set feature t interface interface code void (Vendor DeviceRequestD(void) 19
广州周立功单片机发展有限公司 Tel: (020)38730976 38730977 Fax: 38730925 http://www.zlgmcu.com 19 #include "epphal.h" #include "d12ci.h" #include "mainloop.h" #include "usb100.h" #include "chap_9.h" #include "protodma.h" /* //************************************************************************* // USB protocol function pointer arrays //************************************************************************* */ code void (*StandardDeviceRequest[])(void) = { get_status, clear_feature, reserved, set_feature, reserved, set_address, get_descriptor, reserved, get_configuration, set_configuration, get_interface, set_interface, reserved, reserved, reserved, reserved }; code void (*VendorDeviceRequest[])(void) = { reserved, reserved, reserved, reserved, reserved, reserved, reserved, reserved, reserved, reserved