Changeset 83298e8 in mainline
- Timestamp:
- 2012-08-16T21:35:20Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4f351432
- Parents:
- 16639bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/time/cmos-rtc/cmos-rtc.c
r16639bb r83298e8 51 51 #include <macros.h> 52 52 #include <ipc/clock_ctl.h> 53 #include <time.h> 53 54 54 55 #include "cmos-regs.h" … … 75 76 bool removed; 76 77 } 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;84 78 85 79 static int rtc_time_get(ddf_fun_t *fun, struct tm *t); … … 650 644 } 651 645 652 /** Get the current uptime653 *654 * The time variables are memory mapped (read-only) from kernel which655 * 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 we659 * read the seconds again. If a second elapsed in the meantime, set660 * the microseconds to zero.661 *662 * This assures that the values returned by two subsequent calls663 * to gettimeofday() are monotonous.664 *665 */666 646 static time_t 667 647 uptime_get(void) 668 648 { 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; 695 654 } 696 655
Note:
See TracChangeset
for help on using the changeset viewer.