Thursday, July 11, 2013

WaitForMultipleObjects

Please take care while using WaitForMultipleObjects

Today I was trying one of the example given by Microsoft on Windows CE. 

Basically the code is written for Windows Desktop and the code can be seen at the following URL: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686927(v=vs.85).aspx.

In the above given example the main function is creating two threads and waiting for the threads to close using WaitForMultipleObjects API. 

As this example is for desktop in WaitForMultipleObjects API the third parameter fWaitAll is set to TRUE.

I made some modifications such as printf is changed to RETAILMSG and on entry and exit of main, thread function we have enable more RETAIL Messages.

After running the application we are not seeing any messages that are being printed from the worker threads. All we see is the main function entry and exit messages.

After debugging, we came to know that fWaitAll in WaitForMultipleObjects API shall be set to FALSE in Windows CE 6.0.

Hope This Helps.

Thursday, March 28, 2013

Forcing a device driver to a power state for a power manager state

Many of you might already know that in Windows CE 6.0 one can set the device power state to a required power state other than default power state for a particular power manager state.

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\State\useridle] 
"Default"=dword:1
The above entry will keep all the devices in D1 state while entering into User Idle power manager state 


In Windows CE 6.0 we have following default power manager states

ON, UserIdle, SystemIdle, Resuming, Suspend, Coldreboot and reboot.

Let's say one would like to set a stream interface driver XYZ to D4 while entering into D4 state.

Hence the below registry key has to be specified in platform.reg

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Power\State\useridle] 
"xyz1:"=dword:4



Please note that in PM the case for the entry is sensitive. Hence if you set XYZ1 inplace of xyz1 then it will not work. 

Thank You for reading the post.



Friday, January 18, 2013

How to flash images onto production hardware

This article discusses about the ways to flash binaries in production stage to hardware.

As of now I can think of three possibilities for updating binaries to Flash present on Hardware. 

SD Boot
  • Copy all the images to SD Card .
  • Implement boot-loader in such a way that whenever the system boots from SD Card to update the boot-loader images and Kernel image to Flash present on Hardware.
To have this feature the hardware shall support SD Card boot and the boot-loader shall support some file system handling code.

In this method at production stage the only requirement is one SD Card with production images copied onto it.

Using Platform Builder 

  • Flash the boot-loader images onto hardware using JTAG
  • Disconnect the JTAG and boot from Flash. 
  • Connect the hardware using ethernet cable or USB cable.
  • Download the image from Platform builder onto target and flash it.
The drawback of this is at production stage Host PC shall be supplied with Platform Builder Installed and expensive JTAG's might need to be purchased. More over the flashing procedure is a two step procedure.

Using CEDownloader
  • Flash the boot-loader images onto hardware using JTAG
  • Disconnect the JTAG and boot from Flash. 
  • Connect the hardware using ethernet cable or USB cable.
  • Instead of PB the user can install CEDownloader utility (Search for it in Google / Sourceforge.net)
In this method installation of PB onto production Host PC can be avoided.


Happy Flashing.

Monday, November 26, 2012

Using #error macro in Compact 7 BSP Development

This post talks about checking whether a variable is CDEFINED or not using #error macro

We have a file test.c under the path _TARGETPLATROOT\SRC\DRIVERS\test\

When we build test folder it generates test.dll which is present in NK.bin and also the registry entries which corresponds to this DLL are also available in NK.bin. 

We have defined some macros as given below in test.c file

#ifdef BSP_TEST
#define SHARED_GPIO GPIO_81
#else
#define SHARED_GPIO GPIO_51
#endif

BSP_TEST was set in <Platform>.bat file and corresponding CDEFINE was done in sources.cmn

Issue: When we load the driver the interface which is controlled test.dll found not working. 

The following debug steps are identified to know what is causing the issue

  • Check if the driver is present or not in Active Registry
  • Enable messages in all the functions of the driver (Test.DLL) if the driver is unloading
  • Print SHARED_GPIO macro value using RETAILMSG

Tools used for the identified steps

  • For the first one we have used Remote Tools from Compact 7 and searched for the test.dll in HKLM\Active path
  • Used RETAIL Messages in all the functions
  • For the third I had come to know a useful macro that is #error
    • Use the below code to check BSP_TEST is enabled or not
    • Include the following lines of code in test.c 
                      #ifndef BSP_TEST 
                            #error "BSP_TEST is not enabled" 
                      #endif
    • With this if by chance the driver is not able to see the CDEFINE for BSP_TEST your build fails and you need not check by booting the system with the NK.bin
  • using #error while preliminary testing of the BSP will save significant amount of your time


Monday, November 5, 2012

Batch File To Clean Windows CE 6.0 BSP

Hi,

This post talks about cleaning the Windows CE 6.0 BSP.

Before shipping the BSP to the customer it is good to remove unwanted files from it. 

What I use to do is search for these files for each item and remove them. 

The below list shows the unwanted files
  • lib and target folders that are created under _TARGETPLATROOT
  • build.* files that are created when BSP is compiled 
  • *.bak files that might be created from WinMerge Tool
  • Intermediate folders such as OBJ
  • Sub-Version files such as .svn folders
The below windows batch file is written for cleaning the BSP
Note: Please take a backup of your BSP before running this batch file


Steps to be followed for cleaning the BSP


  • Copy the below contents to a notepad
