OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [OBSOLETE/] [altera_de1_board/] [software/] [bin/] [mifwrite.cpp] - Blame information for rev 221

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 olivier.gi
// this prog is taken from http://www.johnloomis.org/ece595c/notes/isa/mifwrite.html
2
// and slightly changed to satisfy quartus6.1 *.mif eating engine.
3
//
4
// it takes binary file of arbitrary length and treating it as collection of 16-bit words,
5
// writes *.mif file for quartus
6
//
7
//
8
 
9
 
10
#include <stdio.h>
11
#include <stdlib.h>
12
 
13
void mifwrite(FILE *in, FILE *out, int offset);
14
 
15
int main(int argc, char *argv[])
16
{
17
        char *filename;
18
 
19
        if (argc<3) {
20
                printf("usage: mifwrite input_file output_file [offset]\n");
21
                printf("The default offset is zero");
22
                return -1;
23
        }
24
 
25
        FILE *in, *out;
26
        filename = argv[1];
27
        in = fopen(filename,"rb");
28
        if (!in) {
29
                printf("file: %s not found\n",filename);
30
                return -1;
31
        }
32
        filename = argv[2];
33
        out = fopen(filename,"wt");
34
        if (!out) {
35
                printf("file: %s not opened\n",filename);
36
                return -1;
37
        }
38
        int offset = 0;
39
        if (argc>3) sscanf(argv[3],"%x",&offset);
40
        if (offset) printf("address_offset %x\n",offset);
41
        mifwrite(in,out,offset);
42
        return 0;
43
}
44
 
45
void mifwrite(FILE *in, FILE *out,int offset)
46
{
47
        int count;
48
        unsigned int data;
49
        unsigned int address = 0;
50
        int ndepth;
51
        int nwidth = 16;
52
 
53
        fseek(in,0,SEEK_END);
54
        ndepth = ftell(in)/2;
55
        fseek(in,0,SEEK_SET);
56
 
57
 
58
        fprintf(out,"DEPTH = %d;\n",ndepth);
59
        fprintf(out,"WIDTH = %d;\n\n",nwidth);
60
        fprintf(out,"ADDRESS_RADIX = HEX;\n");
61
        fprintf(out,"DATA_RADIX = HEX;\n");
62
        fprintf(out,"CONTENT\n  BEGIN\n");
63
        fprintf(out,"[0..%x]   :  0;\n",ndepth-1);
64
        address = 0;
65
        offset = offset>>2;
66
        data=0;
67
        while (count = fread(&data,2,1,in)) {
68
                if (address<offset) {
69
                        offset--;
70
                        continue;
71
                }
72
                fprintf(out,"%04x  : %04x;\n",address,data);
73
                address++;
74
//              if (address>=ndepth) break;
75
        }
76
        fprintf(out,"END;\n");
77
        fclose(in);
78
        fclose(out);
79
}

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.