📄 gpif.c
字号:
//---------------------------------------------------------------------------//
// GPIF Program Code for Single
// DO NOT EDIT ...
const char xdata WaveData[128] =
{
// Wave 0
/* LenBr */ 0x02, 0x02, 0x01, 0x01, 0x01, 0xF0, 0x06, 0x07,
/* Opcode*/ 0x00, 0x01, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00,
/* Output*/ 0x3F, 0x3F, 0x35, 0x35, 0x37, 0x37, 0x3E, 0x3F,
/* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F,
// Wave 1
/* LenBr */ 0x02, 0x09, 0x3F, 0x01, 0x01, 0x01, 0x01, 0x07,
/* Opcode*/ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
/* Output*/ 0x3F, 0x3E, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
/* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F,
// Wave 2
/* LenBr */ 0x02, 0x02, 0x03, 0x01, 0x01, 0x01, 0x01, 0x07,
/* Opcode*/ 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x00,
/* Output*/ 0x3F, 0x35, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
/* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F,
// Wave 3
/* LenBr */ 0x02, 0x01, 0x03, 0x02, 0x03, 0x05, 0x01, 0x07,
/* Opcode*/ 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00,
/* Output*/ 0x3F, 0x37, 0x33, 0x37, 0x3F, 0x3E, 0x3E, 0x3F,
/* LFun */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F,
};
// END DO NOT EDIT
// DO NOT EDIT ...
// END DO NOT EDIT
// DO NOT EDIT ...
const char data InitData[7] =
{
/* Regs */ 0xA0,0x00,0x00,0x3F,0x8E,0xE4,0x00
};
// END DO NOT EDIT
// GPIF Program Code
// DO NOT EDIT ...
#include "fx2.h"
#include "fx2regs.h"
#include "fx2sdly.h" // SYNCDELAY macro
#include "gpif.h"
// END DO NOT EDIT
//-------------------------------------------------------------------//
// TO DO: You may add additional code below.
void GpifInit( void )
{
IFCONFIG = 0x8E;
// IFCLKSRC=1 , FIFOs executes on internal clk source
// xMHz=1 , 48MHz internal clk rate
// IFCLKOE=0 , Don't drive IFCLK pin signal at 48MHz
// IFCLKPOL=0 , Don't invert IFCLK pin signal from internal clk
// ASYNC=1 , master samples asynchronous
// GSTATE=1 , Drive GPIF states out on PORTE[2:0], debug WF
// IFCFG[1:0]=10, FX2 in GPIF master mode
GPIFABORT = 0xFF; // abort any waveforms pending
// Configure GPIF Address pins, output initial value,
PORTCCFG = 0xFF; // [7:0] as alt. func. GPIFADR[7:0]
OEC = 0xFF; // and as outputs
PORTECFG |= 0x80; // [8] as alt. func. GPIFADR[8]
OEE |= 0x80; // and as output
// ...OR... tri-state GPIFADR[8:0] pins
// PORTCCFG = 0x00; // [7:0] as port I/O
// OEC = 0x00; // and as inputs
// PORTECFG &= 0x7F; // [8] as port I/O
// OEE &= 0x7F; // and as input
// GPIF address pins update when GPIFADRH/L written
SYNCDELAY; //
GPIFADRH = 0x00; // bits[7:1] always 0
SYNCDELAY; //
GPIFADRL = 0x00; // point to PERIPHERAL address 0x0000
// Configure GPIF FlowStates registers for Wave 0 of WaveData
/* FLOWSTATE = 0x00;//FlowStates[ 0 ];
FLOWLOGIC = 0x00;//FlowStates[ 1 ];
FLOWEQ0CTL = 0x00;//FlowStates[ 2 ];
FLOWEQ1CTL = 0x00;//FlowStates[ 3 ];
FLOWHOLDOFF = 0x00;//FlowStates[ 4 ];
FLOWSTB = 0x00;//FlowStates[ 5 ];
FLOWSTBEDGE = 0x00;//FlowStates[ 6 ];
FLOWSTBHPERIOD = 0x00;//FlowStates[ 7 ];*/
}
void Peripheral_SetEP6GPIFTC( WORD xfrcnt )
{
SYNCDELAY; //
EP6GPIFTCH = xfrcnt >> 8; // setup transaction count
SYNCDELAY; //
EP6GPIFTCL = ( BYTE )xfrcnt;
}
void SetEP6GPIFPFSTOP( void )
{
EP6GPIFPFSTOP = 0x01;
}
void Peripheral_SingleWordWrite( WORD gdata )
{
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
{
;
}
// using register(s) in XDATA space
XGPIFSGLDATH = gdata >> 8;
XGPIFSGLDATLX = gdata; // trigger GPIF
// ...single word write transaction
}
// read single word from PERIPHERAL, using GPIF
void Peripheral_SingleWordRead( WORD xdata *gdata )
{
BYTE xdata g_data = 0x00;
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
{
;
}
// using register(s) in XDATA space, dummy read
g_data = XGPIFSGLDATLX; // trigger GPIF
// ...single word read transaction
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
{
;
}
// using register(s) in XDATA space, GPIF reads word from PERIPHERAL
*gdata = ( ( WORD )XGPIFSGLDATH << 8 ) | ( WORD )XGPIFSGLDATLNOX;
}
#define GPIFTRIGRD 4
#define GPIF_EP2 0
#define GPIF_EP4 1
#define GPIF_EP6 2
#define GPIF_EP8 3
void Peripheral_FIFORead( BYTE FIFO_EpNum )
{
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 GPIF Done bit
{
;
}
// trigger FIFO read transaction(s), using SFR
GPIFTRIG = GPIFTRIGRD | FIFO_EpNum; // R/W=1, EP[1:0]=FIFO_EpNum for EPx read(s)
}
//---------------------------------------------------------------------------//
/*void GPIF_LOAD_SINGLE()//单通道
{
}
void GPIF_LOAD_DOUBLE()//双通道
{
}
void GPIF_LOAD_TRI() //三通道
{
}
void GPIF_LOAD_QUAD() //四通道
{
}
void GPIF_LOAD_PWDW() //AD 掉电模式
{
Peripheral_SingleWordWrite(0x2000);//Set AD Power Down
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -