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

Subversion Repositories light8080

[/] [light8080/] [trunk/] [vhdl/] [soc/] [l80pkg.vhdl] - Blame information for rev 70

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
 
43
end package;
44
 
45
package body l80pkg is
46
 
47
-- Builds BRAM initialization constant from a constant CONSTRAINED byte array
48
-- containing the application object code.
49
function objcode_to_bram(oC : obj_code_t; size : integer) return ram_t is
50
variable br : ram_t(integer range 0 to size-1);
51
variable i : integer;
52
variable obj_size : integer;
53
begin
54
 
55
    -- If the object code table is longer than the array size, truncate code
56
    if oC'length > size then
57
        obj_size := size;
58
    else
59
        obj_size := oC'length;
60
    end if;
61
 
62
    -- Copy object code to start of BRAM...
63
    for i in 0 to obj_size-1 loop
64
        br(i) := oC(i);
65
    end loop;
66
 
67
    -- ... and fill the rest with zeros
68
    br(obj_size to size-1) := (others => x"00");
69
 
70
    return br;
71
end function objcode_to_bram;
72
 
73
end package body;

powered by: WebSVN 2.1.0

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