?? bulk_test.c
字號:
#pragma NOIV // Do not generate interrupt vectors
//-----------------------------------------------------------------------------
// File: portcstb.c
// Contents: Hooks required to implement USB peripheral function.
// Code written for FX2 100-pin REVD...
// This firmware is used to demonstrate the PORTC STROBE FEATURE
// Copyright (c) 2001 Cypress Semiconductor All rights reserved
//-----------------------------------------------------------------------------
#include "fx2.h"
#include "fx2regs.h"
#include "fx2sdly.h" // SYNCDELAY macro
extern BOOL GotSUD; // Received setup data flag
extern BOOL Sleep;
extern BOOL Rwuen;
extern BOOL Selfpwr;
BYTE Read(BYTE add);//讀數據
BYTE Configuration; // Current configuration
BYTE AlternateSetting; // Alternate settings
// EZUSB FX2 PORTA i/o...
//sbit LATRIGWR = IOA ^ 0; // alt. func., INT0#
//sbit LATRIGRD = IOA ^ 1; // alt. func., INT1#
sbit NPD = IOA ^ 2;//PA2
sbit RST = IOA ^ 3;//PA3
sbit NCS = IOA ^ 4;//PA4
sbit MISO = IOA ^ 5;//PA5
sbit SCLK = IOA ^ 6;//PA6
sbit MOSI = IOA ^ 7;//PA7
sbit LEN = IOB ^ 7;//PB7
// EZUSB FX2 PORTE is not bit-addressable...
// use this global variable when (de)asserting debug LEDs...
//-----------------------------------------------------------------------------
// Task Dispatcher hooks
// The following hooks are called by the task dispatcher.
//-----------------------------------------------------------------------------
void TD_Init( void )
{ // Called once at startup
CPUCS = 0x10 ;
IFCONFIG = 0xC0;
EP1OUTCFG = 0xB0;
EP1INCFG = 0xB0;
SYNCDELAY;
OEA = 0xFC; //使能讀寫允許的引腳PA2、PA3、PA4、PA5、PA6、PA7、
OEB = 0x80; //PB7
Rwuen = TRUE; // Enable remote-wakeup
}
void TD_Poll( void )
{ // Called repeatedly while the device is idle
if( !( EP1OUTCS & 0x02 ) && EP1OUTBC )//BUSY=0,OUT的緩沖區數據有效;若
{
if(EP1OUTBUF[0]==0x11 && EP1OUTBUF[1]==0x22)
{
LEN=1;
EZUSB_Delay(50);
LEN=0;
EZUSB_Delay(50);
NPD = 0;//NPD->0 ->1供電
NPD=1;
RST=1;//Reset->0 ->1復位
EZUSB_Delay1ms();//Delay(>=10us);
RST=0;
SCLK=1;//時鐘閑置時上拉
NCS=1;//NCS->1 ->0芯片選擇
NCS=0;
EP1INBUF[0]=Read(0x1f);
EZUSB_Delay1ms();
EP1INBUF[1]=Read(0x00);//PID 0x17
EZUSB_Delay1ms();
EP1INBUF[2]=Read(0x01);
EZUSB_Delay1ms();
EP1INBUF[3]=Read(0x02);
EZUSB_Delay1ms();
EP1INBUF[4]=Read(0x03);
EZUSB_Delay1ms();
EP1INBUF[5]=Read(0x04);
EZUSB_Delay1ms();
EP1INBUF[6]=Read(0x0a);
EZUSB_Delay1ms();
EP1INBUF[7]=Read(0x0e);
EZUSB_Delay1ms();
EP1INBUF[8]=Read(0x10);
EZUSB_Delay1ms();
EP1INBUF[9]=Read(0x11);
EZUSB_Delay1ms();
EP1INBUF[10]=Read(0x3f);
EZUSB_Delay1ms();
EP1INBUF[11]=Read(0x60);
EZUSB_Delay1ms();
EP1INBUF[12]=Read(0x3D);
EZUSB_Delay1ms();
EP1INBUF[13]=(BYTE)MISO;
EZUSB_Delay1ms();
EP1INBC=20;// 設置端點為IN傳輸,BUSY位自動置1
}
if(EP1OUTBUF[0]==0x11 && EP1OUTBUF[1]==0x33)
{
NCS=1;//A3080停止工作
}
if(EP1OUTBUF[0]==0x22 && EP1OUTBUF[1]==0x33)
{
LEN=1;
EZUSB_Delay(50);
LEN=0;
EZUSB_Delay(50);
EP1INBUF[0]=0x11;
EP1INBC=20;// 設置端點為IN傳輸,BUSY位自動置1
}
EP1OUTBC = 0x00;
}
}
BYTE Read(BYTE add)
{
char a_add[9];
BYTE data0;
BYTE temp_data0;
char i;
//1、寫地址
a_add[0]=0;//讀數據標志位
a_add[1]=(add & 0x40)>>6;
a_add[2]=(add & 0x20)>>5;
a_add[3]=(add & 0x10)>>4;
a_add[4]=(add & 0x08)>>3;
a_add[5]=(add & 0x04)>>2;
a_add[6]=(add & 0x02)>>1;
a_add[7]=add & 0x01;
for(i=0;i<8;i++)//寫地址
{
SCLK=0;
EZUSB_Delay1ms();
MOSI=a_add[i];
EZUSB_Delay1ms();
SCLK=1;
EZUSB_Delay1ms();
}
EZUSB_Delay1ms();//Tread>=50us
SCLK=0;
SCLK=1;
for(i=0;i<8;i++)//讀數據
{
SCLK=1;
EZUSB_Delay1ms();
//data0 += (BYTE)MISO<<(7-i);
temp_data0 = MISO;
data0 +=temp_data0<<(7-i);
EZUSB_Delay1ms();
SCLK=0;
EZUSB_Delay1ms();
SCLK=1;
}
LEN=1;
EZUSB_Delay(50);
LEN=0;
EZUSB_Delay(50);
return data0;
}
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);
}
BOOL DR_VendorCmnd( void )
{
return(TRUE);
}
//-----------------------------------------------------------------------------
// 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
{
if (EZUSB_HIGHSPEED())
{
pConfigDscr = pHighSpeedConfigDscr;
pOtherConfigDscr = pFullSpeedConfigDscr;
}
else
{
pConfigDscr = pFullSpeedConfigDscr;
pOtherConfigDscr = pHighSpeedConfigDscr;
}
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;
pOtherConfigDscr = pFullSpeedConfigDscr;
}
else
{
pConfigDscr = pFullSpeedConfigDscr;
pOtherConfigDscr = pHighSpeedConfigDscr;
}
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 + -