@echo My first batch file
@echo Deleting *.bif files
del /s /f *.bif
@echo Deleting build.*
del /s /f build.*
@echo Deleting *.bak files
del /p /s /f *.bak
@echo Deleting *.user files
del /s /f *.user
@echo Deleting lib folder
rd /s/q lib
@echo Deleting lib folder
rd /s/q target
@echo Deleting obj folders
for /d /r . %%d in (obj) do @if exist "%%d" rd /s/q "%%d"
@echo Deleting .svn folders
for /d /r . %%d in (.svn) do @if exist "%%d" rd /s/q "%%d"

  • Save this text file as CleanBSP.bat in the following folder _WINCEROOT\Platform\_YOUR_BSPNAME_
  • Open a windows COMMAND Prompt and navigate to the following path _WINCEROOT\Platform\_YOUR_BSPNAME_
  • Now run CleanBSP.bat

Note: Please refer the following URL to refer how to eliminate all the above steps http://social.msdn.microsoft.com/Forums/en-US/winembplatdev/thread/743382e1-2ee1-4df1-9f01-524ee8ea5a80



Thursday, October 25, 2012

Accessing Memory Mapped Registers from Windows Compact-7 Eboot

This post covers accessing Memory Mapped Register from Windows Compact 7 BSP

When I was debugging one of the peripheral in Eboot, we are not sure about the sequence of initialization as the documentation on the hardware is little and we also had very little support from the vendor.

Given this scenario if we modify a single bit in a register do the following for each iteration

  • Build the EBoot Module
  • Insert SD Card into Card Reader
  • Copy binaries to SD Card 
  • Safe Remove from PC
  • Reinsert into target Micro-SD Slot
  • Wait for Eboot to boot
  • Check the Register Values by dumping them
This process has eaten out most of our time.

Then we thought of having a Eboot menu in which we can read and write to Memory Mapped Registers. 

For this we have followed below steps
  1. Implement RegRead function
  2. Implement RegWrite funciton
  3. Implement OALStringToHex
  4. Create a menu for the Register Utility
  5. Add the Utility to Eboot Main Menu
The code that I wrote is directly given below for reference

For RegRead

VOID  RegRead
(
OAL_BLMENU_ITEM *pMenu
)
{
    WCHAR  szVal[9];
UINT32 u32RegAddr;

    OALLog(L"\r\n Enter Register Address: ");

    if (OALBLMenuReadLine(szVal, dimof(szVal)) == 0)
        {
        goto cleanUp;
        }

    u32RegAddr = OALStringToHex(szVal);

OALMSG (1,(L"\r\n\tReg Addr:0x%08x Val:0x%08x\r\n",
u32RegAddr, *((DWORD *)u32RegAddr)));
cleanUp:
    return;
}

For RegWrite

For this function we need to take two inputs. The first one is Register Address and the second input  is Register Value. The source code for the same is given below.


VOID  RegWrite
(
OAL_BLMENU_ITEM *pMenu
)
{
    WCHAR  szVal[9];
UINT32 u32RegAddr;
UINT32 u32RegVal;

    OALLog(L"\r\n Enter Register Address: ");

    if (OALBLMenuReadLine(szVal, dimof(szVal)) == 0)
        {
        goto cleanUp;
        }

    u32RegAddr = OALStringToHex(szVal);

    OALLog(L"\r\n Enter Register Value: ");

    if (OALBLMenuReadLine(szVal, dimof(szVal)) == 0)
        {
        goto cleanUp;
        }

    u32RegVal = OALStringToHex(szVal);

OALMSG (1,(L"\r\n\tWriting to Register Addr:0x%08x Val:0x%08x\r\n",
u32RegAddr, u32RegVal));
*((DWORD *)u32RegAddr) = u32RegVal;

cleanUp:
    return;
}

OALStringtoHex

The String to hex conversion function has to convert string to hex and it is left for the readers to write themselves.


Creating Menu for Register Utility


static OAL_BLMENU_ITEM  g_menuRegisterUtilities[] = {
    {
        L'1', L"Write Reg", RegWrite,
        NULL, NULL, NULL
    }, {
        L'2', L"Read Reg", RegRead,
        NULL, NULL, NULL
    }, {
        L'0', L"Exit and Continue", NULL,
        NULL, NULL, NULL
    }, {
        0, NULL, NULL,
        NULL, NULL, NULL
    }
};


Adding Register Utility Menu to Main Menu

Please add below lines before Exit and Continue of the Eboot Main Menu


    }, {
L'R', L"Register Utility Menu", OALBLMenuShow,
        L"Register Utility Menu", &g_menuRegisterUtilities, NULL


Note: Please do remember to remove this option while shipping the products.

Thank You for reading the post.

Careful with watchdog timer


OS: Windows CE 6.0 R3
Platform: OMAP3530 EVM

I was debugging one of the driver present in OMAP3530 BSP provided by some vendor some time ago. So, the driver is compiled with COMPILE_DEBUG option so that I can keep breakpoints and see what are the issues with the driver. As soon as the control hits break point I was looking at the variables in watch window. All of a sudden the processor starts rebooting. After two days at last when  we are looking at the catalog items we observed that Watch Dog Catalog item has been selected from BSP.

Just make a note that we have to disable Watch Dog Timer when the software needs debugging with breakpoints.

Happy Debugging.