1 Introduction
The time display function of the desktop Windows system is well known and implemented by the BIOS clock module. You can click the time in the lower-right corner of the taskbar of the desktop system to modify the current time and time zone, and synchronize time with the Internet.
Currently, many popular embedded systems such as mobile phones, PDAs, and HMI (Human-Machine Interface Devices) have been transplanted to Microsoft's Windows
CE operating system. Although the wince system also implements time display, its principles and methods are very different from those of the desktop system in specific implementation.
Also, it is different. Due to the complexity and dispersibility of the embedded system, the real-time clock RTC function of the embedded system is mostly implemented in the RTC function IP module embedded in the SOC processor.
Based on the software-driven implementation.
S3C2440 is a low-power, high-performance embedded SoC processor developed by Samsung Based on the ARM920T processor architecture. It is widely used. RTC is one of the S3C2440
Function module. This article first introduces the hardware architecture of the S3C2440, analyzes the working mechanism of the RTC function module of the S3C2440, and finally provides
The RTC driver of ce.net is designed and implemented. The driver is successfully applied
The implementation of the real-time clock function of the CE platform's handheld gps machine can be used as a reference for implementing the RTC function based on other Windows ce.net hardware platforms.
2 hardware architecture
The implementation of the RTC function in wince is based on the RTC module. This section briefly introduces the S3C2440 processor, and mainly analyzes the hardware structure and working mechanism of the RTC of S3C2440, these are the basis for implementing the RTC function in Windows ce.net.
2.1 Introduction
S3C2440
It is an embedded processor developed by Samsung Based on ARM920T. It features a clock speed of up to 400 MHz, a maximum of 533 MHz, low power consumption and high performance. It is widely used in PDA and portable media playback.
On-chip integration of commands/data separation of 16 kcache, SDRAM Controller, LCD controller, 4-channel DMA, 3-channel UART, IIC bus,
IIS Bus, SD host interface, PWM timer, watchdog, on-chip PLL clock generator, 8-Channel 10-bit ad controller, touch screen interface, and real-time clock with Calendar function, which greatly facilitates the system
Integrated development.
2.2 hardware architecture of the s3c244o processor rtc
The structure of the Internal RTC module of S3C2440 is shown in Figure 1. The RTC module of the S3C2440 processor relies on the external 32.768khz crystal oscillator to provide the benchmark clock, and the system can be powered off.
Powered by a backup battery to continue working, the 8-bit data can be converted into BCD code format and transferred to the processor. The data includes seconds, minutes, hours, dates, weeks, months, and years.
As shown in 1, the RTC module consists of the connection pin of the reference crystal oscillator, the clock tick generator, the 215 clock divider, the control and reset registers, the leap year generator, the alarm generator, and the BCD number (seconds, minutes,
Time, date, week, month, and year. xtlrtc and xtortc are two pins connected to the external crystal oscillator 32.768khz, providing internal input for the RTC. 215 clock Division
Is responsible for dividing the benchmark frequency. The clock tick generator can generate a clock tick, which can cause interruption. The leap year generator determines the last day of a month based on the BCD data obtained from date, month, and year,
29, 30, or 31 (that is, whether the calculation is a leap year ). The alarm generator can decide whether to trigger an alarm based on the time set by the system and the current time. Control register control includes read/write BCD register enabling
Clock reset, clock selection, etc. To reset the register, you can select "second" to "Minute" carry boundary, which provides three optional boundary: 30, 40, or 50 seconds.
Figure 1 structure of the Internal RTC module of S3C2440
Working principle of 2.3 S3C2440 processor rtc
According to the structure of the RTC module, the RTC module has three functions: generating clock ticking, real-time timing, and serving as the system's trigger wake-up device. The RTC clock tick can be used as the kernel clock tick of the real-time operating system (RTOs). When the clock tick cycle is determined, scheduled interruptions will occur, the interrupt service program of the operating system processes the interrupt in real time.
The RTC module can trigger an alarm simultaneously at the set time (given by BCD data) in the power-down mode of the processor or in normal mode. In normal mode, almint is active. In power-down mode, pmwkup (Power Management wake-up signal) and almint are both in the alarm state.
The most important function of RTC is to display the time. In power-down mode, the RTC still works normally. At this time, the RTC module works through an external battery. The RTC time display function is implemented by reading/writing registers.
. To display the second, minute, hour, date, month, and year, the processor only needs to read data that exists in bcdsec, bcdmin, bcdhour, bcdday, bcddate,
Bcdmon and bcdyear registers.
3. Driver implementation
The implementation of the RTC function is based on the S3C2440 embedded development platform. It is implemented through the driver program of the RTC module under wince, while the RTC driver under wince is implemented at the underlying layer,
Body must be implemented in oal (OEM adaption Layer. The following describes the oal code layer, analyzes the RTC driver code, and provides some source programs.
3.1 oal Overview
The full name of oal is OEM adaption.
Layer, that is, the adaptation layer of the original device manufacturer. In terms of logic structure, oal is located between the kernel and hardware of the operating system and is the hub connecting the system and hardware. In terms of functions, oal is linked to the kernel.
Library, which can be used to create executable files of the kernel. OAL communicates with the target device in the system kernel. It is affiliated with the operating system and is part of the operating system. OAL is a group of functions.
Aggregate. These functions reflect oal functions, as shown in figure 2.
Figure 2 oal functional structure
The oal layer includes startup (), oeminit (), real-time clock function, serial port debugging function, underlying interrupt processing function, Ethernet port debugging function, and kitl (kernel ).
Independent Transport Layer) kernel independent transport layer, in addition, it also implements advanced features including power management, module authentication.
The Startup Process of Wince is: the CPU executes the boot vector and jumps to the hardware initialization code, that is, the startup function.
After the startup function completes the minimum hardware environment initialization, it jumps to the kernelstart function to initialize the kernel. The kernelstart function is called.
Oeminitdebugserial initializes the debugging serial port, calls the oeminit function to complete hardware initialization, sets the clock and interrupts, and calls
The oemgetextensiondram function is used to determine whether there is another dram.
Therefore, the real-time clock driver implementation code is implemented at the oal layer. When Windows CE starts, it calls the real-time clock function to initialize the system time. The following describes the specific implementation of these functions.
3.2 clock functions
To implement the RTC function, three functions are required: oemgetrealtime (), oemsetrealtime (), and oemsetalarmtime (). The following describes the three functions.
Oemgetrealtime () to get the current time. This function name cannot be changed. It is defined by the wince kernel, that is, it is called directly when the kernel needs to know the current time. Figure 3 shows the execution process of the function oemgetrealtime.
Because RTC cannot be arbitrarily modified, it will lead to time confusion. Therefore, RTC must be disabled after each time the time is obtained or set. This is achieved by setting the RTC enable/disable register.
However, you must use it before each read time or set the time. When the read time is 0, the read time must be re-read because the "points" have been carried.
Oemsetrealtime () is used to set the time. Like oemgetrealtime (), it cannot be renamed. With this function, the core can directly modify the time. That is to say, if you click the time in the wince taskbar, the modification time will eventually call this function.
Oemsetalarmtime () sets the system alert time. Its parameter is a long pointer to the buffer zone containing the systemtime struct. Returns true if the function is successfully executed,
If the execution fails, false is returned. This function must be unique to prevent multiple hardware operations. For general user operations, you do not need to write this function. If you want the system to complete the task at a specific time
You need to write this function.
The source code of oemgetrealtime () is provided below for reference only.
Oemgetrealtime (lpsystemtime lpst)
{
Volatile rtcreg * s2440rtc;
S2440rtc = (rtcreg *) rtc_base;
// Retailmsg (1, (_ T ("oemgetrealtime ")));
// Enable rtc
S2440rtc-> rrtccon = 0x1;
Lpst-> wmilliseconds = 0;
Lpst-> wsecond = from_bcd (s2440rtc-> rbcdsec & 0x7f );
Lpst-> wminute = from_bcd (s2440rtc-> rbcdmin & 0x7f );
Lpst-> whour = from_bcd (s2440rtc-> rbcdhour & 0x3f );
Lpst-> wdayofweek = (s2440rtc-> rBCDDATE-1 );
Lpst-> wday = from_bcd (s2440rtc-> rbcdday & 0x3f );
Lpst-> wmonth = from_bcd (s2440rtc-> rbcdmon & 0x1f );
// Lpst-> wyear = (2000 + s2440rtc-> rbcdyear );
Lpst-> wyear = from_bcd (s2440rtc-> rbcdyear) + 2000;
If (lpst-> wsecond = 0)
{
Lpst-> wsecond = from_bcd (s2440rtc-> rbcdsec & 0x7f );
Lpst-> wminute = from_bcd (s2440rtc-> rbcdmin & 0x7f );
Lpst-> whour = from_bcd (s2440rtc-> rbcdhour & 0x3f );
Lpst-> wdayofweek = (s2440rtc-> rBCDDATE-1 );
Lpst-> wday = from_bcd (s2440rtc-> rbcdday & 0x3f );
Lpst-> wmonth = from_bcd (s240rtc-> rbcdmon & 0x1f );
Lpst-> wyear = (2000 + s240rtc-> rbcdyear );
}
// Disable rtc
S2440rtc-> rrtccon = 0;
Return true;
}
System I/O 3.3
The oal code layer provides functions for interaction with the kernel, through which information about the hardware platform can be obtained through the kernel. In the oal layer, the function to complete this function is oemiocontrol (). The function prototype is as follows:
Bool oemiocontol (......)
{Switch (dwiocontro1)
{Case ioctl_hal_init_rtc;
If (ninbufsize> = sizeof (systemtime ))
Return oemsetrealtime (lpsystemtime) lpinbuf );
Else
Return false;
Break;
......
Default: Return false;
}
Each time wince is started, the kerneliocontrl () function calls oemiocontrol () to read the underlying hardware information.
Dwiocontrol is the control code for Kernel-to-oal communication. It can be used to read hardware information. The control code is generally defined by Microsoft. The control code defined by the RTC module is
Ioctl_hal_init_rtc, which can be used to initialize the underlying RTC module.
Ninbufsize is the size of the buffer to which the lpinbuf (pointer) points. The buffer size is calculated in bytes. Systemtime is a representation defined internally by wince.
And lpsystemtime is the pointer to this struct. The systemtime struct prototype is as follows. The prototype defines the year, month, week, day, hour, minute, second,
Milliseconds.
Typedef struct _ systemtime
{
Word wyear;
Word wmonth;
Word wdayofweek;
Word wday;
Word whour;
Word wminute;
Word wseeond;
Word wmilliseconds;
} Systemtime;
In this design, the time resolution of RTC is "seconds", because the minimum time reference provided by the RTC module of S3C2440 is "seconds ". Users can write system I/O files as needed
You can also disable the RTC initialization code. If wince cannot read the clock parameter from the oal layer, it initializes the systemtime struct with the default time value of the system.
4 Conclusion
Currently, most popular ARM embedded processors, such as Samsung's s3c series, Intel's XScale series, and Motorola's Dragon Ball series, are embedded with RTC models.
Block. It makes time display of many embedded products such as mobile phones and PDAs rich and colorful, such as the display of calendars, calendars, calendars and other functions. This article provides the implementation of the wince driver of the RTC module, based on
The design can further develop clock application functions, such as the clock interface, to meet the application requirements of the clock function in a colorful embedded system.