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

Subversion Repositories softavrcore

[/] [softavrcore/] [trunk/] [util/] [progmem-ice40.sh] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 apal
#!/bin/bash
2
 
3
infile=""
4
 
5
depth=8
6
 
7
name=rom_16bit
8
 
9
while [ -n "$1" ]; do
10
        case "$1" in
11
                -h|--help)
12
                        echo -e "Usage:\t$0 [-h|--help] [-w|--width <width>] <16-bit-image.bin>"
13
                        exit    0
14
                        ;;
15
                -w|--width|-d|--depth)
16
                        depth="$2"
17
                        shift
18
                        ;;
19
                -n|--name)
20
                        name="$2"
21
                        shift
22
                        ;;
23
                -*)
24
                        echo -e "$0: error: invalid command line argument near '$1'." >> /dev/stderr
25
                        exit    1
26
                        ;;
27
                *)
28
                        infile="$1"
29
                        ;;
30
        esac; shift
31
done
32
 
33
if ! [ -n "$infile" ] || ! [ -f "$infile" ]; then
34
        echo "$0: error: input file is missing or not found." >> /dev/stderr
35
        exit    1
36
fi
37
 
38
nword=$((1<<depth))
39
 
40
cat "$infile" /dev/zero | \
41
head -c $((2*nword)) | \
42
hexdump -v -e '/2 "%.4x\n"' | \
43
awk -v f=0 -v i=0 -v n=0 -v nword=$nword -v depth=$depth -v name=$name \
44
 'BEGIN \
45
  {     printf("module %s\n",name);
46
        printf(" (      input           clk,\n");
47
        printf("        input           mem_ce,\n");
48
        printf("        input   [%d:0]  mem_a,\n",depth-1);
49
        printf("        output  [15:0]  mem_d\n");
50
        printf(" );\n");
51
        if ( depth==9 )
52
         {      printf("reg mem_hi;\n");
53
                printf("always @(posedge clk) mem_hi <= mem_a[8];\n");
54
         }
55
        else if ( 10<=depth )
56
         {      printf("reg [%d:0] mem_hi;\n",depth-9);
57
                printf("always @(posedge clk) mem_hi <= mem_a[%d:8];\n",depth-1);
58
         }
59
        if ( 9<=depth )
60
                printf("reg [15:0] mem_d;\n");
61
 
62
  } \
63
  {     arr[n+1]=$1;
64
        n++;
65
        if ( n==16 )
66
         {      if ( i==0 )
67
                 {      printf("wire [15:0] db%d;\n",f);
68
                        printf("SB_RAM40_4K flash%d\n",f);
69
                        printf(" (      .RDATA(db%d),\n",f);
70
                        printf("        .RADDR({3%cb000,mem_a[7:0]}),\n",39);
71
                        printf("        .RCLKE(1%cb1),\n",39);
72
                        printf("        .RCLK(clk),\n");
73
                        printf("        .RE(mem_ce),\n");
74
                        printf("        .WADDR(11%cb00000000000),\n",39);
75
                        printf("        .MASK(16%cb0000000000000000),\n",39);
76
                        printf("        .WDATA(16%cb0000000000000000),\n",39);
77
                        printf("        .WCLKE(1%cb0),\n",39);
78
                        printf("        .WCLK(1%cb0),\n",39);
79
                        printf("        .WE(1%cb0)\n",39);
80
                        printf(" );\n");
81
                        printf("defparam flash%d.READ_MODE = 0;\n",f);
82
                 }
83
 
84
                printf("defparam flash%d.INIT_%X = 256%ch",f,i,39);
85
                for ( k=0 ; k<16 ; k++ )
86
                 {      if ( k )        printf("_");
87
                        printf("%s",arr[16-k]);
88
                 }
89
                printf(";\n");
90
                n=0;
91
                i++;
92
         }
93
        if ( i==16 )
94
         {      i=0;
95
                f++;
96
         }
97
  } \
98
 END \
99
  {     if ( 9<=depth )
100
         {      printf("always @(*) begin\n");
101
                printf("        casex (mem_hi)\n");
102
                for ( k=0 ; k<nword/256 ; k++ )
103
                        printf("                %d%cd%d: mem_d = db%d;\n",depth-8,39,k,k);
104
                printf("                default: mem_d = 16%ch0000;\n",39);
105
                printf("        endcase\n");
106
                printf("end\n");
107
         }
108
        else
109
                printf("assign mem_d = db0;\n");
110
 
111
        printf("\n");
112
        printf("endmodule\n");
113
  }'
114
 
115
 

powered by: WebSVN 2.1.0

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