Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 type mem_model_t is protected type mem_t is array(0 to 255) of std_logic_vector(7 downto 0); variable mem : mem_t; function std_logic_vector read(addr : integer range 0 to 255) is return mem(addr); end function; procedure write(d : std_logic_vector(7 downto 0); addr : integer range 0 to 255) is mem(addr) := d; end procedure; end protected mem_model_t; shared variable mem_model : mem_model_t; ....... process begin input <= mem_model.read(N); ...... mem_model.write(N, output); end process;
Code VHDL - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 package ll_test_pkg is generic ( type data_t; NULL_VALUE : data_t ); type link_list_t is protected procedure add_item( d : data_t ); impure function get_item return data_t; end protected link_list_t; end package ll_test_pkg; package body ll_test_pkg is type link_list_t is protected body type data_ll_t; type data_ll_ptr_t is access data_ll_t; type data_ll_t is record d : data_t; d_next : data_ll_ptr_t; end record data_ll_t; variable start : data_ll_ptr_t; procedure add_item( d : data_t ) is variable ptr : data_ll_ptr_t; begin ptr := new data_ll_t; ptr.d := d; ptr.d_next := start; start := ptr; end procedure add_item; impure function get_item return data_t is variable ret : data_t; variable ptr : data_ll_ptr_t; begin if start /= null then ret := start.d; ptr := start.d_next; DEALLOCATE(start); start := ptr; else ret := NULL_VALUE; end if; return ret; end function get_item; end protected body link_list_t; end package body ll_test_pkg; library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use std.textio.all; entity ll_test is end entity ll_test; architecture sim of ll_test is begin process package ll_test_us_pkg is new work.ll_test_pkg generic map ( data_t => unsigned(7 downto 0), NULL_VALUE => x"XX" ); package ll_test_int_pkg is new work.ll_test_pkg generic map ( data_t => integer, NULL_VALUE => -1 ); variable ll_us : ll_test_us_pkg.link_list_t; variable ll_int : ll_test_int_pkg.link_list_t; begin ll_us.add_item( to_unsigned(6 , 8) ); ll_us.add_item( to_unsigned(10, 8) ); ll_us.add_item( to_unsigned(12, 8) ); ll_us.add_item( to_unsigned(21, 8) ); ll_us.add_item( to_unsigned(31, 8) ); for i in 1 to 5 loop ll_int.add_item( to_integer( ll_us.get_item) ); end loop; for i in 1 to 5 loop --write(OUTPUT, to_hstring( ll_us.get_item ) & LF ); write(OUTPUT, to_string( ll_int.get_item ) & LF ); end loop; wait; end process; end architecture sim;