Changeset bd41ac52 in mainline for uspace/drv/time/cmos-rtc/cmos-rtc.c


Ignore:
Timestamp:
2018-08-25T22:21:25Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cca80a2
Parents:
e2625b1a
Message:

Get rid of sys/time.h

This commit moves the POSIX-like time functionality from libc's
sys/time.h to libposix and introduces C11-like or HelenOS-specific
interfaces to libc.

Specifically, use of sys/time.h, struct timeval, suseconds_t and
gettimeofday is replaced by time.h (C11), struct timespec (C11), usec_t
(HelenOS) and getuptime / getrealtime (HelenOS).

Also attempt to fix the implementation of clock() to return microseconds
(clocks) rather than processor cycles and move it to libc.

File:
1 edited

Legend:

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

    re2625b1a rbd41ac52  
    7575        int clients_connected;
    7676        /** time at which the system booted */
    77         struct timeval boot_time;
     77        struct timespec boot_time;
    7878} rtc_t;
    7979
     
    204204
    205205        rtc->boot_time.tv_sec = 0;
    206         rtc->boot_time.tv_usec = 0;
     206        rtc->boot_time.tv_nsec = 0;
    207207        rtc->clients_connected = 0;
    208208
     
    331331                 */
    332332
    333                 struct timeval curtime;
     333                struct timespec curtime;
    334334
    335335                getuptime(&curtime);
    336                 tv_add(&curtime, &rtc->boot_time);
     336                ts_add(&curtime, &rtc->boot_time);
    337337                fibril_mutex_unlock(&rtc->mutex);
    338338
    339                 return time_tv2tm(&curtime, t);
     339                return time_ts2tm(&curtime, t);
    340340        }
    341341
     
    346346        }
    347347
    348         /* Microseconds are below RTC's resolution, assume 0. */
    349         t->tm_usec = 0;
     348        /* Nanoseconds are below RTC's resolution, assume 0. */
     349        t->tm_nsec = 0;
    350350
    351351        /* now read the registers */
     
    419419                result = EINVAL;
    420420        else {
    421                 struct timeval uptime;
     421                struct timespec uptime;
    422422
    423423                getuptime(&uptime);
    424424                rtc->boot_time.tv_sec = r;
    425                 rtc->boot_time.tv_usec = t->tm_usec;    /* normalized */
    426                 tv_sub(&rtc->boot_time, &uptime);
     425                rtc->boot_time.tv_nsec = t->tm_nsec;    /* normalized */
     426                ts_sub(&rtc->boot_time, &uptime);
    427427                result = EOK;
    428428        }
     
    445445        bool bcd_mode;
    446446        time_t norm_time;
    447         struct timeval uptime;
    448         struct timeval ntv;
     447        struct timespec uptime;
     448        struct timespec ntv;
    449449        int  reg_b;
    450450        int  reg_a;
     
    457457
    458458        ntv.tv_sec = norm_time;
    459         ntv.tv_usec = t->tm_usec;
     459        ntv.tv_nsec = t->tm_nsec;
    460460        getuptime(&uptime);
    461461
    462         if (tv_gteq(&uptime, &ntv)) {
     462        if (ts_gteq(&uptime, &ntv)) {
    463463                /* This is not acceptable */
    464464                return EINVAL;
     
    474474        /* boot_time must be recomputed */
    475475        rtc->boot_time.tv_sec = 0;
    476         rtc->boot_time.tv_usec = 0;
     476        rtc->boot_time.tv_nsec = 0;
    477477
    478478        /* Detect the RTC epoch */
Note: See TracChangeset for help on using the changeset viewer.