When does RTC update the system time?

Source: Internet
Author: User

RTC-real time clock maintains the system's hardware time. When Linux is started, you need to use the RTC hardware clock to set the system time.

This process is implemented in the drivers/RTC/hctosys. c driver. This driver actually only has one init function and declares its own init function

Late_initcall to ensure that the RTC driver is running properly.

The init function reads the current hardware clock from the RTC device, and then calls do_settimeofday to rewrite the system clock.

27 static int _ init rtc_hctosys (void)
28 {
29 int err =-enodev;
30 struct rtc_time TM;
31 struct timespec TV = {
32. TV _nsec = nsec_per_sec> 1,
33 };
34 struct rtc_device * RTC = rtc_class_open (config_rtc_hctosys_device );
35
36 IF (RTC = NULL ){
37 pr_err ("% s: Unable to open RTC device (% s) \ n ",
38 _ file __, config_rtc_hctosys_device );
39 goto err_open;
40}
41
42 err = rtc_read_time (RTC, & TM );
43 If (ERR ){
44 dev_err (RTC-> Dev. parent,
45 "hctosys: unable to read the hardware clock \ n ");
46 goto err_read;
47
48}
49
50 err = rtc_valid_tm (& TM );
51 if (ERR ){
52 dev_err (RTC-> Dev. parent,
53 "hctosys: Invalid date/time \ n ");
54 goto err_invalid;
55}
56
57 rtc_tm_to_time (& TM, & TV. TV _sec );
58
59 do_settimeofday (& TV );
60
61 dev_info (RTC-> Dev. parent,
62 "setting system clock"
63 "% d-% 02d-% 02d % 02d: % 02d: % 02d UTC (% u) \ n ",
64 TM. tm_year + 1900, TM. tm_mon + 1, TM. tm_mday,
65 TM. tm_hour, TM. tm_min, TM. tm_sec,
66 (unsigned INT) TV. TV _sec );
67
68 err_invalid:
69 err_read:
70 rtc_class_close (RTC );
71
72 err_open:
73 rtc_hctosys_ret = err;
74
75 return err;
76}
77

78 late_initcall (rtc_hctosys );

34. Obtain the RTC Device

42. The read time from the RTC device. rtc_read_time is only the read time interface function of the RTC subsystem. The real read operation is implemented in a specific RTC hardware driver.

The returned value is in the TM structure. rtc_valid_tm verifies that the returned value is valid.

57 to UTC seconds format

59 set the system time

78 ensure that this initialization function is called at least after the RTC driver initialization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.