📄 usbmain.org.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 <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "Option.h"
#include "2460addr.h"
#include "2460lib.h"
#include "2460usb.h"
#include "usbmain.h"
#include "usblib.h"
#include "usbsetup.h"
#include "usbout.h"
#include "usbin.h"
#include "type.h"
/**************************
Some PrepareEp1Fifo() should be deleted
**************************/
void UsbdMain(void)
{
int i;
// Standard USB Descriptor Definitions
InitDescriptorTable();
//ResetUsbd();
ConfigUsbd();
PrepareEp1Fifo();
#if 0
while(1)
{
if(DbgPrintfLoop())continue;
Delay(5000);
if((i++%2)==0)Led_Display(0x8);
else Led_Display(0x0);
}
#endif
}
extern unsigned char not_suspend;
extern unsigned char not_resume;
extern unsigned char sus_res_print;
extern void Led_Display_Temp(void);
void __irq IsrUsbd(void)
{
unsigned char usbdIntpnd,epIntpnd;
unsigned char saveIndexReg=rINDEX_REG;
unsigned char suspend_check=TRUE;
usbdIntpnd=rUSB_INT_REG;
epIntpnd=rEP_INT_REG;
rINTSUBMSK |= (BIT_SUB_USBD);
if(sus_res_print == TRUE)
{
//Led_Display_Temp();
printf("\n\nUSB_INT_REG=0x%01x\n",usbdIntpnd);
}
if(usbdIntpnd&RESUME_INT)
{
rUSB_INT_REG=RESUME_INT;
DbgPrintf("<RSM]");
//Led_Display_Temp();
if(sus_res_print==TRUE)
printf("!!!RESUME!!!\n");
not_resume = FALSE;
rUSB_INT_EN_REG = (RESET_INT|SUSPEND_INT);
//work-around!!!
if(usbdIntpnd&SUSPEND_INT)
{
rUSB_INT_REG=SUSPEND_INT;
suspend_check=FALSE;
}
}
if((usbdIntpnd&SUSPEND_INT)&&(suspend_check==TRUE))
{
//rUSB_INT_EN_REG &= ~SUSPEND_INT;
rUSB_INT_EN_REG = 0;
rUSB_INT_REG=SUSPEND_INT;
//rPWR_REG &= ~0x01; //disable suspend mode
DbgPrintf( "<SUS]");
if(sus_res_print==TRUE)
{
printf("!!!SUSPEND!!!\n");
}
not_suspend = FALSE;
}
if(usbdIntpnd&RESET_INT)
{
rUSB_INT_REG=RESET_INT; //RESET_INT should be cleared after ResetUsbd().
DbgPrintf( "<RST]");
if(sus_res_print==TRUE)
{
//Led_Display_Temp();
//printf("Curent USB_INT_EN_Reg Value is 0x%01x\n", (rUSB_INT_EN_REG&0xf));
printf("!!!RESET!!!\n");
}
//ResetUsbd();
ReconfigUsbd();
sus_res_print = FALSE;
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();
}
rSUBSRCPND=BIT_SUB_USBD;
ClearPending(BIT_USB);
rINTSUBMSK&=~(BIT_SUB_USBD);
rINDEX_REG=saveIndexReg;
}
/******************* Consol printf for debug *********************/
#define DBGSTR_LENGTH (0x1000)
unsigned char dbgStrFifo[DBGSTR_LENGTH];
volatile unsigned int dbgStrRdPt=0;
volatile unsigned int dbgStrWrPt=0;
void _WrDbgStrFifo(unsigned char c)
{
dbgStrFifo[dbgStrWrPt++]=c;
if(dbgStrWrPt==DBGSTR_LENGTH)dbgStrWrPt=0;
}
int DbgPrintfLoop(void)
{
if(dbgStrRdPt==dbgStrWrPt)return 0;
putchar(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 + -