iMX28 Windows CE 6.0 - Implement RTC through I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

iMX28 Windows CE 6.0 - Implement RTC through I2C

Jump to solution
1,837 Views
pravinyadav
Contributor III

Hi.

We have custom hardware with iMX28 porting Windows CE 6.0. We are using external RTC (M41T81S) which are connected through I2C interface. I am trying to modify some functions like OALIoCtlHalInitRTC, OEMGetRealTime and OEMSetRealTime from rtc.c file (located at C:\WINCE600\PLATFORM\COMMON\SRC\SOC\MX28_FSL_V2_PDK1_9\OAL\RTC). Instead of internal RTC read, we trying to set and get date, time from external RTC through I2C. The I2C implementation lies within i2c_io.cpp and i2cClass.cpp (located at C:\WINCE600\PLATFORM\COMMON\SRC\SOC\MX28_FSL_V2_PDK1_9\I2C\PDK). So questions are -

- How do i initialize I2C interface from RTC files (rtc.c)? If we consider I2C is initializing (through driver initialization) then how do i call ProcessPackets function from rtc.c

- There are no functions like ReadPacket(...) and WritePacket(...) in i2cClass.cpp. only ProcessPackets is available and only accessible through I2C_IOControl(...) (deviceIOControl)

Please share your thoughts on simplest way to implement RTC through I2C.

Labels (2)
0 Kudos
1 Solution
1,069 Views
jimmerkle
Contributor I

You are correct.  The normal RTC APIs are routed directly into the kernel OAL code.

The method described up above involves creating a minimal streaming device driver who's job is to interact with the I2C-RTC chip.  Steaming-RTC driver talking to the streaming-I2C driver, talking to the I2C-RTC chip.  So, when you see "RTC Driver" above, it is a steaming device driver, not kernel OAL.  You end up with dual RTC modules,  The kernel "owns" the processor's RTC hardware, and the streaming device driver RTC owns the RTC on the I2C bus.  A named event is used to wake the streaming device driver when then time is changed with the kernel OAL's RTC.  The streaming device driver can use the standard system time calls to access it, or it can access it via the processor's registers.  I'd use the direct register approach..

Within the kernel, you'll need to use the kernel methods for events vs "user methods".  Search the sample kernel code for "Event".  I believe it's something like SH_CreateEvent() and SH_SetEvent().

View solution in original post

5 Replies
1,069 Views
Yuri
NXP Employee
NXP Employee

Hi,

  Basically, Your specific RTC driver may communicate over the I2C, using

DeviceIoControl() calls (of I2C driver) to read and write to the RTC device.

Please take a look at Chapter 11 [Inter-Integrated Circuit (I2C) Driver]

of “EVK_imx28_WinCE60_RM.pdf”

Also, the following may be useful :

http://www.e-consystems.com/blog/windowsce/?p=121

Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,069 Views
pravinyadav
Contributor III

Thanks for update...

I have done successfully read and write operation of RTC through I2C. The read operation is implemented after I2C init (on device boot) and write operation is implemented in different application using DeviceIoControl(...). Now only concern is how to write data in RTC when date/time is updated from date/time property window (on UI) in this case kernel call OEMSetAlarmTime function (alarm.c). Ultimately i need to implement RTC write operation in OEMSetAlarmTime function which lies within 'C file and its quite challenging to make Win32 API's (which are used in I2C class for read/write operation) compatible in OAL layer (rtc. alaram.c files).

0 Kudos
1,069 Views
jimmerkle
Contributor I

I'd recommend creating a named event that both the kernel and an RTC device driver can share.  When the kernel receives an OEMSetAlarm() call, it will write the new time information to the processor's RTC then set the named event that an RTC driver update thread is waiting on.  The thread will wake up, read the time from the processor's RTC registers, then write the new time to the RTC chip on the I2C bus.  Periodically, an RTC thread can update the processor's RTC with the time from the RTC chip on the I2C bus.

1,069 Views
pravinyadav
Contributor III

RTC driver lies within OAL layer so is it possible to create named event in OAL layer? How can i access CreateEvent, WaitForSingleObject in OAL layer. Compiler throws linking error 'unresolved external symbol'. Please share if you have a sample code..

Thanks

0 Kudos
1,070 Views
jimmerkle
Contributor I

You are correct.  The normal RTC APIs are routed directly into the kernel OAL code.

The method described up above involves creating a minimal streaming device driver who's job is to interact with the I2C-RTC chip.  Steaming-RTC driver talking to the streaming-I2C driver, talking to the I2C-RTC chip.  So, when you see "RTC Driver" above, it is a steaming device driver, not kernel OAL.  You end up with dual RTC modules,  The kernel "owns" the processor's RTC hardware, and the streaming device driver RTC owns the RTC on the I2C bus.  A named event is used to wake the streaming device driver when then time is changed with the kernel OAL's RTC.  The streaming device driver can use the standard system time calls to access it, or it can access it via the processor's registers.  I'd use the direct register approach..

Within the kernel, you'll need to use the kernel methods for events vs "user methods".  Search the sample kernel code for "Event".  I believe it's something like SH_CreateEvent() and SH_SetEvent().