vendor.c
资源名称:USB_2.0.rar [点击查看]
上传用户:ids068
上传日期:2013-04-04
资源大小:639k
文件大小:7k
源码类别:
USB编程
开发平台:
C/C++
- //***********************************************************************
- // *
- // P H I L I P S P R O P R I E T A R Y *
- // *
- // COPYRIGHT (c) 1999 BY PHILIPS SINGAPORE (APIC). *
- // -- ALL RIGHTS RESERVED -- *
- // *
- // File Name : DMADebug.c *
- // Author : Albert Goh *
- // Created : 3 March 2000 *
- // *
- //***********************************************************************
- //***********************************************************************
- // *
- // GDMADebug.c is the file that contain the routine for the GDMA debug *
- // It will be able to configured as master for slave for the debugging *
- // *
- //***********************************************************************
- //***********************************************************************
- // *
- // Module History *
- // ************** *
- // *
- // Date Version Author Changes *
- // ==== ======= ====== ======= *
- // 030300 0.1 Albert Created *
- // *
- // *
- //***********************************************************************
- //***********************************************************************
- //* *
- //* Include Files Definition *
- //* *
- //***********************************************************************
- #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;
- D14_Cntrl_Reg.D14_DMA_ENDPOINT = 2;
- //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;
- D14_Cntrl_Reg.D14_DMA_ENDPOINT = 2;
- //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);
- //stop DMA controller
- DMA_Start = GDMA_Stop;
- //transfewr done,reset internal variables
- DMA_Int_Flag.BITS.DMA_DONE = 0;
- Count_PIO = 0;
- }
- Kernel_Flag.BITS.Transfer_Start = 0;
- }