//
// Copyright (c) 1999 Thomas Coonan (tcoonan@mindspring.com)
//
// This source code is free software; you can redistribute it
// and/or modify it in source code form under the terms of the GNU
// General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
//
// Intel HEX to Verilog converter.
//
// Usage:
// hex2v <file>
//
// You probably want to simply redirect the output into a file.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Input and Output file streams.
FILE *fpi;
// Well.. Let's read stuff in completely before outputting.. Programs
// should be pretty small..
//
#define MAX_MEMORY_SIZE 1024
struct {
unsigned int nAddress;
unsigned int byData;
} Memory[MAX_MEMORY_SIZE];
char szLine[80];
unsigned int start_address, address, ndata_bytes, ndata_words;
unsigned int data;
unsigned int nMemoryCount;
int main (int argc, char *argv[])
{
int i;
if (argc != 2) {
printf ("\nThe Synthetic PIC --- Intel HEX File to Verilog memory file");
printf ("\nUsage: hex2verilog <infile>");
printf ("\n");
return 0;
}
// Open input HEX file
fpi=fopen(argv[1], "r");
if (!fpi) {
printf("\nCan't open input file %s.\n", argv[1]);
return 1;
}
// Read in the HEX file
//
// !! Note, that things are a little strange for us, because the PIC is
// a 12-bit instruction, addresses are 16-bit, and the hex format is
// 8-bit oriented!!
//
nMemoryCount = 0;
while (!feof(fpi)) {
// Get one Intel HEX line
fgets (szLine, 80, fpi);
if (strlen(szLine) >= 10) {
// This is the PIC, with its 12-bit "words". We're interested in these
// words and not the bytes. Read 4 hex digits at a time for each
// address.
//
sscanf (&szLine[1], "%2x%4x", &ndata_bytes, &start_address);
if (start_address >= 0 && start_address <= 20000 && ndata_bytes > 0) {
// Suck up data bytes starting at 9th byte.
i = 9;
// Words.. not bytes..
ndata_words = ndata_bytes/2;
start_address = start_address/2;
// Spit out all the data that is supposed to be on this line.
for (address = start_address; address < start_address + ndata_words; address++) {
// Scan out 4 hex digits for a word. This will be one address.
sscanf (&szLine[i], "%04x", &data);
// Need to swap bytes...
data = ((data >> 8) & 0x00ff) | ((data << 8) & 0xff00);
i += 4;
// Store in our memory buffer
Memory[nMemoryCount].nAddress = address;
Memory[nMemoryCount].byData = data;
nMemoryCount++;
}
}
}
}
fclose (fpi);
// Now output the Verilog $readmemh format!
//
for (i = 0; i < nMemoryCount; i++) {
printf ("\n@%03X %03X", Memory[i].nAddress, Memory[i].byData);
}
printf ("\n");
}
基于 Verilog 的 PIC16C57 RISC CPU 设计.rar
4星 · 超过85%的资源 需积分: 0 45 浏览量
2020-08-21
15:00:39
上传
评论 5
收藏 14KB RAR 举报
新芯设计
- 粉丝: 5074
- 资源: 5
最新资源
- 操作简单的Mongodb网页web管理工具,基于Spring Boot2.0支持mongodb集群.zip
- tms-mongodb-web,提供访问mongodb数据的REST API和可灵活扩展的mongodb web 客户端.zip
- SpringBoot整合mongodb学习MongoTemplate和MongoRepository两种方式CRUD使用.zip
- SpringBoot整合MongoDB实现对数据库的CRUD小demo.zip
- Python操作MongoDB数据库的基本一些操作 .zip
- NOSQL数据库监控工具,目前实现了对Redis、MongoDB的监控功能 .zip
- mongoDB数据库的增删改查,以及所需要的配置.zip
- mongodb数据库idea测试.zip
- koa 分别 连接 mysql、mongodb数据库操作.zip
- 基于pytorch实现的人体部件分割源码+模型.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