[轉] RTC驱动 date hwclock

出處:http://blog.csdn.net/uvsjoh/article/details/6273399

RTC功能:
RTC time: 系统关机后保持计时,当系统启动根据RTC时间来更新系统时间,之后系统时间独自运行。关机时把系统时间更新至RTC,因为系统时间精度比较高,相对准确一些。
RTC alarm: 当系统休眠时,用来唤醒系统。比如定时开关机。
RTC watchdog: 系统宕机时,自动重启系统。

The sysfs interface under /sys/class/rtc/rtcN provides access to various
rtc attributes without requiring the use of ioctls.
hctosys: 1 if the RTC provided the system time at boot via the
                 CONFIG_RTC_HCTOSYS kernel option, 0 otherwise
ioctl中有RTC_SET_TIME并且set_time不为NULL
.set_time        = rtc_settime,那么执行哪一个?
系统会先调用RTC_SET_TIME判断其返回状态,如果返回ENOIOCTLCMD,则执行.set_time。

If a driver supports “Magic Close”, the driver will not disable the
watchdog unless a specific magic character ‘V’ has been sent to
/dev/watchdog just before closing the file.
如果你支持:Magic Close ,驱动代码大概会是这样子:
if (c == ‘V’)
    set_bit(WDT_OK_TO_CLOSE, &wdt_status);

RTC 测试:
time 相关:
date 更改系统时间
设置系统时间:date 032409282011
查看系统时间:date

查看RTC时间:
hwclock -r
把系统时间更新至RTC
hwclock -w
把RTC时间更新至系统
hwclock -s

设置后可以如下查看RTC信息:
cat /proc/driver/rtc
rtc_time        : 09:32:13
rtc_date        : 2011-03-24
alrm_time        : **:**:**
alrm_date        : 2063-**-31
alarm_IRQ        : no
alrm_pending        : no
24hr                : yes

最大值最小值:
date 123123592127
date 限制最大值为2037?(1970 – 2037)
设置格式由上层去做,确保传给驱动的值是合法值

闰年问题:
主要看2月份
闰年:date 022823592020 平年:date 022823592011
设置为2月28日,等一会查看是变为29日还是3月1日。

alarm相关:
 /kernel/Documentation/rtc.txt中有个测试程序

watchdog相关:
cat /dev/watchdog 后, watchdog 将启动,timeout后会重启系统
/kernel/Documentation/watchdog下面有测试例子

未經允許不得轉載:GoMCU » [轉] RTC驱动 date hwclock