FL2440 driver added (2): RTC (Real time clock)

Publisher:huanxinLatest update time:2024-07-24 Source: elecfansKeywords:FL2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

First, there are two types of time under Linux, system time and hardware time (RTC chip):

1. System time is the time that can be directly seen by the running system;

2. Hardware time is the time in the RTC chip, which is still powered by battery even when power is off;

When the Linux system is turned on, it will read the current time from the RTC as the system time, and the system time will tick independently from then on. This means that if you use the date command to modify the system time, the hardware time will not be affected. If you shut down the system at this time, the next system time will still be wrong. To save the system time to the hardware time, you can use the hwclock or clock command, where hwclock means hardware clock.



Because my development board does not support the clock command, I will only explain the hwclock command:


: hwclock --help
BusyBox v1.20.2 (2014-07-26 20:22:32 CST) multi-call binary.

Usage: hwclock [-r|--show] [-s|--hctosys] [ -w|--systohc] [-t|--systz] [-l|--localtime] [-u|--utc] [-f|--rtc FILE]

Query and set hardware clock (RTC)


-r Show hardware clock time
-s Set system time from hardware clock
-w Set hardware clock from system time
-t Set in-kernel timezone, correct system time
if hardware clock is in local time
-u Assume hardware clock is kept in UTC
-l Assume hardware clock is kept in local time
-f FILE Use specified device (eg /dev/rtc2)


:


hwclock –r show, displays the hardware clock, equivalent to hwclock without parameters.
hwclock –s hctosys, hardware clock to system, writes the time of the "hardware clock" RTC to the Linux "system" clock.
hwclock –w systohc, system to hardware clock, writes the "system" clock to the "hardware clock" RTC


Second, add support for RTC in the kernel (kernel linux-3.8)

1. RTC is already well supported in the kernel. You only need to add kernel compilation and register it:

Modify arch/arm/mach-s3c24xx/mach-smdk2440.c and add (just add the RTC device, in red):

static struct platform_device *smdk2440_devices[] __initdata = {
&s3c_device_ohci,
&s3c_device_lcd
, &s3c_device_wdt
, &s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_dm9000,
&s3c_device_adc,
&s3c_device_ts,
&s3c_device_rtc,
};


In arch/arm/plat-samsung/devs.c there is s3c_device_rtc definition:

#ifdef CONFIG_PLAT_S3C24XX
static struct resource s3c_rtc_resource[] = {
[0] = DEFINE_RES_MEM(S3C24XX_PA_RTC, SZ_256),
[1] = DEFINE_RES_IRQ(IRQ_RTC),
[2] = DEFINE_RES_IRQ(IRQ_TICK),
};

struct platform_device s3c_device _rtc = {
.name = "s3c2410-rtc",
.id = -1,
.num_resources = ARRAY_SIZE(s3c_rtc_resource),
.resource = s3c_rtc_resource,
};
#endif /* CONFIG_PLAT_S3C24XX */


2. Make menuconfig to add configuration options:


DeviceDrivers --->

[*] Real Time Clock --->

--- Real Time Clock

[*] Set system time from RTC on startup and resume

(rtc0) RTC used to set the system time

[*] /sys/class/rtc/rtcN (sysfs)

[*] /proc/driver/rtc (procfs for rtcN)

[*] /dev/rtcN(character devices)


After the Linux RTC driver is implemented, it is usually a normal character device, a misc device, or a platform device by default. If the driver is insmoded or compiled directly into the kernel, the corresponding device file is usually /dev/rtc or /dev/rtc0 or /dev/misc/rtc. In the linux-3.8 kernel, the root file system tool busybox-1.20.2 includes the hwclock command definition:



In busybox-1.20.2's libbb/rtc.c there is:

int FAST_FUNCrtc_xopen(const char **default_rtc, int flags)

{

int rtc;

if(!*default_rtc) {

*default_rtc = "/dev/rtc";

rtc =open(*default_rtc, flags);

if (rtc>= 0)

return rtc;

*default_rtc ="/dev/rtc0";

rtc = open(*default_rtc, flags);

if (rtc >= 0)

return rtc;

*default_rtc = "/dev/misc/rtc";

}

returnxopen(*default_rtc, flags);

}


3. Compile, download and start: red font means RTC is added ok


[s3c2440@zhou]# boot

NAND read: device 0 offset 0x100000, size 0x800000

8388608 bytesread: OK

## Booting kernel from Legacy Image at 30008000 ...

ImageName: Linux Kernel

Created: 2014-08-13 7:55:08 UTC

ImageType: ARM Linux Kernel Image(uncompressed)

DataSize: 3115480 Bytes = 3 MiB

Load Address:30008000

EntryPoint: 30008040

VerifyingChecksum ... OK

XIP KernelImage ... OK

OK

OS entry point: 30008040

Image entry point=30008040

Starting kernel ...

NAND device: Manufacturer ID: 0xec, Chip ID: 0xda(Samsung NAND 256MiB 3,3V 8-bit), 256MiB, page size: 2048, OOB size: 64

Scanning device for bad blocks

Bad eraseblock 236 at 0x000001d80000

Bad eraseblock 704 at 0x000005800000

Bad eraseblock 705 at 0x000005820000

Bad eraseblock 717 at 0x0000059a0000

Bad eraseblock 1251 at 0x000009c60000

Bad eraseblock 1631 at 0x00000cbe0000

Bad eraseblock 1771 at 0x00000dd60000

Bad eraseblock 1947 at 0x00000f360000

Creating 9 MTD partitions on "NAND":

0x000000000000-0x000000100000 : "mtdblock0_u-Boot1MB "

0x000000100000-0x000001000000 : "mtdbolck1_kernel15MB"

0x000001000000-0x000002400000 :"mtdbolck2_ramdisk 20MB"

0x000002400000-0x000003800000 : "mtdblock3_cramfs20MB"

0x000003800000-0x000006000000 : "mtdblock4_jffs240MB"

0x000006000000-0x000008800000 : "mtdblock5_yaffs240MB"

0x000008800000-0x00000b000000 : "mtdblock6_ubifs40MB"

0x00000b000000-0x00000d800000 : "mtdblock7_apps40MB"

0x00000d800000-0x000010000000 : "mtdblock8_data40MB"

. . . . .

usbserial: USB Serial support registered for pl2303

mousedev: PS/2 mouse device common for all mice

s3c-rtc s3c2410-rtc: rtc disabled, re-enabling

s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0

sdhci: Secure Digital Host Controller Interface driver

sdhci: Copyright(c) Pierre Ossman

. . . . .

UBI: background thread "ubi_bgt0d" started,PID 472

s3c-rtc s3c2410-rtc: setting system clock to 2024-04-2611:18:22 UTC (1714130302)

ALSA device list:

. . . . .

Freeing init memory: 156K

usb 1-1: New USB device found, idVendor=05e3,idProduct=0606

usb 1-1: New USB device strings: Mfr=1, Product=2,SerialNumber=0

usb 1-1: Product: USB Hub 2.0

hub 1-1:1.0: USB hub found

hub 1-1:1.0: 4 ports detected

dm9000 dm9000 eth0: link down dm9000 dm9000 eth0: linkup, 100Mbps, full-duplex, lpa 0xCDE1

Copyright (C) 2014zhouguangfeng

root for passwd: 12345

root login: root

Password:


: ls

apps data etc init linuxrc my2440 root sys usr

bin dev info lib mnt proc sbin tmp var

: date //Display the current system time

Wed Jan 1 01:04:08 MST 2014

: date -s 2014.8.13-17:51:10 //Set the current system time
to Wed Aug 13 17:51:10 MDT 2014

: hwclock -r //Display the current RTC time, which is different from the system time
Wed Jan 1 01:05:08 2014 0.000000 seconds
: hwclock -s //Set the RTC time to the current system time
: date
Wed Jan 1 01:05:26 MST 2014
: date -s 2014.8.13-17:51:10 //Set the current system time
Wed Aug 13 17:51:10 MDT 2014
: hwclock -r //Display the current RTC time
Wed Jan 1 01:05:59 2014 0.000000 seconds
: hwclock -w //Write the system time to the RTC
: hwclock -r
Wed Aug 13 17:51:25 2014 0.000000 seconds
: ll /dev/rtc0 // The system creates a facility file to drive the RTC

crw-rw---- 1 root root 254, 0 Dec 31 1969 /dev/rtc0


Keywords:FL2440 Reference address:FL2440 driver added (2): RTC (Real time clock)

Previous article:Kernel transplantation and file system creation (3) Ramdisk introduction and common problems
Next article:Module cannot be rmmod after insmod

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号