Commit 3da02853 authored by Grzegorz Daniluk's avatar Grzegorz Daniluk

diot_diag: simplify diag type for simpler handling

parent 758d6ea2
......@@ -37,21 +37,18 @@ package diag_pkg is
constant c_CMD_FAN_SPEED : integer := 3;
constant c_CMD_TEMP : integer := 4;
type t_diag_buf is array (natural range<>) of std_logic_vector(7 downto 0);
type t_diag_out is record
fan_status : std_logic_vector(7 downto 0);
temp_status : std_logic_vector(7 downto 0);
volt_status : std_logic_vector(7 downto 0);
fan1_speed : std_logic_vector(15 downto 0);
fan2_speed : std_logic_vector(15 downto 0);
fan3_speed : std_logic_vector(15 downto 0);
temp1 : std_logic_vector(7 downto 0);
temp2 : std_logic_vector(7 downto 0);
temp3 : std_logic_vector(7 downto 0);
temp4 : std_logic_vector(7 downto 0);
temp5 : std_logic_vector(7 downto 0);
temp6 : std_logic_vector(7 downto 0);
fans_speed : t_diag_buf(0 to 5); -- 3 fans, each speed 2 bytes
temps : t_diag_buf(0 to 5);
end record;
type t_diag_buf is array (natural range<>) of std_logic_vector(7 downto 0);
constant c_DIAGS_DUMMY : t_diag_out := (x"CA", x"FE", x"BE",
(x"01", x"02", x"03", x"04", x"05", x"06"),
(x"11", x"12", x"13", x"14", x"15", x"16"));
end diag_pkg;
......@@ -88,7 +88,6 @@ architecture rtl of diot_diag is
signal cmd : unsigned(7 downto 0);
signal cnt : unsigned(15 downto 0);
signal fan_buf : t_diag_buf(0 to 11);
signal temp_buf : t_diag_buf(0 to 5);
signal last_byte : std_logic;
begin
......@@ -137,6 +136,8 @@ begin
i2c_txbyte <= (others=>'0');
cmd <= (others=>'0');
cnt <= (others=>'0');
fan_buf <= (others=>(others=>'0'));
diags_o <= c_DIAGS_DUMMY;
state <= IDLE;
else
case state is
......@@ -236,11 +237,12 @@ begin
i2c_txack <= '0';
i2c_txbyte <= (others=>'0');
diags_o.fans_speed(0 to 5) <= fan_buf(0 to 5);
-- save read byte to appropriate place
if (i2c_done = '1' and cmd = c_CMD_FAN_SPEED) then
fan_buf(to_integer(cnt)) <= i2c_rxbyte;
elsif (i2c_done = '1' and cmd = c_CMD_TEMP) then
temp_buf(to_integer(cnt)) <= i2c_rxbyte;
diags_o.temps(to_integer(cnt)) <= i2c_rxbyte;
end if;
if (i2c_done = '1' and last_byte = '1') then
......@@ -264,6 +266,7 @@ begin
i2c_txack <= '1';
i2c_txbyte <= (others=>'0');
diags_o.fans_speed(0 to 5) <= fan_buf(0 to 5);
-- save read byte to appropriate place
if (i2c_done = '1' and cmd = c_CMD_FAN_STAT) then
diags_o.fan_status <= i2c_rxbyte;
......@@ -278,7 +281,7 @@ begin
fan_buf(to_integer(cnt)) <= i2c_rxbyte;
elsif (i2c_done = '1' and cmd = c_CMD_TEMP) then
temp_buf(to_integer(cnt)) <= i2c_rxbyte;
diags_o.temps(to_integer(cnt)) <= i2c_rxbyte;
end if;
if (i2c_done = '1' and cmd < c_CMD_TEMP) then
......@@ -333,18 +336,7 @@ begin
-- signal when we're reading one but last byte for multi-byte commands
last_byte <= '1' when (cmd = c_CMD_FAN_SPEED and cnt = fan_buf'high - 1) else
'1' when (cmd = c_CMD_TEMP and cnt = temp_buf'high - 1) else
'1' when (cmd = c_CMD_TEMP and cnt = diags_o.temps'high - 1) else
'0';
-- parse multibyte buffers to t_diag_out
diags_o.fan1_speed <= fan_buf(0) & fan_buf(1);
diags_o.fan2_speed <= fan_buf(2) & fan_buf(3);
diags_o.fan3_speed <= fan_buf(4) & fan_buf(5);
diags_o.temp1 <= temp_buf(0);
diags_o.temp2 <= temp_buf(1);
diags_o.temp3 <= temp_buf(2);
diags_o.temp4 <= temp_buf(3);
diags_o.temp5 <= temp_buf(4);
diags_o.temp6 <= temp_buf(5);
end rtl;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment