| 1 |
70 |
ja_rd |
--------------------------------------------------------------------------------
|
| 2 |
|
|
-- l80pkg.vhdl -- Support package for Light8080 SoC.
|
| 3 |
|
|
--
|
| 4 |
|
|
-- Contains functions used to initialize internal BRAM with object code.
|
| 5 |
|
|
--
|
| 6 |
|
|
-- This package will be used from the object code package where the program
|
| 7 |
|
|
-- initialized RAM constant is defined. If you use script obj2hdl it will
|
| 8 |
|
|
-- take care of this for you.
|
| 9 |
|
|
-- The package is used in entity l80soc too, and nowhere else.
|
| 10 |
|
|
--
|
| 11 |
|
|
-- This file and all the light8080 project files are freeware (See COPYING.TXT)
|
| 12 |
|
|
--------------------------------------------------------------------------------
|
| 13 |
|
|
|
| 14 |
|
|
library ieee;
|
| 15 |
|
|
use ieee.std_logic_1164.all;
|
| 16 |
|
|
use ieee.std_logic_arith.all;
|
| 17 |
|
|
use ieee.std_logic_unsigned.all;
|
| 18 |
|
|
|
| 19 |
|
|
package l80pkg is
|
| 20 |
|
|
|
| 21 |
|
|
-- Basic array type for the declaration of initialization constants.
|
| 22 |
|
|
-- This type is meant to be used to declare a constant with the object code
|
| 23 |
|
|
-- that is to be preprogrammed in an initialized RAM.
|
| 24 |
|
|
type obj_code_t is array(integer range <>) of std_logic_vector(7 downto 0);
|
| 25 |
|
|
|
| 26 |
|
|
-- Basic array type for the definition of initialized RAMs.
|
| 27 |
|
|
type ram_t is array(integer range <>) of std_logic_vector(7 downto 0);
|
| 28 |
|
|
|
| 29 |
|
|
-- Builds BRAM initialization constant from a constant CONSTRAINED byte array
|
| 30 |
|
|
-- containing the application object code.
|
| 31 |
|
|
-- The object code is placed at the beginning of the BRAM and the rest is
|
| 32 |
|
|
-- filled with zeros.
|
| 33 |
|
|
-- CAN BE USED IN SYNTHESIZABLE CODE to compute a BRAM initialization constant
|
| 34 |
|
|
-- from a constant argument.
|
| 35 |
|
|
--
|
| 36 |
|
|
-- oC: Object code table (as generated by utility script obj2hdl for instance).
|
| 37 |
|
|
-- size: Size of the target memory.
|
| 38 |
|
|
-- Returns ram_t value size-bytes long, suitable for synth-time initialization
|
| 39 |
|
|
-- of a BRAM.
|
| 40 |
|
|
function objcode_to_bram(oC : obj_code_t; size : integer) return ram_t;
|
| 41 |
|
|
|
| 42 |
80 |
ja_rd |
-- Compute log2(A), rounding up.
|
| 43 |
|
|
-- Use this to get the minimum width of the address bus necessary to
|
| 44 |
|
|
-- address A locations.
|
| 45 |
|
|
function log2(A : natural) return natural;
|
| 46 |
70 |
ja_rd |
|
| 47 |
|
|
end package;
|
| 48 |
|
|
|
| 49 |
|
|
package body l80pkg is
|
| 50 |
|
|
|
| 51 |
|
|
-- Builds BRAM initialization constant from a constant CONSTRAINED byte array
|
| 52 |
|
|
-- containing the application object code.
|
| 53 |
|
|
function objcode_to_bram(oC : obj_code_t; size : integer) return ram_t is
|
| 54 |
|
|
variable br : ram_t(integer range 0 to size-1);
|
| 55 |
|
|
variable i : integer;
|
| 56 |
|
|
variable obj_size : integer;
|
| 57 |
|
|
begin
|
| 58 |
|
|
|
| 59 |
|
|
-- If the object code table is longer than the array size, truncate code
|
| 60 |
|
|
if oC'length > size then
|
| 61 |
|
|
obj_size := size;
|
| 62 |
|
|
else
|
| 63 |
|
|
obj_size := oC'length;
|
| 64 |
|
|
end if;
|
| 65 |
|
|
|
| 66 |
|
|
-- Copy object code to start of BRAM...
|
| 67 |
|
|
for i in 0 to obj_size-1 loop
|
| 68 |
|
|
br(i) := oC(i);
|
| 69 |
|
|
end loop;
|
| 70 |
|
|
|
| 71 |
|
|
-- ... and fill the rest with zeros
|
| 72 |
|
|
br(obj_size to size-1) := (others => x"00");
|
| 73 |
|
|
|
| 74 |
|
|
return br;
|
| 75 |
|
|
end function objcode_to_bram;
|
| 76 |
|
|
|
| 77 |
80 |
ja_rd |
|
| 78 |
|
|
function log2(A : natural) return natural is
|
| 79 |
|
|
begin
|
| 80 |
|
|
for I in 1 to 30 loop -- Works for up to 32 bit integers
|
| 81 |
|
|
if(2**I >= A) then
|
| 82 |
|
|
return(I);
|
| 83 |
|
|
end if;
|
| 84 |
|
|
end loop;
|
| 85 |
|
|
return(30);
|
| 86 |
|
|
end function log2;
|
| 87 |
|
|
|
| 88 |
70 |
ja_rd |
end package body;
|