?? 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 "fx2.h"
#include "fx2regs.h"
#include "io.h"
#include "key.h"
#include "led.h"
#include "serial.h"
#include "eeprom.h"
#include "fx2sdly.h"
extern BOOL GotSUD; // Received setup data flag
extern BOOL Sleep;
extern BOOL Rwuen;
extern BOOL Selfpwr;
BYTE Configuration; // Current configuration
BYTE AlternateSetting; // Alternate settings
//-----------------------------------------------------------------------------
// Task Dispatcher hooks
// The following hooks are called by the task dispatcher.
//-----------------------------------------------------------------------------
void TD_Init(void) // Called once at startup
{
REVCTL = 0x03; // MUST set REVCTL.0 and REVCTL.1 to 1
SYNCDELAY;
BREAKPT &= ~bmBPEN; // to see BKPT LED go out TGE
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
{
EP0BUF[0] = Configuration;
EP0BCH = 0;
EP0BCL = 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
{
EP0BUF[0] = AlternateSetting;
EP0BCH = 0;
EP0BCL = 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);
}
#define VR_UPLOAD 0xc0
#define VR_DOWNLOAD 0x40
#define ZSUSB20DDB_VENDOR_REQUEST_LED_DISP 0xB0 //led顯示
#define ZSUSB20DDB_VENDOR_REQUEST_KEY_READ 0xB1 //鍵盤讀取
#define ZSUSB20DDB_VENDOR_REQUEST_EEPROM_ACCESS 0xB2 //EEPROM訪問
#define ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS 0xB3 //SRAM訪問
#define ZSUSB20DDB_VENDOR_REQUEST_SERIAL_ACCESS 0xB4 //串口訪問
BOOL DR_VendorCmnd(void)
{
WORD addr, len, bc,length;
WORD i;
BYTE flag;
BYTE xdata *point;
len = SETUPDAT[6];
len |= (SETUPDAT[7] << 8);
switch(SETUPDAT[1])
{
case ZSUSB20DDB_VENDOR_REQUEST_LED_DISP: //led顯示
{
DispBuf[SETUPDAT[3]&3] = SETUPDAT[2]; //wValueH為第幾位了led,wValueL為顯示值
break;
}
case ZSUSB20DDB_VENDOR_REQUEST_KEY_READ: //鍵盤讀取
{
if(OKey_Value != 0xFF)
{
EP0BUF[0] = OKey_Value;
EP0BCH = 0;
EP0BCL = 1;
OKey_Value = 0xFF;
}
else
{
EP0BCH = 0;
EP0BCL = 0;
}
break;
}
case ZSUSB20DDB_VENDOR_REQUEST_EEPROM_ACCESS:
case ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS:
{
addr = SETUPDAT[2]; // Get address and length
addr |= SETUPDAT[3] << 8;
// Is this an upload command ?
if(SETUPDAT[0] == VR_UPLOAD)
{
while(len) // Move requested data through EP0IN
{ // one packet at a time.
if(len < 64)
bc = len;
else
bc = 64;
// Is this a RAM upload ?
if(SETUPDAT[1] == ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS)
{
for(i=0; i<bc; i++)
*(EP0BUF+i) = *((BYTE xdata *)addr+i);
}
else
{
EEPROMRead(addr,bc,(WORD)EP0BUF);
}
EP0BCH = 0;
EP0BCL = (BYTE)bc; // Arm endpoint
addr += bc;
len -= bc;
while(EP0CS & bmEPBUSY);
}
}
// Is this a download command ?
else if(SETUPDAT[0] == VR_DOWNLOAD)
{
while(len) // Move new data through EP0OUT
{ // one packet at a time.
// Arm endpoint - do it here to clear (after sud avail)
EP0BCH = 0;
EP0BCL = 0; // Clear bytecount to allow new data in; also stops NAKing
while(EP0CS & bmEPBUSY);
bc = EP0BCL; // Get the new bytecount
// Is this a RAM download ?
if(SETUPDAT[1] == ZSUSB20DDB_VENDOR_REQUEST_SRAM_ACCESS)
{
for(i=0; i<bc; i++)
*((BYTE xdata *)addr+i) = *(EP0BUF+i);
}
else
EEPROMWrite(addr,bc,(WORD)EP0BUF);
addr += bc;
len -= bc;
}
}
break;
}
case ZSUSB20DDB_VENDOR_REQUEST_SERIAL_ACCESS:
{
flag = SETUPDAT[2];
// Is this an upload command ?
if(SETUPDAT[0] == VR_UPLOAD)
{
if(flag == 0) ES0 = 0;
else ES1 = 0;
length = ((flag == 0)?ReceiveCount0:ReceiveCount1);
point = ((flag == 0)?ReceiveBuf0:ReceiveBuf1);
if(length > len) //只能傳輸小于或等于請求長度的數據
length = len; //limit to the requested length
while(length) // Move requested data through EP0IN
{
// one packet at a time.
if(length < 64)
bc = length;
else
bc = 64;
for(i=0; i<bc; i++)
*(EP0BUF+i) = *(point+i);
//set length and arm Endpoint
EP0BCH = 0;
EP0BCL = bc;
length -= bc;
point += bc;
while(EP0CS & bmEPBUSY);
}
EP0BCH = 0;
EP0BCL = 0;
if(flag == 0)
{
ReceiveCount0 = 0;
ES0 = 1;
}
else
{
ReceiveCount1 = 0;
ES1 = 1;
}
}
// Is this a download command ?
else if(SETUPDAT[0] == VR_DOWNLOAD)
{
while(len) // Move new data through EP0OUT
{ // one packet at a time.
// Arm endpoint - do it here to clear (after sud avail)
EP0BCH = 0;
EP0BCL = 0; // Clear bytecount to allow new data in; also stops NAKing
while(EP0CS & bmEPBUSY);
bc = EP0BCL; // Get the new bytecount
Serial_SendString((WORD)EP0BUF,bc,flag);
len -= bc;
}
}
break;
}
default:return(TRUE);
}
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; // Clear SOF IRQ
}
void ISR_Ures(void) interrupt 0
{
// whenever we get a USB reset, we should revert to full speed mode
pConfigDscr = pFullSpeedConfigDscr;
((CONFIGDSCR xdata *) pConfigDscr)->type = CONFIG_DSCR;
pOtherConfigDscr = pHighSpeedConfigDscr;
((CONFIGDSCR xdata *) pOtherConfigDscr)->type = OTHERSPEED_DSCR;
EZUSB_IRQ_CLEAR();
USBIRQ = bmURES; // Clear URES IRQ
}
void ISR_Susp(void) interrupt 0
{
Sleep = TRUE;
EZUSB_IRQ_CLEAR();
USBIRQ = bmSUSP;
}
void ISR_Highspeed(void) interrupt 0
{
if (EZUSB_HIGHSPEED())
{
pConfigDscr = pHighSpeedConfigDscr;
((CONFIGDSCR xdata *) pConfigDscr)->type = CONFIG_DSCR;
pOtherConfigDscr = pFullSpeedConfigDscr;
((CONFIGDSCR xdata *) pOtherConfigDscr)->type = OTHERSPEED_DSCR;
}
EZUSB_IRQ_CLEAR();
USBIRQ = bmHSGRANT;
}
void ISR_Ep0ack(void) interrupt 0
{
}
void ISR_Stub(void) interrupt 0
{
}
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_Ep2inout(void) interrupt 0
{
}
void ISR_Ep4inout(void) interrupt 0
{
}
void ISR_Ep6inout(void) interrupt 0
{
}
void ISR_Ep8inout(void) interrupt 0
{
}
void ISR_Ibn(void) interrupt 0
{
}
void ISR_Ep0pingnak(void) interrupt 0
{
}
void ISR_Ep1pingnak(void) interrupt 0
{
}
void ISR_Ep2pingnak(void) interrupt 0
{
}
void ISR_Ep4pingnak(void) interrupt 0
{
}
void ISR_Ep6pingnak(void) interrupt 0
{
}
void ISR_Ep8pingnak(void) interrupt 0
{
}
void ISR_Errorlimit(void) interrupt 0
{
}
void ISR_Ep2piderror(void) interrupt 0
{
}
void ISR_Ep4piderror(void) interrupt 0
{
}
void ISR_Ep6piderror(void) interrupt 0
{
}
void ISR_Ep8piderror(void) interrupt 0
{
}
void ISR_Ep2pflag(void) interrupt 0
{
}
void ISR_Ep4pflag(void) interrupt 0
{
}
void ISR_Ep6pflag(void) interrupt 0
{
}
void ISR_Ep8pflag(void) interrupt 0
{
}
void ISR_Ep2eflag(void) interrupt 0
{
}
void ISR_Ep4eflag(void) interrupt 0
{
}
void ISR_Ep6eflag(void) interrupt 0
{
}
void ISR_Ep8eflag(void) interrupt 0
{
}
void ISR_Ep2fflag(void) interrupt 0
{
}
void ISR_Ep4fflag(void) interrupt 0
{
}
void ISR_Ep6fflag(void) interrupt 0
{
}
void ISR_Ep8fflag(void) interrupt 0
{
}
void ISR_GpifComplete(void) interrupt 0
{
}
void ISR_GpifWaveform(void) interrupt 0
{
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -