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

Subversion Repositories neorv32

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

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

Rev 11 Rev 12
Line 50... Line 50...
 *
 *
 * @return 0 if MTIME was not synthesized, 1 if MTIME is available.
 * @return 0 if MTIME was not synthesized, 1 if MTIME is available.
 **************************************************************************/
 **************************************************************************/
int neorv32_mtime_available(void) {
int neorv32_mtime_available(void) {
 
 
  if (neorv32_cpu_csr_read(CSR_MFEATURES) & (1 << CPU_MFEATURES_IO_MTIME)) {
  if (SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_IO_MTIME)) {
    return 1;
    return 1;
  }
  }
  else {
  else {
    return 0;
    return 0;
  }
  }
Line 68... Line 68...
 *
 *
 * @param[in] time New system time (uint64_t)
 * @param[in] time New system time (uint64_t)
 **************************************************************************/
 **************************************************************************/
void neorv32_mtime_set_time(uint64_t time) {
void neorv32_mtime_set_time(uint64_t time) {
 
 
  MTIME = time;
  union {
 
    uint64_t uint64;
 
    uint32_t uint32[sizeof(uint64_t)/2];
 
  } cycles;
 
 
 
  cycles.uint64 = time;
 
 
 
  MTIME_LO = 0;
 
  MTIME_HI = cycles.uint32[1];
 
  MTIME_LO = cycles.uint32[0];
 
 
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Get current system time.
 * Get current system time.
Line 81... Line 91...
 *
 *
 * @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) {
 
 
  return MTIME;
  union {
 
    uint64_t uint64;
 
    uint32_t uint32[sizeof(uint64_t)/2];
 
  } cycles;
 
 
 
  uint32_t tmp1, tmp2, tmp3;
 
  while(1) {
 
    tmp1 = MTIME_HI;
 
    tmp2 = MTIME_LO;
 
    tmp3 = MTIME_HI;
 
    if (tmp1 == tmp3) {
 
      break;
 
    }
 
  }
 
 
 
  cycles.uint32[0] = tmp2;
 
  cycles.uint32[1] = tmp3;
 
 
 
  return cycles.uint64;
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Set compare time register (MTIMECMP) for generating interrupts.
 * Set compare time register (MTIMECMP) for generating interrupts.

powered by: WebSVN 2.1.0

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