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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [rtl/] [core/] [neorv32_mtime.vhd] - Diff between revs 56 and 57

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

Rev 56 Rev 57
Line 1... Line 1...
-- #################################################################################################
-- #################################################################################################
-- # << NEORV32 - Machine System Timer (MTIME) >>                                                  #
-- # << NEORV32 - Machine System Timer (MTIME) >>                                                  #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # Compatible to RISC-V spec's 64-bit MACHINE system timer including "mtime[h]" & "mtimecmp[h]". #
-- # Compatible to RISC-V spec's 64-bit MACHINE system timer including "mtime[h]" & "mtimecmp[h]". #
-- # Note: The 64-bit counter and compare system is broken and de-coupled into two 32-bit systems. #
-- # Note: The 64-bit counter and compare systems are de-coupled into two 32-bit systems.          #
-- # ********************************************************************************************* #
-- # ********************************************************************************************* #
-- # BSD 3-Clause License                                                                          #
-- # BSD 3-Clause License                                                                          #
-- #                                                                                               #
-- #                                                                                               #
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
-- # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
-- #                                                                                               #
-- #                                                                                               #
Line 69... Line 69...
  -- access control --
  -- access control --
  signal acc_en : std_ulogic; -- module access enable
  signal acc_en : std_ulogic; -- module access enable
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
  signal addr   : std_ulogic_vector(31 downto 0); -- access address
  signal wren   : std_ulogic; -- module access enable
  signal wren   : std_ulogic; -- module access enable
 
 
 
  -- time write access buffer --
 
  signal wdata_buf   : std_ulogic_vector(31 downto 0);
 
  signal mtime_lo_we : std_ulogic;
 
  signal mtime_hi_we : std_ulogic;
 
 
  -- accessible regs --
  -- accessible regs --
  signal mtimecmp_lo     : std_ulogic_vector(31 downto 0);
  signal mtimecmp_lo     : std_ulogic_vector(31 downto 0);
  signal mtimecmp_hi     : std_ulogic_vector(31 downto 0);
  signal mtimecmp_hi     : std_ulogic_vector(31 downto 0);
  signal mtime_lo        : std_ulogic_vector(32 downto 0);
  signal mtime_lo        : std_ulogic_vector(32 downto 0);
  signal mtime_lo_msb_ff : std_ulogic;
  signal mtime_lo_msb_ff : std_ulogic;
  signal mtime_hi        : std_ulogic_vector(31 downto 0);
  signal mtime_hi        : std_ulogic_vector(31 downto 0);
 
  signal inc_hi          : std_ulogic_vector(31 downto 0);
 
 
  -- irq control --
  -- irq control --
  signal cmp_lo       : std_ulogic;
  signal cmp_lo       : std_ulogic;
  signal cmp_lo_ff    : std_ulogic;
  signal cmp_lo_ff    : std_ulogic;
  signal cmp_hi       : std_ulogic;
  signal cmp_hi       : std_ulogic;
Line 96... Line 102...
  -- Write Access ---------------------------------------------------------------------------
  -- Write Access ---------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  wr_access: process(clk_i)
  wr_access: process(clk_i)
  begin
  begin
    if rising_edge(clk_i) then
    if rising_edge(clk_i) then
      -- mtimecmp low --
      -- mtimecmp --
      if (wren = '1') and (addr = mtime_cmp_lo_addr_c) then
      if (wren = '1') then
 
        if (addr = mtime_cmp_lo_addr_c) then
        mtimecmp_lo <= data_i;
        mtimecmp_lo <= data_i;
      end if;
      end if;
 
        if (addr = mtime_cmp_hi_addr_c) then
      -- mtimecmp high --
 
      if (wren = '1') and (addr = mtime_cmp_hi_addr_c) then
 
        mtimecmp_hi <= data_i;
        mtimecmp_hi <= data_i;
      end if;
      end if;
 
      end if;
 
 
 
      -- mtime access buffer --
 
      wdata_buf   <= data_i;
 
      mtime_lo_we <= wren and bool_to_ulogic_f(boolean(addr = mtime_time_lo_addr_c));
 
      mtime_hi_we <= wren and bool_to_ulogic_f(boolean(addr = mtime_time_hi_addr_c));
 
 
      -- mtime low --
      -- mtime low --
      if (wren = '1') and (addr = mtime_time_lo_addr_c) then
      if (mtime_lo_we = '1') then -- write access
        mtime_lo_msb_ff <= '0';
        mtime_lo_msb_ff <= '0';
        mtime_lo <= '0' & data_i;
        mtime_lo <= '0' & wdata_buf;
      else -- auto increment
      else -- auto increment
        mtime_lo_msb_ff <= mtime_lo(mtime_lo'left);
        mtime_lo_msb_ff <= mtime_lo(mtime_lo'left);
        mtime_lo <= std_ulogic_vector(unsigned(mtime_lo) + 1);
        mtime_lo <= std_ulogic_vector(unsigned(mtime_lo) + 1);
      end if;
      end if;
 
 
      -- mtime high --
      -- mtime high --
      if (wren = '1') and (addr = mtime_time_hi_addr_c) then
      if (mtime_hi_we = '1') then -- write access
        mtime_hi <= data_i;
        mtime_hi <= wdata_buf;
      elsif ((mtime_lo_msb_ff xor mtime_lo(mtime_lo'left)) = '1') then -- auto increment: mtime_lo carry?
      else -- auto increment (if mtime.low overflows)
        mtime_hi <= std_ulogic_vector(unsigned(mtime_hi) + 1);
        mtime_hi <= std_ulogic_vector(unsigned(mtime_hi) + unsigned(inc_hi));
      end if;
      end if;
    end if;
    end if;
  end process wr_access;
  end process wr_access;
 
 
 
  -- mtime.time_HI increment (0 or 1) --
 
  inc_hi(0) <= mtime_lo_msb_ff xor mtime_lo(mtime_lo'left);
 
  inc_hi(31 downto 1) <= (others => '0');
 
 
 
 
  -- Read Access ----------------------------------------------------------------------------
  -- Read Access ----------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  -- -------------------------------------------------------------------------------------------
  rd_access: process(clk_i)
  rd_access: process(clk_i)
  begin
  begin

powered by: WebSVN 2.1.0

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