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

Subversion Repositories neorv32

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

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

Rev 59 Rev 64
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 (SYSINFO_FEATURES & (1 << SYSINFO_FEATURES_IO_MTIME)) {
  if (NEORV32_SYSINFO.SOC & (1 << SYSINFO_SOC_IO_MTIME)) {
    return 1;
    return 1;
  }
  }
  else {
  else {
    return 0;
    return 0;
  }
  }
Line 75... Line 75...
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/2];
  } cycles;
  } cycles;
 
 
  cycles.uint64 = time;
  cycles.uint64 = time;
 
 
  MTIME_LO = 0;
  NEORV32_MTIME.TIME_LO = 0;
  MTIME_HI = cycles.uint32[1];
  NEORV32_MTIME.TIME_HI = cycles.uint32[1];
  MTIME_LO = cycles.uint32[0];
  NEORV32_MTIME.TIME_LO = cycles.uint32[0];
 
 
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
Line 98... Line 98...
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/2];
  } cycles;
  } cycles;
 
 
  uint32_t tmp1, tmp2, tmp3;
  uint32_t tmp1, tmp2, tmp3;
  while(1) {
  while(1) {
    tmp1 = MTIME_HI;
    tmp1 = NEORV32_MTIME.TIME_HI;
    tmp2 = MTIME_LO;
    tmp2 = NEORV32_MTIME.TIME_LO;
    tmp3 = MTIME_HI;
    tmp3 = NEORV32_MTIME.TIME_HI;
    if (tmp1 == tmp3) {
    if (tmp1 == tmp3) {
      break;
      break;
    }
    }
  }
  }
 
 
Line 130... Line 130...
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/2];
  } cycles;
  } cycles;
 
 
  cycles.uint64 = timecmp;
  cycles.uint64 = timecmp;
 
 
  MTIMECMP_LO = -1; // prevent MTIMECMP from temporarily becoming smaller than the lesser of the old and new values
  NEORV32_MTIME.TIMECMP_LO = -1; // prevent MTIMECMP from temporarily becoming smaller than the lesser of the old and new values
  MTIMECMP_HI = cycles.uint32[1];
  NEORV32_MTIME.TIMECMP_HI = cycles.uint32[1];
  MTIMECMP_LO = cycles.uint32[0];
  NEORV32_MTIME.TIMECMP_LO = cycles.uint32[0];
}
}
 
 
 
 
/**********************************************************************//**
/**********************************************************************//**
 * Get compare time register (MTIMECMP).
 * Get compare time register (MTIMECMP).
 *
 *
 * @return Current MTIMECMP value.
 * @return Current MTIMECMP value.
 **************************************************************************/
 **************************************************************************/
uint64_t neorv32_mtime_get_timecmp(void) {
uint64_t neorv32_mtime_get_timecmp(void) {
 
 
  return MTIMECMP;
  union {
 
    uint64_t uint64;
 
    uint32_t uint32[sizeof(uint64_t)/2];
 
  } cycles;
 
 
 
  cycles.uint32[0] = NEORV32_MTIME.TIMECMP_LO;
 
  cycles.uint32[1] = NEORV32_MTIME.TIMECMP_HI;
 
 
 
  return cycles.uint64;
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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