<feed xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
    <title>Windows Embedded Annotations</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/Atom.aspx" />
    <subtitle type="html"> </subtitle>
    <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/Default.aspx</id>
    <author>
        <name>Luca Calligaris</name>
        <uri>http://geekswithblogs.net/WindowsEmbeddedAnnotations/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2010-11-04T06:25:00Z</updated>
    <entry>
        <title>Moving</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2010/11/04/moving.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2010/11/04/moving.aspx</id>
        <published>2010-11-04T06:25:00-12:00:00</published>
        <updated>2010-11-04T06:25:00Z</updated>
        <content type="html">&lt;p&gt;Dear readers (if any!): i decide to move my blog to WordPress @ &lt;a href="http://lcalligaris.wordpress.com/"&gt;http://lcalligaris.wordpress.com/&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/142592.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/142592.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/142592.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/142592.aspx</trackback:ping>
    </entry>
    <entry>
        <title>NNTP bridge for MS forums</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2010/05/20/nntp-bridge-for-ms-forums.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2010/05/20/nntp-bridge-for-ms-forums.aspx</id>
        <published>2010-05-20T04:33:22-12:00:00</published>
        <updated>2010-05-20T04:33:22Z</updated>
        <content type="html">&lt;p&gt;For those who wants to use their newsreader to interact with MS forums there's a new tool: the NNTP Bridge application serves as a channel that enables access for NNTP newsreaders to read and write content to Microsoft Forums. You can download the applcation and documentation from &lt;a href="http://connect.microsoft.com/MicrosoftForums"&gt;http://connect.microsoft.com/MicrosoftForums&lt;/a&gt; (registration required).&lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/139963.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/139963.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/139963.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/139963.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Learning Windows CE</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/12/24/learning-windows-ce.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/12/24/learning-windows-ce.aspx</id>
        <published>2009-12-24T01:42:21-12:00:00</published>
        <updated>2009-12-24T01:42:21Z</updated>
        <content type="html">&lt;p&gt;Maybe you didn't notice that &lt;a href="http://msdn.microsoft.com/en-us/windowsembedded/ce/default.aspx"&gt;Windows Embedded CE Developer Center&lt;/a&gt; web site has a &lt;em&gt;&lt;a href="http://msdn.microsoft.com/en-us/windowsembedded/ce/dd367860.aspx"&gt;Learn&lt;/a&gt;&lt;/em&gt; section: in this section you can find a lot of interesting content in various formats (video, text, slide presentations, MSDN links, etc.) about several Windows Embedded CE development areas, specifically:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;General Content&lt;/li&gt;
    &lt;li&gt;OS Design &amp;amp; Build&lt;/li&gt;
    &lt;li&gt;BSP &amp;amp; Other Hardware&lt;/li&gt;
    &lt;li&gt;Application Development&lt;/li&gt;
    &lt;li&gt;Communication &amp;amp; Connectivity&lt;/li&gt;
    &lt;li&gt;Silverlight for Windows Embedded&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For each area you can find &lt;em&gt;entry-level, intermediate&lt;/em&gt; and &lt;em&gt;advanced&lt;/em&gt; content.&lt;/p&gt;
&lt;p&gt;Some of the things you'll find aren't really new but the I think that having a lot of interesting information concentrated in a single site is valuable.  From the same site you can download the free guide to Windows Embedded CE Exam Preparation Kit written by MS and &lt;a href="http://www.adeneo-embedded.com"&gt;Adeneo&lt;/a&gt; and a free electronic copy of Windows Embedded CE 6.0 Fundamentals book&lt;strong&gt;,&lt;/strong&gt; by Stanislav Pavlov and Pavel Belevsky.&lt;/p&gt;
&lt;p&gt;Last but not least, another interesting site, in my opinion is the &lt;a href="http://channel9.msdn.com/wiki/cedeveloper/homepage/"&gt;Windows Embedded CE Developers Wiki&lt;/a&gt; , especially the &lt;a href="http://channel9.msdn.com/wiki/cedeveloper/windowscebsp/"&gt;BSP&lt;/a&gt; section.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/137203.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/137203.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/137203.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/137203.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Flash device driver in Windows Embedded CE 6.0</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/11/05/flash-device-driver-in-windows-embedded-ce-6.0.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/11/05/flash-device-driver-in-windows-embedded-ce-6.0.aspx</id>
        <published>2009-11-05T09:35:05-12:00:00</published>
        <updated>2009-11-05T09:37:11Z</updated>
        <content type="html">&lt;p&gt;&lt;font face="Arial"&gt;In previous version of Windows CE the flash drivers followed a model based on FAL (Flash Abstraction Layer): the developer had to write the FMD (Flash Media Driver) layer and link it with fal.lib to create a DLL which exposed a block (DSK_Xxx) stream interface. Starting with Windows Embedded CE 6.0 R2 MS introduces a new model based on a MDD/PDD layer structure. The MDD part is implemented in a DLL (flashmdd.dll) exposing a block (DSK_Xxx) stream interface which handles some specific IOCTL_FLASH_XXX codes; the DLL calls the PDD DLL which the developer has to write according to the interface specified by MS; this interface is similar to the MDD (a block stream interface driver) which handles some specific IOCTL_FLASH_PDD_XXX codes. The FAL/FMD model is still supported.&lt;br /&gt;
In addition, in Windows Embedded CE 6.0, you have a new partion driver (flashpart.dll) specifically designed for flash block devices. This partition driver has to be used with the MDD DLL since it's aware of the specific IOCTL_FLASH_XXX codes that the MDD DLL implements.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;MS provides a library (flashpddwrapper.lib) which gives the developer the opportunity to reuse the FMD code in the new architecture: this library exposes the PDD interface to the MDD DLL but internally calls the old FMD entry point.  &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Notice that the shared source for &lt;font face="Arial"&gt;Windows Embedded CE 6.0 includes the FAL library source code which was not available before: the FAL is implemented in C++  while in previous versions it was implemented in C. Other source code which is available (in the public part of %_WINCEROOT%) includes flashpddwrapper and some specific FMD. Some of these FMD (for example the sample RAM flash driver) are linked in two different ways to create a flash driver which uses the FAL (for example &lt;font face="Arial"&gt;ramfmd) &lt;/font&gt;and another one which benefits from the new model (flashpdd_ram). &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Flash driver architecture before Windows Embedded CE 6.0 R2&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;
&lt;table border="1" cellspacing="1" summary="" cellpadding="1" width="200"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;font face="Arial"&gt;FAL.LIB + FMD.LIB (developer)&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font face="Arial"&gt;Flash driver architecture after Windows Embedded CE 6.0 R2&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;font face="Arial"&gt;MDD/PDD&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;font face="Arial"&gt;
&lt;table border="1" cellspacing="1" summary="" cellpadding="1" width="200"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;&lt;font face="Arial"&gt;FLASHMDD.DLL&lt;/font&gt;&lt;/p&gt;
            &lt;p&gt;FLASHPDD.DLL (developer)&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;/font&gt;&lt;font face="Arial"&gt;MDD/PDD wrapping the FMD&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;
&lt;table border="1" cellspacing="1" summary="" cellpadding="1" width="200"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;
            &lt;p&gt;&lt;font face="Arial"&gt;&lt;font face="Arial"&gt;FLASHMDD.DLL&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
            &lt;p&gt;FLASHPDD.DLL (FLASHPDDWRAPPER.LIB + FMD.LIB (developer))&lt;/p&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;font face="Arial"&gt;FAL/FMD  &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;
&lt;table border="1" cellspacing="1" summary="" cellpadding="1" width="200"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;font face="Arial"&gt;FAL.LIB + FMD.LIB (developer)&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;For additional info see &lt;a href="http://msdn.microsoft.com/en-us/library/bb821532.aspx"&gt;MSDN documentation&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/136017.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/136017.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/136017.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/136017.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Get last error and set it meaningfully</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/11/04/get-last-error-and-set-it-meaningfully.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/11/04/get-last-error-and-set-it-meaningfully.aspx</id>
        <published>2009-11-04T10:41:02-12:00:00</published>
        <updated>2009-11-04T10:42:39Z</updated>
        <content type="html">&lt;p&gt;&lt;font face="Arial"&gt;Very often I read posts in the newsgroups like:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;em&gt;I call function Foo(dwParam) and it returns FALSE. What's wrong?&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;If I cannot tell it immediately -for example because the dwParam is clearly wrong - my standard answer is:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;em&gt;Have you called GetLastError()? Which error value it returns?&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;GetLastError (if the call that fails actually sets an error and the error is meaningful) can be very helpful to detect why the call is failing. If you do not understand exactly what the code means and you have the code you may figure out where and why the failing function is calling SetLastError with that specific code.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Take in account that the error value you get is per thread -the kernel structure modeling the thread has a DWORD member named &lt;em&gt;dwLastError&lt;/em&gt;: Since GetLastError retrieves the latest error this means that, if the failing function you are investigating does not uses SetLastError(), the error you get is related to a previous call to another function so can be misleading (or it can be 0 since a function you call before succeded and set the error to &lt;em&gt;ERROR_SUCCESS&lt;/em&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;The error codes are defined in the documentation but, for a more complete list and meaning you can check  &lt;/font&gt;&lt;font face="Arial"&gt;&lt;em&gt;%_WINCEROOT%\PUBLIC\COMMON\SDK\INC\winerror.h.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;When you write your own code is a good practice to use SetLastError(dwError) with a meaningful error value; if you do not find an adapted system value for the error you can define your own: an error code which has bit 29 set  is guaranteed not to conflict with any system error code.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;The error codes are DWORD's which should be formatted as follows - according to winerror.h:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Bits 31 &amp;amp; 30 are the severity code where&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;          00 - Success&lt;br /&gt;
          01 - Informational&lt;br /&gt;
          10 - Warning&lt;br /&gt;
          11 - Error&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Bit 29 is the &lt;/font&gt;&lt;font face="Arial"&gt;Customer code flag&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Bit 28 is a reserved bit&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Bits 28-16 are the facility code,  which -more or less- identifies the subsytem generating the error, Internet, Storage, etc&lt;/p&gt;
&lt;p&gt;Bits 15-0 are the actual error code&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font face="Arial"&gt;Take in account that the severity code is almost not used in winerror.h codes: for example ERROR_INVALID_PARAMETER which is undoubtly an error (neither a warning nor an information) has a value of 0x57L, not 0xC0000057L. &lt;/font&gt;
&lt;p&gt;&lt;font face="Arial"&gt;On the contrary the severity bits are used in Windows NT-based OS NTSTATUS error codes: for example STATUS_UNSUCCESSFUL which is the more generic error that you will have has a value of 0xC0000001L. &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;By the way, most DDK functions returns an NTSTATUS code so there's no need to call a function like GetLastError to have more information about the error itself.&lt;/font&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/135989.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/135989.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/135989.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/135989.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Windows Embedded CE 6.0 R3 released</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/09/30/windows-embedded-ce-6.0-r3-released.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/09/30/windows-embedded-ce-6.0-r3-released.aspx</id>
        <published>2009-09-30T02:15:50-12:00:00</published>
        <updated>2009-09-30T09:45:53Z</updated>
        <content type="html">&lt;p&gt;&lt;font size="3"&gt;Windows Embedded CE 6.0 R3 is finally available for download &lt;/font&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=bc247d88-ddb6-4d4a-a595-8eee3556fe46"&gt;&lt;font size="3"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;. This intermediate release (while we wait for Windows Embedded Compact in 2010) brings several features, the most important of which is probably &lt;/font&gt;&lt;a href="http://www.microsoft.com/windowsembedded/en-us/products/windowsce/silverlightforwe.mspx"&gt;&lt;font size="3"&gt;Silverlight for Windows Embedded&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;. &lt;/font&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=E82DB5E2-7106-419E-80B0-65CCE89F06BB&amp;amp;displaylang=en"&gt;&lt;font size="3"&gt;Download&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; a free trial of Expression Blend to create new user interface experience for your embedded device!&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;For more info on the features included in CE 6.0 R3 check the following links:&lt;/font&gt;&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;a href="http://geekswithblogs.net/BruceEitman/archive/2009/09/23/windows-ce-soon-to-be-available--6.0-r3.aspx"&gt;&lt;font size="3"&gt;Bruce Eitman's blog&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; &lt;/font&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://blogs.msdn.com/obloch/archive/2009/09/23/windows-embedded-ce-6-0-r3-release.aspx"&gt;&lt;font size="3"&gt;Olivier Bloch's blog&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; &lt;/font&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://download.microsoft.com/download/F/5/2/F5296720-250A-4055-991C-0CEA5DE11436/Windows%20Embedded%20CE%206.0%20R3%20Release%20Notes.htm"&gt;&lt;font size="3"&gt;Windows Embedded CE 6.0 R3 release notes&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; &lt;/font&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;font size="3"&gt;Note that Office and PDF viewers for Windows Embedded CE 6.0 are available as a separate download &lt;/font&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=d2fd14eb-7d5c-428b-951c-343f910047c1"&gt;&lt;font size="3"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; while Mobile QQ Messenger Client can be downloaded &lt;/font&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;amp;FamilyID=527042f7-bb5b-4831-a6ad-5081808824ec"&gt;&lt;font size="3"&gt;here&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt; (both the packages are from 3rd party providers).&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="3"&gt;CE 6.0 R3 includes the Adobe Flash Lite Plug-In for IE browser: if you are interested in developing Flash applications you can find a lot of info and resources from &lt;/font&gt;&lt;a href="http://livedocs.adobe.com/flashlite/3.0/docs/"&gt;&lt;font size="3"&gt;Adobe site&lt;/font&gt;&lt;/a&gt;&lt;font size="3"&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/135175.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/135175.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/135175.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/135175.aspx</trackback:ping>
    </entry>
    <entry>
        <title>A curious issue with PCI bus driver &amp; hive  based registry</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/09/09/a-curious-issue-with-pci-bus-driver--hive.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/09/09/a-curious-issue-with-pci-bus-driver--hive.aspx</id>
        <published>2009-09-09T08:35:47-12:00:00</published>
        <updated>2009-09-09T08:35:47Z</updated>
        <content type="html">&lt;font face="Arial"&gt;
&lt;p&gt;Recently we faced a strange problem on one of our x86 systems: after some successfull boots the system was unable to start the OS anymore but deleting the 'Documents and Settings' folder on the storage device (we included the hive based registry in the OS) the system behave normally.&lt;/p&gt;
&lt;p&gt;After some investigation we found out that when the system was not booting correctly the USB OHCI driver was performing an endless loop waiting for the host controller to reset (thus preventing the device manager to load the other drivers - never&lt;br /&gt;
write an XXX_Init routine which can spin forever!). &lt;/p&gt;
&lt;p&gt;The code looks like:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;m_portBase-&amp;gt;HcCommandStatus.HCR = 1;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;while (m_portBase-&amp;gt;HcCommandStatus.HCR == 1)&lt;br /&gt;
   ;&lt;br /&gt;
&lt;/em&gt; &lt;br /&gt;
With the debugger we found out that all the memory area used to map the USB controller registers was 0xFF (!), thus the bit was never cleared. This looked very strange so we started looking at the system registry founding out that the BAR (Base Address Registry) of the USB host on the PCI bus was 0x80003000 while the device was actually mapped at 0xDA000 (both flat physical addresses).&lt;/p&gt;
&lt;p&gt;An additional information: our BIOS implements legacy USB support which means that the BIOS maps the USB host at 0x80003000 when it assigns the resources to the PCI bus. If the legacy USB support is enabled the BIOS maps the USB host at 0xDA000 (under the 1MB limit), configures it and tries to find possibly connected manageable USB devices (i.e. storage and keyboard). If such devices are not detected the controller is remapped back at 0x80003000 otherwise it remains at 0xDA000 (this allow the BIOS to boot the OS from a USB disk redirecting INT13 on the USB - but this is another story...).  &lt;/p&gt;
&lt;p&gt;After accusing one collegue of mine (he wrote the BIOS after all!) we realized that you could trigger the problem this way:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Connect the USB keyboard to the system, turn it on and boot a clean OS (no hives on the storage).&lt;/li&gt;
    &lt;li&gt;Turn off the system, disconnect the keyboard and turn the system on: the OS does not boot anymore.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Turn on the system (no USB keyboard) and boot a clean OS (no hives on the storage).&lt;/li&gt;
    &lt;li&gt;Turn off the system, connect the keyboard and turn the system on: the OS does not boot anymore.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Looking at the PCIBUS code the problem became clear: on a cold boot the bus driver enumerates the PCI devices and build the  &lt;em&gt;'Instance'&lt;/em&gt; keys based on the &lt;em&gt;'Template'&lt;/em&gt; keys. Under the &lt;em&gt;'Instance'&lt;/em&gt; key the bus driver saves relevant informations like the &lt;em&gt;SysIntr&lt;/em&gt; value and the BAR's (look &lt;a href="http://msdn.microsoft.com/en-us/library/aa929565.aspx"&gt;here&lt;/a&gt; for more information). &lt;/p&gt;
&lt;p&gt;The PCIBUS driver is quite smart so, in subsequent boots, it enumerates the PCI devices and analyze the &lt;em&gt;'Instance'&lt;/em&gt; keys (using the hive based registry they're already set up) first - this allow the bus driver not to load a driver for a device which is not present anymore. If it founds that there is already an &lt;em&gt;'Instance'&lt;/em&gt; key for a specific device (with matching PCI ID's and location in terms of bus/device/function) it says "Ha ha! Here it is, do not bother to recreate the 'Instance' key and all its values for this device, neither the BAR value".&lt;/p&gt;
&lt;p&gt;Do you see the problem? When you boot the first time with the USB keyboard connected the BIOS maps the USB host at 0xDA000 which is the address saved in the hive under the &lt;em&gt;'Instance'&lt;/em&gt; key. Some time later you will turn on the system without the keyboard, the BIOS will map the host at 0x80003000 but the USB host device driver will retrieve the wrong 0xDA000 BAR from the registry, thus accessing unused RAM instead of the controller registers.&lt;/p&gt;
&lt;p&gt;I cloned the PCIBUS and modified it so that it ignores the &lt;em&gt;'Instance'&lt;/em&gt; key for PCI USB hosts, deletes it and recreates it at every boot based on the &lt;em&gt;'Template' &lt;/em&gt;key. &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;   &lt;br /&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/134572.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/134572.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/134572.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/134572.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Windows Embedded CE 6.0 KITL in PQOAL</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/09/03/windows-embedded-ce-6.0-kitl-in-pqoal.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/09/03/windows-embedded-ce-6.0-kitl-in-pqoal.aspx</id>
        <published>2009-09-03T10:09:20-12:00:00</published>
        <updated>2009-09-03T10:11:54Z</updated>
        <content type="html">&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;In Windows Embedded CE 6.0, the kernel and OEM code are divided into the following three components:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;
&lt;ul type="disc"&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l2 level1 lfo1; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;oal.exe (nk.exe)&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;: Startup code and the OEM adaptation layer (OAL) implementation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l2 level1 lfo1; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;kernel.dll&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;: OAL-independent kernel implementation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l2 level1 lfo1; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;KITL.dll&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;: This contains the platform-specific Kernel Independent Transport Layer support.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-ALIGN: justify; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;In previous versions the OAL and the Kernel where linked together in one executable (kern.exe) which would possibly include KITL support (in this case the executable was kernkitl.exe).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;From Windows CE 5.0 Microsoft introduced the concept of &lt;a href="http://msdn.microsoft.com/en-us/library/aa915743.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;Production Quality OAL&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; : one of the benefits of this design is that you can take advantage from a set of libraries which can be shared among specific BSP’s.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;For example, if you look at &lt;em style="mso-bidi-font-style: normal"&gt;%_WINCEROOT%\PLATFORM\COMMON\SRC&lt;/em&gt; tree you can find a directory structure like the following:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul type="disc"&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l0 level1 lfo4; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;COMMON&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;: common code which is processor architecture independent.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l0 level1 lfo4; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;ARM, MIPS, SHX, X86&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;: code which depends on the specific processor architecture but not on the specific implementation.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l0 level1 lfo4; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;SOC&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;: code which depends on the specific processor&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-ALIGN: justify; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;With this structure the single BSP should contain only the code which is really specific for the specific board.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; mso-ansi-language: EN" lang="EN"&gt;The PQOAL architecture extends even to KITL: in this scenario KITL.dll is made up essentially by the following components:&lt;/span&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0cm" type="disc"&gt;
    &lt;li style="TEXT-ALIGN: justify; MARGIN-TOP: 3pt; MARGIN-BOTTOM: 3pt; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;BSP specific KITL code (built from &lt;em style="mso-bidi-font-style: normal"&gt;%_WINCEROOT%\PLATFORM\&amp;lt;BSP&amp;gt;\KITL&lt;/em&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; MARGIN-TOP: 3pt; MARGIN-BOTTOM: 3pt; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;KITL specific device code (built from &lt;em style="mso-bidi-font-style: normal"&gt;%_WINCEROOT%\PLATFORM\&amp;lt;BSP&amp;gt;\SRC\COMMON\ETHDBG&lt;/em&gt;) &lt;em style="mso-bidi-font-style: normal"&gt;(see NOTE 1)&lt;/em&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;Common OAL KITL library (&lt;em style="mso-bidi-font-style: normal"&gt;oal_kitl.lib&lt;/em&gt;, built from &lt;em style="mso-bidi-font-style: normal"&gt;%_WINCEROOT%\PLATFORM\COMMON\SRC\COMMON\KITL&lt;/em&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;KITL core library (&lt;em style="mso-bidi-font-style: normal"&gt;kitlcore.lib&lt;/em&gt;, built from &lt;em style="mso-bidi-font-style: normal"&gt;%_WINCEROOT%\PRIVATE\WINCEOS\COREOS\NK\KITL&lt;/em&gt;)&lt;/span&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-ALIGN: justify; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;/span&gt; &lt;img alt="" src="/images/geekswithblogs_net/WindowsEmbeddedAnnotations/KITL/Immagine.bmp" /&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;font size="4"&gt;Fig 1: KITL.DLL&lt;/font&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify; COLOR: black; mso-list: l1 level1 lfo2; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;1. &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OEMInit()&lt;/span&gt;&lt;/em&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;This function, called by the kernel, invokes &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;KITLIoctl (IOCTL_KITL_STARTUP, NULL, 0, NULL, 0, NULL)&lt;/span&gt;&lt;/em&gt; which simply calls &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OEMKitlStartup()&lt;/span&gt;&lt;/em&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;2. &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OEMKitlStartup()&lt;/span&gt;&lt;/em&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;The function sets up:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul type="disc"&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l3 level1 lfo3; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;KITL device name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l3 level1 lfo3; tab-stops: list 36.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa917780.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;OAL_KITL_ARGS&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/em&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt; structure: retrieved from data – normally called &lt;em style="mso-bidi-font-style: normal"&gt;BSP_ARGS (see NOTE 1) &lt;/em&gt;–&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;setup by the boot loader since the KITL device is normally the same used by the boot loader to download the OS image, or hardcoded in the OAL. The structure contains:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;
    &lt;ul type="circle"&gt;
        &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l3 level2 lfo3; tab-stops: list 72.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;KITL &lt;a href="http://msdn.microsoft.com/en-us/library/aa913528.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;flags&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; describing some KITL functionalities (use interrupt or polling, etc.)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
        &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l3 level2 lfo3; tab-stops: list 72.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa910105.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;L&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;ocation&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; of the KITL hardware device in terms of its interface, bus number, and logical location&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
        &lt;li style="TEXT-ALIGN: justify; COLOR: black; mso-list: l3 level2 lfo3; tab-stops: list 72.0pt; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;Communication parameters: for a serial interface baud rate, parity, etc. ; for an ethernet interface MAC, IP, ...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/li&gt;
    &lt;/ul&gt;
    &lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-ALIGN: justify; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto" class="MsoNormal"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;These information are passed to &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OALKitlInit&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="FONT-STYLE: normal; FONT-FAMILY: Verdana; mso-bidi-font-style: italic"&gt; with a NULL terminated array of &lt;/span&gt;&lt;/em&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa915390.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;OAL_KITL_DEVICE&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/em&gt; structures – normally called &lt;em style="mso-bidi-font-style: normal"&gt;g_kitlDevices (see NOTE 1)&lt;/em&gt;; each element defines one of the available KITL devices on the platform; each device is represented by its type (&lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_TYPE_SERIAL&lt;/em&gt;, &lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_TYPE_ETH&lt;/em&gt;,...), physical location and by a structure which defines the function pointers to handle the KITL device according to the device type: for example if KITL device is an ethernet chip the structure holds a pointer to an &lt;em style="mso-bidi-font-style: normal"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/aa914857.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;OAL_KITL_ETH_DRIVER&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/em&gt; structure. These entry points are typically shared among KITL and the boot loader and are defined in &lt;em style="mso-bidi-font-style: normal"&gt;%_WINCEROOT%\PLATFORM\&amp;lt;BSP&amp;gt;\SRC\COMMON\ETHDBG.&lt;/em&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;3. &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OALKitlInit(LPCSTR deviceId, OAL_KITL_ARGS *pArgs, OAL_KITL_DEVICE *pDevice)&lt;/span&gt;&lt;/em&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;This function, if KITL flags include &lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_FLAGS_ENABLED&lt;/em&gt;, calls &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OALKitlFindDevice(DEVICE_LOCATION *pDevLoc, OAL_KITL_DEVICE *pDevice)&lt;/span&gt;&lt;/em&gt; which checks if the KITL device specified in &lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_ARGS&lt;/em&gt; is supported - i.e. it is present in the &lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_DEVICE&lt;/em&gt; array; if this is the case &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;KitlInit&lt;/span&gt;&lt;/em&gt; is called.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;4. &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;KitlInit(BOOL fStartKitl)&lt;/span&gt;&lt;/em&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;This function, if &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;fStartKitl&lt;/span&gt;&lt;/em&gt; is &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;TRUE&lt;/span&gt;&lt;/em&gt; (which means that &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OAL_KITL_FLAGS_PASSIVE&lt;/span&gt;&lt;/em&gt; flag is &lt;strong&gt;&lt;span style="FONT-FAMILY: Verdana; FONT-WEIGHT: normal; mso-bidi-font-weight: bold"&gt;not&lt;/span&gt;&lt;/strong&gt; set) calls &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;StartKitl(TRUE)&lt;/span&gt;&lt;/em&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;5. &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;StartKitl (BOOL fInit)&lt;/span&gt;&lt;/em&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;This function&lt;em style="mso-bidi-font-style: normal"&gt; &lt;/em&gt;calls &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OEMKitlInit &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="FONT-STYLE: normal; FONT-FAMILY: Verdana; mso-bidi-font-style: italic"&gt;to initialize a &lt;a href="http://msdn.microsoft.com/en-us/library/aa914512.aspx"&gt;&lt;em style="mso-bidi-font-style: normal"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;KITLTRANSPORT&lt;/span&gt;&lt;/span&gt;&lt;/em&gt;&lt;/a&gt; structure;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;6. &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OEMKitlInit(PKITLTRANSPORT pKitl)&lt;/span&gt;&lt;/em&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;This function calls the KITL device initialization function according to the KITL device type (for example &lt;em&gt;&lt;span style="FONT-FAMILY: Verdana"&gt;OALKitlEthInit&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="FONT-STYLE: normal; FONT-FAMILY: Verdana; mso-bidi-font-style: italic"&gt; if the device is &lt;/span&gt;&lt;/em&gt;&lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_TYPE_ETH&lt;/em&gt; or &lt;em style="mso-bidi-font-style: normal"&gt;OALKitlSerialInit&lt;/em&gt; if the device is &lt;em style="mso-bidi-font-style: normal"&gt;OAL_KITL_TYPE_SERIAL&lt;/em&gt;). The function initializes the KITL hardware and fills the &lt;em style="mso-bidi-font-style: normal"&gt;KITLTRANSPORT &lt;/em&gt;structure with pointers to functions which are used to perform several actions (for example send or receive a KITL frame) over the specific transport: remember that KITL stands for Kernel Independent Transport Layer so using the &lt;em style="mso-bidi-font-style: normal"&gt;KITLTRANSPORT&lt;/em&gt; pointers to functions abstracts the transport from the specific device.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;7. The control is back to &lt;em style="mso-bidi-font-style: normal"&gt;StartKitl&lt;/em&gt; which tries to connect to the desktop (i.e. Platform Builder). If the connection is established the function tries to enable the interrupt handling for the KITL device to achieve a better performance. The interrupt handler is not used if you specified &lt;em style="mso-bidi-font-style: normal"&gt;KITL_SYSINTR_NOINTR&lt;/em&gt; in &lt;em style="mso-bidi-font-style: normal"&gt;KITLTRANSPORT::Interrupt&lt;/em&gt; or if you specified that KITL has to run in &lt;a href="http://msdn.microsoft.com/en-us/library/aa914894.aspx"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;&lt;span style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-TOP: medium none; BORDER-RIGHT: medium none"&gt;passive&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; mode. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;8. Back from &lt;em style="mso-bidi-font-style: normal"&gt;StartKitl&lt;/em&gt; the KITL has been setup and the control is finally back to &lt;em style="mso-bidi-font-style: normal"&gt;OEMInit&lt;/em&gt; the to the kernel which will continue to boot the operating system.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;With the PQOAL design the BSP specific code required to setup KITL may be reduced to implement &lt;em style="mso-bidi-font-style: normal"&gt;OEMKitlStartup&lt;/em&gt; and the functions used to communicate with the actual KITL device. In some case you may need to customize the common KITL library: for example CEPC KITL adds to the common KITL library the support for PCI &lt;/span&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;since the ethernet device on an x86 board will be probably interfaced on that bus&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;span style="mso-tab-count: 1"&gt;&lt;font face="Arial"&gt;NOTE 0: This post is about KITL initialization at system startup. When KITL reinitializes after a suspend/resume cycle some steps are skipped or performed in a different way&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify" class="line862"&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;span style="mso-tab-count: 1"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="FONT-FAMILY: Verdana; COLOR: black; FONT-SIZE: 11pt; mso-ansi-language: EN" lang="EN"&gt;&lt;span style="mso-tab-count: 1"&gt;&lt;font face="Arial"&gt;NOTE 1: This name is typically used but it is not mandatory&lt;br /&gt;
&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/134470.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/134470.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/134470.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/134470.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Backlight Management</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/08/26/backlight-management.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/08/26/backlight-management.aspx</id>
        <published>2009-08-26T07:49:30-12:00:00</published>
        <updated>2009-10-28T02:50:13Z</updated>
        <content type="html">&lt;p&gt;&lt;font face="Arial"&gt;Many Windows Embedded CE device drivers have a defined interface: they can be stream interface driver with a well defined MDD/PDD layer like audio drivers; or drivers which have a  MDD/PDD layer but do not expose a stream interface, like touch screen drivers; another type of device driver is network adapter miniport drivers which must implement some defined functions to interact with NDIS; and there are other examples.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;There is no specification about how a backlight driver has to be designed so you have to design it yourself, maybe taking a look to implementations of the various BSP's shipped with Platform Builder (for example, in VOIP_PXA270 BSP folder you can find a backlight stream interface driver which has been implemented with a MDD/PDD design in mind).&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;A simple backlight management can be embedded in the display device driver: the code which handles the power IOCTL's&lt;br /&gt;
could turn off the backlight if the display is requested to go to D4 state and turn it on for higher consumption power states; n&lt;/font&gt;&lt;font face="Arial"&gt;evertheless this does not handle all the options that Windows CE control panels offer to the user.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Despite of what the documentation &lt;a href="http://msdn.microsoft.com/en-us/library/aa925923.aspx"&gt;says&lt;/a&gt; you have nothing special to do to include backlight support in the control panel since it's included by default; possibly you have to modify &lt;em&gt;%_WINCEROOT%\PUBLIC\CEBASE\OAK\MISC\wceshellfe.bat&lt;/em&gt; if you do not want to support the backlight user interface removing &lt;em&gt;backlight&lt;/em&gt; from &lt;em&gt;%CPLMAIN_COMPONENTS%&lt;/em&gt; environment variable.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;The &lt;em&gt;Screen&lt;/em&gt; control panel applet allows to configure the backlight behaviour with different settings when the device is powered by an AC supply or when it's powered by a battery. In both cases the user can select to keep the backlight always on or to turn it off after a specified amount of time that the device is not in use (on WM devices you can decide to turn on the backlight if the user taps the screen or presses a button). &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Every time the user changes one of these settings the screen control panel applet saves it to the registry under &lt;em&gt;[HKEY_CURRENT_USER\ControlPanel\Backlight]&lt;/em&gt; key (note that the settings are per user). &lt;br /&gt;
Registry values are defined in &lt;em&gt;%_WINCEROOT%\PUBLIC\WCESHELLFE\OAK\CTLPNL\CPLMAIN\regcpl.h&lt;/em&gt; and the most relevant are the following:&lt;/font&gt;&lt;/p&gt;
&lt;blockquote style="MARGIN-RIGHT: 0px" dir="ltr"&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;em&gt;"UseBattery"=dword             ;if '1' turn off the backligh after "BatteryTimeout" seconds&lt;br /&gt;
"UseExt"=dword:                   ;if '1' turn off the backligh after "ACTimeout" seconds&lt;br /&gt;
"BatteryTimeout"=dword:X ;backlight timeout in seconds &lt;br /&gt;
"ACTimeout"=dword:Y        ;backlight timeout in seconds&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;font face="Arial"&gt;In addition when a value is modified the screen control panel applet sets the  named event &lt;em&gt;"BackLightChangeEvent"&lt;/em&gt; to warn about the change.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;If you want to expose custom or advanced backlight settings to the user you can implement an advanced backlight control panel applet (for example I did it to allow the user to adjust the backlight level moving a trackbar): the applet must be implemented in a DLL which exports a function with this name and prototype:&lt;/font&gt;&lt;/p&gt;
&lt;blockquote style="MARGIN-RIGHT: 0px" dir="ltr"&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;em&gt;BOOL BacklightAdvApplet(&lt;br /&gt;
  HWND hDlg&lt;br /&gt;
);&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;font face="Arial"&gt;If you add to the backlight registry key &lt;em&gt;[HKEY_CURRENT_USER\ControlPanel\BackLight]&lt;/em&gt; the string value &lt;em&gt;"AdvancedCPL"&lt;/em&gt; which holds the name of the DLL which implements the applet, the screen control panel applet will show an &lt;em&gt;'Advanced...'&lt;/em&gt; button in the backlight tab. When the user clicks the button the &lt;em&gt;BacklightAdvApplet&lt;/em&gt; function will be called. &lt;br /&gt;
You can find a sample advanced applet under &lt;em&gt;%_WINCEROOT%\PUBLIC\WCESHELLFE\OAK\CTLPNL\ADVBACKLIGHT.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Instead of the simple backlight management decribed in the first paragraph, the following code shows as a thread can be used to manage the backlight taking in account the user settings from the control panel.&lt;/font&gt;&lt;/p&gt;
&lt;pre&gt; //Warning: this code has not be tested; for simplicity there's no error handling or check on functions return values &lt;br /&gt;#include &amp;lt;windows.h&amp;gt;&lt;br /&gt;#include &amp;lt;ceddk.h&amp;gt;&lt;/pre&gt;
&lt;pre&gt;#define REGISTRY_CHANGE_EVENT_SZ _T("BackLightChangeEvent")  &lt;br /&gt;#define USER_ACTIVITY_EVENT_SZ  _T("PowerManager/UserActivity_Active")&lt;br /&gt; &lt;br /&gt;#define USER_ACTIVITY_EVENT  0&lt;br /&gt;#define POWER_CHANGE_EVENT  1&lt;br /&gt;#define REGISTRY_CHANGE_EVENT 2  &lt;br /&gt; &lt;br /&gt;//Helper function to retrieve values from [HKEY_CURRENT_USER\ControlPanel\Backlight]; not implemented&lt;br /&gt;BOOL GetRegistrySettings(DWORD * pdwUseExt, DWORD * pdwUseBattery, DWORD * pdwACTimeout, DWORD * pdwBatteryTimeout);&lt;br /&gt;//Helper function to enable/disable the backlight; returns the backlight status just set; not implemented&lt;br /&gt;BOOL EnableBacklight(BOOL fOn);&lt;/pre&gt;
&lt;pre&gt;DWORD WINAPI BacklightControlThread(LPVOID lpParam)&lt;br /&gt;{&lt;br /&gt; //Backlight timeout&lt;br /&gt; DWORD      dwBacklightTimeout; &lt;br /&gt; //Current power status, AC / battery&lt;br /&gt; BOOL      fACLineStatus;  &lt;br /&gt; //Current backlight status &lt;br /&gt; BOOL      fBacklightOn; &lt;br /&gt; //Current settings&lt;br /&gt; DWORD      dwUseExt, dwUseBattery, dwACTimeout, dwBatteryTimeout;&lt;br /&gt; //&lt;br /&gt; DWORD      dwWaitStatus, dwBytesRead, dwFlags;&lt;br /&gt; //For power status change notifications&lt;br /&gt; MSGQUEUEOPTIONS    MsgQueueOpt;&lt;br /&gt; UCHAR      PowerInfoBuffer[sizeof(POWER_BROADCAST)+sizeof(PBT_POWERINFOCHANGE)];&lt;br /&gt; PPOWER_BROADCAST   pPowerInfo = (PPOWER_BROADCAST)PowerInfoBuffer;&lt;br /&gt; POWER_BROADCAST_POWER_INFO  *ppbpi;&lt;br /&gt; //Handles to the various events we wait on&lt;br /&gt; HANDLE       hEvents[3];&lt;br /&gt; SYSTEM_POWER_STATUS_EX  PowerStatus;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; //Enable the backlight at the beginning&lt;br /&gt; fBacklightOn = EnableBacklight(TRUE);&lt;br /&gt; &lt;br /&gt; //Get the current power supply status&lt;br /&gt; GetSystemPowerStatusEx(&amp;amp;PowerStatus,TRUE);&lt;br /&gt; &lt;br /&gt; fACLineStatus = (PowerStatus.ACLineStatus  &amp;amp; AC_LINE_ONLINE) ? TRUE : FALSE; &lt;br /&gt; &lt;br /&gt; //Get the backlight settings&lt;br /&gt; GetRegistrySettings(&amp;amp;dwUseExt, &amp;amp;dwUseBattery, &amp;amp;dwACTimeout, &amp;amp;dwBatteryTimeout);&lt;/pre&gt;
&lt;pre&gt; //Evaluate the timeout&lt;br /&gt; dwBacklightTimeout = (fACLineStatus ? dwUseExt : dwUseBattery) ?  //Check if we must turn off according to power supply&lt;br /&gt;  (fACLineStatus ? dwACTimeout : dwBatteryTimeout) :      //Set the timeout if we must turn off&lt;br /&gt;  INFINITE;               //Otherwise set user activity timeout to INFINITE&lt;/pre&gt;
&lt;pre&gt; //Handle to user activity event signaled by the power manager.&lt;br /&gt; hEvents[USER_ACTIVITY_EVENT] = CreateEvent(NULL, FALSE, FALSE, USER_ACTIVITY_EVENT_SZ); &lt;/pre&gt;
&lt;pre&gt; //Handle to notification for power status change&lt;br /&gt; MsgQueueOpt.dwSize = sizeof(MSGQUEUEOPTIONS);&lt;br /&gt; MsgQueueOpt.dwFlags =  MSGQUEUE_NOPRECOMMIT |  MSGQUEUE_ALLOW_BROKEN;&lt;br /&gt; MsgQueueOpt.dwMaxMessages = 0;&lt;br /&gt; MsgQueueOpt.cbMaxMessage = sizeof(POWER_BROADCAST) + sizeof(PBT_POWERINFOCHANGE);&lt;br /&gt; MsgQueueOpt.bReadAccess = TRUE;&lt;br /&gt; hEvents[POWER_CHANGE_EVENT] = CreateMsgQueue(NULL,&amp;amp;MsgQueueOpt);&lt;br /&gt; RequestPowerNotifications(hEvents[POWER_CHANGE_EVENT],PBT_POWERINFOCHANGE);&lt;br /&gt; &lt;br /&gt; //Handle to registry change event. Note that we use CreateEvent, not OpenEvent, since the screen control panel applet&lt;br /&gt; //actually creates the event only when it needs to set it then closes it&lt;br /&gt; hEvents[REGISTRY_CHANGE_EVENT] = CreateEvent(NULL, FALSE, FALSE, REGISTRY_CHANGE_EVENT_SZ);&lt;br /&gt; &lt;br /&gt; while(1)&lt;br /&gt; {&lt;br /&gt;  dwWaitStatus = WaitForMultipleObjects(_countof(hEvents), hEvents, FALSE, &lt;br /&gt;   (dwBacklightTimeout != INFINITE) ? dwBacklightTimeout*1000 : INFINITE);&lt;br /&gt;   &lt;br /&gt;  switch(dwWaitStatus)&lt;br /&gt;  {&lt;br /&gt;   //user activity timeout elapsed, turn off the backlight if it's on&lt;br /&gt;   case WAIT_TIMEOUT:&lt;br /&gt;   &lt;br /&gt;    if(fBacklightOn)&lt;br /&gt;     fBacklightOn = EnableBacklight(FALSE);&lt;/pre&gt;
&lt;pre&gt;    break;&lt;br /&gt;    &lt;br /&gt;   //user activity, turn on the backlight if it's off &lt;br /&gt;   case WAIT_OBJECT_0 + USER_ACTIVITY_EVENT:&lt;br /&gt;   &lt;br /&gt;   &lt;br /&gt;    if(!fBacklightOn)&lt;br /&gt;     fBacklightOn = EnableBacklight(TRUE);&lt;br /&gt;    &lt;br /&gt;    break;&lt;br /&gt;    &lt;br /&gt;   //power change notification    &lt;br /&gt;   case WAIT_OBJECT_0 + POWER_CHANGE_EVENT:&lt;br /&gt;   &lt;br /&gt;    //Get information about the power supply state&lt;br /&gt;    ReadMsgQueue(hEvents[POWER_CHANGE_EVENT],&amp;amp;pPowerInfo,sizeof(PowerInfoBuffer),&amp;amp;dwBytesRead, 0, &amp;amp;dwFlags);&lt;br /&gt;    ppbpi = (PPOWER_BROADCAST_POWER_INFO) &amp;amp;pPowerInfo-&amp;gt;SystemPowerState[0];&lt;br /&gt;    fACLineStatus = ppbpi-&amp;gt;bACLineStatus;&lt;br /&gt;    &lt;br /&gt;    //Evaluate the timeout&lt;br /&gt;    dwBacklightTimeout = (fACLineStatus ? dwUseExt : dwUseBattery) ? &lt;br /&gt;       (fACLineStatus ? dwACTimeout : dwBatteryTimeout) :   &lt;br /&gt;       INFINITE;            &lt;br /&gt;       &lt;br /&gt;    //Consider a change in power supply as user activity so turn on the backlight      &lt;br /&gt;    if(!fBacklightOn)&lt;br /&gt;     fBacklightOn = EnableBacklight(TRUE);&lt;br /&gt;     &lt;br /&gt;    break;&lt;br /&gt;    &lt;br /&gt;   //registry change notification    &lt;br /&gt;   case WAIT_OBJECT_0 + REGISTRY_CHANGE_EVENT:&lt;br /&gt;   &lt;br /&gt;    //Get the new backlight settings&lt;br /&gt;    GetRegistrySettings(&amp;amp;dwUseExt, &amp;amp;dwUseBattery, &amp;amp;dwACTimeout, &amp;amp;dwBatteryTimeout);&lt;br /&gt;   &lt;br /&gt;    //Evaluate the timeout&lt;br /&gt;    dwBacklightTimeout = (fACLineStatus ? dwUseExt : dwUseBattery) ? &lt;br /&gt;       (fACLineStatus ? dwACTimeout : dwBatteryTimeout) :   &lt;br /&gt;       INFINITE; &lt;br /&gt;       &lt;br /&gt;    //Enable the backlight if it's off       &lt;br /&gt;    if(!fBacklightOn)&lt;br /&gt;     fBacklightOn = EnableBacklight(TRUE);       &lt;br /&gt;   &lt;br /&gt;    break;&lt;/pre&gt;
&lt;pre&gt;   case WAIT_FAILED:&lt;br /&gt;   default:&lt;br /&gt;    ;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}   &lt;br /&gt;&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/134325.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/134325.aspx</wfw:comment>
        <slash:comments>4</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/134325.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/134325.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Integrating your project in the 3rdParty folder</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/06/29/integrating-your-project-in-the-3rdparty-folder-tree.aspx" />
        <id>http://geekswithblogs.net/WindowsEmbeddedAnnotations/archive/2009/06/29/integrating-your-project-in-the-3rdparty-folder-tree.aspx</id>
        <published>2009-06-29T09:52:50-12:00:00</published>
        <updated>2009-06-30T09:44:09Z</updated>
        <content type="html">&lt;p&gt;&lt;font face="Arial"&gt;A recent feedback by Bjoern Feld on my post about 'Integrating your project in the PUBLIC tree' leads me to write this new one. &lt;/font&gt;&lt;font face="Arial"&gt;Once you have created your driver/application you want probably to distribute it to your customer; maybe you want to&lt;br /&gt;
