EMB422 Advanced Embedded Visual C++ Application Development Control - View Nat Frampton President Real Time Development nat@realtimeonline.com Hardware/Drivers OEM/IHV Supplied Programming Model Data Device Building Tools BSP (ARM, SH4, MIPS) EDB SQL Server 2005 Mobile Edition Relational Native Server Side Standard PC Hardware and Drivers Windows XP DDK Windows Embedded Studio Platform Builder Lightweight Managed OEM Hardware and Standard Drivers SQL Server 2005 Express Edition SQL Server 2005 Win32 MFC 8.0, ATL 8.0 .NET Compact Framework ASP.NET Mobile Controls .NET Framework ASP.NET Windows Media DirectX Multimedia Location Services MapPoint Development Tools Visual Studio 2005 Internet Security and Acceleration Server Exchange Server Live Communications Server Speech Server Communications & Messaging Device Update Agent Management Tools Image Update Software Update Services Systems Management Server Microsoft Operations Manager Goal Develop Control Application View Application Leverage eVC++ MFC Win32 Observe Real Time Practices Overview Native vs. .NET Compact Framework SDK Creation Application Architecture Win32 Application Development MFC Application Development Windows CE 5.0 Tools Operating System Development Windows CE 5.0 Platform Builder Application Development Windows CE 5.0 Platform Builder eMbedded Visual C++ Visual Studio .NET Smart Device Extensions Windows CE 5.0 Application Development eMbedded Visual C++ 4.0 SP4 Native Code Win32, MFC, ATL Visual Studio .NET 2003 Managed Code C#, Visual Basic .NET Framework Sizes Windows XP Embedded Windows CE .NET Win32 MFC .NET Framework ----- 1.25 MB 280 KB 34 MB 1.5 MB Windows CE 5.0 OLECE400.DLL ~ 200 KB Windows XP Embedded ASP .NET ~ 1.5 MB Framework - Strengths API Microsoft Win32 (C / C++) MFC (C++) .NET Framework (C# and Microsoft Visual Basic® .NET) Strengths Smallest and fastest .exe files and DLLs Lowest memory overhead Required for device drivers, control panel applets, shell extensions No runtime required; Windows CE 5.0 is the runtime Object-oriented. Inheritance, Encapsulation, Polymorphism, also called .function overloading Container classes support arrays, lists, object maps and simplify data handling Type safety Complete MFC source code ships with Embedded Visual Tools Good tool support & wizards Well-designed programming interface Object-oriented. Inheritance, Encapsulation, Polymorphism, also called function overloading Container classes support arrays, lists, hashtables, dictionaries, and stacks Type safety Namespaces Automatic garbage collection eliminates memory leaks Portable machine instruction set, MSIL / CIL, provides binary portable of executable (.exe & .dll) files Web service clients are quick and easy to write Great support for handling XML Great tool support — Forms Designer Framework - Weaknesses API Weaknesses Microsoft Win32 (C / C++) Object cleanup is the responsibility of the application/driver programmer, making this API prone to memory leaks Low-level API — can be hard to learn Procedure-oriented API, not object-oriented MFC (C++) Object cleanup only semi-automatic, therefore less prone to memory leaks than Win32, but still somewhat vulnerable since MFC is thin wrapper on top of Win32 Size of runtime ~ 500 KB (MFC & OLECE) .NET Framework (C# and Microsoft Visual Basic® .NET) Size of runtime ~ 1.5 MB Overhead of calls between managed and unmanaged code is high COM Interoperability somewhat clumsy. Requires writing Win32 wrappers that call the COM interface functions Source code is not available Requires display based platform .NET Compact Framework Lightweight version of .NET Framework Designed for resource-constrained devices Compatible with VS.NET, C#, VB.NET Runs applications securely on-device High performance JIT compiler Guarantees robustness and security Highly interactive, offline, and networked experiences Makes it easy to consume web services Tunable size and performance .NET Compact Framework System.Web Services Description UI HtmlControls Discovery WebControls System.WinForms Design ComponentModel System.Drawing Protocols Caching Security Drawing2D Printing Configuration SessionState Imaging Text System.Data System.Xml ADO.NET SqlClient XmlDocument Serialization Design SqlServerCe Xslt/XPath Reader/Writers System Collections IO Configuration Security Net ServiceProcess Runtime InteropServices Text Reflection Diagnostics Remoting Globalization Resources Threading Serialization SDK Creation Encapsulation Mechanism Contains Compiler Component Documentation OEM Help, Docs and Libraries Understand the target user Application Only? Device Driver? Real Time Applications? Application Architecture Synchronization Strategy 1 Copy Event 2 3 Demo Memory 4 Finished Event 5 Control Architecture IST Checks for Button up Inc Button Push Button IST Flashes the LED Interrupt Done Control Thread Checks for Finished Flag Increments the Bin Count Copy Event Calcs the Bin Stats Check for Copy Request Event Copies Data to Shared Memory Sets the Copy Finished Event Demo Memory Sleeps 5 ms Loop Finished Event LED Hardware Push-On/Push-Off Switch Radio Shack Part # 275-011A Connects Pins 4-8 (DTR To CTS) Button Anode D-Sub Connector 9 Position Female Radio Shack Part # 276-1428 LED RED LED 12V - 30 ma Radio Shack Part # 276-011 Connects Pins 5-7 (GND to RTS) Cathode RS232 DB9 Connector DB-9M Function Pin Pin Pin Pin Pin Pin Pin Pin Pin Data Carrier Detect CD Receive Data RD or RX or RXD Transmitted Data TD or TX or TXD Data Terminal Ready DTR Signal Ground GND Data Set Ready DSR Request To Send RTS Clear To Send CTS Ring Indicator RI #1 #2 #3 #4 #5 #6 #7 #8 #9 Abbreviation DemoControl.exe A Win32 App Interrupt Architecture ISR1 IST ISRN OAL ISR Latency Thread IST Latency ISR ID Kernel Set Event ISR All Except ID All HW All Higher Enabled Windows CE 5.0 Priority Map Priority 0-19 20 21-89 99 Component Open – Real Time Above Drivers Permedia Vertical Retrace Open – Real Time Above Drivers Power management Resume Thread 100-108 USB OHCI UHCI, Serial 109-129 Irsir1, NDIS, Touch 130 KITL 131 VMini 132 CxPort 133-144 145 146-147 Open – Device Drivers PS2 Keyboard Open – Device Drivers 148 IRComm 149 Open – Device Drivers 150 TAPI 151-152 Open – Device Drivers 153-247 Open – Real Time Below Drivers 248 Power Management 249 WaveDev, TVIA5000,Mouse,PnP,Power 250 WaveAPI 251 Power Manager Battery Thread 252-257 Open Interrupt Initialization // Create the Event gIntEvent = CreateEvent( NULL, FALSE, FALSE, NULL // NULL // Manual reset // Init as not signaled // No Named Events ); // Create a thread that waits for signaling gThreadInt = CreateThread( NULL, // NULL 0, // No Stack Size 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, gIntEvent, NULL, (DWORD)NULL // Get the thread going ResumeThread( gThreadInt ); // From Map // Global Event // Not Used // Not Used ) ) Interrupt Service Thread DWORD WINAPI ThreadInt( LPVOID lpvParam ) { // The magic thread waits for the event. while( gRun ) { // Wait until we have been signaled that there is an interrupt WaitForSingleObject( gIntEvent, INFINITE ); // Increment the counter gInterruptCount ++; // Run your logic here // Reset the interrupt so we can get another one InterruptDone( gSysIntNum ); } return 0; } DemoView.exe a MFC App Review Native and .NET CFW applications both have their place Complex Applications can be rapidly Development in Embedded Visual C++ Windows CE provides a rich real-time environment for a variety of application architectures Embedded Visual C++ is now your most powerful tool! While at MEDC 2005… Fill out an evaluation for this session Randomly selected instant WIN prizes! Visit the Microsoft Product Pavilion in the Exhibit Hall Shorelines B Use real technology in a lab Instructor led Reef E/F & Breakers L Self-paced Reef B/C After The Conference… Build Install Full-featured trial versions of Windows CE and/or Windows XP Embedded Build Cool stuff & tell us about it: msdn.microsoft.com/embedded/community Join Windows Embedded Partner Program: www.mswep.com Develop Install Windows Mobile 5.0 Eval Kit including Visual Studio 2005 Beta 2 Enter Mobile2Market Contest and win up to $25000: mobile2marketcontest.com Join Microsoft Solutions Partner Program: partner.microsoft.com Tools & Resources Build Develop msdn.microsoft.com/ embedded msdn.microsoft.com/ mobility microsoft.public. windowsxp.embedded windowsce.platbuilder windowsce.embedded.vc microsoft.public. pocketpc.developer smartphone.developer dotnet.framework.compactframework Blogs blogs.msdn.com/ mikehall blogs.msdn.com/ windowsmobile vsdteam netcfteam Tools Windows CE 5.0 Eval Kit Windows XP Embedded Eval Kit Windows Mobile 5.0 Eval Kit Websites Newsgroups