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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. begin
  52. if ( reset = '1' ) then
  53. current_task_state <= work.task.TASK_IDLE;
  54. Calc_State <= CALC_IDLE;
  55. lsfr <= SIGNED(seed);
  56. lsfr_std_logic <= seed;
  57. POLYNOM <= (others => '0');
  58. POLYNOM(31) <= '1';
  59. POLYNOM(21) <= '1';
  60. POLYNOM(1) <= '1';
  61. POLYNOM(0) <= '1';
  62. index <= 0;
  63. elsif ( rising_edge( clk ) ) then
  64. current_task_state <= next_task_state;
  65. case next_task_state is
  66. when work.task.TASK_IDLE =>
  67. index <= 0;
  68. lsfr <= SIGNED(seed);
  69. signal_write <= '0';
  70. when work.task.TASK_RUNNING =>
  71. case Calc_State is
  72. when CALC_IDLE =>
  73. signal_write <= '0';
  74. lsfr_std_logic <= STD_LOGIC_VECTOR(lsfr);
  75. if(lsfr_std_logic(0) = '1') then
  76. lsfr <= SIGNED(lsfr_std_logic srl 1);
  77. lsfr <= SIGNED(lsfr_std_logic XOR POLYNOM);
  78. else
  79. lsfr <= SIGNED(lsfr_std_logic srl 1);
  80. end if;
  81. lsfr <= SIGNED(lsfr_std_logic);
  82. lsfr_dump <= lsfr;
  83. if(lsfr_std_logic(30) = '1') then
  84. lsfr <= lsfr(31 downto 31) & "1000000" & lsfr(23 downto 0);
  85. else
  86. lsfr <= lsfr(31 downto 31) & "011111" & lsfr(24 downto 0);
  87. end if;
  88. Calc_State <= CALC_WRITE;
  89. when CALC_WRITE =>
  90. signal_write <= '1';
  91. index <= index + 1;
  92. Calc_State <= CALC_IDLE;
  93. end case;
  94. when work.task.TASK_DONE =>
  95. index <= 0;
  96. signal_write <= '0';
  97. end case;
  98. end if;
  99. end process sync;
  100. task_state <= current_task_state;
  101. signal_writedata <= STD_LOGIC_VECTOR(lsfr);
  102. end architecture rtl;