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

📄 usbmain.c

📁 基于arm9的,usb设备(u盘)的读写操作实现.
💻 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 "2410addr.h"
#include "2410lib.h"
#include "def.h"

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

/**************************
    Some PrepareEp1Fifo() should be deleted
 **************************/   
void UsbdMain(void)
{
    //ChangeUPllValue(0x48,0x3,0x2);  //UCLK=48Mhz     
    ChangeUPllValue(40,1,2);  //UCLK=48Mhz     
    InitDescriptorTable();
    //ResetUsbd();
    
    ConfigUsbd(); 

    //DetectVbus(); //not used in S3C2400X
#ifdef _FOR_UDISK_
	if(USBD_flg==0)
		PrepareEp1Fifo(); 
#else
	PrepareEp1Fifo(); 
#endif   
}

void __irq IsrUsbd(void)
{
    U8 usbdIntpnd,epIntpnd;
    U8 saveIndexReg=rINDEX_REG;	//PUSH rINDEX_REG
    usbdIntpnd=rUSB_INT_REG;	//0x52000158(L)
    epIntpnd=rEP_INT_REG;		//0x52000148(L)
   // Uart_Printf( "[INT:EP_I=%x,USBI=%x]\n",epIntpnd,usbdIntpnd );

    if(usbdIntpnd&SUSPEND_INT)	//#define SUSPEND_INT=0x01  
    {
    	rUSB_INT_REG=SUSPEND_INT;//Clear Suspend INT,write "0x01"
    	//DbgPrintf( "<SUS]");
    }
    if(usbdIntpnd&RESUME_INT)	//#define RESUME_INT=0x02  
    {
    	rUSB_INT_REG=RESUME_INT;//Clear Resume INT,write "0x02"
    	//DbgPrintf("<RSM]");
    }
    if(usbdIntpnd&RESET_INT)	//#define RESET_INT=0x04 
    {
    	//DbgPrintf( "<RST]");  
    	
    	//ResetUsbd();
    	ReconfigUsbd();

    	rUSB_INT_REG=RESET_INT;  //RESET_INT should be cleared after ResetUsbd().
#ifdef _FOR_UDISK_
	if(USBD_flg==0)
		PrepareEp1Fifo(); 
#else
	PrepareEp1Fifo(); 
#endif
    }

    if(epIntpnd&EP0_INT)	//#define EP0_INT=0x01
    {
	rEP_INT_REG=EP0_INT;//Clear EP0's INT  
    	Ep0Handler();
    }
    if(epIntpnd&EP1_INT)	//#define EP1_INT=0x02
    {
    	rEP_INT_REG=EP1_INT;//Clear EP1's INT
    	Ep1Handler();
    }

    if(epIntpnd&EP2_INT)	//#define EP2_INT=0x04
    {
    	rEP_INT_REG=EP2_INT;//Clear EP2's INT  
    	//DbgPrintf("<2:TBD]");   //not implemented yet	
    	//Ep2Handler();
    }

    if(epIntpnd&EP3_INT)	//#define EP3_INT=0x08
    {
    	rEP_INT_REG=EP3_INT;//Clear EP3's INT
    	Ep3Handler();
    }

    if(epIntpnd&EP4_INT)	//#define EP4_INT=0x10
    {
    	rEP_INT_REG=EP4_INT;//Clear EP4's INT
    	//DbgPrintf("<4:TBD]");   //not implemented yet	
    	//Ep4Handler();
    }

    ClearPending(BIT_USBD);//Clear USBD's INT by set the corresponding bit of the rSRCPND first then rINTPND.
	 
    rINDEX_REG=saveIndexReg;	//POP rINDEX_REG
}

/******************* 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
*/

⌨️ 快捷键说明

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