install your product in the %_WINCEROOT%\3rdParty folder. In this example I will assume that ACME wants to distribute a device driver for a new rocket -which will hopefully help Wile E. Coyote to terminate the Road Runner.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Open a Platform Builder workspace you have on hand and, from Project menu choose 'Add new subproject...'. Select 'WCE Dynamic-Link library' name it 'ROCKET001' then choose to create an empty subproject.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;In the folder you'll end up with the following files:&lt;/font&gt;&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;rocket001.bib&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;rocket001.dat&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;rocket001.db&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;rocket001.def&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;rocket001.pbpxml&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;rocket001.reg&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;makefile&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;postlink.bat&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;prelink.bat&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;ProjSysgen.bat&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;ReadMe.txt&lt;/font&gt; &lt;/li&gt;
    &lt;li&gt;&lt;font face="Arial"&gt;sources     &lt;/font&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Remove the prelink.bat, ProjSysgen.bat and ReadMe.txt which are not useful for the example then: &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Modify the sources file content as following:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1" face="Tahoma"&gt;TARGETNAME=ROCKT001&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1" face="Tahoma"&gt;SOURCES= \&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1" face="Tahoma"&gt;TARGETTYPE=NOTARGET&lt;br /&gt;
POSTLINK_PASS_CMD=postlink.bat&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Fill the postlink.bat file with this:&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1" face="Tahoma"&gt;copy Target\%_TGTCPU%\%WINCEDEBUG%\ROCKT001.*  %_FLATRELEASEDIR%&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;This will copy the binary files to %_FLATRELEASEDIR%: I'm supposing that you will place a binary file for the rocket driver for several CPU architecures and for both the release and the debug build (just in case that Wile E. Coyote wanted to debug why the rocket blew up).&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Create an ACME folder under %_WINCEROOT%\3rdParty and copy the ROCKT001 folder into it.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Create a catalog file rockt001.pbcxml for your project in  %_WINCEROOT%\PUBLIC\COMMON\CATALOG; the content of the file will be the following&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="1" face="Tahoma"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br /&gt;
&amp;lt;CatalogFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" RequiredVersion="6.00" xsi:schemaLocation="urn:Microsoft.PlatformBuilder/Catalog PbcXml600.xsd" xmlns="urn:Microsoft.PlatformBuilder/Catalog"&amp;gt;&lt;br /&gt;
  &amp;lt;FileInformation Id="FileInformation:ACME:Rocket001"&amp;gt;&lt;br /&gt;
    &amp;lt;Title&amp;gt;ACME Rocket&amp;lt;/Title&amp;gt;&lt;br /&gt;
    &amp;lt;Description&amp;gt;Anti-road-runner weapon&amp;lt;/Description&amp;gt;&lt;br /&gt;
    &amp;lt;Vendor&amp;gt;ACME&amp;lt;/Vendor&amp;gt;&lt;br /&gt;
    &amp;lt;OSVersion&amp;gt;6.00&amp;lt;/OSVersion&amp;gt;&lt;br /&gt;
    &amp;lt;FileVersion&amp;gt;1.00&amp;lt;/FileVersion&amp;gt;&lt;br /&gt;
  &amp;lt;/FileInformation&amp;gt;&lt;br /&gt;
  &amp;lt;Item Id="ROCKET001"&amp;gt;&lt;br /&gt;
    &amp;lt;Title&amp;gt;ACME Rocket v 001&amp;lt;/Title&amp;gt;&lt;br /&gt;
    &amp;lt;Variable&amp;gt;BSP_ACME_ROCKET001&amp;lt;/Variable&amp;gt;&lt;br /&gt;
    &amp;lt;Module&amp;gt;rockt001.dll&amp;lt;/Module&amp;gt;&lt;br /&gt;
    &amp;lt;Project&amp;gt;$(_WINCEROOT)\3RDPARTY\ACME\ROCKT001\ROCKT001.PBPXML&amp;lt;/Project&amp;gt;&lt;br /&gt;
    &amp;lt;Location&amp;gt;Device Drivers&amp;lt;/Location&amp;gt;&lt;br /&gt;
  &amp;lt;/Item&amp;gt;&lt;br /&gt;
&amp;lt;/CatalogFile&amp;gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;Ok, now you have all you need to distribute your binaries: the last but not least thing you have to do is create an .msi file to distribute your rocket driver: I will not consider here how to do it, but you can take a look &lt;a href="http://msdn.microsoft.com/en-us/library/ms242499(VS.80).aspx"&gt;here&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;You can download the sample folder for the rocket driver &lt;a href="/images/geekswithblogs_net/WindowsEmbeddedAnnotations/3rdParty/ACME.zip"&gt;here&lt;/a&gt;. It includes the catalog file that you have to copy under %_WINCEROOT%\PUBLIC\COMMON\CATALOG. I put only the ARMV4I retail binaries (which are actually related to a sample DLL).&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;br /&gt;
  &lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/WindowsEmbeddedAnnotations/aggbug/133120.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/133120.aspx</wfw:comment>
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/WindowsEmbeddedAnnotations/comments/commentRss/133120.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/WindowsEmbeddedAnnotations/services/trackbacks/133120.aspx</trackback:ping>
    </entry>
</feed>
