📄 usb_device_lib.c
字号:
#include "def.h"
#include "2410addr.h"
#include "2410lib.h"
#include "USB_device_lib.h"
#include "uart.h"
// *** End point information ***
// EP0: control
// EP1: bulk in end point
// EP2: not used
// EP3: bulk out end point
// EP4: not used
// *** VERY IMPORTANT NOTE ***
// Every descriptor size of EP0 should be 8n+m(m=1~7).
// Otherwise, USB will not operate normally because the program
// doesn't prepare the case that the descriptor size is 8n+0.
// If the size of a descriptor is 8n, the 0 length packit should be sent.
// Special thanks to E.S.Choi for reminding me of this USB specification.
// ===================================================================
// All following commands will operate only in case
// - ep0_csr is valid.
// ===================================================================
void RdPktEp0(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
buf[i]=(U8)rEP0_FIFO;
}
}
void WrPktEp0(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
rEP0_FIFO=buf[i];
}
}
void RdPktEp1(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
buf[i]=(U8)rEP1_FIFO;
}
}
void WrPktEp1(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
rEP1_FIFO=buf[i];
}
}
void WrPktEp2(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
rEP2_FIFO=buf[i];
}
}
void RdPktEp3(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
buf[i]=(U8)rEP3_FIFO;
}
}
void RdPktEp4(U8 *buf,int num)
{
int i;
for(i=0;i<num;i++)
{
buf[i]=(U8)rEP4_FIFO;
}
}
void Print_USB_SETUP_DATA(struct USB_SETUP_DATA descSetup0)
{
Uart_Printf("bmRequestType = %x \n",descSetup0.bmRequestType);
Uart_Printf("bRequest = %x \n",descSetup0.bRequest);
Uart_Printf("bValueL = %x \n",descSetup0.bValueL);
Uart_Printf("bValueH = %x \n",descSetup0.bValueH);
Uart_Printf("bIndexL = %x \n",descSetup0.bIndexL);
Uart_Printf("bIndexH = %x \n",descSetup0.bIndexH);
Uart_Printf("bLengthL = %x \n",descSetup0.bLengthL);
Uart_Printf("bLengthH = %x \n",descSetup0.bLengthH);
}
extern ep0_csr;
void Ep0_Interrupt_Identify(void){
if(rEP0_CSR & EP0_SETUP_END)
Uart_Puts("Reason :[4].SETUP_END BIT IS SET\n");
else if(rEP0_CSR & EP0_SENT_STALL)
Uart_Puts("Reason :[3].SENT_STALL BIT IS SET\n");
else if(rEP0_CSR & EP0_OUT_PKT_READY )
Uart_Puts("Reason :[1].OUT_PKT_RDY BIT IS SET\n");
else if((!(rEP0_CSR&EP0_IN_PKT_READY))&&(ep0_csr&EP0_IN_PKT_READY))
Uart_Puts("Reason :[2].IN_PKT_RDY BIT IS CLEARED\n");
else if((!(rEP0_CSR&EP0_DATA_END))&&(ep0_csr&EP0_DATA_END))
Uart_Puts("Reason :[5].DATA_END BIT IS CLEARED\n");
else Uart_Puts("Unkown EP0 INTERRUPT !!!!\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -