在 Linux 上驱动 RTC 的方法

内核自带的 RTC 驱动

Posted by Jerry Chen on November 6, 2020

RX-8025T 资料

发送序列

(2) 号字节高 7bit 是从机地址:

从机地址说明

配置 Linux I2C 设备的从机地址只需要高 7bits(0b’0110010,即 0x32):

FEX 配置

RX-8025T 连接到全志芯片 I2C1 上,引脚号为 PB18、PB19;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;----------------------------------------------------------------------------------
;i2c configuration
;----------------------------------------------------------------------------------
[twi1]
twi1_used        = 1
twi1_scl         = port:PB18<2><default><default><default>
twi1_sda         = port:PB19<2><default><default><default>

;----------------------------------------------------------------------------------
;TWI device configuration
;compatible        --- device name
;reg               --- device address
;----------------------------------------------------------------------------------
[twi1/twi_board1]
compatible        = "rx8025t"
reg               = 0x32

rx8025t 驱动

这个驱动 Linux3.10 内核自带,改 id_table 中匹配名为 “rx8025t” 即可;

应用层控制

使用 timedatectl 工具设置时间和时区;

设置时区

系统时钟:

1
2
3
4
# 设置为 UTC 时区
timedatectl set-timezone UTC
# 设置为亚洲上海时区
timedatectl set-timezone "Asia/Shanghai"

硬件时钟(RTC 时钟):

1
2
3
4
# 设置硬件时钟为本地时区(即和系统时钟时区相同)
timedatectl set-local-rtc 1
# 设置硬件时钟为 UTC 时区
timedatectl set-local-rtc 0

设置系统时间

1
2
3
4
# 方式一:设置系统时间的日期和时间
timedatectl set-time "2020-11-08 17:30:40"
# 方式二:设置系统时间的日期和时间
date -s "2020-11-08 17:30:40"

同步系统时间和 RTC 时间

当系统时间的时区为 UTC 和非 UTC 时,同步时间的指令有所不同;

  系统时区为 UTC 系统时区不为 UTC
查看系统时间 date date
查看 RTC 时间 hwclock hwclock -u
设置系统时间 date -s "2020-11-08 17:30:40" date -s "2020-11-08 17:30:40"
同步系统时间到RTC hwclock --systohc hwclock --systohc -u
同步RTC时间到系统 hwclock --hctosys hwclock --hctosys -u