📄 gpif1.lst
字号:
// Set EP6GPIF Programmable Flag STOP, overrides Transaction Count
void SetEP6GPIFPFSTOP( void )
{
EP6GPIFPFSTOP = 0x01;
}
// Set EP8GPIF Programmable Flag STOP, overrides Transaction Count
void SetEP8GPIFPFSTOP( void )
{
EP8GPIFPFSTOP = 0x01;
}
// write single byte to PERIPHERAL, using GPIF
void Peripheral_SingleByteWrite( BYTE gdata )
{
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
{
;
}
XGPIFSGLDATLX = gdata; // trigger GPIF
// ...single byte write transaction
}
// write single word to PERIPHERAL, using GPIF
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 byte from PERIPHERAL, using GPIF
void Peripheral_SingleByteRead( BYTE xdata *gdata )
{
static BYTE 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 byte read transaction
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
{
;
}
C51 COMPILER V6.23a GPIF1 10/26/2005 19:02:16 PAGE 8
// using register(s) in XDATA space,
*gdata = XGPIFSGLDATLNOX; // ...GPIF reads byte from PERIPHERAL
}
// read single word from PERIPHERAL, using GPIF
void Peripheral_SingleWordRead( WORD xdata *gdata )
{
BYTE 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 GPIFTRIGWR 0
#define GPIFTRIGRD 4
#define GPIF_EP2 0
#define GPIF_EP4 1
#define GPIF_EP6 2
#define GPIF_EP8 3
// write byte(s)/word(s) to PERIPHERAL, using GPIF and EPxFIFO
// if EPx WORDWIDE=0 then write byte(s)
// if EPx WORDWIDE=1 then write word(s)
void Peripheral_FIFOWrite( BYTE FIFO_EpNum )
{
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
{
;
}
// trigger FIFO write transaction(s), using SFR
GPIFTRIG = FIFO_EpNum; // R/W=0, EP[1:0]=FIFO_EpNum for EPx write(s)
}
// read byte(s)/word(s) from PERIPHERAL, using GPIF and EPxFIFO
// if EPx WORDWIDE=0 then read byte(s)
// if EPx WORDWIDE=1 then read word(s)
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)
C51 COMPILER V6.23a GPIF1 10/26/2005 19:02:16 PAGE 9
}
void main( void )
{
WORD xdata wData = 0x0000;
BYTE xdata bData = 0x00;
WORD myi = 0x0000;
BOOL bResult = 1;
OtherInit( );
GpifInit( );
if( bResult == 0 )
{ // stub out unused functions; avoid UNCALLED SEGMENT link error
Peripheral_SingleWordWrite( 0x5678 );
Peripheral_SingleByteWrite( 0xAA );
Peripheral_SingleWordRead( &wData );
Peripheral_SingleByteRead( &bData );
// GPIF automatically throttles when performing FIFO read(s)/write(s)
// ...what this means is that it doesn't transition from IDLE, while...
// ...the EPx OUT FIFO is empty... OR ...the EPx IN FIFO is full...
Peripheral_FIFOWrite( GPIF_EP2 ); // GPIF will not read from an empty FIFO
Peripheral_FIFORead( GPIF_EP8 ); // GPIF will not write to a full FIFO
Peripheral_SetEP2GPIFTC( 0x0000 );
Peripheral_SetEP4GPIFTC( 0x0000 );
Peripheral_SetEP6GPIFTC( 0x0000 );
Peripheral_SetEP8GPIFTC( 0x0000 );
SetEP2GPIFFLGSEL( GPIF_FLGSELPF );
SetEP4GPIFFLGSEL( GPIF_FLGSELEF );
SetEP6GPIFFLGSEL( GPIF_FLGSELFF );
SetEP8GPIFFLGSEL( GPIF_FLGSELPF );
SetEP2GPIFPFSTOP(); // use GPIF_PF to transition GPIF to done
SetEP4GPIFPFSTOP(); // use GPIF_PF to transition GPIF to done
SetEP6GPIFPFSTOP(); // use GPIF_PF to transition GPIF to done
SetEP8GPIFPFSTOP(); // use GPIF_PF to transition GPIF to done
}
Peripheral_SetAddress( 0x0155 );
while( 1 )
{ // ...the EPx WORDWIDE bits must to be set to
// ...configure PORTD as FD[15:8] for single transactions
if( EP2FIFOCFG & 0x01 ) // If 16-bit mode - EPx WORDWIDE=1
{ // illustrate use of efficient 16 bit functions
Peripheral_SingleWordWrite( 0xAA55 );
Peripheral_SingleWordRead( &wData );
}
else
{
Peripheral_SingleByteWrite( 0xA5 );
Peripheral_SingleByteRead( &bData );
}
}
}
#endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 116 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 135 ----
PDATA SIZE = ---- ----
C51 COMPILER V6.23a GPIF1 10/26/2005 19:02:16 PAGE 10
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -