📄 periph.c
字号:
#pragma NOIV // Do not generate interrupt vectors
//-----------------------------------------------------------------------------
// File: periph.c
// Contents: Hooks required to implement USB peripheral function.
//
// Copyright (c) 1997 AnchorChips, Inc. All rights reserved
//-----------------------------------------------------------------------------
#include <ezusb.h>
#include <ezregs.h>
//#include <fx.h>
#include "ABSACC.H"
extern BOOL GotSUD; // Received setup data flag
extern BOOL Sleep;
extern BOOL Rwuen;
extern BOOL Selfpwr;
int nTimes=0;
int nCount=-1;
int i;
//int nCount1=-1;
int flag1,flag2;
int flag3,flag4;
int flag5,flag6;
int flag7,flag8;
int flagin4=1;////////////////////////////////
//int flagin5=1; //////////////////////////////
xdata char HPICL _at_ 0x8000;
xdata char HPICH _at_ 0x8002;
xdata char HPIAL _at_ 0x8004;
xdata char HPIAH _at_ 0x8006;
xdata char HPIDRL _at_ 0x800d; //0x8009;/
xdata char HPIDRH _at_ 0x800f; ///0x800b;
xdata char HPIDWL _at_ 0x800c; //0x8008;
xdata char HPIDWH _at_ 0x800e; //0x800a;
xdata char HPIDRLAUTO _at_ 0x8009;
xdata char HPIDRHAUTO _at_ 0x800b;
xdata char HPIDWLAUTO _at_ 0x8008;
xdata char HPIDWHAUTO _at_ 0x800a;
//int flag3;
//extern void a();
BYTE Configuration; // Current configuration
BYTE AlternateSetting; // Alternate settings
BYTE suspCount;
typedef struct _ISO_REPORT
{
WORD length;
WORD frame;
} ISO_REPORT, *PISO_REPORT;
//-----------------------------------------------------------------------------
// Task Dispatcher hooks
// The following hooks are called by the task dispatcher.
//-----------------------------------------------------------------------------
void TD_Init(void) // Called once at startup
{
IN07VAL |= bmEP3;//+bmEP4;//+bmEP3+bmEP4+bmEP5; //for change 041202 reback collect 1024
IN07IEN |= bmEP3;//+bmEP4;//+bmEP3+bmEP4+bmEP5;
// OUT07VAL |= bmEP2;
/// OUT07IEN |= bmEP2;
suspCount = 1;
OEA=0xff;
/* HPICL=1;
HPICH=1;
HPIAL=0X00;
HPIAH=0x15;
*/
Rwuen = TRUE; // Enable remote-wakeup
}
void TD_Poll(void) // Called repeatedly while the device is idle
{
}
BOOL TD_Suspend(void) // Called before the device goes into suspend mode
{
return(TRUE);
}
BOOL TD_Resume(void) // Called after the device resumes
{
return(TRUE);
}
//-----------------------------------------------------------------------------
// Device Request hooks
// The following hooks are called by the end point 0 device request parser.
//-----------------------------------------------------------------------------
BOOL DR_GetDescriptor(void)
{
return(TRUE);
}
BOOL DR_SetConfiguration(void) // Called when a Set Configuration command is received
{
Configuration = SETUPDAT[2];
return(TRUE); // Handled by user code
}
BOOL DR_GetConfiguration(void) // Called when a Get Configuration command is received
{
IN0BUF[0] = Configuration;
EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
return(TRUE); // Handled by user code
}
BOOL DR_SetInterface(void) // Called when a Set Interface command is received
{
AlternateSetting = SETUPDAT[2];
return(TRUE); // Handled by user code
}
BOOL DR_GetInterface(void) // Called when a Set Interface command is received
{
IN0BUF[0] = AlternateSetting;
EZUSB_SET_EP_BYTES(IN0BUF_ID,1);
return(TRUE); // Handled by user code
}
BOOL DR_GetStatus(void)
{
return(TRUE);
}
BOOL DR_ClearFeature(void)
{
return(TRUE);
}
BOOL DR_SetFeature(void)
{
return(TRUE);
}
BOOL DR_VendorCmnd(void)
{
return(FALSE);
}
//-----------------------------------------------------------------------------
// USB Interrupt Handlers
// The following functions are called by the USB interrupt jump table.
//-----------------------------------------------------------------------------
// Setup Data Available Interrupt Handler
void ISR_Sudav(void) interrupt 0
{
GotSUD = TRUE; // Set flag
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUDAV; // Clear SUDAV IRQ
}
// Setup Token Interrupt Handler
void ISR_Sutok(void) interrupt 0
{
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUTOK; // Clear SUTOK IRQ
}
void ISR_Sof(void) interrupt 0
{
EZUSB_IRQ_CLEAR();
USBIRQ = bmSOF;
}
void ISR_Ures(void) interrupt 0
{
//
// Arm all of the OUT endpoints so they can accept data
//
EPIO[IN3BUF_ID].bytes = 0;
EZUSB_IRQ_CLEAR();
USBIRQ = bmURES; // Clear URE
}
void ISR_IBN(void) interrupt 0
{
// ISR for the IN Bulk NAK (IBN) interrupt.
}
void ISR_Susp(void) interrupt 0
{
Sleep = TRUE;
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUSP;
}
void ISR_Ep0in(void) interrupt 0
{
}
void ISR_Ep0out(void) interrupt 0
{
}
void ISR_Ep1in(void) interrupt 0
{
}
void ISR_Ep1out(void) interrupt 0
{
}
void ISR_Ep2in(void) interrupt 0
{
}
void ISR_Ep2out(void) interrupt 0
{
}
void ISR_Ep3in(void) interrupt 0
{
if(nCount==-1)
{
HPICL=1;
HPICH=1;
HPIAL=0xff;
HPIAH=0x14;
flag1=HPIDRL;
flag2=HPIDRH;
if(flag1==0x08&&flag2==0x08)
{
HPIAL=0x00;
HPIAH=0x15;
nCount=0;
}
}
if(nCount>=0)
{
for(i=0;i<63;)
{
IN3BUF[i++] =HPIDRLAUTO;//(nCount*32+i/2+100)%256;
IN3BUF[i++] =HPIDRHAUTO;//(nCount*32+i/2+100)/256;
}
/* else
{
for(i=0;i<63;)
{
IN3BUF[i++] =nTimes;
IN3BUF[i++] =0;
}
}
*/
nCount++;
if(nCount==48)
{
/* nTimes++;
if(nTimes>=98)
nTimes=0;
*/
nCount=-1;
HPICL=1;
HPICH=1;
HPIAL=0x0ff;
HPIAH=0x14;
HPIDWL=0x01;
HPIDWH=0x01;
}
// Arm the IN endpoint
IN3BC = 64; //at this time, automatically set INCS.IN2BSY=1;
}
else
IN3BC = 0;
// clear the IRQ
EZUSB_IRQ_CLEAR();
IN07IRQ = bmEP3;
}
void ISR_Ep3out(void) interrupt 0
{
}
void ISR_Ep4in(void) interrupt 0
{
/* if(nCount==-1)
{
HPICL=1;
HPICH=1;
HPIAL=0xfe;
HPIAH=0x14;
flag1=HPIDRL;
flag2=HPIDRH;
if(flag1==0x08&&flag2==0x08)
{
HPIAL=0x00;
HPIAH=0x19;
nCount=0;
}
}
if(nCount>=0)
{
for(i=0;i<63;)
{
IN4BUF[i++] =HPIDRLAUTO;
IN4BUF[i++] =HPIDRHAUTO;
}
nCount++;
if(nCount==16)
{
nCount=-1;
HPICL=1;
HPICH=1;
HPIAL=0x0fe;
HPIAH=0x14;
HPIDWL=0x01;
HPIDWH=0x01;
}
// Arm the IN endpoint
IN4BC = 64; //at this time, automatically set INCS.IN2BSY=1;
}
else
IN4BC = 0;
// clear the IRQ
EZUSB_IRQ_CLEAR();
IN07IRQ = bmEP4; */
}
void ISR_Ep4out(void) interrupt 0
{
}
void ISR_Ep5in(void) interrupt 0
{
}
void ISR_Ep5out(void) interrupt 0
{
}
void ISR_Ep6in(void) interrupt 0
{
}
void ISR_Ep6out(void) interrupt 0
{
}
void ISR_Ep7in(void) interrupt 0
{
}
void ISR_Ep7out(void) interrupt 0
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -