Showing posts with label .NET Micro Framework. Show all posts
Showing posts with label .NET Micro Framework. Show all posts

Now that you know why Microsoft developed the .NET Micro Framework, let’s take a look at how it works.

Introducing the Bootable Runtime Environment
The .NET Micro Framework does not require an underlying operating system and can run directly on the hardware. It provides the following services that are usually provided by an operating system:
• Boot code
• Code execution
• Thread management
• Memory management
• Hardware I/O
However, the .NET Micro Framework is not a full-featured operating system; it’s a bootable runtime environment tailored for embedded development. That’s how the .NET Micro Framework can run directly on the hardware without an underlying operating system. Nonetheless, the .NET Micro Framework can still use an underlying operating system and its services; the extensible emulator running on Windows is an example of that.



Architecture
As I said, the .NET Micro Framework is not a full-featured operating system but a bootable runtime environment tailored for embedded development; it consists of the four.



User Code Layer
The topmost layer is the user code layer. This layer consists of your managed application written in C#. Your application can use your reusable class libraries shared with other projects.



Base Class Library Layer
The next layer is the .NET Micro base class library layer, which provides a subset of the common .NET libraries and domain-specific extensions, such as libraries for touching the hardware, simple drawing, complex graphical user interfaces, and networking.

The .NET Micro Framework provides a subset of the full .NET Framework base class library (BCL). Microsoft tried to stay in line with the full .NET Framework class library wherever possible. If the functionality or interface of a class deviates from the full .NET Framework, that class or interface was moved to the new namespace Microsoft.SPOT.
The .NET Micro Framework base class libraries use a mix of managed and native code. The
class libraries do not contain native code. The native methods are built into the runtime environment and are used to perform time-critical tasks or access hardware.



TinyCLR
The TinyCLR layer consists of three components:
• Hardware abstraction layer (HAL): The HAL is tightly coupled to the hardware and provides functions to access the hardware and peripherals. When running on an operating system, the HAL provides functionality by using the services of the underlying OS.

• Platform abstraction layer (PAL): The PAL provides additional abstractions of the HAL, such as timers and memory blocks.

• .NET Micro Framework CLR: The CLR consists of the execution engine that manages code at execution time. The managed type system ensures strict type safety. The CLR also contains the garbage collector, which is responsible for automatically freeing unused memory blocks, and the internal native methods called by the base class library. In addition, there is a boot loader that loads and starts the TinyCLR.



Hardware Layer
The hardware layer consists of the actual hardware platform. This is either the target device (microprocessor and peripheral) or the hardware emulator running on a Windows PC.



Compiling for the .NET Micro Framework
In .NET, compilers, such as the C# compiler, transform the source code to assemblies—executables (.exe files) and libraries (.dll files)—containing the common intermediate language and metadata for a self-describing code. The CLR then executes the managed code.

The .NET Micro Framework uses a special variant of the common intermediate language (CIL) optimized for size. A global, shared string table for text and metadata such as type, method, and field names is used to reduce ROM and RAM usage on the devices.

Therefore, the .NET Micro Framework metadata processor tool generates the optimized portable executable files (pe-files) to be deployed out of the managed .NET assemblies. Visual Studio and the .NET Micro Framework plug-in hide all these steps from you. You will not see that the metadata processor is used, but you should know that Visual Studio actually deploys special optimized assemblies that the .NET Micro Framework CLR will interpret.


Currently, the .NET Micro Framework supports only Visual C#. Theoretically, every .NET language compiler could be supported because the metadata processor parses common .NET assemblies that each .NET compiler should be able to generate. In practice, Visual Basic uses a special Visual Basic runtime library that has not yet been ported to the .NET Micro Framework. An article at www.christec.co.nz/blog/archives/317 describes how to compile Visual Basic code manually without using the runtime library on the command-line shell.



Target platforms
Currently, the .NET Micro Framework runs on ARM7 and ARM9 chipsets and also on the Blackfin processor, from Analog Devices. The extensible emulator is another port of the CLR on X86 processors; it uses an underlying operating system, such as Windows XP or Vista.



Platform Porting
The .NET Micro Framework separates all code that interfaces with the hardware in the hardware and platform abstraction layers (HAL and PAL). Theoretically, porting to a new platform seems like it ought to be an easy task, but it is complex and requires a complete understanding of the hardware being used. In practice, a full porting effort will be done by hardware platform vendors rather than by individual embedded developers.
Microsoft provides a porting kit and porting workshops. The porting kit includes the source code for a reference HAL and PAL implementation. The porting kit requires a porting agreement along with payment of an associated fee. The chipset itself is not so important when programming with the .NET Micro Framework because the code is processor independent. There are several platforms available that provide all the peripheral hardware supported by the .NET Micro Framework. The devices vary only in display and networking support. This is an active area of development, and we will certainly see interesting new platforms in the future.



Native Code Interoperability
You can accomplish a lot with managed code and the .NET Micro Framework runtime library, but sometimes advanced scenarios can require increased performance for a time-critical algorithm or to access resources that cannot be reached with managed code. The .NET Micro Framework therefore supports native code interoperability. Native interoperability allows you to implement your own methods in native code with C/C++ and call them from managed code. To do so requires a porting kit. The great news is that the porting kit is included with most Microsoft Developer Network (MSDN) subscriptions and will be offered at no cost due to a new licensing model that is in progress at time of this writing. Steve Maillet has a good, practical tutorial about using native interoperability with the .NET Micro Framework at http://blogs.msdn.com/netmfteam/pages/using-interop-in-net-micro-frameworkv3-0.aspx. Microsoft also provides a porting kit-related forum called microsoft.public.dotnet.framework.microframework.porting.



Highlights of the .NET Micro Framework (3.0)
Version 3.0 of the.NET Micro Framework includes many significant features that are sure to facilitate programming micro devices, including:
• The ability to program with the C# programming language
• The Microsoft Visual Studio 2008 development environment (the Express Edition is ffree)
• Development boards staring at $100 and QVGA LCD displays starting at $350
• Modules available starting at $30
• Rapid prototyping and debugging with the extensible emulator
• Live debugging directly on the devices
• General purpose input/output (GPIO) ports
• Serial ports
• Serial peripheral interface (SPI) bus
• Inter-integrated circuit (I²C) bus
• Ethernet with TCP/IP and UDP sockets
• Wireless LAN
• Secure network connections with secure sockets layer (SSL)
• Web services on devices with DPWS, including code-generation tools
• LCD displays
• User interfaces with simplified Windows Presentation Foundation–style classes
• Stylus and touch panel
• Battery control
• Monotone Piezo speaker
• Data persistence in the flash memory
• USB-device capable
• File system for example on SD-cards
• Pulse width modulation (provided indirectly by hardware manufacturer’s own API)
• USB host (provided indirectly by hardware manufacturer’s own API)
• Controller area network (CAN) bus (provided indirectly by hardware manufacturer’s own API)

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)

You often hear about Microsoft Windows SideShow together with the .NET Micro Framework. SideShow is an environment based on the .NET Micro Framework that runs on devices containing the framework; it can get content from a host computer and display that content on small devices. SideShow-enabled devices can be permanently connected to a computer, or you can use them independently of the host computer that provides the content. For example, a SideShow-enabled auxiliary display on a notebook cover enables you to browse your appointments or read e-mail while your notebook is turned off. The next time the notebook is turned on, the two devices synchronize.

Devices enabled to use SideShow include the following:
• An auxiliary display for a PC or notebook
• A remote control with a display
• A designer bag with a built-in
• A cordless phone
• A picture frame
• A portable media player

You can see more SideShow-enabled devices at www.SideShowDevices.com.

The content displayed by SideShow-enabled devices is described in the Simple Content Format (SCF), which is based on XML. You can create a custom gadget application for SideShow in native or managed code that runs on your Windows host computer and provides SCF content to a connected SideShow-enabled device. The device’s SideShow-enabled environment, which is written with the .NET Micro Framework, shows the SCF content as well as supporting interaction, like menu navigation and responses to other user input.

The SideShow-enabled environment on the devices is now also available for Windows Mobile and could theoretically be ported to other platforms. However, the .NET Micro Framework does the job well. Microsoft provides a Windows SideShow Device SDK for the .NET Micro Framework that allows original equipment manufacturers (OEMs) to write built-in applications with the .NET Micro Framework and install them on their SideShow-enabled devices.

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)

Benefits of the .NET Micro Framework

For embedded development, the advantages of the .NET Micro Framework can be summarized as follows:
• Lower development costs than other traditional embedded platforms
• Faster time-to-market than other traditional embedded platforms
• Lower hardware costs than other managed platforms
• Smaller hardware size than other managed platforms
• Lower power consumption than other managed platforms
• Not bound to a specific chipset or board vendor
• Important part of Microsoft’s embedded strategy

The following features of the .NET Micro Framework allow you to reduce development costs and bring your products to market faster than competing traditional embedded platforms:
• Managed code and all its benefits
• Modern language with Visual C#
• Rich base class library (a subset of common .NET and extensions for embedded development)
• Ability to touch the hardware with managed drivers
• Integration with Visual Studio, a first-class and widespread development tool
• Large pool of existing .NET developers
• Ability to share code with existing .NET solutions
• Rapid prototyping and debugging using the extensible emulator
• Live debugging on devices

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)

Where the .NET Micro Framework Fits

Now that we have looked at the benefits of managed code, let’s examine where the .NET Micro Framework fits in the range of Microsoft’s offerings (see Figure 1-6). Windows XP, Windows XP Embedded, and Windows Vista support the full .NET Framework, while Windows CE supports the .NET Compact Framework. There might be an overlap among the offerings, so two systems might fit well and be good choices for a given application.

The .NET Micro Framework is the smallest .NET platform to date and provides only a subset of the full .NET Framework and .NET Compact Framework. While Windows CE configurations supporting managed code with the.NET Compact Framework require at least 12MB of RAM, the .NET Micro Framework running directly on targeted hardware requires less than 100KB of RAM The smallest currently available module with the.NET Micro Framework built in is a headless device with a 72MHz ARM7 Core, 96KB RAM, 512KB Flash memory, and a power consumption of 10mA with all hardware components enabled.

The .NET Micro Framework requires a 32-bit processor. Although common embedded programming in assembly language or C still takes place on 16-bit or even 8-bit processors, improved production techniques have reduced the manufacturing costs and power requirements of 32-bit processors. However, the fact that the .NET Micro Framework does not require an MMU means it can run on less expensive processors than Windows CE can.


What the Framework Is Not
The .NET Micro Framework is not a real-time system. Although it is very fast and suitable for most applications, do not expect real-time deterministic behavior. A timer event might not be triggered exactly after the specified amount of time (varying by some milliseconds), or the runtime environment might take a few milliseconds to react to an interruption provoked by an interrupt service routine. Also, the garbage collector will run to free unused memory when memory gets low. Garbage collection might block all threads for a few milliseconds. You should also be aware that executing managed code is a bit slower than executing native code. With the .NET Micro Framework, all managed code is interpreted. There is no just-in-time compiler that compiles managed code parts to native machine code on the first execution, as there is for the full .NET Framework and .NET Compact Framework.


Downloading a Free Development Environment
The .NET Micro Framework SDK is available for download at no cost. To develop for the .NET Micro Framework, you need Microsoft Visual Studio 2008. It is also possible to use the free Express Editions for Visual C#. The .NET Micro Framework is a free add-in that can be integrated with the free Express Edition of Microsoft Visual Studio development environment. You can find more information and a download link at www.microsoft.com/express/vcsharp/Default.aspx.
Combining these development tools with the extensible hardware emulator of the .NET Micro Framework SDK enables you to start playing around immediately with the .NET Micro Framework—at no cost.


Licensing the .NET Micro Framework
A fee is charged for each device containing the .NET Micro Framework, but the fee is lower than the one for Windows CE. Also, you are not required to pay the fee directly. When you buy ready-to-use prebuilt modules or development boards containing the .NET Micro Framework, the license fee has already been paid to Microsoft. At time of I write this, Microsoft is changing the license model, moving the product from a revenue model to an “open” model. This means the platform is owned and maintained mainly by Microsoft, which will release nearly all the source of the base class library, tools, and porting kit to the public to make the platform broadly accessible. Microsoft will accept contributions from the community, and there will no longer be a runtime fee per device.

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)

Benefits of Managed Code

The .NET Micro Framework contains the TinyCLR. Code that is executed and managed by the CLR is referred to as managed code, whereas code that does not target the CLR is known as unmanaged (native) code. The CLR executes intermediate-language code and provides the following core services and benefits:

• Automatic memory management using a garbage collector
• Thread management and synchronization
• Exception handling
• Strict type safety
• Secure and robust managed code
• Debugging services

The CLR uses a garbage collector that automatically frees unused memory blocks and manages threads by providing time slices to the individual threads and methods to synchronize access to shared resources. Managed code is executed under the control of the CLR, which takes care of references to objects, so you do not have to deal with the unsafe pointers that are common with native programming. With managed code, you can’t access memory blocks once they’ve been disposed of because the CLR frees objects only when they are not referenced anymore. It also enforces strict type safety, and the TinyCLR prevents execution of unsafe, nonsystem native code. Together with exception handling, a modern way to handle errors, managed code enables you to build secure and robust applications. Managed code assemblies contain much information (metadata). Therefore, using managed code also allows you to use static code analysis tools like FxCop to detect and enforce good programming practices such as:

• Enforcing consistent naming of classes and methods
• Detecting unused code
• Detecting performance issues
• Detecting design issues

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)

Embedded Development in the Past

Developing an embedded device from scratch and programming it with C++, C, or even assembly language can be challenging. Embedded developers are used to writing code that interfaces directly with the hardware. Running the software written for one controller on another platform will not work, even if the CPU core is the same. Every board has different buses, interrupt controllers, memory, and I/O interfaces. The tools and development environments for embedded development are not very easy-to-use or complete even today. Also, every CPU vendor provides its own compiler and development tools, and simulating hardware and debugging embedded applications on your development PC is hard.



A Different Approach
Standard hardware platforms with the .NET Micro Framework already on board provide a different approach. The .NET Micro Framework hardware features ready-to-use single-board computers with common hardware components such as memory, general purpose input/output (GPIO) ports, serial ports, and a display on board. The code to interface with the hardware components is already complete. You just need to write your application, and you can focus on domain-specific problems. The .NET Micro Framework abstracts hardware access through its base class library and treats hardware components as objects. That enables you to program hardware components in an objectorientated way. Instead of dealing with hardware details and setting bit masks to configure peripheral hardware, you just need to set the properties of an object. This approach is also referred to as a managed driver approach and will help make your embedded application independent from a particular platform. .NET Micro Framework applications can be programmed using C# and Visual Studio, Microsoft’s ubiquitous state-of-the-art development tool. If you are already programming .NET applications for the desktop, smartphones, or PDAs, you can continue using your everyday development tool. C# is a modern high-level programming language that allows you to write clear and reusable object-orientated code. With the .NET Micro Framework, every developer familiar with the .NET base class library and tools can also be an embedded developer!

Like the full .NET Framework and the .NET Compact Framework, the .NET Micro Framework runs managed code. The C# compiler generates a processor-independent intermediate language that the TinyCLR executes on the device. The next section describes the benefits of managed code.

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)

What Is the .NET Micro Framework?

The Microsoft .NET Micro Framework is a small and efficient .NET runtime environment used to run managed code on devices that are too small and resource-constrained for Windows CE and the .NET Compact Framework.

The .NET Micro Framework enables you to write embedded applications for small, connected, embedded devices with Visual Studio and C#. The .NET Micro Framework, .NET Compact Framework, and full .NET Framework are so similar that you can now use the same development tools and language that you use to build desktop and smart device (PDA and smartphone) applications to develop applications for microcontrollers. The .NET Micro Framework also provides an extensible hardware emulator for rapid prototyping and debugging.

The .NET Micro Framework requires no underlying operating system. A scaled-down version of the Common Language Runtime (TinyCLR) sits directly on the hardware, so the framework is often called a bootable runtime. The runtime has a small footprint; it uses only a few hundred kilobytes of RAM, and it does not require the processor to have a memory management unit (MMU). Therefore, the .NET Micro Framework can run on small and inexpensive 32-bit processors without consuming a lot of power.



.NET Micro Framework History
Let’s take a look at the history and versions of the .NET Micro Framework:

• Smart Personal Object Technology (SPOT) started at Microsoft Research in 2001. David Massarenti developed the first proof-of-concept version of a scaled-down and ECMAcompliant CLR, the TinyCLR.

• Smart watches first shipped in 2004 (see Figure 1-1) and Microsoft TV set top boxes in 2005. However, both smart watches and Microsoft TV set top boxes based on SPOT have been discontinued.

• The .NET Micro Framework 1.0 on Sumo robots (see Figure 1-2), which included a Sumo robot emulator, was presented at the 2006 Mobile and Embedded Developers Conference (MEDC);
the conference also featured a Sumo robot contest.

• In February 2007, the .NET Micro Framework 2.0, with a customizable emulator, was released. Some development boards (see Figure 1-3) and devices (see Figure 1-4) were available, and others followed in 2007. You will learn more about the available development boards and hardware platforms in the next chapter.

• In 2007, Microsoft presented Windows SideShow, which is based on the .NET Micro Framework, and hardware manufacturers started shipping Windows SideShow-capable devices.

• Later in 2007, Service Pack 1 for the .NET Micro Framework 2.0 was released.

• In February 2008, Microsoft released the .NET Micro Framework 2.5.

• In October 2008, Microsoft released the .NET Micro Framework 3.0.

Source of Information : Apress Expert Dot NET Micro Framework 2nd Edition (09-2009)


Subscribe to Developer Techno ?
Enter your email address:

Delivered by FeedBurner