⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpif.c

📁 一个有关EZ-USB FX2 系列CY7C68013的应用实例
💻 C
📖 第 1 页 / 共 2 页
字号:
  
  // destination
  AUTOPTRH2 = 0xE4;
  AUTOPTRL2 = 0x00;

  // transfer
  for ( i = 0x00; i < 128; i++ )
  {
    EXTAUTODAT2 = EXTAUTODAT1;
  }



// Configure GPIF Address pins, output initial value,    初使化GPIF的9位地址线。
  PORTCCFG = 0xFF;    // [7:0] as alt. func. GPIFADR[7:0]  当为1则选定为GPIFADR
  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                   或初使化作为普通I/O口
//  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        当gpifadrh/l被写,gpif地址脚赋值
  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 = FlowStates[ 0 ];
  FLOWLOGIC = FlowStates[ 1 ];
  FLOWEQ0CTL = FlowStates[ 2 ];
  FLOWEQ1CTL = FlowStates[ 3 ];
  FLOWHOLDOFF = FlowStates[ 4 ];
  FLOWSTB = FlowStates[ 5 ];
  FLOWSTBEDGE = FlowStates[ 6 ];
  FLOWSTBHPERIOD = FlowStates[ 7 ];
}
#define TESTING_GPIF // NOTE: Comment this line out for frameworks based firmware
                     // 注意: 
                     // See the example GPIF Tool Utility under Application
                     // Reference Material for more advanced development info
#ifdef TESTING_GPIF
// TODO: You may add additional code below.

void OtherInit( void )
{ // interface initialization
  // ...see TD_Init( );
}

// Set Address GPIFADR[8:0] to PERIPHERAL  地址设置给外部设备
void Peripheral_SetAddress( WORD gaddr )
{
  SYNCDELAY;                    // 
  GPIFADRH = gaddr >> 8;
  SYNCDELAY;                    // 
  GPIFADRL = ( BYTE )gaddr; // setup GPIF address 
}

// Set EP2GPIF Transaction Count               设定端点2的传送计数器
void Peripheral_SetEP2GPIFTC( WORD xfrcnt )
{
  SYNCDELAY;                    //  
  EP2GPIFTCH = xfrcnt >> 8;  // setup transaction count
  SYNCDELAY;                    // 
  EP2GPIFTCL = ( BYTE )xfrcnt;
}

// Set EP4GPIF Transaction Count				设定端点四的传送计数器
void Peripheral_SetEP4GPIFTC( WORD xfrcnt )    
{
  SYNCDELAY;                    // 
  EP4GPIFTCH = xfrcnt >> 8;  // setup transaction count
  SYNCDELAY;                    // 
  EP4GPIFTCL = ( BYTE )xfrcnt;
}

// Set EP6GPIF Transaction Count				设定端点6的传送计数器
void Peripheral_SetEP6GPIFTC( WORD xfrcnt )
{
  SYNCDELAY;                    // 
  EP6GPIFTCH = xfrcnt >> 8;  // setup transaction count
  SYNCDELAY;                    // 
  EP6GPIFTCL = ( BYTE )xfrcnt;
}

// Set EP8GPIF Transaction Count				设定端点8的传送计数器
void Peripheral_SetEP8GPIFTC( WORD xfrcnt )
{
  SYNCDELAY;                    // 
  EP8GPIFTCH = xfrcnt >> 8;  // setup transaction count
  SYNCDELAY;                    // 
  EP8GPIFTCL = ( BYTE )xfrcnt;
}

#define GPIF_FLGSELPF 0         //端点EPxGPIFFLGSEL	最后两位FS1:FS0的值
#define GPIF_FLGSELEF 1         //00=PF 01=EF 10=FF
#define GPIF_FLGSELFF 2

// Set EP2GPIF Decision Point FIFO Flag Select (PF, EF, FF) 设置端点2的FIFO标志。
void SetEP2GPIFFLGSEL( WORD DP_FIFOFlag )
{
  EP2GPIFFLGSEL = DP_FIFOFlag;
}

// Set EP4GPIF Decision Point FIFO Flag Select (PF, EF, FF)	设置端点4的FIFO标志
void SetEP4GPIFFLGSEL( WORD DP_FIFOFlag )
{
  EP4GPIFFLGSEL = DP_FIFOFlag;
}

// Set EP6GPIF Decision Point FIFO Flag Select (PF, EF, FF)	设置端点6的FIFO标志
void SetEP6GPIFFLGSEL( WORD DP_FIFOFlag )
{
  EP6GPIFFLGSEL = DP_FIFOFlag;
}

// Set EP8GPIF Decision Point FIFO Flag Select (PF, EF, FF)	设置端点8的FIFO标志
void SetEP8GPIFFLGSEL( WORD DP_FIFOFlag )
{
  EP8GPIFFLGSEL = DP_FIFOFlag;
}
//设置PFstop 不管传送计数器的值 当被选则的EF,PF,FF产生的时候怎直接将DONE=1结束GPIF.
// Set EP2GPIF Programmable Flag STOP, overrides Transaction Count  
void SetEP2GPIFPFSTOP( void )
{
  EP2GPIFPFSTOP = 0x01;
}

// Set EP4GPIF Programmable Flag STOP, overrides Transaction Count
void SetEP4GPIFPFSTOP( void )
{
  EP4GPIFPFSTOP = 0x01;
}

// 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 使用GPIF写一个字节到外部设备
void Peripheral_SingleByteWrite( BYTE gdata )
{
  while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit 获取done位
  {
     ;
  }

  XGPIFSGLDATLX = gdata;        // trigger GPIF    把数据送到XGPIFSGLDATLX并触发GPIF
                                // ...single byte write transaction
}

// write single word to PERIPHERAL, using GPIF  使用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  把数据字写到XGPIFSGLGATLX和XGPIFSGLGATH中触发GPIF
                                // ...single word write transaction
}

// read single byte from PERIPHERAL, using GPIF     使用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  首先要一个虚读来启动GPIF
  g_data = XGPIFSGLDATLX;       // trigger GPIF 
                                // ...single byte read transaction
  while( !( GPIFTRIG & 0x80 ) ) // poll GPIFTRIG.7 Done bit
  {
     ;
  }

// using register(s) in XDATA space,  从B口pin读取外设的数据
  *gdata = XGPIFSGLDATLNOX;     // ...GPIF reads byte from PERIPHERAL
}

// read single word from PERIPHERAL, using GPIF    使用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   虚读操作,启动GPIF
  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                //EP1:EP0=00
#define GPIF_EP4 1                //EP1:EP0=01
#define GPIF_EP6 2                //EP1:EP0=10
#define GPIF_EP8 3                //EP1:EP0=11

// 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 获取done位。当为0在这里等待为1就跳出
  {
     ;
  }

  // trigger FIFO write transaction(s), using SFR     通过sfr, 触发FIFO写处理
  GPIFTRIG = FIFO_EpNum;  // R/W=0, EP[1:0]=FIFO_EpNum for EPx write(s) 设定写和FIFO通道
}

// 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 获取done位,0等待,1跳出
  {
     ;
  }

  // trigger FIFO read transaction(s), using SFR  使用sfr触发FIFO读操作
  GPIFTRIG = GPIFTRIGRD | FIFO_EpNum; // R/W=1, EP[1:0]=FIFO_EpNum for EPx read(s)
}


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -