]> git.proxmox.com Git - grub2.git/blame - grub-core/kern/generic/rtc_get_time_ms.c
rtc_get_time_ms.c (grub_rtc_get_time_ms): Avoid division by zero.
[grub2.git] / grub-core / kern / generic / rtc_get_time_ms.c
CommitLineData
a829251b 1/* rtc_get_time_ms.c - get_time_ms implementation using platform RTC.
2 * The generic implementation of these functions can be used for architectures
3 * or platforms that do not have a more specialized implementation. */
4/*
5 * GRUB -- GRand Unified Bootloader
6 * Copyright (C) 2008 Free Software Foundation, Inc.
7 *
8 * GRUB is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * GRUB is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <grub/time.h>
23#include <grub/misc.h>
7da036bb 24#include <grub/machine/time.h>
a829251b 25
26/* Calculate the time in milliseconds since the epoch based on the RTC. */
27grub_uint64_t
28grub_rtc_get_time_ms (void)
29{
b39f9d20 30 /* By dimensional analysis:
31
a829251b 32 1000 ms N rtc ticks 1 s
33 ------- * ----------- * ----------- = 1000*N/T ms
34 1 s 1 T rtc ticks
35 */
36 grub_uint64_t ticks_ms_per_sec = ((grub_uint64_t) 1000) * grub_get_rtc ();
4e0a25a4 37 return grub_divmod64 (ticks_ms_per_sec, GRUB_TICKS_PER_SECOND ? : 1000, 0);
a829251b 38}