F28377S_EMIF_异步读写FPGA

DSP芯片:TMS320F28377SPTPS

基于已有的FPGA程序与板子,操作DSP读取FPGA内的数据。如果写入、读取成功,则点亮LED。



//
// Included Files
//
#include "F28x_Project.h"




#define TEST_PASS            0xABCDABCD
#define TEST_FAIL            0xDEADDEAD
#define ASRAM_CS2_START_ADDR 0x100000
#define ASRAM_CS2_SIZE       0x8000
#define EMIF1                0
#define EMIF2                1
#define MEM_D_WIDTH          1            // 16Bit Memory Interface
#define TURN_AROUND_TIME     0            // Turn Around time of 2 Emif Clock
#define RD_SETUP_TIME        0            // Read Setup time of 1 Emif Clock
#define RD_STROBE_TIME       3            // Read Strobe time of 4 Emif Clock
#define RD_HOLD_TIME         0            // Read Hold time of 1 Emif Clock
#define WR_SETUP_TIME        0            // Write Hold time of 1 Emif Clock
#define WR_STROBE_TIME       0            // Write Setup time of 1 Emif Clock
#define WR_HOLD_TIME         0            // Write Hold time of 1 Emif Clock
#define EXTEND_WAIT          0            // Disable Extended Wait
#define STROBE_SEL           0            // Disable Strobe Mode.
#define WAIT_POLAR_INV       0
#define WAIT_COUNT           0

//#define cpu_sel           0
//
// Globals

Uint16  ErrCount = 0;
Uint32  TEST_STATUS;
int i;

//
// EMIF引脚设置
//
extern void setup_emif1_pinmux_async_16bit(Uint16 cpu_sel)
{
	GPIO_SetupPinMux(31,0,2);//第31个引脚,第1个CPU,第3个功能;写入使能
	//GPIO_SetupPinMux(33,0,2);//DF_EMIF_RNW,未使用,外部存储器接口 1 读/不写
	GPIO_SetupPinMux(35,0,2);//DF_EMIF_CSn片选信号
	GPIO_SetupPinMux(37,0,2);//	DF_EMIF_RDn读取使能

	GPIO_SetupPinMux(91,0,0);//BA0,以普通IO作为BA0*
	GPIO_SetupPinMux(92,0,3);//BA1,*

	GPIO_SetupPinMux(93,0,0);//外部中断输出到DSP  32.5us一次
	GPIO_SetupPinMux(62,0,0);//外部中断输出到DSP  32.5us一次

    for (i=38; i<=52; i++)//a0 -a12
    {
        if ((i != 42) && (i != 43))
        {
            GPIO_SetupPinMux(i,cpu_sel,2);
        }
    }
    GPIO_SetupPinMux(86,cpu_sel,2);//A13-A15
    GPIO_SetupPinMux(87,cpu_sel,2);
    GPIO_SetupPinMux(88,cpu_sel,2);

    for (i=69; i<=85; i++)//D0 -D15
    {
        if (i != 84)
        {
            GPIO_SetupPinMux(i,cpu_sel,2);
        }
    }

    for (i=69; i<=85; i++)
    {
        if (i != 84)
        {
            GPIO_SetupPinOptions(i,0,0x31); // GPIO_ASYNC||GPIO_PULLUP
        }
    }

}


//读取值
Uint16 Read_FPGA(long Read_ADD){

	unsigned int Read_data = *((volatile unsigned int *)Read_ADD);

return(Read_data);
}

//写入值
void Write_FPGA(long Write_ADD,long Write_DATA)
{
	*((volatile unsigned int *)Write_ADD)= Write_DATA;
}


