Commit 40557d7a authored by Tristan Gingold's avatar Tristan Gingold

cr/csr: remove unimplemented ader to reduce number of registers.

parent ee2fd3cc
...@@ -327,9 +327,19 @@ begin ...@@ -327,9 +327,19 @@ begin
-- Write -- Write
process (clk_i) process (clk_i)
variable v_addr : unsigned(18 downto 2); -- Write to ADER bytes, if implemented. Take advantage of VITAL-1-1 Rule
variable v_index : integer; -- 10.19
variable v_byte : integer; procedure set_ADER (Idx : natural range 0 to 7) is
variable v_byte : integer;
begin
if g_ADEM (Idx) /= x"0000_0000" then
v_byte := 3 - to_integer(s_addr(3 downto 2));
s_reg_ader(Idx)(8*v_byte+7 downto 8*v_byte) <= data_i;
end if;
end set_ADER;
variable csr_idx : unsigned(7 downto 4);
variable csr_boff : unsigned(3 downto 2);
begin begin
if rising_edge(clk_i) then if rising_edge(clk_i) then
if rst_n_i = '0' then if rst_n_i = '0' then
...@@ -344,48 +354,66 @@ begin ...@@ -344,48 +354,66 @@ begin
s_reg_ader <= (others => x"00000000"); s_reg_ader <= (others => x"00000000");
else else
if we_i = '1' and s_csr_access = '1' then if we_i = '1' and s_csr_access = '1' then
case to_integer(s_addr) is csr_idx := s_addr(7 downto 4);
when c_BAR_REG => csr_boff := s_addr(3 downto 2);
s_reg_bar <= data_i; case csr_idx is
when x"f" =>
when c_BIT_SET_REG => case csr_boff is
s_reg_bit_reg <= s_reg_bit_reg or data_i; when "11" => -- BAR
s_reg_bar <= data_i;
when c_BIT_CLR_REG => when "10" => -- Bit Set
s_reg_bit_reg <= s_reg_bit_reg and not data_i; s_reg_bit_reg <= s_reg_bit_reg or data_i;
-- VITAL-1-1 Rule 10.27 when "01" => -- Bit Clr
-- 4) Ownership shall be released by writing any value with s_reg_bit_reg <= s_reg_bit_reg and not data_i;
-- bit 2 set (eg 0x04) to the CSR Bit Clear Register -- VITAL-1-1 Rule 10.27
-- located at 0x7fff7. This clears the CRAM_OWNER -- 4) Ownership shall be released by writing any value with
-- register and leaves it with a value of zero and also -- bit 2 set (eg 0x04) to the CSR Bit Clear Register
-- clears the CRAM owned status. -- located at 0x7fff7. This clears the CRAM_OWNER
if data_i(c_CRAM_OWNER_BIT) = '1' then -- register and leaves it with a value of zero and also
s_reg_cram_owner <= x"00"; -- clears the CRAM owned status.
end if; if data_i(c_CRAM_OWNER_BIT) = '1' then
s_reg_cram_owner <= x"00";
when c_CRAM_OWNER_REG => end if;
-- VITAL-1-1 Rule 10.27 when "00" => -- CRAM_OWNER
-- 2) Writing to CRAM_OWNER register when it contains a non- -- VITAL-1-1 Rule 10.27
-- zero value shall not change the value of the -- 2) Writing to CRAM_OWNER register when it contains a non-
-- CRAM_OWNER. That allows the first master that writes -- zero value shall not change the value of the
-- a non-zero value to acquire ownership. -- CRAM_OWNER. That allows the first master that writes
if s_reg_cram_owner = x"00" then -- a non-zero value to acquire ownership.
s_reg_cram_owner <= data_i; if s_reg_cram_owner = x"00" then
s_reg_bit_reg(c_CRAM_OWNER_BIT) <= '1'; s_reg_cram_owner <= data_i;
end if; s_reg_bit_reg(c_CRAM_OWNER_BIT) <= '1';
end if;
when c_USR_SET_REG => when others =>
s_reg_usr_bit_reg <= s_reg_usr_bit_reg or data_i; null;
end case;
when c_USR_CLR_REG => when x"e" =>
s_reg_usr_bit_reg <= s_reg_usr_bit_reg and not data_i; case csr_boff is
when "11" => -- User Set
when c_ADER_REG_BEG to c_ADER_REG_END => s_reg_usr_bit_reg <= s_reg_usr_bit_reg or data_i;
v_addr := s_addr(18 downto 2) - to_unsigned(c_ADER_REG_BEG, 17); when "10" => -- User Clr
v_index := to_integer(v_addr(6 downto 4)); s_reg_usr_bit_reg <= s_reg_usr_bit_reg and not data_i;
v_byte := 3-to_integer(v_addr(3 downto 2)); when others =>
-- FIXME: force DFSR and XAM to 0 ? null;
s_reg_ader(v_index)(8*v_byte+7 downto 8*v_byte) <= data_i; end case;
-- Decompose ADER so that unimplemented one can be removed.
when x"d" => -- ADER 7
Set_ADER(7);
when x"c" => -- ADER 6
Set_ADER(6);
when x"b" => -- ADER 5
Set_ADER(5);
when x"a" => -- ADER 4
Set_ADER(4);
when x"9" => -- ADER 3
Set_ADER(3);
when x"8" => -- ADER 2
Set_ADER(2);
when x"7" => -- ADER 1
Set_ADER(1);
when x"6" => -- ADER 0
Set_ADER(0);
when others => when others =>
null; null;
...@@ -411,41 +439,77 @@ begin ...@@ -411,41 +439,77 @@ begin
-- Read -- Read
process (clk_i) process (clk_i)
procedure Get_ADER(Idx : natural range 0 to 7)
is
variable v_byte : integer;
begin
if g_ADEM(Idx) /= x"0000_0000" then
v_byte := 3 - to_integer(s_addr(3 downto 2));
s_csr_data <= s_reg_ader(Idx)(8*v_byte+7 downto 8*v_byte);
end if;
end Get_ADER;
variable csr_idx : unsigned(7 downto 4);
variable csr_boff : unsigned(3 downto 2);
variable v_addr : unsigned(18 downto 2); variable v_addr : unsigned(18 downto 2);
variable v_index : integer; variable v_index : integer;
variable v_byte : integer; variable v_byte : integer;
begin begin
if rising_edge(clk_i) then if rising_edge(clk_i) then
if rst_n_i = '0' then if rst_n_i = '0' then
s_csr_data <= c_UNUSED; s_csr_data <= x"00";
else else
case to_integer(s_addr) is -- VITAL-1-1 Rule 10.14
when c_BAR_REG => -- All unimplemented locations in the Defined CSR Area shall read as
s_csr_data <= s_reg_bar; -- 0x00
s_csr_data <= x"00";
when c_BIT_SET_REG =>
s_csr_data <= s_reg_bit_reg; csr_idx := s_addr(7 downto 4);
csr_boff := s_addr(3 downto 2);
when c_BIT_CLR_REG => case csr_idx is
s_csr_data <= s_reg_bit_reg; when x"f" =>
case csr_boff is
when c_CRAM_OWNER_REG => when "11" => -- BAR
s_csr_data <= s_reg_cram_owner; s_csr_data <= s_reg_bar;
when "10" => -- Bit Set
when c_USR_SET_REG => s_csr_data <= s_reg_bit_reg;
s_csr_data <= s_reg_usr_bit_reg; when "01" => -- Bit Clr
s_csr_data <= s_reg_bit_reg;
when c_USR_CLR_REG => when "00" => -- CRAM_OWNER
s_csr_data <= s_reg_usr_bit_reg; s_csr_data <= s_reg_cram_owner;
when others =>
when c_ADER_REG_BEG to c_ADER_REG_END => null;
v_addr := s_addr(18 downto 2) - to_unsigned(c_ADER_REG_BEG, 17); end case;
v_index := to_integer(v_addr(6 downto 4)); when x"e" =>
v_byte := 3-to_integer(v_addr(3 downto 2)); case csr_boff is
s_csr_data <= s_reg_ader(v_index)(8*v_byte+7 downto 8*v_byte); when "11" => -- User Set
s_csr_data <= s_reg_usr_bit_reg;
when "10" => -- User Clr
s_csr_data <= s_reg_usr_bit_reg;
when others =>
null;
end case;
-- Unroll to disable unused ADER. Not the best readable style.
when x"d" =>
Get_ADER(7);
when x"c" =>
Get_ADER(6);
when x"b" =>
Get_ADER(5);
when x"a" =>
Get_ADER(4);
when x"9" =>
Get_ADER(3);
when x"8" =>
Get_ADER(2);
when x"7" =>
Get_ADER(1);
when x"6" =>
Get_ADER(0);
when others => when others =>
s_csr_data <= c_UNUSED; null;
end case; end case;
end if; end if;
end if; end if;
......
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