赞
踩
当你想把bit文件通过程序写入fpga的时候,你会发现总是不对。因为bit格式是bitgen生成的jtag用的格式。
使用impact工具能够完成转换。
如果你想通过代码直接读取,就需要了解文件结构了。网上搜了搜,没有这类的应用。特将研究成果写下来,为后来人使用方便。
ushort siglength
char[] sig
ushort version[00 01]
char a// type {a-e}
ushort project name length
char[] project name
char b
ushort xilinx fpga name length
char[] xilinx fpga name
char c
ushort date length
char[] date name
char d
ushort time length
char[] time name
char e
uint32_t fpga bit length
char[] fpga bit //start with {FF FF FF FF}
————————————————
版权声明:本文为CSDN博主「wdxzkp」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/wdxzkp/article/details/6722353
int ConfigFpgaFromFlash(void) { uint8_t buf[1024]; uint32_t tmpSize; uint32_t offset = 0; sf_read(5, buf, FPGA_FW_OFFSET, 1024); //Sig tmpSize = buf[0]<<8 | buf[1]; offset += 2; offset += tmpSize; //version tmpSize = buf[offset]<<8 | buf[offset+1]; offset += 2; offset += tmpSize; //char a if(buf[offset] != 'a') { printf("Invalid FPGA configuration file!\n"); printBuf(buf, 128); return -1; } offset += 2; offset += tmpSize; //project name tmpSize = buf[offset]<<8 | buf[offset+1]; offset += 2; printf("Project Name: %s\n", &buf[offset]); offset += tmpSize; //char b if(buf[offset] != 'b') { printf("Invalid FPGA configuration file!\n"); printBuf(buf, 128); return -1; } offset += 2; offset += tmpSize; //FPGA name tmpSize = buf[offset]<<8 | buf[offset+1]; offset += 2; printf("FPGA Name: %s\n", &buf[offset]); offset += tmpSize; //char c if(buf[offset] != 'c') { printf("Invalid FPGA configuration file!\n"); printBuf(buf, 128); return -1; } offset += 2; offset += tmpSize; //Build date tmpSize = buf[offset]<<8 | buf[offset+1]; tmpSize += 2; printf("Buid Date: %s\n", &buf[offset]); tmpSize += tmpSize; //char d if(buf[offset] != 'd') { printf("Invalid FPGA configuration file!\n"); printBuf(buf, 128); return -1; } offset += 2; offset += tmpSize; //Buid time tmpSize = buf[offset]<<8 | buf[offset+1]; tmpSize += 2; printf("Buid Time: %s\n", &buf[offset]); tmpSize += tmpSize; //char e if(buf[offset] != 'e') { printf("Invalid FPGA configuration file!\n"); printBuf(buf, 128); return -1; } offset += 2; offset += tmpSize; //FPGA config data length tmpSize = buf[offset]<<24 | buf[offset+1]<<16 | buf[offset+2]<<8 | buf[offset+3]; offset += 4; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。