Pico Blaze

FPGASynth.PicoBlaze History

Hide minor edits - Show changes to markup

June 13, 2008, at 09:19 PM by 71.189.44.199 -
Changed lines 3-4 from:

PicoBlaze SCRATCH PAD RAM PREINITIALIZATION (Verilog):

to:

PicoBlaze SCRATCH PAD RAM PREINITIALIZATION (Verilog):

June 13, 2008, at 09:17 PM by 71.189.44.199 -
Changed lines 3-4 from:

PicoBlaze SCRATCH PAD RAM PREINITIALIZATION (Verilog):

to:

PicoBlaze SCRATCH PAD RAM PREINITIALIZATION (Verilog):

February 05, 2007, at 02:26 PM by 71.106.217.87 -
Changed lines 3-6 from:

VERILOG

SCRATCH PAD RAM PREINITIALIZATION:

to:

PicoBlaze SCRATCH PAD RAM PREINITIALIZATION (Verilog):

February 05, 2007, at 02:24 PM by 71.106.217.87 -
Changed lines 34-36 from:

// do bit extraction from file ./spRAMdata and modify kcpsm3 with // initialization code for scratch pad RAM.

to:

// do bit extraction from file ./spRAMdata and modify kcpsm3.v // with initialization code for scratch pad RAM.

February 05, 2007, at 02:23 PM by 71.106.217.87 -
Added lines 32-36:

// bitex.c // Scott R. Gravenhorst 2007-02-04 // do bit extraction from file ./spRAMdata and modify kcpsm3 with // initialization code for scratch pad RAM.

February 05, 2007, at 02:19 PM by 71.106.217.87 -
Changed lines 25-26 from:

Note that this C source was written for a Linux environment capable of handling 64 bit integer type "unsigned long long". It was tested with Fedora Core 5 Linux.

to:

Note1: This C source was written for a Linux environment capable of handling 64 bit integer type "unsigned long long". It was tested with Fedora Core 5 Linux.

Note2: The kcpsm3.v module source code contains defparam statements which look syntax correct and should initialize the scratch pad RAM. However, using WebPACK ISE 8.1i, I could not get this to work. So the bitex program below does two things: 1) calculate bit extraction and create implicit initializer code using #() format and 2) removes the defparam statements meant to initialize the RAM.

Added line 39:

FILE *fi, *fo;

Changed lines 43-45 from:

FILE *fi; FILE *fo; unsigned int bit, i;

to:

char data[8][32]; unsigned int bit, i, val;

Deleted line 45:

unsigned int val;

Changed lines 47-48 from:

char data[8][32];

to:
Changed lines 51-52 from:
  n = 0LL;
  for ( i=0; i<64; i++ )            // for each byte
to:
  for ( n=0LL,i=0; i<64; i++ )            // for entire address range
Changed line 54 from:
    p = strtok( buf, "=" );         //
to:
    p = strtok( buf, "=" );         // toss address...
Changed lines 56-58 from:
    sscanf( p, "%X", &val );
    n = n >> 1LL;
    n = n + ( ((val & mask)!=0) ? 0x8000000000000000LL : 0LL );
to:
    sscanf( p, "%X", &val );        // convert ASCII hex to binary
    n = n >> 1;                     // shift bits right to make room in MSB
    n = n + ( ((val & mask)!=0) ? 0x8000000000000000LL : 0LL );  // add in new MSB
Changed line 61 from:
  mask = mask << 1;
to:
  mask = mask << 1;                 // advance bit to extract
Changed lines 75-76 from:
  if ( strstr( buf, "RAM64X1S" ) == NULL )    fprintf( fo, "%s", buf );
  else
to:
  if ( strstr( buf, "RAM64X1S" ) == NULL )
Changed lines 77-78 from:
    fprintf( fo, " RAM64X1S #(.INIT(64'hd (\n", data[i], i );
    i++;
to:
    // The kcpsm3.v module comes with defparam statements that are meant to initialize the SP RAM,
    // but they don't work with WebPACK ISE (8i).  Therefore, this program removes them to prevent
    // confusing the compiler.
    if ( strstr( buf, "defparam memory_bit_" ) == NULL )  fprintf( fo, "%s", buf );
Added lines 82-86:
  else
    {
    fprintf( fo, " RAM64X1S #(.INIT(64'hd (\n", data[i], i );
    i++;
    }
February 04, 2007, at 11:06 PM by 71.106.217.87 -
Changed lines 13-14 from:

I have written a C program (gcc) which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization values for all 64 locations of the RAM in the form:

