OpenCores
URL https://opencores.org/ocsvn/mlite/mlite/trunk

Subversion Repositories mlite

[/] [mlite/] [trunk/] [vhdl/] [mem_ctrl.vhd] - Diff between revs 47 and 49

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 47 Rev 49
Line 46... Line 46...
   --"00" = big_endian; "11" = little_endian
   --"00" = big_endian; "11" = little_endian
   constant little_endian : std_logic_vector(1 downto 0) := "00";
   constant little_endian : std_logic_vector(1 downto 0) := "00";
   signal opcode_reg : std_logic_vector(31 downto 0);
   signal opcode_reg : std_logic_vector(31 downto 0);
   signal next_opcode_reg : std_logic_vector(31 downto 0);
   signal next_opcode_reg : std_logic_vector(31 downto 0);
 
 
   subtype setup_state_type is std_logic_vector(1 downto 0);
   subtype mem_state_type is std_logic_vector(1 downto 0);
   signal setup_state : setup_state_type;
   signal mem_state_reg  : mem_state_type;
   constant STATE_FETCH  : setup_state_type := "00";
   constant STATE_FETCH  : mem_state_type := "00";
   constant STATE_ADDR   : setup_state_type := "01";
   constant STATE_ADDR   : mem_state_type := "01";
   constant STATE_WRITE  : setup_state_type := "10";
   constant STATE_WRITE  : mem_state_type := "10";
   constant STATE_PAUSE  : setup_state_type := "11";
   constant STATE_PAUSE  : mem_state_type := "11";
begin
begin
 
 
mem_proc: process(clk, reset_in, pause_in, nullify_op,
mem_proc: process(clk, reset_in, pause_in, nullify_op,
                  address_pc, address_data, mem_source, data_write,
                  address_pc, address_data, mem_source, data_write,
                  mem_data_r, mem_pause,
                  mem_data_r, mem_pause,
                  opcode_reg, next_opcode_reg, setup_state)
                  opcode_reg, next_opcode_reg, mem_state_reg)
   variable data, datab   : std_logic_vector(31 downto 0);
   variable data, datab   : std_logic_vector(31 downto 0);
   variable opcode_next   : std_logic_vector(31 downto 0);
   variable opcode_next   : std_logic_vector(31 downto 0);
   variable byte_sel_next : std_logic_vector(3 downto 0);
   variable byte_sel_next : std_logic_vector(3 downto 0);
   variable write_next    : std_logic;
   variable write_next    : std_logic;
   variable setup_state_next : setup_state_type;
   variable mem_state_next : mem_state_type;
   variable pause         : std_logic;
   variable pause         : std_logic;
   variable address_next  : std_logic_vector(31 downto 0);
   variable address_next  : std_logic_vector(31 downto 0);
   variable bits          : std_logic_vector(1 downto 0);
   variable bits          : std_logic_vector(1 downto 0);
   variable mem_data_w_v  : std_logic_vector(31 downto 0);
   variable mem_data_w_v  : std_logic_vector(31 downto 0);
begin
begin
   byte_sel_next := "0000";
   byte_sel_next := "0000";
   write_next := '0';
   write_next := '0';
   pause := '0';
   pause := '0';
   setup_state_next := setup_state;
   mem_state_next := mem_state_reg;
 
 
   address_next := address_pc;
   address_next := address_pc;
   data := mem_data_r;
   data := mem_data_r;
   datab := ZERO;
   datab := ZERO;
   mem_data_w_v := ZERO;
   mem_data_w_v := ZERO;
Line 136... Line 136...
      end case;
      end case;
   when others =>
   when others =>
   end case;
   end case;
 
 
   opcode_next := opcode_reg;
   opcode_next := opcode_reg;
   if mem_source = mem_none then
   if mem_source = mem_none then --opcode fetch
      setup_state_next := STATE_FETCH;
      mem_state_next := STATE_FETCH;
      if pause_in = '0' and mem_pause = '0' then
      if pause_in = '0' and mem_pause = '0' then
         opcode_next := data;
         opcode_next := data;
      end if;
      end if;
   else
   else  --data read or write (not opcode fetch)
      if setup_state = STATE_FETCH then
      case mem_state_reg is
 
      when STATE_FETCH =>
         pause := '1';
         pause := '1';
         byte_sel_next := "0000";
         byte_sel_next := "0000";
         if mem_pause = '0' then
         if mem_pause = '0' then
            setup_state_next := STATE_ADDR;
            mem_state_next := STATE_ADDR;
         end if;
         end if;
      elsif setup_state = STATE_ADDR then
      when STATE_ADDR =>  --address lines pre-hold
         address_next := address_data;
         address_next := address_data;
         if write_next ='1' and address_data(31) = '0' then
         if write_next ='1' and address_data(31) = '0' then
            pause := '1';
            pause := '1';
            byte_sel_next := "0000";
            byte_sel_next := "0000";
            if mem_pause = '0' then
            if mem_pause = '0' then
               setup_state_next := STATE_WRITE;       --4 cycle access
               mem_state_next := STATE_WRITE;    --4 cycle access
            end if;
            end if;
         else
         else
            if mem_pause = '0' then
            if mem_pause = '0' then
               opcode_next := next_opcode_reg;
               opcode_next := next_opcode_reg;
               setup_state_next := STATE_FETCH;    --2 cycle access
               mem_state_next := STATE_FETCH;    --2 cycle access
            end if;
            end if;
         end if;
         end if;
      elsif setup_state = STATE_WRITE then
      when STATE_WRITE =>
         pause := '1';
         pause := '1';
         address_next := address_data;
         address_next := address_data;
         if mem_pause = '0' then
         if mem_pause = '0' then
            setup_state_next := STATE_PAUSE;
            mem_state_next := STATE_PAUSE;
         end if;
         end if;
      elsif setup_state = STATE_PAUSE then
      when OTHERS =>  --STATE_PAUSE address lines post-hold
         address_next := address_data;
         address_next := address_data;
         byte_sel_next := "0000";
         byte_sel_next := "0000";
         opcode_next := next_opcode_reg;
 
         if mem_pause = '0' then
         if mem_pause = '0' then
            setup_state_next := STATE_FETCH;
            opcode_next := next_opcode_reg;
         end if;
            mem_state_next := STATE_FETCH;
      end if;
      end if;
 
      end case;
   end if;
   end if;
 
 
   if nullify_op = '1' then
   if nullify_op = '1' then
      opcode_next := ZERO;  --NOP
      opcode_next := ZERO;  --NOP
   end if;
   end if;
   if reset_in = '1' then
   if reset_in = '1' then
      setup_state_next := STATE_FETCH;
      mem_state_next := STATE_FETCH;
      opcode_next := ZERO;
      opcode_next := ZERO;
   end if;
   end if;
 
 
   if rising_edge(clk) then
   if rising_edge(clk) then
      opcode_reg <= opcode_next;
      opcode_reg <= opcode_next;
      if setup_state = STATE_FETCH then
      if mem_state_reg = STATE_FETCH then
         next_opcode_reg <= data;
         next_opcode_reg <= data;
      end if;
      end if;
      setup_state <= setup_state_next;
      mem_state_reg <= mem_state_next;
   end if;
   end if;
 
 
   if reset_in = '0' then
   if reset_in = '0' then
      opcode_out <= opcode_reg;
      opcode_out <= opcode_reg;
   else
   else
Line 203... Line 204...
   end if;
   end if;
   data_read <= datab;
   data_read <= datab;
   pause_out <= mem_pause or pause;
   pause_out <= mem_pause or pause;
   mem_byte_sel <= byte_sel_next;
   mem_byte_sel <= byte_sel_next;
   mem_address <= address_next;
   mem_address <= address_next;
   if write_next = '1' and setup_state /= STATE_FETCH then
   if write_next = '1' and mem_state_reg /= STATE_FETCH then
      mem_write <= '1';
      mem_write <= '1';
      mem_data_w <= mem_data_w_v;
      mem_data_w <= mem_data_w_v;
   else
   else
      mem_write <= '0';
      mem_write <= '0';
      mem_data_w <= HIGH_Z; --ZERO;
      mem_data_w <= HIGH_Z; --ZERO;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.