//
// Main
//
void main(void)
{
	//memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
	 InitGpio();
	 GPIO_SetupPinMux(34, GPIO_MUX_CPU1, 0);
	 GPIO_SetupPinOptions(34, GPIO_OUTPUT, GPIO_PUSHPULL);
	 GPIO_WritePin(34, 0);//D8L

	//以上LED需要,D8=GPIO34,低电平亮



//
// Initialize system control
//
    InitSysCtrl();

    DINT;

//
//  Initialize the PIE control registers to their default state.
//  The default state is all PIE interrupts disabled and flags
//  are cleared.
    //将PIE控制寄存器初始化为其默认状态。
    //默认状态是禁用所有PIE中断并清除标志。
    //  This function is found in the F2837xS_PieCtrl.c file.
//
    InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
    EALLOW;
    IER = 0x0000;
    IFR = 0x0000;
    EDIS;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// GService Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in F2837xS_DefaultIsr.c.
// This function is found in F2837xS_PieVect.c.
//
   InitPieVectTable();

//
//Configure to run EMIF1 on full Rate (EMIF1CLK = CPU1SYSCLK)
//配置为以全速率运行EMIF1(EMIF1CLK=CPU1SYSCLK)
//
  EALLOW;
  ClkCfgRegs.PERCLKDIVSEL.bit.EMIF1CLKDIV = 0x1;//EMIF时钟配置,设置EM1模块运行速度
  EDIS;


//
//Disable Access Protection (CPU_FETCH/CPU_WR/DMA_WR)
 禁止EMIF1模块读写保护
  EALLOW;
  Emif1ConfigRegs.EMIF1ACCPROT0.all = 0x0;
  if(Emif1ConfigRegs.EMIF1ACCPROT0.all != 0x0)
  {
      ErrCount++;
  }

//
// Commit the configuration related to protection. Till this bit remains set
// content of EMIF1ACCPROT0 register can't be changed.
提交与保护相关的配置。在该位保留之前,EMIF1ACCPROT0寄存器的设置内容不能更改????
  // 锁定寄存器配置
  Emif1ConfigRegs.EMIF1COMMIT.all = 0x1;
  if(Emif1ConfigRegs.EMIF1COMMIT.all != 0x1)
  {
     ErrCount++;
  }

//
// Lock the configuration so that EMIF1COMMIT register can't be
// changed any more.
  // 锁定寄存器配置
//
  Emif1ConfigRegs.EMIF1LOCK.all = 0x1;
  if(Emif1ConfigRegs.EMIF1LOCK.all != 1)
  {
      ErrCount++;
  }

  EDIS;

//
//配置cpu 0 的EMIF模块引脚
//
  setup_emif1_pinmux_async_16bit(0);

//
//Configure the access timing for CS2 space配置CS2空间的访问定时
//根据实际引脚配置CS,这里是CS3
//
  Emif1Regs.ASYNC_CS3_CR.all =  (EMIF_ASYNC_ASIZE_16    | // 16Bit Memory
                                                          // Interface
                                 EMIF_ASYNC_TA_2        | // Turn Around time
                                                          // of 2 Emif Clock
                                 EMIF_ASYNC_RHOLD_1     | // Read Hold time
                                                          // of 1 Emif Clock
                                 EMIF_ASYNC_RSTROBE_4   | // Read Strobe time
                                                          // of 4 Emif Clock
                                 EMIF_ASYNC_RSETUP_1    | // Read Setup time
                                                          // of 1 Emif Clock
                                 EMIF_ASYNC_WHOLD_1     | // Write Hold time
                                                          // of 1 Emif Clock
                                 EMIF_ASYNC_WSTROBE_3   | // Write Strobe time
                                                          // of 1 Emif Clock
                                 EMIF_ASYNC_WSETUP_1    | // Write Setup time
                                                          // of 1 Emif Clock
                                 EMIF_ASYNC_EW_DISABLE  | // Extended Wait
                                                          // Disable.
                                 EMIF_ASYNC_SS_DISABLE    // Strobe Select Mode
                                                          // Disable.
                                );

  //地址===值,读写状态
  //0x30_0106===0x5555,r
  //0x30_0107===0xaaaa,r
  //0x30_0115===0x0000,r&w

  Write_FPGA(0x300115,4567);
  Uint16 TEMP =Read_FPGA(0x300115);

  if(TEMP==4567|| Read_FPGA(0x300106)==0x5555 ||Read_FPGA(0x300106)==0xaaaa)
      {
    	  GPIO_WritePin(34, 0);//读写正常则led亮
      }
      else
      {
    	  GPIO_WritePin(34, 1);
      }




  while (1);
}

//
// End of file
//

你可能感兴趣的:(dsp开发,fpga开发,c#)