Loesung des Praktikums Systementwurf - Bjarne Hoesch - Bernhard Schoeffel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rand.vhd 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. library work;
  5. use work.reg32.all;
  6. use work.task.all;
  7. entity rand is
  8. port (
  9. clk : in std_logic;
  10. reset : in std_logic;
  11. task_start : in std_logic;
  12. task_state : out work.task.State;
  13. seed : in work.reg32.word;
  14. signal_write : out std_logic;
  15. signal_writedata : out std_logic_vector( 31 downto 0 )
  16. );
  17. end entity rand;
  18. architecture rtl of rand is
  19. signal current_task_state : work.task.State;
  20. signal next_task_state : work.task.State;
  21. signal index : integer range 0 to work.task.STREAM_LEN;
  22. type CalcState is (
  23. CALC_IDLE,
  24. CALC_WRITE
  25. );
  26. signal Calc_State : CalcState;
  27. signal lsfr : SIGNED( 31 downto 0 );
  28. signal lsfr_std_logic : std_logic_vector( 31 downto 0 );
  29. signal POLYNOM : std_logic_vector (31 downto 0);
  30. signal lsfr_dump : SIGNED( 31 downto 0 );
  31. begin
  32. task_state_transitions : process ( current_task_state, task_start, index ) is
  33. begin
  34. next_task_state <= current_task_state;
  35. case current_task_state is
  36. when work.task.TASK_IDLE =>
  37. if ( task_start = '1' ) then
  38. next_task_state <= work.task.TASK_RUNNING;
  39. end if;
  40. when work.task.TASK_RUNNING =>
  41. if ( index = work.task.STREAM_LEN - 1 ) then
  42. next_task_state <= work.task.TASK_DONE;
  43. end if;
  44. when work.task.TASK_DONE =>
  45. if ( task_start = '1' ) then
  46. next_task_state <= work.task.TASK_RUNNING;
  47. end if;
  48. end case;
  49. end process task_state_transitions;
  50. sync : process ( clk, reset ) is
  51. variable var_lsfr_logic : std_logic_vector( 31 downto 0);
  52. variable var_lsfr_signed : SIGNED( 31 downto 0);
  53. begin
  54. if ( reset = '1' ) then
  55. current_task_state <= work.task.TASK_IDLE;
  56. Calc_State <= CALC_IDLE;
  57. lsfr <= SIGNED(seed);
  58. lsfr_std_logic <= seed;
  59. POLYNOM <= (others => '0');
  60. POLYNOM(31) <= '1';
  61. POLYNOM(21) <= '1';
  62. POLYNOM(1) <= '1';
  63. POLYNOM(0) <= '1';
  64. index <= 0;
  65. elsif ( rising_edge( clk ) ) then
  66. current_task_state <= next_task_state;
  67. case next_task_state is
  68. when work.task.TASK_IDLE =>
  69. index <= 0;
  70. lsfr <= SIGNED(seed);
  71. signal_write <= '0';
  72. when work.task.TASK_RUNNING =>
  73. case Calc_State is
  74. when CALC_IDLE =>
  75. signal_write <= '0';
  76. var_lsfr_logic := STD_LOGIC_VECTOR(lsfr);
  77. if(var_lsfr_logic(0) = '1') then
  78. var_lsfr_logic := '0' & (var_lsfr_logic(31 downto 1));
  79. --var_lsfr_logic := (var_lsfr_logic(31:1);
  80. var_lsfr_logic := (var_lsfr_logic XOR POLYNOM);
  81. else
  82. --var_lsfr_logic := (var_lsfr_logic srl 1);
  83. var_lsfr_logic := '0' & var_lsfr_logic(31 downto 1);
  84. end if;
  85. var_lsfr_signed := SIGNED(var_lsfr_logic);
  86. lsfr_dump <= SIGNED(var_lsfr_logic);
  87. if(var_lsfr_signed(30) = '1') then
  88. var_lsfr_signed := var_lsfr_signed(31 downto 31) & "1000000" & var_lsfr_signed(23 downto 0);
  89. else
  90. var_lsfr_signed := var_lsfr_signed(31 downto 31) & "011111" & var_lsfr_signed(24 downto 0);
  91. end if;
  92. lsfr <= var_lsfr_signed;
  93. Calc_State <= CALC_WRITE;
  94. when CALC_WRITE =>
  95. signal_write <= '1';
  96. index <= index + 1;
  97. Calc_State <= CALC_IDLE;
  98. end case;
  99. when work.task.TASK_DONE =>
  100. index <= 0;
  101. signal_write <= '0';
  102. end case;
  103. end if;
  104. end process sync;
  105. task_state <= current_task_state;
  106. signal_writedata <= STD_LOGIC_VECTOR(lsfr);
  107. end architecture rtl;