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

Subversion Repositories iicmb

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /iicmb/trunk
    from Rev 3 to Rev 4
    Reverse comparison

Rev 3 → Rev 4

/src_tb/test.vhd
6,6 → 6,7
-- Module: Test package. |
-- Version: |
-- 1.0, April 29, 2016 |
-- 1.1, May 10, 2016 Removed obsolete stuff |
-- |
-- Author: Sergey Shuvalkin, (sshuv2@opencores.org) |
-- |
353,72 → 354,8
 
-- Conversion functions
function to_integer (value : in string) return integer;
 
 
 
 
procedure read_identifier(file f : char_file; value : inout string_ptr);
procedure read_integer(file f : char_file; value : out integer);
procedure find_token(file f : char_file; value : in string);
------------------------------------------------------------------------------
 
 
------------------------------------------------------------------------------
-- Working with commands:
------------------------------------------------------------------------------
-- First level of abstraction: tokens.
constant max_token_size : integer := 80;
type token_kind is
(
name,
integer_number,
end_of_line,
end_of_file,
start_of_comment,
separator,
not_recognized
);
 
type token is record
kind : token_kind;
value_ptr : string_ptr;
end record;
 
procedure read_token(file f : char_file; value : inout token);
procedure write_token(file f : char_file; value : inout token);
--
 
------------------------------------------------------------------------------
-- Second level of abstraction: commands.
-- Maximum number of arguments in a command:
constant max_args_in_command : integer := 4*1024;
 
-- Command type:
type command is record
time_cnt : natural; -- The time, when the command should be applied
id : string_ptr; -- Pointer to the command ID.
arg : integer_array_ptr; -- Pointer to the array of arguments.
end record;
 
procedure read_command(file f : char_file; id : in string; cmd : inout command);
 
type command_list_elem;
type command_list_elem_ptr is access command_list_elem;
type command_list_elem is record
cmd : command;
prv : command_list_elem_ptr;
nxt : command_list_elem_ptr;
end record;
type command_list is record
number : natural;
first : command_list_elem_ptr;
last : command_list_elem_ptr;
end record;
procedure init_command_list(fname : in string; variable clist : inout command_list; block_id : in string);
procedure put_command(variable clist : inout command_list; cmd : inout command);
procedure get_command(variable clist : inout command_list; cmd : inout command);
------------------------------------------------------------------------------
 
end test;
--==============================================================================
 
461,87 → 398,6
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
procedure read_integer(file f : char_file; value : out integer) is
variable buf : string(1 to 256);
variable ch0 : character;
variable idx : positive;
begin
-- Searching for first character:
while true loop
assert not(endfile(f)) report "read_integer(): Unexpected End Of File." severity failure;
read(f, ch0);
exit when ((ch0 >= '0')and(ch0 <= '9'))or(ch0 = '-');
end loop;
 
buf(1) := ch0;
idx := 2;
 
-- Reading other characters:
while (not(endfile(f))) loop
read(f, ch0);
if ((ch0 >= '0')and(ch0 <= '9'))or((ch0 >= 'a')and(ch0 <= 'f'))or((ch0 >= 'A')and(ch0 <= 'F'))or(ch0 = 'x') then
buf(idx) := ch0;
idx := idx + 1;
else
exit;
end if;
end loop;
value := to_integer(buf(1 to idx - 1));
end procedure read_integer;
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
procedure read_identifier(file f : char_file; value : inout string_ptr) is
variable buf : string(1 to 256);
variable ch0 : character;
variable idx : positive;
begin
-- Searching for first character:
while true loop
assert not(endfile(f)) report "read_identifier(): Unexpected End Of File." severity failure;
read(f, ch0);
exit when ((ch0 >= 'A')and(ch0 <= 'Z'))or((ch0 >= 'a')and(ch0 <= 'z'))or(ch0 = '_');
end loop;
 
buf(1) := ch0;
idx := 2;
 
