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

Subversion Repositories plasma

[/] [plasma/] [trunk/] [tools/] [ram_image.c] - Blame information for rev 358

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 137 rhoads
/* ram_image.c by Steve Rhoads 11/7/05
2
 * This program take the ram_xilinx.vhd file as input
3
 * and the code.txt file as input.
4
 * It then creates ram_image.vhd as output with the
5
 * initialization vectors set to the contents of code.txt.
6
 */
7
#include <stdio.h>
8
#include <stdlib.h>
9
#include <string.h>
10
 
11
#define BUF_SIZE (1024*1024)
12
 
13
int main(int argc, char *argv[])
14
{
15
   FILE *file;
16
   int i, j, index, size, count;
17
   char *buf, *ptr, *ptr_list[64*4], text[80];
18 336 rhoads
   unsigned int *code;
19 137 rhoads
 
20
   if(argc < 4)
21
   {
22
      printf("Usage: ram_image <in.vhd> <in_code.txt> <out.vhd>\n");
23
      printf("Usage: ram_image ram_xilinx.vhd code.txt ram_image.vhd\n");
24
      return 0;
25
   }
26
 
27
   buf = (char*)malloc(BUF_SIZE);
28 336 rhoads
   code = (unsigned int*)malloc(BUF_SIZE);
29 137 rhoads
 
30
   //Read ram_xilinx.vhd
31
   file = fopen(argv[1], "rb");
32
   if(file == NULL)
33
   {
34
      printf("Can't open %s!\n", argv[1]);
35
      return -1;
36
   }
37
   size = fread(buf, 1, BUF_SIZE, file);
38
   fclose(file);
39
 
40
   //Read code.txt
41
   file = fopen(argv[2], "r");
42
   if(file == NULL)
43
   {
44
      printf("Can't open %s!\n", argv[2]);
45
      return -1;
46
   }
47
   for(count = 0; count < 16*1024; ++count)
48
   {
49
      if(feof(file))
50
         break;
51
      fscanf(file, "%x", &code[count]);
52
   }
53
   fclose(file);
54
 
55
   //Find 'INIT_00 => X"'
56
   ptr = buf;
57
   for(i = 0; i < 64*4; ++i)
58
   {
59
      sprintf(text, "INIT_%2.2X => X\"", i % 64);
60
      ptr = strstr(ptr, text);
61
      if(ptr == NULL)
62
      {
63
         printf("ERROR:  Can't find '%s' in file!\n", text);
64
         return -1;
65
      }
66
      ptr_list[i] = ptr + strlen(text);
67
   }
68
 
69
   //Modify vhdl source code
70
   j = 62;
71
   for(i = 0; i < count; ++i)
72
   {
73
      sprintf(text, "%8.8x", code[i]);
74
      index = i / 32;
75
      ptr_list[index][j] = text[0];
76
      ptr_list[index][j+1] = text[1];
77
      ptr_list[index+64][j] = text[2];
78
      ptr_list[index+64][j+1] = text[3];
79
      ptr_list[index+128][j] = text[4];
80
      ptr_list[index+128][j+1] = text[5];
81
      ptr_list[index+192][j] = text[6];
82
      ptr_list[index+192][j+1] = text[7];
83
      j -= 2;
84
      if(j < 0)
85
         j = 62;
86
   }
87
 
88
   //Write ram_image.vhd
89
   file = fopen(argv[3], "wb");
90
   if(file == NULL)
91
   {
92
      printf("Can't write %s!\n", argv[3]);
93
      return -1;
94
   }
95
   fwrite(buf, 1, size, file);
96
   fclose(file);
97
   free(buf);
98
   free(code);
99
   return 0;
100
}

powered by: WebSVN 2.1.0

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