Re: CeRunAppAtEvent and SetSystemTime question

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Jeff Cooper (jacooper_at_visi.com)
Date: 01/12/05

  • Next message: John Spaith [MS]: "Re: How to configure windows ce 4.2 device's web server"
    Date: Wed, 12 Jan 2005 14:37:54 -0600
    
    

    Paul,

    Thanks for the pointer. It turns out that notifications need to have
    shell around in addition to the Device Manager, so I needed spin on
    IsAPIReady( SH_SHELL ). After that, my named event was registered
    without error.

    Naturally, things still didn't work, my event never occured when the
    time was changed.

    I noticed when I was checking out the debug logs that a driver for
    Daylight Saving Time gets loaded after my driver and also registers for
    a NOTIFICATION_EVENT_TIME_CHANGE event.

    I'm guessing that only one named event can be set for a particular
    notification and since DST got there last, they get the notification.

    Does anyone know if that's a true statement?

    In my next attempt, I'll try waiting for DST to setup their named event
    and then use OpenEvent on it. My only concern is not knowing how the
    notifications are implmented. If two threads are waiting on the event,
    and the event occurs, will both threads get release (i.e. SetEvent()) or
    does only one get released (i.e. PulseEvent())?

    It's times like this that I love Open Source!

    thanks,
    Jeff

    Paul G. Tobey [eMVP] wrote:
    > Ah, yes, I see. I have the I2C stuff in the kernel, in my case. I suppose
    > that you could signal the driver from the kernel somehow. It seems to me
    > that we had a discussion on this topic some time ago and I think it was I2C
    > related too. Maybe there's something there that will point you in the right
    > direction.
    >
    > I think, without any documented reason, that the Device Manager is
    > responsible for notifications. You might try IsAPIReady( SH_DEVMGR_APIS ),
    > or any of the other potential candidates in kfuncs.h.
    >
    > I think that, other than not being able to call the APIs you're trying to
    > use so early, no, that's the basic code. You can look at the explorer shell
    > code, dst.cpp, in the PUBLIC branch of the Windows CE source, if you want to
    > compare what you're doing to the 'standard'.
    >
    > Paul T.
    >
    >
    > "Jeff Cooper" <jacooper@visi.com> wrote in message
    > news:41e45a2a$0$78851$a1866201@visi.com...
    >
    >>Paul,
    >>
    >>Thanks for the reply.
    >>
    >>I was thinking of modifying the OEMSetRealTime, but I had an issue that I
    >>wasn't sure how to handle: The RTC and I2C drivers are stream drivers so
    >>how do I make IOCTL calls from within the kernel. We don't want to put
    >>the bus driver (I2C) in the kernel so I was investigating other solutions
    >>when I found out about NOTIFICATION_EVENT_TIME_CHANGE.
    >>
    >>When is the notification system ready for use (i.e. what loads it)? Is
    >>there any routines that call be called to check the state of the
    >>notification system, perhaps similar to IsAPIReady()?
    >>
    >>Is there any reason that the approach I've taking with spinning a thread
    >>from the RTC_Init() routine in my driver won't work?
    >>
    >>thanks,
    >>Jeff Cooper
    >>
    >>Paul G. Tobey [eMVP] wrote:
    >>
    >>>Jeff,
    >>>
    >>>OEMSetRealTime() will be called whenever the time is changed. You don't
    >>>have to register for anything.
    >>>
    >>>Paul T.
    >>>
    >>>"Jeff Cooper" <jeffc@logicpd.com> wrote in message
    >>>news:ulibb2-t08.ln1@lpdlnx00.logicpd.com...
    >>>
    >>>
    >>>>Hello,
    >>>>
    >>>>I'm writing a device driver for a Real Time Clock (RTC) on a I2C bus
    >>>>attached to the processor. I'm using WinCE 4.2. I have my device
    >>>>drivers for the I2C and RTC working fine but I have one intergration
    >>>>issue that I'm getting stuck on:
    >>>>
    >>>>I need to have SetSystemTime() write the time to the RTC on the I2C bus
    >>>>anytime the system time is changed by the user. I'm trying to use the
    >>>>notification event, NOTIFICATION_EVENT_TIME_CHANGE, for this purpose.
    >>>>
    >>>>However, I'm having trouble registering the event and I'm hoping someone
    >>>>can help me. My basic approach is that in n my drivers RTC_Init()
    >>>>routine, I spin off a thread to keep the RTC in sync. Then the thread
    >>>>will create a named event and call CeRunAppAtEvent with that named event.
    >>>>Then whenever the SetSystemTime() call is made, my event should be
    >>>>triggered.
    >>>>
    >>>>The beginning of my thread looks like:
    >>>>
    >>>> // Create a named event for notification
    >>>> aheEvents[SYNC_TIME_CHANGE_EVENT] =
    >>>> CreateEvent( NULL // ignored
    >>>> ,FALSE // not manual reset
    >>>> ,FALSE // not signaled
    >>>> ,TEXT("RTCSync")
    >>>> );
    >>>> if( NULL == aheEvents[SYNC_TIME_CHANGE_EVENT] )
    >>>> {
    >>>> RTCMSG( ZONE_INIT | ZONE_ERROR | ZONE_WARN
    >>>> ,(TEXT("SyncRtcTime: Error: Couldn't create event
    >>>>(0x%08x) (line:%d)\r\n")
    >>>> ,GetLastError()
    >>>> ,__LINE__
    >>>> )
    >>>> );
    >>>> return( -1 );
    >>>> }
    >>>>
    >>>> // Make sure that the GDI is ready before we try to call
    >>>>CeRunAppAtEvent()
    >>>> // otherwise we'll get an exception
    >>>> while( !IsAPIReady( SH_GDI ) && !IsAPIReady( SH_WMGR) )
    >>>> ;
    >>>>
    >>>> // Set the notification to signal the named event
    >>>> bRet = CeRunAppAtEvent(
    >>>>TEXT("\\\\.\\Notifications\\NamedEvents\\RTCSync")
    >>>> ,NOTIFICATION_EVENT_TIME_CHANGE
    >>>> );
    >>>> if( !bRet )
    >>>> {
    >>>> RTCMSG( ZONE_INIT | ZONE_ERROR | ZONE_WARN
    >>>> ,(TEXT("SyncRtcTime: Error: Couldn't setup notification
    >>>>(0x%08x) (line:%d)\r\n")
    >>>> ,GetLastError()
    >>>> ,__LINE__
    >>>> )
    >>>> );
    >>>> CloseHandle( aheEvents[SYNC_TIME_CHANGE_EVENT] );
    >>>> return( -1 );
    >>>> }
    >>>>
    >>>>In theory I think this should work. However, I get the following error
    >>>>messages when the thread runs:
    >>>>
    >>>> 4294773052 PID:41b53526 TID:81b8423e 0x81b84000:
    >>>>NOTIFICATION::XCeRunAppAtEvent
    >>>> 4294773054 PID:41b53526 TID:81b8423e 0x81b84000: ERROR in
    >>>>NOTIFICATION::XCeRunAppAtEvent::Notification subsystem not yet
    >>>>initialized
    >>>> 4294773063 PID:1bca15e TID:81b8423e 0x81b84000: SyncRtcTime: Error:
    >>>>Couldn't setup
    >>>> notification (0x0000041d) (line:2620)
    >>>>
    >>>>So I think my problem is that I'm trying to call these functions before
    >>>>the notification system is running. I can't find any documentation on
    >>>>when it's ok to call these functions.
    >>>>
    >>>>Can anyone help me either with documentation on the notification system
    >>>>used in CE 4.2 or suggest another approach to solving my problem.
    >>>>
    >>>>thanks,
    >>>>Jeff Cooper
    >>>>jeffc at logicpd dot com
    >>>
    >>>
    >


  • Next message: John Spaith [MS]: "Re: How to configure windows ce 4.2 device's web server"

    Relevant Pages

    • Handling abnormal process termination in linux device drivers
      ... notification of when a process that is using my driver terminates? ... Create a kernel thread that blocks on a kernel construct such as a ...
      (comp.os.linux.development.system)
    • RE: Device driver load/unload notifications
      ... notification for every StreamDevice driver which is in the system. ... you'll get only the notification for your special device. ... if you use your own guid or the DEVCLASS_STREAM_GUID. ... When stream driver A is being loaded and unloaded, ...
      (microsoft.public.windowsce.platbuilder)
    • Re: [Fastboot] [RFC][PATCH] Add missing notifier before crashing
      ... the risk of hanging in between and reducing the reliability of dump operation. ... the kdump kernel and has decided to take a dump in case of a crash event. ... -Doing notification directly in the panic function would only cost a few CPU cycles. ...
      (Linux-Kernel)
    • Re: communication from a dd to an application
      ... >>Signals are good if you have no requisite data to pass along with the ... >>Creating a ioctl in your device driver that an application thread can ... >>of associated data with the event notification. ...
      (comp.os.linux.development.system)
    • Re: Kernel patches enabling better POSIX AIO (Was Re: [3/4] kevent: AIO, aio_sendfile)
      ... but only internal to the kernel implementation. ... Zach had suggested inferring THREAD_ID notification if the pid specified ... To implement lio_listio, one has to set up such an array, with the first iocb ...
      (Linux-Kernel)