usbout.c
来自「2440超级bios(ads1.2 rvds2.2)通用」· C语言 代码 · 共 127 行
C
127 行
/****************************************************************
NAME: usbout.c
DESC: USB bulk-OUT operation related functions
HISTORY:
Mar.25.2002:purnnamu: ported for S3C2410X.
Mar.27.2002:purnnamu: DMA is enabled.
****************************************************************/
#include "Includes.h"
static void PrintEpoPkt(U08 *pt,int cnt);
static void RdPktEp3_ChkSum(U08 *buf,int num);
// ===================================================================
// All following commands will operate in case
// - out_csr3 is valid.
// ===================================================================
#define CLR_EP3_OUT_PKT_READY() rOUT_CSR1_REG= ( out_csr3 &(~ EPO_WR_BITS)\
&(~EPO_OUT_PKT_READY) )
#define SET_EP3_SEND_STALL() rOUT_CSR1_REG= ( out_csr3 & (~EPO_WR_BITS)\
| EPO_SEND_STALL) )
#define CLR_EP3_SENT_STALL() rOUT_CSR1_REG= ( out_csr3 & (~EPO_WR_BITS)\
&(~EPO_SENT_STALL) )
#define FLUSH_EP3_FIFO() rOUT_CSR1_REG= ( out_csr3 & (~EPO_WR_BITS)\
|EPO_FIFO_FLUSH) )
// ***************************
// *** VERY IMPORTANT NOTE ***
// ***************************
// Prepare for the packit size constraint!!!
// EP3 = OUT end point.
U08 ep3Buf[EP3_PKT_SIZE];
static U08 tempBuf[64+1];
void Ep3Handler(void)
{
U08 out_csr3;
int fifoCnt;
rINDEX_REG = 3;
out_csr3 = rOUT_CSR1_REG;
DbgPrintf("<3:%x]",out_csr3);
if(out_csr3 & EPO_OUT_PKT_READY)
{
fifoCnt = rOUT_FIFO_CNT1_REG;
#if 0
RdPktEp3(ep3Buf,fifoCnt);
PrintEpoPkt(ep3Buf,fifoCnt);
#else
if(downloadFileSize == 0)
{
RdPktEp3((U08 *)DownPnt,8);
downloadAddress = progRunAddr;
downloadFileSize =
*((U08 *)(DownPnt+4))+
(*((U08 *)(DownPnt+5))<<8)+
(*((U08 *)(DownPnt+6))<<16)+
(*((U08 *)(DownPnt+7))<<24);
CheckSum = 0;
DownPnt = (U08 *)downloadAddress;
RdPktEp3_ChkSum((U08 *)DownPnt,fifoCnt-8); //The first 8-bytes are deleted.
DownPnt += fifoCnt-8;
#if USBDMA
//CLR_EP3_OUT_PKT_READY() is not executed.
//So, USBD may generate NAK until DMA2 is configured for USB_EP3;
rINTMSK |= BIT_USBD; //for debug
return;
#endif
}
else
{
#if USBDMA
UartPutStr(1,"<ERROR>");
#endif
RdPktEp3_ChkSum((U08 *)DownPnt,fifoCnt);
DownPnt += fifoCnt; //fifoCnt=64
}
#endif
CLR_EP3_OUT_PKT_READY();
if (((rOUT_CSR1_REG&0x1) == 1) &&
((rEP_INT_REG & 0x8) == 0))
{
fifoCnt = rOUT_FIFO_CNT1_REG;
RdPktEp3_ChkSum((U08 *)DownPnt,fifoCnt);
DownPnt += fifoCnt; //fifoCnt=64
CLR_EP3_OUT_PKT_READY();
}
return;
}
//I think that EPO_SENT_STALL will not be set to 1.
if(out_csr3 & EPO_SENT_STALL)
{
DbgPrintf("[STALL]");
CLR_EP3_SENT_STALL();
return;
}
}
void PrintEpoPkt(U08 *pt,int cnt)
{
int i;
DbgPrintf("[BOUT:%d:",cnt);
for(i=0;i<cnt;i++)
DbgPrintf("%x,",pt[i]);
DbgPrintf("]");
}
void RdPktEp3_ChkSum(U08 *buf,int num)
{
int i;
for(i=0; i<num; i++)
{
buf[i]=(U08)rEP3_FIFO;
CheckSum+=buf[i];
}
}
void ClearEp3OutPktReady(void)
{
U08 out_csr3;
rINDEX_REG = 3;
out_csr3 = rOUT_CSR1_REG;
CLR_EP3_OUT_PKT_READY();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?