checksum.vhd 869 B

12345678910111213141516171819202122232425262728293031323334
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.std_logic_arith.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5. use work.myPackage.ALL;
  6. entity checksum is
  7. generic(
  8. busWidth : integer:=32);
  9. Port ( clk : in STD_LOGIC;
  10. reset : in STD_LOGIC;
  11. enable : in STD_LOGIC;
  12. dataIn : in std_logic_vector(busWidth-1 downto 0);
  13. output : out std_logic_vector(busWidth-1 downto 0));
  14. end checksum;
  15. architecture Behavioral of checksum is
  16. signal sum : unsigned(busWidth-1 downto 0);
  17. begin
  18. main : process(clk, reset)
  19. begin
  20. if(reset = '0') then
  21. sum <= (others => '0');
  22. elsif(rising_edge(clk)) then
  23. if(enable = '1') then
  24. sum <= sum + unsigned(dataIn);
  25. end if;
  26. end if;
  27. end process;
  28. output <= std_logic_vector(sum);
  29. end Behavioral;