X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/2236410f4582ab45ae8c384dd6eeeef5d10aab15..refs/heads/nov/multiuser:/lunaix-os/kernel/time/clock.c?ds=sidebyside diff --git a/lunaix-os/kernel/time/clock.c b/lunaix-os/kernel/time/clock.c index 2bf61d4..93354bb 100644 --- a/lunaix-os/kernel/time/clock.c +++ b/lunaix-os/kernel/time/clock.c @@ -5,51 +5,30 @@ #include -void -__clock_read_systime(struct twimap* map) +static void +__twimap_read_systime(struct twimap* map) { ticks_t sys_time = clock_systime(); twimap_printf(map, "%u", sys_time); } -void -__clock_read_datetime(struct twimap* map) +static void +__twimap_read_datetime(struct twimap* map) { datetime_t dt; clock_walltime(&dt); twimap_printf(map, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", - dt.year, - dt.month, - dt.day, - dt.hour, - dt.minute, - dt.second); + dt.year, dt.month, dt.day, + dt.hour, dt.minute, dt.second); } -void -__clock_read_unix(struct twimap* map) +static void +__twimap_read_unixtime(struct twimap* map) { twimap_printf(map, "%u", clock_unixtime()); } -void -clock_build_mapping() -{ - struct twifs_node* root = twifs_dir_node(NULL, "clock"); - struct twimap* map; - - map = twifs_mapping(root, NULL, "systime"); - map->read = __clock_read_systime; - - map = twifs_mapping(root, NULL, "unix"); - map->read = __clock_read_unix; - - map = twifs_mapping(root, NULL, "datetime"); - map->read = __clock_read_datetime; -} -EXPORT_TWIFS_PLUGIN(sys_clock, clock_build_mapping); - time_t clock_unixtime() { @@ -67,26 +46,30 @@ clock_systime() ticks_t t = hwtimer_current_systicks(); ticks_t tu = systimer->running_freq / 1000; - return t / (tu + 1); + + if (unlikely(!tu)) { + return t; + } + + return t / (tu); } void clock_walltime(datetime_t* datetime) { - sysrtc->get_walltime(sysrtc, datetime); + sysrtc->ops->get_walltime(sysrtc, datetime); } -void -clock_init() +static void +clock_build_mapping() { - int idx = 0; - struct device_def* pos; - foreach_exported_device_of(load_timedev, idx, pos) - { - if (pos->class.device != DEV_RTC) { - continue; - } + struct twifs_node* root; + struct twimap* map; - pos->init(pos); - } -} \ No newline at end of file + root = twifs_dir_node(NULL, "clock"); + + twimap_export_value(root, systime, FSACL_ugR, NULL); + twimap_export_value(root, unixtime, FSACL_ugR, NULL); + twimap_export_value(root, datetime, FSACL_ugR, NULL); +} +EXPORT_TWIFS_PLUGIN(sys_clock, clock_build_mapping);