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

Subversion Repositories softavrcore

[/] [softavrcore/] [trunk/] [util/] [progmem-ice40.sh] - Rev 2

Compare with Previous | Blame | View Log

#!/bin/bash
 
infile=""
 
depth=8
 
name=rom_16bit
 
while [ -n "$1" ]; do
	case "$1" in
		-h|--help)
			echo -e "Usage:\t$0 [-h|--help] [-w|--width <width>] <16-bit-image.bin>"
			exit	0
			;;
		-w|--width|-d|--depth)
			depth="$2"
			shift
			;;
		-n|--name)
			name="$2"
			shift
			;;
		-*)
			echo -e "$0: error: invalid command line argument near '$1'." >> /dev/stderr
			exit	1
			;;
		*)
			infile="$1"
			;;
	esac; shift
done
 
if ! [ -n "$infile" ] || ! [ -f "$infile" ]; then
	echo "$0: error: input file is missing or not found." >> /dev/stderr
	exit	1
fi
 
nword=$((1<<depth))
 
cat "$infile" /dev/zero | \
head -c $((2*nword)) | \
hexdump -v -e '/2 "%.4x\n"' | \
awk -v f=0 -v i=0 -v n=0 -v nword=$nword -v depth=$depth -v name=$name \
 'BEGIN \
  {	printf("module %s\n",name);
	printf(" (	input		clk,\n");
	printf("	input		mem_ce,\n");
	printf("	input	[%d:0]	mem_a,\n",depth-1);
	printf("	output	[15:0]	mem_d\n");
	printf(" );\n");
	if ( depth==9 )
	 {	printf("reg mem_hi;\n");
		printf("always @(posedge clk) mem_hi <= mem_a[8];\n");
	 }
	else if ( 10<=depth )
	 {	printf("reg [%d:0] mem_hi;\n",depth-9);
		printf("always @(posedge clk) mem_hi <= mem_a[%d:8];\n",depth-1);
	 }
	if ( 9<=depth )
		printf("reg [15:0] mem_d;\n");
 
  } \
  {	arr[n+1]=$1;
	n++;
	if ( n==16 )
	 {	if ( i==0 )
		 {	printf("wire [15:0] db%d;\n",f);
			printf("SB_RAM40_4K flash%d\n",f);
			printf(" (	.RDATA(db%d),\n",f);
			printf("	.RADDR({3%cb000,mem_a[7:0]}),\n",39);
			printf("	.RCLKE(1%cb1),\n",39);
			printf("	.RCLK(clk),\n");
			printf("	.RE(mem_ce),\n");
			printf("	.WADDR(11%cb00000000000),\n",39);
			printf("	.MASK(16%cb0000000000000000),\n",39);
			printf("	.WDATA(16%cb0000000000000000),\n",39);
			printf("	.WCLKE(1%cb0),\n",39);
			printf("	.WCLK(1%cb0),\n",39);
			printf("	.WE(1%cb0)\n",39);
			printf(" );\n");
			printf("defparam flash%d.READ_MODE = 0;\n",f);
		 }
 
		printf("defparam flash%d.INIT_%X = 256%ch",f,i,39);
		for ( k=0 ; k<16 ; k++ )
		 {	if ( k )	printf("_");
			printf("%s",arr[16-k]);			
		 }
		printf(";\n");
		n=0;
		i++;
	 }
	if ( i==16 )
 	 {	i=0;
		f++;
	 }
  } \
 END \
  {	if ( 9<=depth )
	 {	printf("always @(*) begin\n");
		printf("	casex (mem_hi)\n");
		for ( k=0 ; k<nword/256 ; k++ )
			printf("		%d%cd%d: mem_d = db%d;\n",depth-8,39,k,k);
		printf("		default: mem_d = 16%ch0000;\n",39);
		printf("	endcase\n");
		printf("end\n");
	 }
	else
		printf("assign mem_d = db0;\n");
 
	printf("\n");
	printf("endmodule\n");
  }'
 
 
 

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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