Hi,

I am using an external real time clock to store the local time.
Inside RTC_Init(), I start an endless thread waiting for time events
"NOTIFICATION_EVENT_TIME_CHANGE" and "NOTIFICATION_EVENT_TZ_CHANGE" to
be notified about time changes (see code below). This works fine until
Suspend/Resume!

If the board did a Suspend/Resume, I get following errors at bootup:
> Notification Error : Cannot execute \\.\Notifications\NamedEvents\DSTTimeChange
> Notification Error : Cannot execute \\.\Notifications\NamedEvents\TaskbarTimeChangeEvent
Afterwards, a "NOTIFICATION_EVENT_TIME_CHANGE" event occurs.

When I delete my persistent registry, the errors disappear until I do
another Suspend/Resume.

If I disable the RTC driver, no errors are visible at all!

Does anybody know why these errors happen or do I make something wrong
inside my endless thread?

Thanks in advance
beat

DWORD WINAPI synchronizerThread(LPVOID param)
{
HANDLE hTimeEvent[2];
CE_NOTIFICATION_TRIGGER trigger[2];
SYSTEMTIME time;
DWORD rWaitObject;

// Time change
GetLocalTime(&trigger[0].stStartTime);
trigger[0].dwSize = sizeof(CE_NOTIFICATION_TRIGGER);
trigger[0].dwType = CNT_EVENT ;
trigger[0].dwEvent = NOTIFICATION_EVENT_TIME_CHANGE;
trigger[0].lpszApplication = L"\\\\.\\Notifications\\NamedEvents\
\TimeNotify";
trigger[0].lpszArguments = 0;
trigger[0].stEndTime = trigger[0].stStartTime;

// TimeZone change
GetLocalTime(&trigger[1].stStartTime);
trigger[1].dwSize = sizeof(CE_NOTIFICATION_TRIGGER);
trigger[1].dwType = CNT_EVENT ;
trigger[1].dwEvent = NOTIFICATION_EVENT_TZ_CHANGE;
trigger[1].lpszApplication = L"\\\\.\\Notifications\\NamedEvents\
\TimeZoneNotify";
trigger[1].lpszArguments = 0;
trigger[1].stEndTime = trigger[1].stStartTime;

hTimeEvent[0] = CreateEvent(0, FALSE, FALSE, L"TimeNotify");
hTimeEvent[1] = CreateEvent(0, FALSE, FALSE, L"TimeZoneNotify");
if ( (hTimeEvent[0] == 0) || (hTimeEvent[1] == 0) ) {
RETAILMSG(1, (L"External RTC - Creation of TimeEvents failed!\r
\n"));
}
else {
WaitForAPIReady(SH_WMGR, INFINITE);
while (CeSetUserNotificationEx(0, &trigger[0], 0) == NULL)
{ Sleep(200); }
while (CeSetUserNotificationEx(0, &trigger[1], 0) == NULL)
{ Sleep(200); }
while (1) {
rWaitObject = WaitForMultipleObjects(2, hTimeEvent, FALSE,
INFINITE);
if ( (WAIT_FAILED == rWaitObject) ||
(WAIT_TIMEOUT == rWaitObject) )
RETAILMSG(1, (L"External RTC Task -
WaitForMultipleObjects ERROR!\r\n"));
}
else {
EnterCriticalSection(&csRTC);
GetLocalTime(&time);
setExternalRtc(&time);
LeaveCriticalSection(&csRTC);
}
}
}
return 0;
}

Re: TimeChange Notification Error at bootup by beat

beat
Wed Jun 04 04:04:57 PDT 2008

Sorry,
I am using Windows CE 6, R2

Re: TimeChange Notification Error at bootup by Bradley

Bradley
Wed Jun 04 09:40:23 PDT 2008

On Jun 4, 3:56 am, beat <beat.m...@gmail.com> wrote:
> I am using an external real time clock to store the local time.
> Inside RTC_Init(), I start an endless thread waiting for time events
> "NOTIFICATION_EVENT_TIME_CHANGE" and "NOTIFICATION_EVENT_TZ_CHANGE" to
> be notified about time changes (see code below). This works fine until
> Suspend/Resume!
>
> If the board did a Suspend/Resume, I get following errors at bootup:> Notification Error : Cannot execute \\.\Notifications\NamedEvents\DSTTimeChange
> > Notification Error : Cannot execute \\.\Notifications\NamedEvents\TaskbarTimeChangeEvent
>
> Afterwards, a "NOTIFICATION_EVENT_TIME_CHANGE" event occurs.
>
> When I delete my persistent registry, the errors disappear until I do
> another Suspend/Resume.
>
> If I disable the RTC driver, no errors are visible at all!
>
> Does anybody know why these errors happen or do I make something wrong
> inside my endless thread?

One thing that I did notice (which may not be a problem) is that you
are using the current time for the end Time in the Trigger. I believe
that Start Time and End time represent the Time window in which you
wish to wait for the Event. I would probably try to have StartTime =
Now and EndTime = <Some Time in the future, say 20 years>.

Also, why do you repeatedly call CeSetUserNotificationEx (with a
Sleep(200)) until it succeeds? Are you seeing the call fail?

Also, am I correct in assuming that you are trying to write an RTC
Driver in the Kernel / User Mode instead of within the OAL? The OAL
itself has RTC functions that will be called when the system is
setting a Time Notification Alarm, or when the System Time is in fact
changing. It may be simpler (if possible in your situation) to simply
place your RTC Driver in the OAL itself.

Regards,
Brad.

Re: TimeChange Notification Error at bootup by beat

beat
Thu Jun 05 01:06:28 PDT 2008

> One thing that I did notice (which may not be a problem) is that you
> are using the current time for the end Time in the Trigger. I believe
> that Start Time and End time represent the Time window in which you
> wish to wait for the Event. I would probably try to have StartTime =
> Now and EndTime = <Some Time in the future, say 20 years>.
I added stEndTime.wYear += 20 but it doesn't show any other behavior!

> Also, why do you repeatedly call CeSetUserNotificationEx (with a
> Sleep(200)) until it succeeds? Are you seeing the call fail?
You're right, there is no retry! It always succeeds the first time.

> Also, am I correct in assuming that you are trying to write an RTC
> Driver in the Kernel / User Mode instead of within the OAL?
I am using another RTC from the CPU (volatile) which is much more
faster than the external I2C RTC.
The RTC I am talking about is just for reading during boot up, and
write back when changes happen.

The errors still appear during bootup! Do you have any idea why they
only appear if the board was once within a suspend/resume?!

thanks

Re: TimeChange Notification Error at bootup by Bradley

Bradley
Thu Jun 05 10:33:29 PDT 2008

On Jun 5, 1:06 am, beat <beat.m...@gmail.com> wrote:
> The errors still appear during bootup! Do you have any idea why they
> only appear if the board was once within a suspend/resume?!

I think that your next step is probably going to involve a Debug build
and Kitl. It seems that for some reason, loading in your Notification
Events, or something that you are doing with the time are causing
other Notification Events to actually fail. You're going to need to
try and breakpoint from within the Notification Code. This code may
be found in WINCE600\PUBLIC\COMMON\OAK\NOTIFY\notifext.cxx (look for
PutCantExecError) by searching for IDS_ERROR_CANTEXECUTE.

You can see how the Notification API Calls work by looking at PRIVATE
\WINCEOS\COREOS\core\tnotify\tnotify.cpp

You'll likely get a lot of valuable information just by simply loading
a debug build with the appropriate zones loaded, so you may want to
simply try that first.

One thing that I would try is to look at the Notification Events that
are in the system (its pretty easy to write an application to list the
events and their settings.) Take a look at what it looks like when
your driver is loaded and when your driver isn't loaded.

When you update the Time on boot, do you go through the OS Calls or do
you directly talk to the RTC in the CPU itself? I am assuming that
you do this on load from the External RTC Device Driver?

Hope this helps,

Re: TimeChange Notification Error at bootup by Steve

Steve
Thu Jun 05 14:39:57 PDT 2008

Where is your thread running? OAL? Driver?

I did the same thing on a PXA 270 platform. Use the internal RTC clock for
"normal use", and use an external I2C RTC to hold the master time.

During startup, the OAL initializes the internal RTC from the external RTC
chip. At that point in time, there is nothing else to synchronize with.

After startup, the OAL never writes to the external I2C RTC chip. The
battery
driver takes care of that. It is notified of RTC changes. When it receives
the change notification, it just writes the new time to the external RTC
chip.

By having the I2C code in a driver, I was able to sync with other parts of
the system (mainly for I2C controller access)



Re: TimeChange Notification Error at bootup by beat

beat
Fri Jun 06 01:52:59 PDT 2008

My RTC driver just
- initializes the internal RTC from the external I2C RTC chip during
startup (the same like Steve!) by using SetLocalTime()
- and starts the thread, waiting for the events
NOTIFICATION_EVENT_TIME_CHANGE and NOTIFICATION_EVENT_TZ_CHANGE.
About the internal RTC I don't care!

Generally, my implementation works and changing the time will wake up
my thread correctly.

Steve, you are using the MDD battery driver for setting your RTC?



Re: TimeChange Notification Error at bootup by beat

beat
Tue Jun 10 00:23:42 PDT 2008

My problem is in running SetLocalTime() in RTC_Init() (so early)!!

If I wait until WaitForAPIReady(SH_SHELL, INFINITE), the NotifyErrors
disappear.

Does anybody know
- how I can set the time from my external-RTC driver during boot up
(before the explorer is started)?!
- when I can set the time as soonest as possible?

Re: TimeChange Notification Error at bootup by Bruce

Bruce
Tue Jun 10 06:07:43 PDT 2008

You could create a KernelIoControl call that wrappers your functions for
setting the internal RTC.

--
Bruce Eitman (eMVP)
Senior Engineer
Bruce.Eitman AT EuroTech DOT com
My BLOG http://geekswithblogs.net/bruceeitman

EuroTech Inc.
www.EuroTech.com

"beat" <beat.morf@gmail.com> wrote in message
news:9b73c12d-16c6-4b05-978b-9bf56ce85432@27g2000hsf.googlegroups.com...
> My problem is in running SetLocalTime() in RTC_Init() (so early)!!
>
> If I wait until WaitForAPIReady(SH_SHELL, INFINITE), the NotifyErrors
> disappear.
>
> Does anybody know
> - how I can set the time from my external-RTC driver during boot up
> (before the explorer is started)?!
> - when I can set the time as soonest as possible?



Re: TimeChange Notification Error at bootup by Tom

Tom
Tue Jun 10 07:58:17 PDT 2008

Does your BSP implement the OEMGetRealTime function? This is the
usual place for setting the system time from an external RTC during
boot.

http://msdn.microsoft.com/en-us/library/aa914848.aspx

Tom

On Tue, 10 Jun 2008 00:23:42 -0700 (PDT), beat <beat.morf@gmail.com>
wrote:

>My problem is in running SetLocalTime() in RTC_Init() (so early)!!
>
>If I wait until WaitForAPIReady(SH_SHELL, INFINITE), the NotifyErrors
>disappear.
>
>Does anybody know
>- how I can set the time from my external-RTC driver during boot up
>(before the explorer is started)?!
>- when I can set the time as soonest as possible?

Re: TimeChange Notification Error at bootup by beat

beat
Thu Jun 12 06:15:46 PDT 2008

Yes, OEMGetRealTime is implemented using the RTC from my processor.

I will not mix the code of my internal RTC (fast) that is implemented
over the OEMGetRealTime,... functions and my external RTC (I2C, means
slow) that is implemented with a separate driver, running in kernel
mode. My external RTC driver only needs to overwrite the SystemTime
during bootup and write back any time changes!

If I wait with SetSystemTime() until the explorer is running
(WaitForAPIReady(SH_SHELL, INFINITE)), I have no errors during bootup.
This looks fine, as well that the time is set late!

Re: TimeChange Notification Error at bootup by Tom

Tom
Thu Jun 12 09:30:01 PDT 2008

Why not use a flag in your OAL to indicate to OEMGetRealTime whether
or not your internal RTC has been initialized from the external RTC.
If not, read the external RTC and set the internal RTC, otherwise,
just read the internal RTC?

Tom

On Thu, 12 Jun 2008 06:15:46 -0700 (PDT), beat <beat.morf@gmail.com>
wrote:

>Yes, OEMGetRealTime is implemented using the RTC from my processor.
>
>I will not mix the code of my internal RTC (fast) that is implemented
>over the OEMGetRealTime,... functions and my external RTC (I2C, means
>slow) that is implemented with a separate driver, running in kernel
>mode. My external RTC driver only needs to overwrite the SystemTime
>during bootup and write back any time changes!
>
>If I wait with SetSystemTime() until the explorer is running
>(WaitForAPIReady(SH_SHELL, INFINITE)), I have no errors during bootup.
>This looks fine, as well that the time is set late!

Re: TimeChange Notification Error at bootup by Valter

Valter
Thu Jun 12 09:38:38 PDT 2008

"Tom Gensel (eMVP)" <tgensel.at.ptgsystems.dot.com> wrote in
news:bjj2545oqc503fs2fg7rhpsvd4r42c942m@4ax.com:

> Why not use a flag in your OAL to indicate to OEMGetRealTime
> whether or not your internal RTC has been initialized from the
> external RTC. If not, read the external RTC and set the internal
> RTC, otherwise, just read the internal RTC?

Or you can initialize the internal RTC inside OEMInit and let
OEMGetRealTime return always the internal RTC value.
The only exception is when the internal RTC is not so reliable and you
have a device that is always on. In this case you may interact with
the external RTC every hour or every day, to resync it with the
internal RTC. This may be done inside OEMGetRealTime or by an external
driver (that may wait for a long time after startup since the clocks
have been synchronized by OEMInit).

--
Valter Minute
www.fortechembeddedlabs.it
Training, support and development for Windows CE
(the reply address of this message is invalid)