📄 gpifpio0.c
字号:
EP4AUTOINLENL = 0x00;
EP6AUTOINLENH = 0x00;
EP6AUTOINLENL = 0x40; // limit EP6IN to 64 bytes for 1.1 speeds
EP8AUTOINLENH = 0x00;
EP8AUTOINLENL = 0x40; // limit EP8IN to 64 bytes for 1.1 speeds
// end interface intialization
// we are just using the default values, yes this is not necessary...
EP1OUTCFG = EP1INCFG = 0xA0;
// out endpoints do not come up armed
// since the defaults are double buffered we must write
// ...dummy byte counts twice
EP2BCL = EP4BCL = 0x80; // arm EP2OUT & EP4OUT by writing to
// ...the byte count w/skip
EP2BCL = EP4BCL = 0x80; // arm EP2OUT & EP4OUT by writing to
// ...the byte count w/skip
}
// write byte to PERIPHERAL, using GPIF
bit Peripheral_SingleByteWrite( WORD gaddr, BYTE gdata )
{
BYTE transaction_err = 0x00;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
XGPIFSGLDATLX = gdata; // initiate GPIF write transaction
while( !( GPIFIDLECS & 0x80 ) ) // poll GPIFIDLECS.7 Done bit
{
if( ++transaction_err > TMOUT ) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // error has occurred
}
}
return( 1 );
}
// write word to PERIPHERAL, using GPIF
bit Peripheral_SingleWordWrite( WORD gaddr, WORD gdata )
{
BYTE transaction_err = 0x00;
WORD xdata temp;
temp = gaddr;
//temp = 0x0111;
temp = 0x00BE;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
// using the register(s) in SFR space
XGPIFSGLDATH = gdata >> 8;
XGPIFSGLDATLX = gdata; // initiate GPIF write transaction
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFIDLECS.7 Done bit
{
if( ++transaction_err > TMOUT ) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // error has occurred
}
}
return( 1 );
}
// read byte from PERIPHERAL, using GPIF
bit Peripheral_SingleByteRead( WORD gaddr, BYTE xdata *gdata )
{
static BYTE g_data = 0x00;
BYTE transaction_err = 0x00;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
g_data = XGPIFSGLDATLX; // dummy read to initiate GPIF read transaction
while( !( GPIFIDLECS & 0x80 ) ) // poll GPIFIDLECS.7 Done bit
{
if( ++transaction_err > TMOUT ) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // error has occurred
}
}
*gdata = XGPIFSGLDATLNOX;
return( 1 );
}
// read word from PERIPHERAL, using GPIF
bit Peripheral_SingleWordRead( WORD gaddr, WORD xdata *gdata )
{
BYTE g_data = 0x00;
BYTE transaction_err = 0x00;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
g_data = XGPIFSGLDATLX; // dummy read to initiate GPIF read transaction
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFIDLECS.7 Done bit
{
if( ++transaction_err > TMOUT ) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // error has occurred
}
}
*gdata = ( ( WORD )XGPIFSGLDATH << 8 ) | ( WORD )XGPIFSGLDATLNOX;
return( 1 );
}
// write byte(s) to PERIPHERAL, using GPIF, and EP2FIFO
bit Peripheral_EP2FIFOByteWrite( WORD gaddr, WORD xfrcnt )
{
BYTE transaction_err = 0x00;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
EP2GPIFTCH = xfrcnt >> 8; // setup transaction count
EP2GPIFTCL = ( BYTE )xfrcnt;
// replaces above xdata register to SFR mov access
GPIFTRIG = 0x00; // R/W=0, EP[1:0]=00 for EP2 write(s)
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFIDLECS.7 Done bit
{ // transaction completed
if( ++transaction_err > TMOUT) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // error has occurred
}
}
return( 1 );
}
// write word(s) to PERIPHERAL, using GPIF, and EP2FIFO
bit Peripheral_EP2FIFOWordWrite( WORD gaddr, WORD xfrcnt )
{
BYTE transaction_err = 0x00;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
EP2GPIFTCH = xfrcnt >> 8; // setup transaction count
EP2GPIFTCL = ( BYTE )xfrcnt;
// FIFO -> GPIF transaction(s)
// replaces above xdata register to SFR mov access
GPIFTRIG = 0x00; // R/W=0, EP[1:0]=00 for EP2 write(s)
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFIDLECS.7 Done bit
{ // transaction completed
if( ++transaction_err > TMOUT) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // error has occurred
}
}
return( 1 );
}
// read byte(s) from PERIPHERAL, using GPIF, and EP6FIFO
bit Peripheral_EP6FIFOByteRead( WORD gaddr, WORD xfrcnt )
{
BYTE transaction_err = 0x00;
BYTE gxfr = 0x00;
// if GPIF addr is static then this is not necessary,
// ...initialize these registers in GPIFInit();
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
// if GPIF transaction count is static then this is not necessary,
// ...initialize these registers in GPIFInit();
EP6GPIFTCH = xfrcnt >> 8; // setup transaction count
EP6GPIFTCL = ( BYTE )xfrcnt;
// replaces above xdata register to SFR mov access
GPIFTRIG = 0x06; // R/W=1, EP[1:0]=10 for EP6 read(s)
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFIDLECS.7 GPIF Done bit
{
if( ++transaction_err > TMOUT ) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // an error has occurred
}
}
// assumes transaction count is buffer size and AUTOIN=0 disabled...
INPKTEND = 0x06; // 8051 stobes EP6FIFO packet end
// ... to commit pkt to USB ep6
return( 1 );
}
// read word(s) from PERIPHERAL, using GPIF, and EP6FIFO
bit Peripheral_EP6FIFOWordRead( WORD gaddr, WORD xfrcnt )
{
BYTE transaction_err = 0x00;
BYTE gxfr = 0x00;
GPIFADRH = gaddr >> 8;
GPIFADRL = ( BYTE )gaddr; // setup GPIF address
EP6GPIFTCH = xfrcnt >> 8; // setup transaction count
EP6GPIFTCL = ( BYTE )xfrcnt;
// replaces above xdata register to SFR mov access
GPIFTRIG = 0x06; // R/W=1, EP[1:0]=10 for EP6 read(s)
while( !( GPIFTRIG & 0x80 ) ) // poll GPIFIDLECS.7 GPIF Done bit
{
if( ++transaction_err > TMOUT ) // trap GPIF transaction for TMOUT
{
GPIFABORT = 0x01;
return( 0 ); // an error has occurred
}
}
// assumes transaction count is buffer size and AUTOIN=0 disabled...
INPKTEND = 0x06; // 8051 stobes EP6FIFO packet end
// ... to commit pkt to USB ep6
return( 1 );
}
void main( void )
{
WORD xdata wData = 0x0000;
BYTE xdata bData = 0x00;
WORD myi = 0x0000;
bit bResult = 1; // bResult will return as 0 if an error has occurred
OtherInit( );
GpifInit( );
if(bResult == 0) // stub out unused functions; avoid "UNCALLED SEGMENT" link error
{
bResult = Peripheral_SingleWordWrite( 0x2345, 0x5678 );
bResult = Peripheral_SingleByteWrite( 0x0055, 0xAA );
bResult = Peripheral_SingleWordRead( 0x0169, &wData );
bResult = Peripheral_SingleByteRead( 0x00AA, &bData );
bResult = Peripheral_EP2FIFOByteWrite( 0x2355, 0x0040 );
bResult = Peripheral_EP2FIFOWordWrite( 0x2355, 0x0040 );
bResult = Peripheral_EP6FIFOByteRead( 0x2355, 0x0040 );
bResult = Peripheral_EP6FIFOWordRead( 0x2355, 0x0040 );
}
while( 1 )
{
if( EP2FIFOCFG & 0x01 ) // If 16-bit mode - wordwide
{ // illustrate use of efficient 16 bit functions
bResult = Peripheral_SingleWordWrite( 0x01FF, 0xFFFF );
bResult = Peripheral_SingleWordRead( 0x0169, &wData );
}
else
{
bResult = Peripheral_SingleByteWrite( 0x0055, 0xFF );
bResult = Peripheral_SingleByteRead( 0x00AA, &bData );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -