EDN China > 技术文章 > 可编程器件 > FPGA > 正文
? 2016博客大赛-不限主题,寻找电子导师,大奖升级??

基于ARM的FPGA加载配置实现

来源:微计算机信息/立明 范多旺 陈光武?? 2007年03月14日 ?? 收藏0

  3软件设计

  本文在设计时使用Linux系统,软件编写和调试是在ADS 下。主要程序如下:

  static AT91PS_PIO pioc;

  inline void pioc_out_0 (int mask)

  {

  ?????? pioc->PIO_CODR = mask;

  }

  inline void pioc_out_1 (int mask)

  {

  ?????? pioc->PIO_SODR = mask;

  }

  inline int pioc_in (int mask)

  {

  ?????? return pioc->PIO_PDSR & mask;

  }

  inline void xmit_byte (char c)

  {

  ?????? int i;

  ?????? for (i = 0; i < 8; i++)

  ?????? {

  ????????????? if (c & 1)

  ???????????????????? pioc_out_1 (DATA0);

  ????????????? else

  ???????????????????? pioc_out_0 (DATA0);

  ????????????????? pioc_out_0 (DCLK);

  ????????????????? pioc_out_1 (DCLK);

  ????????????? c >>= 1;

  ?????? }

  }

  

  void pioc_setup ()

  {

  ?????? pioc->PIO_PER???? =DATA0 | nCONFIG | DCLK | nSTATUS | CONF_DONE;

  ?????? pioc->PIO_OER???? =DATA0 | nCONFIG | DCLK;

  ?????? pioc->PIO_ODR??? =nSTATUS | CONF_DONE;

  ?????? pioc->PIO_IFER??? =nSTATUS | CONF_DONE;

  ?????? pioc->PIO_CODR? =DATA0 | nCONFIG | DCLK;

  ?????? pioc->PIO_IDR???? =DATA0 | nCONFIG | DCLK | nSTATUS | CONF_DONE;

  ?????? pioc->PIO_MDDR =DATA0 | nCONFIG | DCLK;

  ?????? pioc->PIO_PPUDR?????? =DATA0 | nCONFIG | DCLK | nSTATUS | CONF_DONE;

  ?????? pioc->PIO_OWDR =DATA0 | nCONFIG | DCLK | nSTATUS | CONF_DONE;

  }

  int pioc_map ()

  {

  ??????? int fd;

  ?????? off_t addr = 0xFFFFF800;??? // PIO controller C

  ?????? static void *base;

  ??????? if ((fd = open ("/dev/mem", O_RDWR | O_SYNC)) == -1)

  ??????? {

  ??????????????? printf ("Cannot open /dev/mem.\n");

  ??????????????? return 0;

  ??????? }

  ??????? printf ("/dev/mem opened.\n");

  ?????? base = mmap (0, MAP_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr & ~MAP_MASK);

  ??????? if (base == (void *) -1)

  ??????? {

  ???????? printf ("Cannot mmap.\n");

  ??????????????? return 0;

  ??????? }

  ??????? printf ("Memory mapped at address %p.\n", base);

  ?????? pioc = base + (addr & MAP_MASK);

  ?????? return 1;

  }

  int main (int argc, char **argv)

  {

  ?????? FILE *file;

  ?????? char data[16];

  ?????? int nbytes, i;

  ??????

  ?????? if (argc != 2)

  ?????? {

  ????????????? printf ("%s <filename>\n", argv[0]);

  ????????????? return -1;

  ?????? }

  ?????? file = fopen (argv[1], "r");

  ?????? if (!file)

  ?????? {

  ????????????? printf ("File %s not found.\n", argv[1]);

  ????????????? return -1;

  ?????? }

  ?????? if (!pioc_map ())

  ????????????? return -1;

  ?????? pioc_setup ();

  ?????? pioc_out_0 (nCONFIG);

  ?????? for (i = 0; i < 10000 && pioc_in (nSTATUS); i++) { }

  ?????? if (i == 10000)

  ?????? {

  ????????????? printf ("nSTATUS = 1 before attempting configuration.\n");

  ????????????? return -1;

  ?????? }

  ?????? pioc_out_1 (nCONFIG);

  ?????? for (i = 0; i < 10000 && !pioc_in (nSTATUS); i++) { }

  ?????? if (i == 10000)

  ?????? {

  ????????????? printf ("Timeout waiting for nSTATUS = 1.\n");

  ????????????? return -1;

  ?????? }

  ?????? while ((nbytes = fread (data, sizeof (char), sizeof (data), file)) > 0)

  ?????? {

  ????????????? if (pioc_in (CONF_DONE))

  ????????????? {

  ???????????????????? printf ("CONF_DONE = 1 while transmitting data.\n");

  ???????????????????? return -1;

  ????????????? }

  ????????????? if (!pioc_in (nSTATUS))

  ????????????? {

  ???????????????????? printf ("nSTATUS = 0 while transmitting data.\n");

  ???????????????????? return -1;

  ????????????? }

  ????????????? for (i = 0; i < nbytes; i++)

  ???????????????????? xmit_byte (data[i]);

  ?????? }

  ?????? for (i = 0; i < 10000 && !pioc_in (CONF_DONE); i++)

  ?????? {

  ????????????? if (!pioc_in (nSTATUS))

  ????????????? {

  ???????????????????? printf ("nSTATUS = 0 while transmitting data.\n");

  ???????????????????? return -1;

  ????????????? }

  ????????????? pioc_out_0 (DATA0);

  ????????????? pioc_out_0 (DCLK);

  ????????????? pioc_out_1 (DCLK);

  ?????? }

  ?????? if (i == 10000)

  ?????? {

  ????????????? printf ("Timeout waiting for CONF_DONE = 1.\n");

  ????????????? return -1;

  ?????? }

  ??????? return 0;

  }


?? ?? ??


打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮

1.扫描左侧二维码
2.点击右上角的分享按钮
3.选择分享给朋友
?? ??

ARM? FPGA? SRAM?

相关文章

我来评论
美国的游客
美国的游客 ??? (您将以游客身份发表,请登录 | 注册)
?
有问题请反馈