to:

I have written a C program (gcc) which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization values for all 64 eight bit wide locations of the RAM in the form:

February 04, 2007, at 11:05 PM by 71.106.217.87 -
Changed lines 11-12 from:

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes the data to be stored in that bit slice. Unfortunately, we cannot just supply the data as simple bytes because each RAM is only one bit wide and we must supply each single bit (by 64 locations) with a single bit wide initializer, 64 bits long. This requires bit extraction which can be tedious to do by hand.

to:

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes the data to be stored in that bit slice. Unfortunately, we cannot just supply the data as simple bytes because each RAM is only one bit wide and we must supply each single bit (by 64 locations) wide RAM with a single bit wide initializer, 64 bits long, one bit for each of the 64 addressable locations. This requires bit extraction which can be tedious to do by hand.

February 04, 2007, at 11:04 PM by 71.106.217.87 -
Changed lines 11-12 from:

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes the data to be stored in that bit slice.

to:

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes the data to be stored in that bit slice. Unfortunately, we cannot just supply the data as simple bytes because each RAM is only one bit wide and we must supply each single bit (by 64 locations) with a single bit wide initializer, 64 bits long. This requires bit extraction which can be tedious to do by hand.

February 04, 2007, at 10:57 PM by 71.106.217.87 -
Changed lines 23-24 from:

Run the program 'bitex'. bitex does the bit extraction from spRAMdata. kcpsm3.v is read and a modified version is written as kcpsm3.v.new in the project directory. Rename kcpsm3.v.new to kcpsm3.v and then recompile your project and the new values should be apparent to the application.

to:

Change to the project directory and run the program 'bitex'. bitex does the bit extraction from spRAMdata. kcpsm3.v is read and a modified version is written as kcpsm3.v.new in the project directory. Rename kcpsm3.v.new to kcpsm3.v and then recompile your project and the new values should be apparent to the application.

February 04, 2007, at 10:56 PM by 71.106.217.87 -
Changed lines 21-22 from:

The file name for the data should be 'spRAMdata' and should reside in the project directory. kcpsm3.v should also reside there.

to:

The file name for the initialization data should be 'spRAMdata' and should reside in the project directory. kcpsm3.v should also reside there.

February 04, 2007, at 10:44 PM by 71.106.217.87 -
Changed lines 17-18 from:

where aa is the RAM address in hex (00 through 3F) and dd is the hex byte data to use for initialization for address aa.

to:

where aa is the RAM address in hex (00 through 3F) and dd is the hex data byte to use for initialization for address aa.

February 04, 2007, at 10:43 PM by 71.106.217.87 -
Changed lines 17-18 from:

where aa is the RAM address in hex and dd is the hex data to use for initialization for address aa.

to:

where aa is the RAM address in hex (00 through 3F) and dd is the hex byte data to use for initialization for address aa.

February 04, 2007, at 10:42 PM by 71.106.217.87 -
Changed lines 13-14 from:

I have written a C program (gcc) which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization for all 64 locations of the RAM in the form:

to:

I have written a C program (gcc) which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization values for all 64 locations of the RAM in the form:

February 04, 2007, at 10:41 PM by 71.106.217.87 -
Changed lines 19-20 from:

All 64 locations MUST be populated.

to:

All 64 locations MUST be populated, must begin with address 00, must end with address 3F and must be sequential.

February 04, 2007, at 10:39 PM by 71.106.217.87 -
Changed lines 9-10 from:

This can come in handy when you need a table initialized, but are short on instruction space. If done in assembly code, each location would require 2 instructions to initialize, thus to initialize the entire 64 location RAM, you would comsume 128 locations.

to:

This can come in handy when you need a table initialized, but are short on instruction space. If done in assembly code, each location would require 2 instructions to initialize, thus to initialize the entire 64 location RAM, you would consume 128 locations.

February 04, 2007, at 10:35 PM by 71.106.217.87 -
Changed lines 25-26 from:

Note that this C source was written for a Linux environment capable of handling 64 bit integer type "unsigned long long".

to:

Note that this C source was written for a Linux environment capable of handling 64 bit integer type "unsigned long long". It was tested with Fedora Core 5 Linux.

February 04, 2007, at 10:32 PM by 71.106.217.87 -
Changed lines 13-14 from:

I have written a C program which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization for all 64 locations of the RAM in the form:

to:

I have written a C program (gcc) which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization for all 64 locations of the RAM in the form:

Added lines 25-26:

Note that this C source was written for a Linux environment capable of handling 64 bit integer type "unsigned long long".

Deleted line 60:
  //printf( "bit .16llX mask=%.2X\n", bit, n, mask );
Changed lines 76-77 from:
  if ( strstr( buf, "RAM64X1S" ) == NULL )
to:
  if ( strstr( buf, "RAM64X1S" ) == NULL )    fprintf( fo, "%s", buf );
  else
Changed lines 79-80 from:
    fprintf( fo, "%s", buf );
to:
    fprintf( fo, " RAM64X1S #(.INIT(64'hd (\n", data[i], i );
    i++;
Deleted lines 81-85:
  else
    {
    fprintf( fo, " RAM64X1S #(.INIT(64'hd (\n", data[i], i );
    i++;
    }
Deleted line 84:
February 04, 2007, at 10:30 PM by 71.106.217.87 -
Changed lines 11-12 from:

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes that data to be stored in that bit slice.

to:

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes the data to be stored in that bit slice.

February 04, 2007, at 10:28 PM by 71.106.217.87 -
Added lines 5-6:

SCRATCH PAD RAM PREINITIALIZATION:

February 04, 2007, at 10:26 PM by 71.106.217.87 -
Added line 25:

[@

Added line 87:

@]

February 04, 2007, at 10:24 PM by 71.106.217.87 -
Changed lines 1-89 from:
to:

Author: Scott Gravenhorst

VERILOG

This article describes how to modify the kcpsm3.v module file to pre-initialize the scratchpad RAM to values you define as opposed to the default of all zeroes for all 64 locations.

This can come in handy when you need a table initialized, but are short on instruction space. If done in assembly code, each location would require 2 instructions to initialize, thus to initialize the entire 64 location RAM, you would comsume 128 locations.

Since the kcpsm3 module is a source file, we can force it to instantiate it's RAM with values we choose ahead of time and plant in the kcpsm3.v file. This amounts to adding a parameter override clause to the instantiation of each of the 8 RAM64X1S primitives which includes that data to be stored in that bit slice.

I have written a C program which can do this automatically for you. It requires a kcpsm3.v file as well as a file containing the initialization for all 64 locations of the RAM in the form:

aa=dd

where aa is the RAM address in hex and dd is the hex data to use for initialization for address aa.

All 64 locations MUST be populated.

The file name for the data should be 'spRAMdata' and should reside in the project directory. kcpsm3.v should also reside there.

Run the program 'bitex'. bitex does the bit extraction from spRAMdata. kcpsm3.v is read and a modified version is written as kcpsm3.v.new in the project directory. Rename kcpsm3.v.new to kcpsm3.v and then recompile your project and the new values should be apparent to the application.

C source code for bitex.c:


  1. include <stdio.h>
  2. include <string.h>
  3. define BUFSIZE 1024

int main ( int argc, char *argv[] ) { char filename[1024] = {"./spRAMdata"}; char buf[BUFSIZE]; char *p; FILE *fi; FILE *fo; unsigned int bit, i; unsigned int mask = 1; unsigned int val; unsigned long long n; char data[8][32];

for ( bit=0; bit<8; bit++ )

  {
  fi = fopen( filename, "r" );
  n = 0LL;
  for ( i=0; i<64; i++ )            // for each byte
    {
    fgets( buf, BUFSIZE, fi );      // get line from file
    p = strtok( buf, "=" );         //
    p = strtok( NULL, "=" );        // get data byte value
    sscanf( p, "%X", &val );
    n = n >> 1LL;
    n = n + ( ((val & mask)!=0) ? 0x8000000000000000LL : 0LL );
    }
  //printf( "bit .16llX mask=%.2X\n", bit, n, mask );
  sprintf( data[bit], "%.16llX", n );
  mask = mask << 1;
  fclose( fi );
  }

/////////////////// // ASCII hex data generated by bit extraction from input file now resides in array data[] // Now read through kcpsm3.v and add new initialization data

fi = fopen( "./kcpsm3.v", "r" ); fo = fopen( "./kcpsm3.v.new", "w" );

i = 0; while ( fgets( buf, BUFSIZE, fi ) != NULL )

  {
  if ( strstr( buf, "RAM64X1S" ) == NULL )
    {
    fprintf( fo, "%s", buf );
    }
  else
    {
    fprintf( fo, " RAM64X1S #(.INIT(64'hd (\n", data[i], i );
    i++;
    }
  }

fclose( fi ); fclose( fo );

}


February 04, 2007, at 10:09 PM by 71.106.217.87 -
Added line 1: