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

Subversion Repositories neorv32

[/] [neorv32/] [trunk/] [sw/] [lib/] [source/] [neorv32_mtime.c] - Diff between revs 2 and 4

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

Rev 2 Rev 4
Line 60... Line 60...
  }
  }
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Set new system time.
 
 *
 
 * @note The MTIME timer increments with the primary processor clock.
 
 *
 
 * @param[in] time New system time (uint64_t)
 
 **************************************************************************/
 
void neorv32_mtime_set_time(uint64_t time) {
 
 
 
  MTIME = time;
 
}
 
 
 
 
 
/**********************************************************************//**
 
 * Get current system time since reset.
 * Get current system time since reset.
 *
 *
 * @note The MTIME timer increments with the primary processor clock.
 * @note The MTIME timer increments with the primary processor clock.
 *
 *
 * @return Current system time (uint64_t)
 * @return Current system time (uint64_t)
 **************************************************************************/
 **************************************************************************/
uint64_t neorv32_mtime_get_time(void) {
uint64_t neorv32_mtime_get_time(void) {
 
 
  union {
  return MTIME;
    uint64_t uint64;
 
    uint32_t uint32[sizeof(uint64_t)/2];
 
  } sys_mtime;
 
  uint32_t tmp;
 
 
 
  // make sure there is no overflow in mtime_lo during read
 
  while (1) {
 
    sys_mtime.uint32[1] = MTIME_HI;
 
    sys_mtime.uint32[0] = MTIME_LO;
 
    tmp = MTIME_HI;
 
    if (sys_mtime.uint32[1] == tmp) {
 
      break;
 
    }
 
  }
 
 
 
  return sys_mtime.uint64;
 
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Set compare time register (MTIMECMP) for generating interrupts.
 * Set compare time register (MTIMECMP) for generating interrupts.
Line 113... Line 84...
 *
 *
 * @param[in] timecmp System time for interrupt (uint64_t)
 * @param[in] timecmp System time for interrupt (uint64_t)
 **************************************************************************/
 **************************************************************************/
void neorv32_mtime_set_timecmp(uint64_t timecmp) {
void neorv32_mtime_set_timecmp(uint64_t timecmp) {
 
 
  MTIMECMP_LO = 0xFFFFFFFF; // prevent mtimecmp from temporarily becoming smaller than the lesser of the old and new values
  MTIMECMP_LO = -1; // prevent mtimecmp from temporarily becoming smaller than the lesser of the old and new values
  MTIMECMP = timecmp;
  MTIMECMP = timecmp;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**

powered by: WebSVN 2.1.0

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