📄 isr.c
字号:
///////////////////////////////////////////////////////////////////////
#include "common.h"
#include "hal4d12.h"
///////////////////////////////////////////////////////////////////////
u16 ep0_state=ST_IDLE;
u16 ep1_state=ST_IDLE;
u16 ep0_buf_len=0;
u16 ep1_buf_len=0;
u8 *ep0_buf_pt;
u8 *ep1_buf_pt;
void ep0_txdone(void);
void ep0_rxdone(void);
void ep1_txdone(void);
void ep1_rxdone(void);
///////////////////////////////////////////////////////////////////////
void usb_isr()
{
u16 tmp;
Hal4D12_ReadInterruptRegister(&tmp);
//printf("usb_isr:%04x\n",tmp);
if(tmp != 0)
{
if(tmp & D12IS_ENDP0IN)
ep0_txdone();
if(tmp & D12IS_ENDP0OUT)
ep0_rxdone();
if(tmp & D12IS_ENDP1IN)
ep1_txdone();
if(tmp & D12IS_ENDP1OUT)
ep1_rxdone();
}
}
///////////////////////////////////////////////////////////////////////
void ep0_rxdone(void)
{
u8 tmp;
tmp = Hal4D12_ReadLastTransactionStatus(0);
printf("ep0_rxdone:status=%02x\n",tmp);
if (!(tmp & D12ST_SUCCESS))
return;
if (tmp & D12ST_SETUP)
{
ep0_state=ST_SETUP;
}
else /* Data Out Packet : status stage ?*/
{
}
}
///////////////////////////////////////////////////////////////////////
void ep0_txdone(void)
{
u8 tmp;
tmp = Hal4D12_ReadLastTransactionStatus(1); // Clear interrupt flag
if (!(tmp & D12ST_SUCCESS))
return;
if (ep0_state==ST_DATAIN)
{
if( ep0_buf_len >= EP0_PACKET_SIZE)
{
Hal4D12_WriteEndpoint(1, EP0_PACKET_SIZE, ep0_buf_pt);
ep0_buf_pt += EP0_PACKET_SIZE;
ep0_buf_len -= EP0_PACKET_SIZE;
}
else if( ep0_buf_len != 0)
{
Hal4D12_WriteEndpoint(1, (u8)ep0_buf_len, ep0_buf_pt );
ep0_buf_len = 0;
ep0_state = ST_HANDIN;
}
else
{
Hal4D12_WriteEndpoint(1, 0, 0);
ep0_state = ST_IDLE;
}
}
else
{
ep0_state = ST_IDLE;
}
}
///////////////////////////////////////////////////////////////////////
void ep1_txdone(void)
{
Hal4D12_ReadLastTransactionStatus(3);
}
///////////////////////////////////////////////////////////////////////
void ep1_rxdone(void)
{
Hal4D12_ReadLastTransactionStatus(2);
}
///////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -