Wednesday, 31 March 2010

Waiting for Thread / Process termination

When launching child processes from applications I used to use GetExitCodeProcess on the process handle, checking if STILL_ACTIVE is returned if it is still running.. heres the smart way!

After spawning a process or creating a worker thread the end of the process/thread can be waited on using WaitForSingleObject.

For instance for threads:

HANDLE hThread;
hThread = CreateThread(NULL,0,StartThread,&threadParam,0,NULL);
if(hThread1 != NULL)
{
WaitForSingleObject(hThread,INFINITE);
}


For processes:

PROCESS_INFORMATION pi={0};
if (CreateProcess (parameters, NULL, NULL, NULL, 0, 0, NULL, NULL, NULL, &pi))
{
WaitForSingleObject(pi.hProcess,INFINITE);
}


Thursday, 25 March 2010

Registry notifications to pass data between kernel to Apps/drivers

This breifly outlines the technique of passing information or state changes between the Windows CE Kernel/OAL and running drivers or applications. Passing events and notification from the kernel to a driver or application can be a little problematic, information flow the other way is straight forward using the kernel IOCtls.

One thing we can use here is the registry and the registry change notifications, for instance, both drivers/applications and kernel can change the registry, the kernel calls are all preceeded by NK, for instance:

Kernel:

NKRegOpenKeyEx
NKRegCreateKeyEx
NKRegSetValueEx

Driver/App:

RegOpenKeyEx
RegCreateKeyEx
RegSetValueEx

So why not set a state or value to pass in the registry, then wait on a particular registry key or value being changed using the following:


// create an event on a particular registry change
HANDLE event = CeFindFirstRegChange(....)

while(1)
{
// wait for notification of a change
WaitForSingleObject(event, INFINITE);

// clear event
CeFindNextRegChange(event);

}

Using this technique small, or large complex data can be shared very easily.

Thursday, 11 March 2010

Platform Builder: Remember to enable Multiprocessor Build

A support incident today reminded me that many people have forgotten to enable Multiprocessor Build support.

Enabling this will reduce the overall time it takes to build a platform workspace and it can be autodetected if enabled. But it seems the default is a manual selected number of processors=1


The selection is accessed via Tools / Options with the selection options as captured below:




Hope this is of help. Nigel

Thursday, 4 March 2010

Passing data using SetEvent on Windows CE

Martin in the office came across this one, normally SetEvent is used to signal between two threads or even processes that something has happened, a very light weight message queue shall we say, the major limitation is that you can't pass any parameters or data, so you end up having multiple events or storing the parameter information in the registry etc..but using this API you can associate a DWORD of information against an event that is signalled, pretty handy for simple signalling information between drivers and applications...

BOOL SetEventData(   HANDLE hEvent,   DWORD dwData );
For more information look at:

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

Enjoy!

Thursday, 4 February 2010

Southern Electronics Show

Just a quick note to invite you to come visit me on the ByteSnap Design stand at next week's Southern Electronics show in Farnborough from the 10 - 11 February 2010.

We will be demonstrating a number of customer projects including one from Rotalink, a designer and manufacturer of miniature motors, transmission and controls. This demo hooks up a DC motor speed detector to a mini-fairground wheel to show rotation and angle information via a display using our SnapUI product.

We'll also be showcasing other bespoke embedded electronics designs, embedded firmware and board design services. Come down to have a talk about services we can provide you from PCB design, through Firmware/BSP design to application development.

See you there!

Wednesday, 18 November 2009

CE6.0 CETK using ActiveSync failes on ARM devices

One of the guys here was having problems getting his CE6.0 CETK connected using activeSync to the target device. It sounded like something on the platform or his PC was just not setup correctly as the Platform Builder connection test just wouldn't work... very bizzare.

We're all running Vista 64 or Windows 7 64 so we were thinking it was a 64 bit issue (as there are other problems using these OS's for day to day development work but no it seems that the Platman folders on the PC that are used to store the target binaries for the CETK and remote tools is being checked incorrectly. If you look in this directory:

C:\Program Files\Common Files\Microsoft Shared\Windows CE Tools\Platman\target\wce600\

You'll see the ARMv4i directory but not an ARMv4 one like in previous versions of the Windows CE OS releases. It seems that the PC side application to push these target executables is looking (incorrectly) for an ARMV4 not ARMV4i directory.

To work around this simply copy the ARMV4i folder to create an ARMV4 directory and it should now all connect up.

Monday, 2 November 2009

Calling Kernel IO routines from Apps in CE 6.0

In Windows CE 6.0 applications are unable to call kernel IO many routines including new OEM functions in the kernel using KernelIoControl. There are a few exceptions to this rule, these are:

IOCTL_HAL_GET_CACHE_INFO
IOCTL_HAL_GET_DEVICE_INFO
IOCTL_HAL_GET_DEVICEID
IOCTL_HAL_GET_UUID
IOCTL_PROCESSOR_INFORMATION:

What is not commonly known is that this list can be extended by adding any new (or existing) IOCTLs to the following public library and sysgen (or copy this to your platform and update the links to build the OALIOCTL.DLL:

%_WINCEROOT%\PUBLIC\COMMON\OAK\OALIOCTL

If your CE5.0 platform had a lot of support for platform specific operations using KernelIOControl these can continue to be called from CE6.0 applications if you wish now!