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

Subversion Repositories neorv32

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

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

Rev 64 Rev 71
Line 1... Line 1...
// #################################################################################################
// #################################################################################################
// # << NEORV32: neorv32_mtime.c - Machine System Timer (MTIME) HW Driver >>                       #
// # << NEORV32: neorv32_mtime.c - Machine System Timer (MTIME) HW Driver >>                       #
// # ********************************************************************************************* #
// # ********************************************************************************************* #
// # BSD 3-Clause License                                                                          #
// # BSD 3-Clause License                                                                          #
// #                                                                                               #
// #                                                                                               #
// # Copyright (c) 2021, Stephan Nolting. All rights reserved.                                     #
// # Copyright (c) 2022, Stephan Nolting. All rights reserved.                                     #
// #                                                                                               #
// #                                                                                               #
// # Redistribution and use in source and binary forms, with or without modification, are          #
// # Redistribution and use in source and binary forms, with or without modification, are          #
// # permitted provided that the following conditions are met:                                     #
// # permitted provided that the following conditions are met:                                     #
// #                                                                                               #
// #                                                                                               #
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
// # 1. Redistributions of source code must retain the above copyright notice, this list of        #
Line 70... Line 70...
 **************************************************************************/
 **************************************************************************/
void neorv32_mtime_set_time(uint64_t time) {
void neorv32_mtime_set_time(uint64_t time) {
 
 
  union {
  union {
    uint64_t uint64;
    uint64_t uint64;
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
  } cycles;
  } cycles;
 
 
  cycles.uint64 = time;
  cycles.uint64 = time;
 
 
  NEORV32_MTIME.TIME_LO = 0;
  NEORV32_MTIME.TIME_LO = 0;
Line 93... Line 93...
 **************************************************************************/
 **************************************************************************/
uint64_t neorv32_mtime_get_time(void) {
uint64_t neorv32_mtime_get_time(void) {
 
 
  union {
  union {
    uint64_t uint64;
    uint64_t uint64;
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
  } cycles;
  } cycles;
 
 
  uint32_t tmp1, tmp2, tmp3;
  uint32_t tmp1, tmp2, tmp3;
  while(1) {
  while(1) {
    tmp1 = NEORV32_MTIME.TIME_HI;
    tmp1 = NEORV32_MTIME.TIME_HI;
Line 125... Line 125...
 **************************************************************************/
 **************************************************************************/
void neorv32_mtime_set_timecmp(uint64_t timecmp) {
void neorv32_mtime_set_timecmp(uint64_t timecmp) {
 
 
  union {
  union {
    uint64_t uint64;
    uint64_t uint64;
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
  } cycles;
  } cycles;
 
 
  cycles.uint64 = timecmp;
  cycles.uint64 = timecmp;
 
 
  NEORV32_MTIME.TIMECMP_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
Line 145... Line 145...
 **************************************************************************/
 **************************************************************************/
uint64_t neorv32_mtime_get_timecmp(void) {
uint64_t neorv32_mtime_get_timecmp(void) {
 
 
  union {
  union {
    uint64_t uint64;
    uint64_t uint64;
    uint32_t uint32[sizeof(uint64_t)/2];
    uint32_t uint32[sizeof(uint64_t)/sizeof(uint32_t)];
  } cycles;
  } cycles;
 
 
  cycles.uint32[0] = NEORV32_MTIME.TIMECMP_LO;
  cycles.uint32[0] = NEORV32_MTIME.TIMECMP_LO;
  cycles.uint32[1] = NEORV32_MTIME.TIMECMP_HI;
  cycles.uint32[1] = NEORV32_MTIME.TIMECMP_HI;
 
 

powered by: WebSVN 2.1.0

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