-- Reading other characters:
while (not(endfile(f))) loop
read(f, ch0);
if ((ch0 >= 'A')and(ch0 <= 'Z'))or((ch0 >= 'a')and(ch0 <= 'z'))or((ch0 >= '0')and(ch0 <= '9'))or(ch0 = '_') then
buf(idx) := ch0;
idx := idx + 1;
else
exit;
end if;
end loop;
deallocate(value);
value := new string'(buf(1 to idx - 1));
end procedure read_identifier;
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
procedure find_token(file f : char_file; value : in string) is
variable ch0 : character;
variable idx : positive;
begin
idx := value'low;
while true loop
assert not(endfile(f)) report "find_token(" & value & "): Unexpected End Of File." severity failure;
read(f, ch0);
if (ch0 = value(idx)) then
exit when (idx = value'high);
idx := idx + 1;
else
idx := value'low;
end if;
end loop;
end procedure find_token;
------------------------------------------------------------------------------
 
 
------------------------------------------------------------------------------
function to_integer(value : in string) return integer is
variable value_local : integer := 0;
variable start_idx : positive;
661,270 → 517,6
 
 
------------------------------------------------------------------------------
-- Working with commands:
------------------------------------------------------------------------------
-- First level of abstraction: tokens.
procedure read_token(file f : char_file; value : inout token) is
variable ch0 : character;
variable idx : integer := 1;
variable end_of_token : boolean := false;
variable buf : string(1 to max_token_size);
variable kind : token_kind;
begin
deallocate(value.value_ptr);
while (idx <= max_token_size)and(end_of_token = false) loop
if (idx = 1) then
if endfile(f) then
kind := end_of_file;
end_of_token := true;
else
read(f, ch0);
next when (ch0 = ' ')or(ch0 = ht);
buf(idx) := ch0;
idx := idx + 1;
 
if (ch0 = '#') then
kind := start_of_comment;
end_of_token := true;
elsif ((ch0 >= '0')and(ch0 <= '9'))or(ch0 = '-') then
kind := integer_number;
elsif ((ch0 >= 'A')and(ch0 <= 'Z'))or((ch0 >= 'a')and(ch0 <= 'z'))or(ch0 = '_') then
kind := name;
elsif (ch0 = cr) then
kind := end_of_line;
elsif (ch0 = lf) then
kind := end_of_line;
end_of_token := true;
elsif (ch0 = ',')or(ch0 = '(')or(ch0 = ')')or(ch0 = '{')or(ch0 = '}')or(ch0 = ':') then
kind := separator;
end_of_token := true;
else
kind := not_recognized;
end_of_token := true;
end if;
end if;
else
if endfile(f) then
end_of_token := true;
else
read(f, ch0);
case kind is
when integer_number =>
if ((ch0 >= '0')and(ch0 <= '9'))or((ch0 >= 'a')and(ch0 <= 'f'))or((ch0 >= 'A')and(ch0 <= 'F'))or(ch0 = 'x') then
buf(idx) := ch0;
idx := idx + 1;
else
end_of_token := true;
end if;
when name =>
if ((ch0 >= 'A')and(ch0 <= 'Z'))or((ch0 >= 'a')and(ch0 <= 'z'))or((ch0 >= '0')and(ch0 <= '9'))or(ch0 = '_') then
buf(idx) := ch0;
idx := idx + 1;
else
end_of_token := true;
end if;
when end_of_line =>
if (ch0 = lf) then
buf(idx) := ch0;
idx := idx + 1;
end if;
end_of_token := true;
when others =>
end_of_token := true;
end case;
end if;
end if;
end loop;
 
value.kind := kind;
value.value_ptr := new string'(buf(1 to idx - 1));
end procedure read_token;
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
procedure write_token(file f : char_file; value : inout token) is
begin
fprint_string(f, value.value_ptr.all & ' ');
end procedure write_token;
------------------------------------------------------------------------------
--
 
------------------------------------------------------------------------------
-- Second level of abstraction: commands.
-- <integer_number> <name0> <name1> <{> <integer_number> ... <}>
procedure read_command(file f : char_file; id : in string; cmd : inout command) is
variable tmp_token : token;
variable token_idx : integer := 1;
variable arg_idx : integer := 1;
variable tmp_array : integer_array(1 to max_args_in_command);
begin
while true loop
read_token(f, tmp_token);
 
case tmp_token.kind is
when name =>
assert (token_idx /= 1) report "read_command(): identifier " &
tmp_token.value_ptr.all & " found where should be an integer number." severity failure;
assert (token_idx /= 4) report "read_command(): identifier " &
tmp_token.value_ptr.all & " found where should be an { brace." severity failure;
assert (token_idx /= 5) report "read_command(): identifier " &
tmp_token.value_ptr.all & " found where should be an } brace or an integer number." severity failure;
if (token_idx = 2) then
if (tmp_token.value_ptr.all /= id) then -- Not our command, go to the end.
while true loop
read_token(f, tmp_token);
exit when (tmp_token.kind = separator)or(tmp_token.value_ptr.all = "}");
end loop;
token_idx := 1;
else
token_idx := 3;
end if;
else
deallocate(cmd.id);
cmd.id := new string'(tmp_token.value_ptr.all);
token_idx := 4;
end if;
 
when integer_number =>
assert (token_idx /= 2) report "read_command(): integer number " &
tmp_token.value_ptr.all & " found where should be an identifier." severity failure;
assert (token_idx /= 3) report "read_command(): integer number " &
tmp_token.value_ptr.all & " found where should be an identifier." severity failure;
assert (token_idx /= 4) report "read_command(): integer number " &
tmp_token.value_ptr.all & " found where should be an { brace." severity failure;
if (token_idx = 1) then
cmd.time_cnt := to_integer(tmp_token.value_ptr.all);
token_idx := 2;
else
tmp_array(arg_idx) := to_integer(tmp_token.value_ptr.all);
arg_idx := arg_idx + 1;
end if;
 
when end_of_line =>
null;
 
when end_of_file =>
exit;
 
when start_of_comment =>
while true loop
read_token(f, tmp_token);
exit when (tmp_token.kind = end_of_line)or(tmp_token.kind = end_of_file);
end loop;
 
when separator =>
if (token_idx = 4)and(tmp_token.value_ptr.all = "{") then
token_idx := 5;
elsif (token_idx = 5)and(tmp_token.value_ptr.all = "}") then
token_idx := 6;
exit;
end if;
 
when not_recognized =>
assert false report "read_command(): unknown pattern " & tmp_token.value_ptr.all & " found." severity failure;
end case;
end loop;
 
assert (token_idx = 1)or(token_idx = 6) report "read_command(): Unexpected End of File." severity failure;
 
if (token_idx = 1) then
cmd.time_cnt := 0;
deallocate(cmd.id);
cmd.id := new string'("stop");
deallocate(cmd.arg);
else
deallocate(cmd.arg);
cmd.arg := new integer_array'(tmp_array(1 to arg_idx - 1));
end if;
end procedure read_command;
------------------------------------------------------------------------------
 
 
------------------------------------------------------------------------------
procedure put_command(variable clist : inout command_list; cmd : inout command) is
variable new_le : command_list_elem_ptr;
variable tmp : command_list_elem_ptr;
begin
new_le := new command_list_elem;
new_le.all.cmd.time_cnt := cmd.time_cnt;
new_le.all.cmd.id := new string'(cmd.id.all);
new_le.all.cmd.arg := new integer_array'(cmd.arg.all);
 
if (clist.number = 0) then
-- The command list is empty.
new_le.all.prv := null;
new_le.all.nxt := null;
clist.first := new_le;
clist.last := new_le;
else
-- The command list is not empty.
new_le.all.prv := clist.last;
new_le.all.nxt := null;
clist.last.all.nxt := new_le;
clist.last := new_le;
end if;
clist.number := clist.number + 1;
end procedure put_command;
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
procedure init_command_list(fname : in string; variable clist : inout command_list; block_id : in string) is
file cmd_data : char_file;
variable cmd : command;
begin
file_open(cmd_data, fname, read_mode);
 
clist.number := 0;
clist.first := null;
clist.last := null;
 
while (true) loop
read_command(cmd_data, block_id, cmd);
exit when (cmd.id.all = "stop");
put_command(clist, cmd);
end loop;
 
deallocate(cmd.id);
deallocate(cmd.arg);
file_close(cmd_data);
end procedure init_command_list;
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
procedure get_command(variable clist : inout command_list; cmd : inout command) is
variable old_el : command_list_elem_ptr;
begin
deallocate(cmd.id);
deallocate(cmd.arg);
if (clist.number = 0) then
cmd.time_cnt := 0;
cmd.id := new string'("stop");
else
if (clist.number = 1) then
old_el := clist.first;
clist.number := clist.number - 1;
clist.first := null;
clist.last := null;
else
old_el := clist.first;
clist.number := clist.number - 1;
clist.first := clist.first.all.nxt;
old_el.all.nxt.all.prv := null;
end if;
cmd.time_cnt := old_el.all.cmd.time_cnt;
cmd.id := new string'(old_el.all.cmd.id.all);
cmd.arg := new integer_array'(old_el.all.cmd.arg.all);
deallocate(old_el.all.cmd.id);
deallocate(old_el.all.cmd.arg);
deallocate(old_el);
end if;
end procedure get_command;
------------------------------------------------------------------------------
 
 
 
 
------------------------------------------------------------------------------
function to_string(value : in std_logic;
format : in string := "b";
width : in natural := 0;
/src_tb/iicmb_m_sq_tb.vhd
125,7 → 125,7
component i2c_slave_model is
generic
(
i2c_adr : std_logic_vector(6 downto 0)
I2C_ADR : integer
);
port
(
136,11 → 136,11
------------------------------------------------------------------------------
 
------------------------------------------------------------------------------
function get_slave_addr(n : natural) return std_logic_vector is
variable ret : std_logic_vector(6 downto 0);
function get_slave_addr(n : natural) return natural is
variable ret : unsigned(6 downto 0);
begin
ret := "010" & std_logic_vector(to_unsigned(n, 4));
return ret;
ret := "010" & to_unsigned(n, 4);
return to_integer(ret);
end function get_slave_addr;
------------------------------------------------------------------------------
 
264,7 → 264,7
i2c_slave_model_inst0 : i2c_slave_model
generic map
(
i2c_adr => get_slave_addr(i)
I2C_ADR => get_slave_addr(i)
)
port map
(
/src_tb/iicmb_m_sq_arb_tb.vhd
122,7 → 122,7
component i2c_slave_model is
generic
(
i2c_adr : std_logic_vector(6 downto 0)
I2C_ADR : integer
);
port
(
132,31 → 132,34
end component i2c_slave_model;
------------------------------------------------------------------------------
 
signal clk : std_logic := '0';
signal s_rst : std_logic := '1';
constant c_slave_addr : std_logic_vector(6 downto 0) := "0100001";
constant c_i2c_adr : integer := to_integer(unsigned(c_slave_addr));
 
signal cs_start_0 : std_logic := '0';
signal cs_busy_0 : std_logic;
signal cs_status_0 : std_logic_vector(2 downto 0);
signal clk : std_logic := '0';
signal s_rst : std_logic := '1';
 
signal cs_start_1 : std_logic := '0';
signal cs_busy_1 : std_logic;
signal cs_status_1 : std_logic_vector(2 downto 0);
signal cs_start_0 : std_logic := '0';
signal cs_busy_0 : std_logic;
signal cs_status_0 : std_logic_vector(2 downto 0);
 
signal scl_o_0 : std_logic_vector(0 to 0) := (others => '1');
signal sda_o_0 : std_logic_vector(0 to 0) := (others => '1');
signal scl_o_1 : std_logic_vector(0 to 0) := (others => '1');
signal sda_o_1 : std_logic_vector(0 to 0) := (others => '1');
signal scl : std_logic_vector(0 to 0) := (others => 'H');
signal sda : std_logic_vector(0 to 0) := (others => 'H');
signal cs_start_1 : std_logic := '0';
signal cs_busy_1 : std_logic;
signal cs_status_1 : std_logic_vector(2 downto 0);
 
signal scl_o_0 : std_logic_vector(0 to 0) := (others => '1');
signal sda_o_0 : std_logic_vector(0 to 0) := (others => '1');
signal scl_o_1 : std_logic_vector(0 to 0) := (others => '1');
signal sda_o_1 : std_logic_vector(0 to 0) := (others => '1');
signal scl : std_logic_vector(0 to 0) := (others => 'H');
signal sda : std_logic_vector(0 to 0) := (others => 'H');
 
type real_vector is array (natural range <>) of real;
signal scl_real : real_vector(0 to 0);
signal sda_real : real_vector(0 to 0);
signal scl_quant : bit_vector(0 to 0);
signal sda_quant : bit_vector(0 to 0);
signal scl_nquant : bit_vector(0 to 0) := (others => '1');
signal sda_nquant : bit_vector(0 to 0) := (others => '1');
signal scl_real : real_vector(0 to 0);
signal sda_real : real_vector(0 to 0);
signal scl_quant : bit_vector(0 to 0);
signal sda_quant : bit_vector(0 to 0);
signal scl_nquant : bit_vector(0 to 0) := (others => '1');
signal sda_nquant : bit_vector(0 to 0) := (others => '1');
 
begin
 
200,10 → 203,10
g_f_scl_0 => c_f_scl_0,
g_cmd =>
(
scmd_wait(1), -- Wait for 1 ms
scmd_set_bus(0), -- Select bus #0
scmd_write_byte("0100001", x"03", x"4A"), -- Write byte
scmd_write_byte("0100001", x"05", x"27") -- Write byte
scmd_wait(1), -- Wait for 1 ms
scmd_set_bus(0), -- Select bus #0
scmd_write_byte(c_slave_addr, x"03", x"4A"), -- Write byte
scmd_write_byte(c_slave_addr, x"05", x"27") -- Write byte
)
)
port map
229,10 → 232,10
g_f_scl_0 => c_f_scl_1,
g_cmd =>
(
scmd_wait(1), -- Wait for 1 ms
scmd_set_bus(0), -- Select bus #0
scmd_write_byte("0100001", x"03", x"4A"), -- Write byte
scmd_write_byte("0100001", x"05", x"67") -- Write byte
scmd_wait(1), -- Wait for 1 ms
scmd_set_bus(0), -- Select bus #0
scmd_write_byte(c_slave_addr, x"03", x"4A"), -- Write byte
scmd_write_byte(c_slave_addr, x"05", x"67") -- Write byte
)
)
port map
294,7 → 297,7
i2c_slave_model_inst0 : i2c_slave_model
generic map
(
i2c_adr => "0100001"
I2C_ADR => c_i2c_adr
)
port map
(
/src_tb/iicmb_m_wb_tb.vhd
129,7 → 129,7
component i2c_slave_model is
generic
(
i2c_adr : std_logic_vector(6 downto 0)
I2C_ADR : integer
);
port
(
431,7 → 431,7
i2c_slave_model_inst0 : i2c_slave_model
generic map
(
i2c_adr => get_slave_addr(i)
I2C_ADR => to_integer(unsigned(get_slave_addr(i)))
)
port map
(

powered by: WebSVN 2.1.0

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