⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbmain.c

📁 基于S3C2440在ADS环境下开发的USB读写程序。
💻 C
字号:
/****************************************************************
 NAME: usbmain.c
 DESC: endpoint interrupt handler
       USB init jobs
 HISTORY:
 Mar.25.2002:purnnamu: ported for S3C2410X.
 Mar.27.2002:purnnamu: DMA is enabled.
 ****************************************************************/
#include <string.h>
#include <stdarg.h>
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "def.h"

#include "2440usb.h"
#include "usbmain.h"
#include "usblib.h"
#include "usbsetup.h"
#include "usbout.h"
#include "usbin.h"

extern void Uart_Printf(char *fmt,...);
extern void Uart_Init(int baud);
void Uart_SendByte(int data);
void Delay(int x);
volatile U16 checkSum;
volatile U32 downloadFileSize;
volatile unsigned char *downPt;
int download_run=0;
volatile int isUsbdSetConfiguration;
U32 tempDownloadAddress;
volatile U32 downloadAddress;
volatile U32 totalDmaCount;


/**************************
    Some PrepareEp1Fifo() should be deleted
 **************************/   

void Main(void)
{
   // int i;
   // U8 tmp1;
   // U8 oldTmp1=0xff;
    Uart_Init(115200);
    
     
    InitDescriptorTable();
     
    rGPGCON &= ~(3<<18);	
    rGPGUP  |= 1<<9;		//disable pull-up
    
    Delay(2000);
    rGPGCON |= 1<<18;		//output
    rGPGDAT |= 1<<9;		//high    
    
    ConfigUsbd();
    

    PrepareEp1Fifo(); 
    
    
 	pISR_USBD=(unsigned)IsrUsbd;
 
   
	rSRCPND |= BIT_USBD; 
	rINTPND |= BIT_USBD; 
	EnableIrq(BIT_USBD);


 
while(1);
}


void __irq IsrUsbd(void)
{
    U8 usbdIntpnd,epIntpnd;
    
    U8 saveIndexReg=rINDEX_REG;
    
    usbdIntpnd=rUSB_INT_REG;
    
    epIntpnd=rEP_INT_REG;
    
    //DbgPrintf( "[INT:EP_I=%x,USBI=%x]",epIntpnd,usbIntpnd );
    //Uart_SendByte('U');

    if(usbdIntpnd&SUSPEND_INT)
    {
    	rUSB_INT_REG=SUSPEND_INT;
    	DbgPrintf( "<SUS]");
    }
    if(usbdIntpnd&RESUME_INT)
    {
    	rUSB_INT_REG=RESUME_INT;
    	DbgPrintf("<RSM]");
    }
    if(usbdIntpnd&RESET_INT)
    {
    	DbgPrintf( "<RST]");  
    	
    	//ResetUsbd();
    	ReconfigUsbd();

    	rUSB_INT_REG=RESET_INT;  //RESET_INT should be cleared after ResetUsbd().   	

        PrepareEp1Fifo(); 
    }

    if(epIntpnd&EP0_INT)
    {
	rEP_INT_REG=EP0_INT;  
	DbgPrintf("<EP0]"); 
    	Ep0Handler();
    }
    if(epIntpnd&EP1_INT)
    {
    	rEP_INT_REG=EP1_INT;  
    	Ep1Handler();
    }

    if(epIntpnd&EP2_INT)
    {
    	rEP_INT_REG=EP2_INT;  
    	DbgPrintf("<2:TBD]");   //not implemented yet	
    	//Ep2Handler();
    }

    if(epIntpnd&EP3_INT)
    {
    	rEP_INT_REG=EP3_INT;
    	Ep3Handler();
    }

    if(epIntpnd&EP4_INT)
    {
    	rEP_INT_REG=EP4_INT;
    	DbgPrintf("<4:TBD]");   //not implemented yet	
    	//Ep4Handler();
    }

    ClearPending(BIT_USBD);	 
    
    rINDEX_REG=saveIndexReg;
}




/******************* Consol printf for debug *********************/

#define DBGSTR_LENGTH (0x1000)
U8 dbgStrFifo[DBGSTR_LENGTH];
volatile U32 dbgStrRdPt=0;
volatile U32 dbgStrWrPt=0;



void _WrDbgStrFifo(U8 c)
{
    dbgStrFifo[dbgStrWrPt++]=c;
    if(dbgStrWrPt==DBGSTR_LENGTH)dbgStrWrPt=0;

}


int DbgPrintfLoop(void)
{
    if(dbgStrRdPt==dbgStrWrPt)return 0;
    Uart_SendByte(dbgStrFifo[dbgStrRdPt++]);

    if(dbgStrRdPt==DBGSTR_LENGTH)dbgStrRdPt=0;
    return 1;
}


#if 0
void DbgPrintf(char *fmt,...)
{
    int i,slen;
    va_list ap;
    char string[256];

    va_start(ap,fmt);
    vsprintf(string,fmt,ap);
    
    slen=strlen(string);
    
    for(i=0;i<slen;i++)
    	_WrDbgStrFifo(string[i]);
    
    va_end(ap);
}
#else
void DbgPrintf(char *fmt,...)
{
}
#endif

void Delay(int x)
{
	int j,k;
	while(x)
	{
		for(j=0;j<=0xff;j++)
			for(k=0;k<=0xff;k++);
		x--;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -