Real Time Clock(RTC) on Amida

From OpenAlchemy.org

Amida comes with an internal and external RealTimeClock(RTC). The external RTC (DS1337) keeps running even when Amida is switched off. Internal Strongarm RTC resets itself on each shutdown.

RTC Management

The different steps that Amida follows for keeping track of time and alarm are as follows.

Boot Time After Amida boots up, the internal RTC is updated from the external RTC. System time is updated on each timer interrupt. Its a standard feature of Linux.

Sleep Before Amida goes to sleep, the system time is saved in the registers of internal RTC.

Wake up After Amida wakes up, system time is updated from the internal RTC.

Setting time The user can set new time using date command. See man pages of date for more information.

Shutdown When Amida shuts down, the current system time saved to the external RTC.


DS1337

DS1337 chip enables Amida to provide Real Time Clock feature. This section discusses the DS1337 chip and the kernel modules ds1337.o, simputer-rtc.o

DS1337 has timekeeper registers to keep track of year, date, hour, minutes and seconds. It has internal clock to tick seconds, minutes etc. DS1337 has two alarm register sets. Alarm register set has seconds, minutes, hours and date registers and if the content of these registers matches with the timekeeper registers DS1337 generates an interrupt 1 to the processor. DS1337 communicates with the processor via two GPIO lines 2. The communication follows two wire serial I2C protocol.

Kernel modules ds1337.o and simputer-rtc.o

The kernel module ds1337.o implements the I2C protocol and interfaces with the DS1337. It implements routines to read and write the timekeeper registers and alarm registers. It exposes /proc/ds1337 interface for applications to read and write to DS1337. /proc/ds1337 shows DS1337 time in the format MM:DT:HR:MN:YR where 1 <= MM <= 12, 1 <= DT <= 31, 0 <= HR <= 23, 0 <= MN <= 59, 2000 <= Y R <= 2099. This format is useful in setting system date straightaway as follows $date 'cat /proc/ds1337'.

echo 1 > /proc/ds1337 sets the DS1337 time in sync with the system time and is invoked during each shutdown of Amida. Writing 1 to /proc/ds1337 also enables the interrupt for alarm wakeup.

The kernel module simputer-rtc.o implements the interface for alarm. It exposes /proc/schedule alarm and /proc/reset alarm in order to set and reset an alarm, respectively. simputer-rtc.o module uses both internal and external RTC in order to provide the alarm service. RTC alarm has three modes of operation Run, Sleep and Shutdown as described below.

Run In Run mode simputer-rtc.o uses internal RTC to set alarm.

Sleep In Sleep mode simputer-rtc.o uses internal RTC to set alarm and also enables wake up on internal RTC alarm condition in appropriate StrongArm registers.

Shutdown In Shutdown mode external RTC boots up Amida on alarm.

To set an alarm, update the corresponding proc entry. That is, use the following command with appropriate values for SEC,MIN,HR, etc.

echo "SC:MN:HR:DT:MM:YR" > /proc/schedule_alarm, where 0 <= SC <= 59, 0 <=MN <= 59, 0 <= HR <= 23, 1 <= DT <= 31, 1 <= MM <= 12, Y R >= 1970 enables an alarm on SC : MN : HR : DT : MM : Y R. When the alarm expires rtc thread exec's /usr/local/bin/koli. It is assumed that all the alarms are set by koli and hence the alarm events are passed to koli only.

It is important to note that the external RTC only supports Seconds, minutes, hours and date in Alarm register. Hence external RTC can not support alarm of a different month or year.

echo 1 > /proc/reset_alarm resets the alarm set by previous write to /proc/schedule alarm.

Users

OpenAlchemy is a Free and Open Source Software project
proudly supported by
Geodesic Information Systems Limited

Comments? Feedback? Contact Us.

MediaWiki