
EMB427 Writing Real-Time Applications On Windows CE 5.0 Nat Frampton President Real Time Development Corporation nat@realtimeonline.com MEDC DevCon 2005
EMB427 Writing Real-Time Applications On Windows CE 5.0 Nat Frampton President Real Time Development Corporation nat@realtimeonline.com

Microsoft MEDC Mobile Embedded DevCon 2005 May9-12,2005 Las Vegas Microsoft

Windows Mobile 出 Windows CE5.0 Windows EDcoc Hardware/Drivers OEM/IHV Supplied BSP OEM Hardware and Standard PC (ARM,SH4,MIPS) Standard Drivers Hardware and Drivers Device Building Windows XP DDK Tools Platform Builder Windows Embedded Studio Lightweight EDB SQL Server 2005 Express Edition Relational SQL Server 2005 Mobile Edition SQL Server 2005 Native Win32 MFC 8.0,ATL 8.0 Managed .NET Compact Framework .NET Framework server side ASP.NET Mobile Controls ASP.NET Windows Media Multimedia DirectX Location services MapPoint Development Tools Visual Studio 2005 Internet Security and Acceleration Server communications Exchange Server &Messaging Live Communications Server Speech Server Device Update Agent Management Image Update Software Update Services Tools Systems Management Server Microsoft Operations Manager
Management Tools Communications & Messaging Device Update Agent Software Update Services Live Communications Server Exchange Server Internet Security and Acceleration Server Speech Server Image Update Location Services Multimedia MapPoint DirectX Windows Media Development Tools Visual Studio 2005 MFC 8.0, ATL 8.0 Native Win32 Managed Server Side Lightweight Relational EDB SQL Server 2005 Express Edition Data Programming Model Device Building Tools Hardware/Drivers Windows XP DDK Windows Embedded Studio Platform Builder OEM/IHV Supplied BSP (ARM, SH4, MIPS) OEM Hardware and Standard Drivers Standard PC Hardware and Drivers SQL Server 2005 Mobile Edition SQL Server 2005 ASP.NET Mobile Controls ASP.NET .NET Compact Framework .NET Framework Microsoft Operations Manager Systems Management Server

Overview Interrupt architecture Deadlock thread strategy Debugging strategies Priority runner strategy Lessons learned
Overview Interrupt architecture Deadlock thread strategy Debugging strategies Priority runner strategy Lessons learned

Interrupt Architecture IST Latency IST Thread ISR ISRN ISR 是 Latency ISR ISR Set Event Kernel All Higher Enabled All Except D
Kernel Interrupt Architecture HW All Higher Enabled All Except ID All OAL Thread ISR Set Event ID ISR ISR1 ISRN ISR Latency IST IST Latency

Interrupt Initialization //Create the Event gIntEvent CreateEvent( NULL, /security FALSE, /Manual reset FALSE, /Init as not signaled NULL /No Named Events ) /Create a thread that waits for signaling gThreadInt =CreateThread( NULL security 0 /Default //Interrupt Thread CUE SUSD8。are5 /Initilialize the Interrupt gSysInterruptNum KernelIocontrol(IOCTL_HAL TRANSLATE_IRQ &gIRQNum,sizeof(DWORD),&gsysIntNum,sizeof (DWORD),NULL ) InterruptInitialize(gsysIntNum,/From Map gIntEvent, //Global Event NULL, /Not Used (DWORD)NULL /Not Used ) /Get the thread going ResumeThread(gThreadInt )
Interrupt Initialization // Create the Event gIntEvent = CreateEvent( NULL, // Security FALSE, // Manual reset FALSE, // Init as not signaled NULL // No Named Events ); // Create a thread that waits for signaling gThreadInt = CreateThread( NULL, // Security 0, // Default ThreadInt,// Interrupt Thread NULL, // No Parameters CREATE_SUSPENDED,// Suspended &dwThreadID // Thread Id); // Initilialize the Interrupt gSysInterruptNum = KernelIoControl( IOCTL_HAL_TRANSLATE_IRQ, &gIRQNum, sizeof(DWORD), &gSysIntNum, sizeof(DWORD), NULL ); InterruptInitialize( gSysIntNum, // From Map gIntEvent, // Global Event NULL, // Not Used (DWORD)NULL // Not Used ) ) // Get the thread going ResumeThread( gThreadInt ); Kernel HW All Higher Enabled All Except ID All OAL IST ISR Set Event ID ISR ISR1 ISRN IST

Interrupt Service Thread DWORD WINAPI ThreadInt(LPVOID 1pvParam /The magic thread waits for the event. while(gRun /wait until we have been signaled interrupt waitForsingleobject(gIntEvent,INFINITE ) /Increment the counter gInterruptCount ++ /Run your logic here /Reset the interrupt InterruptDone(gsysIntNum ) return 0;
DWORD WINAPI ThreadInt( LPVOID lpvParam ) { // The magic thread waits for the event. while( gRun ) { // Wait until we have been signaled interrupt WaitForSingleObject( gIntEvent, INFINITE ); // Increment the counter gInterruptCount ++; // Run your logic here // Reset the interrupt InterruptDone( gSysIntNum ); } return 0; } Kernel HW All Higher Enabled All Except ID All OAL IST ISR Set Event ID ISR ISR1 ISRN IST Interrupt Service Thread

Deadlock Thread Strategy High and Medium Priority Threads Cooperating through a Critical Section High Priority Thread waits for a time period reading the CPU Counter Gets Critical Section Waits in a Loop High Priority Thread Logs Ownership Releases Critical Section Critical Section Gets Critical Section Logs Ownership Medium Priority Thread Releases Critical Section
Deadlock Thread Strategy High and Medium Priority Threads Cooperating through a Critical Section High Priority Thread waits for a time period reading the CPU Counter High Priority Thread Medium Priority Thread Critical Section Gets Critical Section Waits in a Loop Logs Ownership Releases Critical Section Gets Critical Section Logs Ownership Releases Critical Section

Debugging Strategies Strategy Comments Application IDE Nice Integration and view of application data but not system Data Kernel Debugger Great system access; Requires OEM Integration into OS Printf Slow and limited to the ability to print output Firmware Debugger Great Hardware access but difficult application level information Hardware Debugger Last Resort when system is locked;Often necessary
Debugging Strategies Strategy Comments Application IDE Nice Integration and view of application data but not system Data Kernel Debugger Great system access; Requires OEM Integration into OS Printf Slow and limited to the ability to print output Firmware Debugger Great Hardware access but difficult application level information Hardware Debugger Last Resort when system is locked; Often necessary

Priority Runner Strategy Create a thread that runs priorities Push Button Start-LED Status Stops Blinking when it isn't scheduled! Waits for Start Event Check if Reached Stop Priority Push Button IST TurnsLED ON Waits 100ms Turn LED OFF Increments and Sets Priority Sleeps 1 second LED Loop Sets Finished Event
Priority Runner Strategy Create a thread that runs priorities Push Button Start - LED Status Stops Blinking when it isn’t scheduled! Push Button LED Waits for Start Event Check if Reached Stop Priority Turns LED ON Waits 100 ms Turn LED OFF Increments and Sets Priority Sleeps 1 second Loop Sets Finished Event IST