Line 39... |
Line 39... |
|
|
--! @brief ControlUnit http://en.wikipedia.org/wiki/Control_unit
|
--! @brief ControlUnit http://en.wikipedia.org/wiki/Control_unit
|
--! @details The control unit receives external instructions or commands which it converts into a sequence of control signals that the control \n
|
--! @details The control unit receives external instructions or commands which it converts into a sequence of control signals that the control \n
|
--! unit applies to data path to implement a sequence of register-transfer level operations.
|
--! unit applies to data path to implement a sequence of register-transfer level operations.
|
architecture Behavioral of ControlUnit is
|
architecture Behavioral of ControlUnit is
|
signal currentCpuState : controlUnitStates;
|
signal currentCpuState : controlUnitStates; -- CPU states
|
signal nextCpuState : controlUnitStates;
|
signal nextCpuState : controlUnitStates; -- CPU states
|
signal PC : std_logic_vector(n downto 0);
|
signal PC : std_logic_vector(n downto 0); -- Program Counter
|
signal IR : std_logic_vector(n downto 0);
|
signal IR : std_logic_vector(n downto 0); -- Intruction register
|
|
signal currInstruction : std_logic_vector(n downto 0); -- Current Intruction
|
begin
|
begin
|
|
|
-- Next state logic
|
-- Next state logic
|
process (clk, reset)
|
process (clk, reset)
|
begin
|
begin
|
Line 56... |
Line 57... |
elsif rising_edge(clk) then
|
elsif rising_edge(clk) then
|
currentCpuState <= nextCpuState;
|
currentCpuState <= nextCpuState;
|
end if;
|
end if;
|
end process;
|
end process;
|
|
|
-- assd
|
-- States Fetch, decode, execute from the processor
|
process (currentCpuState)
|
process (currentCpuState)
|
|
variable cyclesExecute : integer range 0 to 20; -- Cycles to wait while executing instruction
|
begin
|
begin
|
case currentCpuState is
|
case currentCpuState is
|
-- Initial state left from reset ...
|
-- Initial state left from reset ...
|
when initial =>
|
when initial =>
|
|
cyclesExecute := 0;
|
PC <= (others => '0');
|
PC <= (others => '0');
|
|
IR <= (others => '0');
|
MemoryDataRead <= (others => '0');
|
MemoryDataRead <= (others => '0');
|
MemoryDataWrite <= (others => '0');
|
MemoryDataWrite <= (others => '0');
|
MemoryDataAddr <= (others => '0');
|
MemoryDataAddr <= (others => '0');
|
nextCpuState <= fetch;
|
nextCpuState <= fetch;
|
|
|
Line 77... |
Line 81... |
MemoryDataAddr <= PC; -- Warning PC is not 1 yet...
|
MemoryDataAddr <= PC; -- Warning PC is not 1 yet...
|
IR <= MemoryDataInput;
|
IR <= MemoryDataInput;
|
MemoryDataRead <= '1';
|
MemoryDataRead <= '1';
|
nextCpuState <= decode;
|
nextCpuState <= decode;
|
|
|
-- Detect with instruction came from memory...
|
-- Detect with instruction came from memory, set the number of cycles to execute...
|
when decode =>
|
when decode =>
|
MemoryDataRead <= '0';
|
MemoryDataRead <= '0';
|
|
MemoryDataWrite <= '0';
|
|
|
|
-- The high attribute points to the highes bit position
|
|
case IR((IR'HIGH) downto (IR'HIGH - 5)) is
|
|
when mov_reg =>
|
|
nextCpuState <= execute;
|
|
cyclesExecute := 2;
|
|
currInstruction <= IR;
|
|
-- Invalid instruction (Now will be ignored, but latter shoud rais a trap
|
|
when others =>
|
|
end case;
|
|
|
|
-- Wait while the process that handles the execution works..
|
|
when execute =>
|
|
if cyclesExecute > 1 then
|
|
cyclesExecute := cyclesExecute - 1;
|
|
else
|
|
nextCpuState <= fetch;
|
|
end if;
|
when others =>
|
when others =>
|
null;
|
null;
|
end case;
|
end case;
|
end process;
|
end process;
|
|
|
|
-- Process that handles the execution of each instruction
|
|
process (currInstruction)
|
|
begin
|
|
|
|
end process;
|
|
|
end Behavioral;
|
end Behavioral;
|
|
|
|
|
No newline at end of file
|
No newline at end of file
|