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

📄 usbmain.c

📁 USB-TEST是USB通信的例子
💻 C
字号:
/*********************************************************************************************
* File:		usbmain.c
* Author:	Embest
* Desc:		USB init jobs and endpoint interrupt handler implement
* History:	
*			R.X.Huang, March 12, 2005
*				Programming modify, style of the program: nomenclature, commentary
*			Y.J.Guo, April 28, 2005
*				Modifying and reusing  of S3C2410X u24xmon
*********************************************************************************************/

/*------------------------------------------------------------------------------------------*/
/*                                     include files	                                    */
/*------------------------------------------------------------------------------------------*/
#include <string.h>
#include <stdarg.h>
#include "2410lib.h"

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

/*********************************************************************************************
* name:		UsbdMain
* func:		Main configuration of USB's Upll and Descriptor Table handler 
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void UsbdMain(void)
{
    int i;
    UINT8T tmp1;
    UINT8T oldTmp1=0xff;
    
    //ChangeUPllValue(0x48,0x3,0x2); ->UCLK=48Mhz     
    ChangeUPllValue(40,1,2);									//UCLK=48Mhz     
    InitDescriptorTable();
    
    ConfigUsbd(); 

#if 0    
    while(1)
    {
    	if(DbgPrintfLoop())continue;
    	
    	Delay(5000);
    	if((i++%2)==0)Led_Display(0x8);
    	else Led_Display(0x0);
   }
#endif    
}

/*********************************************************************************************
* name:		IsrUsbd
* func:		Interrupt hander of USBD 
* para:		none
* ret:		none
* modify:
* comment:		
*********************************************************************************************/
void IsrUsbd(void)
{
    UINT8T usbdIntpnd,epIntpnd;
    UINT8T saveIndexReg=rINDEX_REG;
    usbdIntpnd=rUSB_INT_REG;
    epIntpnd=rEP_INT_REG;
    DbgPrintf( "[INT:EP_I=%x,USBI=%x]",epIntpnd,usbdIntpnd );

    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;  
    	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)
UINT8T dbgStrFifo[DBGSTR_LENGTH];
volatile UINT32T dbgStrRdPt=0;
volatile UINT32T dbgStrWrPt=0;

void _WrDbgStrFifo(UINT8T 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 + -