📄 frm9602.c
字号:
}
void bitclr(USC adr, USC mask)
{
write_usb(adr,(read_usb(adr)&(~mask))); /*clr the bit (RMW) */
}
/***************Here are functions used to fufill USB spec.*****************/
void getdescriptor(void)
{
status_GETDESC=1;
desc_typ = usb_buf[3];
if(desc_typ==DEVICE)
desc_sze = DEV_DESC_SIZE;
else if(desc_typ==CONFIGURATION)
desc_sze = CFG_DESC_SIZE;
if (desc_sze > usb_buf[6])
desc_sze = usb_buf[6];
for(desc_idx=0; ((desc_idx<8) && (desc_idx<desc_sze));
desc_idx++) get_desc();
}
void get_desc(void)
{
USC desc_dta;
if(desc_typ==DEVICE)
{
desc_dta=DEV_DESC[desc_idx];
}
else if(desc_typ==CONFIGURATION)
desc_dta=CFG_DESC[desc_idx];
write_usb(TXD0,desc_dta);
}
void getstatus(void)
{
switch (usb_buf[0]&0x03)
{
case 0:
write_usb(TXD0,0);
break;
case 1:
write_usb(TXD0,0);
break;
case 2:
switch (usb_buf[4]&0x0f)
{
case 0:
if (stall0)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
case 1:
if (stall1)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
case 2:
if (stall2)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
case 3:
if (stall3)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
case 4:
if (stall4)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
case 5:
if (stall5)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
case 6:
if (stall6)write_usb(TXD0,1);else write_usb(TXD0,0);
break;
default:
break;
}
default:
break;
}
write_usb(TXD0,0);
}
void usb_alt(void)
{
USC dma_ev=0,dma_cnt;
evnt = read_usb(ALTEV);
if(evnt & RESET_A)
{
write_usb(NFSR,RST_ST);
write_usb(FAR,AD_EN+0);
write_usb(EPC0, 0x00);
FLUSHTX0;
write_usb(RXC0,RX_EN);
write_usb(NFSR,OPR_ST);
}
else if(evnt & SD3)
{
// write_usb(ALTMSK,RESUME_A+RESET_A);
// write_usb(NFSR,SUS_ST);
}
else if(evnt & RESUME_A)
{
write_usb(ALTMSK,SD3+RESET_A);
write_usb(NFSR,OPR_ST);
}
////////////////////////////////////////
if (evnt & DMA)
{//Now handle DMA events
dma_ev=read_usb(DMAEV);
if(dma_ev & DCNT)
{stop_dma();
}
if(dma_ev & DSIZ)
{}
if(dma_ev & DERR)
{}
if(dma_ev & DSHLT)
{}
if(dma_ev & NTGL)dtapid_TGL3PID=1;
else dtapid_TGL3PID=0;
}
////////////////////////////////////////
}
void clrfeature(void)
{
switch (usb_buf[0]&0x03)
{
case 0:
break;
case 1:
break;
case 2:
switch (usb_buf[4]&0x0f)
{
case 0:
stall0 = 0;
break;
case 1:
stall1 = 0;
break;
case 2:
stall2 = 0;
break;
case 3:
stall3 = 0;
break;
case 4:
stall4 = 0;
break;
case 5:
stall5 = 0;
break;
case 6:
stall6 = 0;
break;
default:
break;
}
break;
default:
break;
}
}
void setfeature(void)
{
switch (usb_buf[0]&0x03)
{
case 0:
break;
case 1:
break;
case 2:
switch (usb_buf[4]&0x0F)
{
case 0:
stall0 = 1;
break;
case 1:
stall1 = 1;
break;
case 2:
stall2 = 1;
break;
case 3:
stall3 = 1;
break;
case 4:
stall4 = 1;
break;
case 5:
stall5 = 1;
break;
case 6:
stall6 = 1;
break;
default:
break;
}
break;
default:
break;
}
}
void nak0(void)
{
if (status_GETDESC)
{
status_GETDESC=0;
FLUSHTX0;
write_usb(RXC0,RX_EN);
}
}
void setconfiguration(void)
{
usb_cfg = usb_buf[2];
if (usb_cfg!=0)
{
dtapid_TGL0PID = 0;
dtapid_TGL1PID = 0;
dtapid_TGL3PID = 0;
stall0 = stall1 =stall2= 0;
stall3 = stall4 =stall5= 0;
stall6=0;
FLUSHTX1;
write_usb(EPC1,EP_EN+01);
FLUSHRX1;
write_usb(EPC2,EP_EN+02);
FLUSHTX2;
write_usb(EPC3,EP_EN+03);
FLUSHRX2;
write_usb(EPC4,EP_EN+04);
FLUSHTX3;
write_usb(EPC5,/*EP_EN+*/05);
FLUSHRX3;
write_usb(EPC6,/*EP_EN+*/06);
write_usb(RXC1,RX_EN);
write_usb(RXC2,RX_EN);
//write_usb(RXC3,RX_EN);
}
else
{
write_usb(EPC1,0);
write_usb(EPC2,0);
write_usb(EPC3,0);
write_usb(EPC4,0);
write_usb(EPC5,0);
write_usb(EPC6,0);
}
}
/******************************************************************************/
// These functions are used to communicate with ASIC
/******************************************************************************/
void spp_write(USC byte)
{
nAddrStb=1;
nWRITE=0;
while(!ACK);
P0=byte;
STB=1;
while(ACK==1);
STB=0;
}
void set_ASIC(USC byte)
{
while(nWait);
nWRITE=0;// What is the default level of nWRITE??? Take for granted to be 1
P0=byte;
nAddrStb=0;
while(!nWait);
nAddrStb=1;
nWRITE=0;
}
void write_MCU(USC byte)
{
while(nWait);
nWRITE=0;
while(DReq);
P0=byte;
nDataStb=0;
while(!nWait);
nDataStb=1;
nWRITE=0;
}
USC read_MCU(void)
{
USC byte;
P0=0xFF;
nDataStb=1;
nWRITE=1;
while(nWait);
while(DReq);
nDataStb=0;
while(!nWait);
byte=P0;
nDataStb=1;
return byte;
nWRITE=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -