vendor.c
资源名称:USB_2.0.rar [点击查看]
上传用户:ids068
上传日期:2013-04-04
资源大小:639k
文件大小:6k
源码类别:
USB编程
开发平台:
C/C++
- /****************************************Copyright (c)**************************************************
- ** 广州周立功单片机发展有限公司
- ** 研 究 所
- ** http://www.zlgmcu.com
- **--------------当前版本修订------------------------------------------------------------------------------
- ** 修改人: 刘英斌
- ** 日 期:2003-03-13
- ** 描 述:ISP1581 V1.0
- **------------------------------------------------------------------------------------------------------
- ********************************************************************************************************/
- #include "standard.h"
- #include "Kernel.h"
- #include "D14.h"
- //***********************************************************************
- //* *
- //* External Variable Definition *
- //* *
- //***********************************************************************
- extern USB_DEVICE USB_Device;
- extern DMA_INT_FLAG DMA_Int_Flag;
- extern USB_INT_FLAG USB_Int_Flag;
- extern volatile D14_CNTRL_REG xdata D14_Cntrl_Reg;
- extern void Start_mSEC_Timer(Data);
- extern UC Data;
- extern UI Temp,PIO_Count;
- extern KERNEL Kernel_Flag;
- extern ULI bytecount;
- extern FILESIZE FileSize;
- extern UI count;
- extern UC idata Endpt_FIFO[MAX_BUF];
- extern UC Type;
- //***********************************************************************
- //* *
- //* Variable Definition *
- //* *
- //***********************************************************************
- UI Count_PIO;
- //***********************************************************************
- //* *
- //* Prototype Definition *
- //* *
- //***********************************************************************
- void DMA_Debug_Mode(void);
- void DMA_Init(void);
- void DMA_Mode(Data);
- //***********************************************************************
- //* *
- //* Routine Definition *
- //* *
- //***********************************************************************
- //***********************************************************************
- //* *
- //* Routine : DMA Debug Mode *
- //* Input : None *
- //* Output : None *
- //* Function : Generic DMA mode routine *
- //* *
- //***********************************************************************
- void DMA_Debug_Mode(void)
- {
- if(Kernel_Flag.BITS.Transfer_Start)
- {
- if(FileSize.Size.Address[0] == 0 &&
- FileSize.Size.Address[1] == 0 &&
- FileSize.Size.Address[2] == 0)
- {
- Kernel_Flag.BITS.Out_Reset_Done = 0;
- Kernel_Flag.BITS.In_Reset_Done = 0;
- }
- if(FileSize.Size.DIR == 0x00 || FileSize.Size.DIR == 0x80)
- DMA_Mode(Write);
- else
- DMA_Mode(Read);
- }
- }
- //***********************************************************************
- //* *
- //* Routine : DMA Mode *
- //* Input : DMA Controller setting *
- //* Output : None *
- //* Function : to do GDMA data transfer *
- //* *
- //***********************************************************************
- void DMA_Mode(Data)
- {
- UI Datcount;
- if(Data)
- {
- //read
- do
- {
- //Check for Out Token ACK interrupt
- while(!USB_Int_Flag.BITS.EP2RX)
- {
- if(USB_Int_Flag.BITS.SUSP || Kernel_Flag.BITS.Bus_Reset || USB_Int_Flag.BITS.EP0SETUP)
- break;
- }
- EA_DISABLE;
- USB_Int_Flag.BITS.EP2RX = 0;
- EA_ENABLE;
- D14_Cntrl_Reg.D14_ENDPT_INDEX = 4;
- //Read in FIFO data
- if (bytecount > PIO_Count)
- {
- Datcount = PIO_Count;
- }
- else
- {
- Datcount = bytecount;
- }
- if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- {
- for(Count_PIO = 0 ; Count_PIO < Datcount ; Count_PIO++)
- Endpt_FIFO[Count_PIO] = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- }
- else
- {
- for(Count_PIO = 0 ; Count_PIO < Datcount; Count_PIO++)
- Temp = D14_Cntrl_Reg.D14_DATA_PORT_LSB;
- }
- bytecount -= Datcount;
- }while(bytecount);
- }
- else
- {
- //write
- do
- {
- //initialize endpoint index
- D14_Cntrl_Reg.D14_ENDPT_INDEX = 5;
- //Write data to FIFO
- if (bytecount>PIO_Count)
- {
- D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB =( unsigned char ) PIO_Count;
- D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = ( unsigned char ) (PIO_Count>>8);
- Datcount = PIO_Count;
- }
- else
- {
- D14_Cntrl_Reg.D14_BUFFER_LENGTH_LSB =( unsigned char ) bytecount;
- D14_Cntrl_Reg.D14_BUFFER_LENGTH_MSB = ( unsigned char ) (bytecount>>8);
- Datcount = bytecount;
- }
- if(Kernel_Flag.BITS.HS_FS_State == FULL_SPEED)
- {
- for(Count_PIO = 0 ; Count_PIO < Datcount ; Count_PIO++)
- D14_Cntrl_Reg.D14_DATA_PORT_LSB = Endpt_FIFO[Count_PIO];
- }
- else
- {
- for(Count_PIO = 0 ; Count_PIO < Datcount ; Count_PIO++)
- D14_Cntrl_Reg.D14_DATA_PORT_LSB = Count_PIO % 256;
- }
- //Check for In Token ACK
- while(!USB_Int_Flag.BITS.EP2TX)
- {
- if(USB_Int_Flag.BITS.SUSP || Kernel_Flag.BITS.Bus_Reset || USB_Int_Flag.BITS.EP0SETUP)
- break;
- }
- EA_DISABLE;
- USB_Int_Flag.BITS.EP2TX = 0;
- EA_ENABLE;
- bytecount -= Datcount;
- }while(bytecount);
- Count_PIO = 0;
- }
- Kernel_Flag.BITS.Transfer_Start = 0;
- }