Handling Real Time Tasks in Windows CE

Published on November 14, 2009

There are certain use cases – we may have to handle the non-standard custom interface to communicate between the processor and the hardware. An example is controlling the brightness of an LCD. The brightness controller is interfaced with the processor in a single GPIO pin. Communication will happen by just toggling the GPIO at a constant rate through software driver.

Since Windows CE is a multi-threading OS, task switching will happen between multiple threads. This task switching may prevent your driver to maintain the constant rate of GPIO toggling. This leads to malfunction.

How to manage this malfunction?

Windows CE supports real time task handling and this can be achieved by assigning the thread priority to high. If we need to have a real time task in Windows CE, then the thread priority has to be between 0 and 96. The function CeSetThreadPriority () is used to set the required thread priority.

Recently, we had to handle one such use case. We were interfacing a new LCD to our Regulus platform and we were developing the driver for LCD brightness control. Whenever we increase or decrease the brightness, we increased the thread priority of the function that was performing the control operation, to the highest and save the previous priority to restore back after finishing the task in the driver, but still the task switching was happening because of the existence of same  higher priority threads or the time slice got over.  Since  the task was getting switched, when the user controls the brightness from the control panel, there is a delay in the effect taking place making it very odd.   So we have to avoid the task switching and make the driver thread to complete the operation without interruptions.

Windows CE provides one more API to control the thread quantum.  CeSetThreadQuantum() is the API that will control the thread running time. Passing zero to this function will run the thread completely without interruption.  . In this case the driver task was completed without interruption.  After completion of  the task, the thread priority and the quantum was set to previous values. This allows the other processes to execute normally.

NOTE: This may not work out to generate higher clock speed for some device through software.

Recently Published