Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3.  
  4. package FSM_codes is
  5. -- define state assignment - binary
  6.  
  7. constant SWIDTH: integer := 3;
  8. subtype state_type is
  9. std_logic_vector( SWIDTH-1 downto 0 );
  10.  
  11. constant LOAD_IR: state_type := "0000";
  12. constant UPDATE_PC: state_type := "0001";
  13. constant DECODE_RN: state_type := "0010";
  14. constant READ_RM: state_type := "0100";
  15. constant ALU_ST: state_type := "1000";
  16. constant WRITE_RDRN: state_type := "0011"
  17.  
  18. end package;
  19.  
  20. ----------------------------------------------------------
  21.  
  22. library ieee;
  23. use ieee.std_logic_1164.all;
  24. use ieee.std_logic_unsigned.all;
  25. use ieee.numeric_std.all;
  26. use work.datapath_declarations.all;
  27. use work.ff.all;
  28. use work.FSM_codes.all;
  29.  
  30. entity FSM is
  31.  
  32. port ( clk : in std_logic;
  33. reset : in std_logic;
  34. opcode : in std_logic_vector( 2 downto 0 );
  35. op : in std_logic_vector( 1 downto 0 );
  36. loadir : out std_logic;
  37. loadpc : out std_logic;
  38. nsel : out std_logic_vector(1 downto 0);
  39. write : out std_logic;
  40. vsel : out std_logic_vector( 1 downto 0 );
  41. loada : out std_logic;
  42. loadb : out std_logic;
  43. asel : out std_logic;
  44. bsel : out std_logic;
  45. loadc : out std_logic;
  46. loads : out std_logic;
  47. msel : out std_logic;
  48. mwrite : out std_logic
  49. );
  50. end FSM;
  51.  
  52. architecture impl of FSM is
  53. signal current_state, next_state, next1: std_logic_vector(SWIDTH-1 downto 0);
  54. begin
  55.  
  56. asel <= '0';
  57. bsel <= '0';
  58. msel <= '0';
  59. mwrite <= '0';
  60.  
  61. loadir <= '1' when current_state = LOAD_IR else '0';
  62. loadpc <= '1' when current_state = UPDATE_PC else '0';
  63. loada <= '1' when current_state = DECODE_RN else '0';
  64. loadb <= '1' when current_state = READ_RM else '0';
  65. loads <= '1' when current_state = ALU_ST else '0';
  66. write <= '1' when current_state = WRITE_RDRN else '0';
  67. loadc <= '1' when current_state = WRITE_RDRN else '0';
  68.  
  69.  
  70.  
  71.  
  72.  
  73. state_reg: vDFF generic map(SWIDTH) port map(clk, next_state, current_state);
  74.  
  75. -- next state logic (e.g.)
  76. process(all) begin
  77. case? opCode & op & current_state is
  78. when "---" & "--" & LOAD_IR => next1 <= UPDATE_PC;
  79. when "---" & "--" & UPDATE_PC => next1 <= DECODE_RN;
  80. when "101" & "--" & DECODE_RN => next1 <= READ_RM;
  81. when "110" & "10" & DECODE_RN => next1 <= WRITE_RDRN;
  82. when "---" & "--" & READ_RM => next1 <= ALU_ST;
  83. when "101" & "01" & ALU_ST => next1 <= LOAD_IR;
  84. when "101" & "00" & ALU_ST => next1 <= WRITE_RDRN;
  85. when "101" & "1-" & ALU_ST => next1 <= WRITE_RDRN;
  86. when "---" & "--" & WRITE_RDRN => next1 <= LOAD_IR;
  87.  
  88.  
  89. end case?;
  90. end process;
  91.  
  92.  
  93.  
  94.  
  95. next_state <= LOAD_IR when reset else next1;
  96. end impl;
  97.  
  98. ----------------------------------------------------------------------
  99. ----------------------------------------------------------------------
  100.  
  101. library ieee;
  102. use ieee.std_logic_1164.all;
  103. use ieee.std_logic_unsigned.all;
  104. use ieee.numeric_std.all;
  105. use work.datapath_declarations.all;
  106. use work.ff.all;
  107.  
  108. entity CPUentity is
  109.  
  110. -- datapath_insta : datapath generic map(16, 8) port map( );
  111. -- FSM_insta: FSM generic map( ) port map( );
  112. end CPUentity;
  113.  
  114. architecture impl of CPUentity is
  115. begin
  116. end impl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement