I guess what I would like is a type that Would not have to be
initialized
before compile time.
Does the following code work?
if not, why not?
--architecture of our testbench
architecture behavior of testbench is
--component I/O
signal data_in, data_out : std_logic_vector(7 downto 0);
signal counter : natural;
-- Images read in from file
signal height, width : natural;
-- test bench start switch,
--so we only read data from file once at start of sim
signal init : boolean := false;
type pixel is natural range 0 to 255;
type pixel_ptr is access pixel;
-- this should be a global variable accessible by any process
shared variable Image : pixel_ptr;
begin
init_ptrs : process(init)
if init = false then
--get image dimensions from file
height <= get_image_height("image.pgm");
width <= get_image_width("image.pgm");
--allocate memory
Image := new pixel_ptr(height * width);
-- get pixel data from file, and put into pointer
get_image_pixels("image.pgm", Image);
init <= true;
end if;
end process;
-- access our pixels in a clocked process...
access_pix : process(clk, rst, data_in, counter
if rst = '1' then
counter <= 0;
data_in <= (others => '0');
elsif rising_edge(clk) then
data_in <= std_logic_vector(to_unsigned(Image(counter),
data_in'length));
counter <= counter + 1;
end if;
end process;
---rest of test bench occurs below...
uut : some_component
port map
(
rst => rst,
clk => clk,
data_in => data_in,
data_out => data_out
);
end architecture;
On Feb 16, 9:12 pm, "KJ" <kkjenni...@sbcglobal.net> wrote:
> "wallge" <wal...@gmail.com> wrote in message
>
> news: ups.com...> Is there a way to use shared variable or something along these lines
> > to be able to access my dynamically allocated memory
> > in multiple processes or procedures.
>
> Like any other variable, a pointer can be a shared variable.
>
> One detail I left out of the first post is the definition of the pointer
> type and might have been confusing about which were pointers and which were
> not.
>
> If you have type 'Image_Type' (presumably a record type along the lines of
> your C 'struct') then you define yet another type which is a pointer to
> something of that type
> type ptr_Image_Type is access Image_Type;
>
> Now you would declare a variable (shared if you'd prefer) of that pointer
> type
> variable A_ptr_Image_Type_variable: ptr_Image_Type;
>
> and then you would get a new thing of that type with the 'new' statement
> like...
> A_ptr_Image_Type_variable := new Image_Type;
>
> The assignment could also have combined with the declaration like this...
> variable A_ptr_Image_Type_variable: ptr_Image_Type := new Image_Type;
>
> Then access elements of that record like this...
>
> A_ptr_Image_Type_variable.element1 := 123;
>
> and lastly deallocate it and free memory with
> deallocate(A_ptr_Image_Type_variable);
>
>
>
> > Also, can the various elements of allocated data types
> > be accessed with standard array(index) notation?
>
> Yes
>
> > For instance in the Image_Type_variable := new
> > Image_Type(Number_Of_Things);
> > declaration, can i write:
> > Image_Type(5)
> > to assign or access that particular array value?
>
> Yes.
>
> > or if I am using a for-loop:
>
> > Image_Type(i) := some_value;
>
> > to assign to that array value?
>
> Yes.
>
> The notation when accessing the variable is identical whether the
> 'Image_Type' variable is a pointer or a plain old fixed type that you're
> used to. It's different than C in that regard in that with C the notation
> you use is different based on whether the variable is a pointer or not.
>
> Kevin Jennings
|