Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 83298e8 in mainline


Ignore:
Timestamp:
2012-08-16T21:35:20Z (9 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master
Children:
4f351432
Parents:
16639bb
Message:

rtc: make use of the getuptime() function

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/time/cmos-rtc/cmos-rtc.c

    r16639bb r83298e8  
    5151#include <macros.h>
    5252#include <ipc/clock_ctl.h>
     53#include <time.h>
    5354
    5455#include "cmos-regs.h"
     
    7576        bool removed;
    7677} rtc_t;
    77 
    78 /** Pointer to the kernel shared variables with time */
    79 struct {
    80         volatile sysarg_t seconds1;
    81         volatile sysarg_t useconds;
    82         volatile sysarg_t seconds2;
    83 } *kuptime = NULL;
    8478
    8579static int  rtc_time_get(ddf_fun_t *fun, struct tm *t);
     
    650644}
    651645
    652 /** Get the current uptime
    653  *
    654  * The time variables are memory mapped (read-only) from kernel which
    655  * updates them periodically.
    656  *
    657  * As it is impossible to read 2 values atomically, we use a trick:
    658  * First we read the seconds, then we read the microseconds, then we
    659  * read the seconds again. If a second elapsed in the meantime, set
    660  * the microseconds to zero.
    661  *
    662  * This assures that the values returned by two subsequent calls
    663  * to gettimeofday() are monotonous.
    664  *
    665  */
    666646static time_t
    667647uptime_get(void)
    668648{
    669         if (kuptime == NULL) {
    670                 uintptr_t faddr;
    671                 int rc = sysinfo_get_value("clock.faddr", &faddr);
    672                 if (rc != EOK) {
    673                         errno = rc;
    674                         return -1;
    675                 }
    676                
    677                 void *addr;
    678                 rc = physmem_map((void *) faddr, 1,
    679                     AS_AREA_READ | AS_AREA_CACHEABLE, &addr);
    680                 if (rc != EOK) {
    681                         as_area_destroy(addr);
    682                         errno = rc;
    683                         return -1;
    684                 }
    685                
    686                 kuptime = addr;
    687         }
    688 
    689         sysarg_t s2 = kuptime->seconds2;
    690        
    691         read_barrier();
    692         sysarg_t s1 = kuptime->seconds1;
    693        
    694         return max(s1, s2);
     649        struct timeval tv;
     650
     651        getuptime(&tv);
     652
     653        return tv.tv_sec;
    695654}
    696655
Note: See TracChangeset for help on using the changeset viewer.