ASIC/FPGA Design and Verification Out Source Services
Run a perl script from vim on a block of text, to enumerate constants for a state machine.
-
In this site, many examples show how to run a perl script, from within vim, on a marked text.
-
In this case a set of constants, written in VHDL for a large state machine, are enumerated, by the script.
This example simply re-numbers the constants, saving precious time, of manual typing.
When a new constant is inserted, for example, such a script is a real asset.
Instead of the simple counter, which I use in this script, a one hot scheme can be easily implemented instead.
-
To operate, first mark the block from within vim: 'a and 'b, for instance. The block may contain remarks. The script will leave remarks untouched.
signal fsm_ns :std_logic_vector(15 downto 0);
--read constatns
constant C_IDLE0 : std_logic_vector(15 downto 0) := "0000000000000001";
--assert CLE and CE
constant C_CLE_0 : std_logic_vector(15 downto 0) := "0000000000000010";
--assert WE for 25 ns / 4 cycles
...
--negate WE
constant C_REST5 : std_logic_vector(15 downto 0) := "0000000000111010";
constant C_REST6 : std_logic_vector(15 downto 0) := "0000000000111011";
-
Run the script by:
:'a,'b !perl scr_C_bin.pl
-
The script is very simple and is shown below. Note how easy a decimal value is converted to a binary format.
#!/bin/perl
$cnt=1;
while (<STDIN>) {
chomp($_);
if($_ =~ /(constant C_.*: std_logic_vector.15 downto 0. := ")([01]*)";/) {
$a=$1;
$b=sprintf("%016b", $cnt);
print(" $a");
print("$b");
print("\";\n");
$cnt++;
}
else {print("$_\n");}
}#while
To have a "walking one paatern", I used the following code:
$cnt=0;
...
#simple increment
#$cnt++;
#
#walking one
if($cnt == 0) { $cnt = 1; }
else {
$cnt *= 2;
}
|
|
Also available on this project:
|
|