Welcome!

Microsoft Cloud Authors: Andreas Grabner, Stackify Blog, Liz McMillan, David H Deans, Automic Blog

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

Introduction to Programming for the TinyCLR

Managed code on embedded devices

When most Windows programmers think of embedded development we typically think of the .NET Compact Framework running under Windows CE. While CE and Windows XP Embedded have been the staples of Microsoft's embedded business for years, there's a new entrant known as Smart Personal Object Technology or SPOT.

Most people, if they're aware of SPOT at all, think that it simply equates to the watches available from a handful of watchmakers, but it's actually much more. SPOT is, in a nutshell, any device based on "Ollie" - a 32-bit ARM7 processor core that runs a very, very stripped down Windows OS. What's exciting about it is that right in the processor is a very scaled-down Common Language Runtime (CLR) known as TinyCLR. This means that hobbyists and developers can write managed applications for what is essentially an embedded microcontroller.

SPOT was developed at Microsoft Research as a technology for task-specific devices. Today's Windows CE devices use expensive, high-power processors so they can do a wide range of things from taking notes to displaying maps or playing music and videos.

Below this level of device is a vast array of electronic devices that we use every day that typically do a single thing, don't need a super-fast processor, and need to be inexpensive. These devices need more logic than can be reasonably done with hardware alone, but not a lot more - things like programmable thermostats for your home furnace or an outdoor holiday light system. This is where SPOT is intended to play.

The TinyCLR: A Very Compact Framework

There's already a large array of 8-, 16- and 32-bit microcontrollers available from many manufacturers. What sets SPOT apart is that it leverages the Rapid Application Development (RAD) capabilities Microsoft provides through managed code and Visual Studio 2005. Instead of having to trudge through procedural BASIC, C, or assembly code, developers can quickly write event-driven, multithreaded applications that run in an environment that automatically takes care of memory management and garbage collection.

Folks familiar with managed code development under Windows CE know that they get access only to a subset of the classes and methods available in the Microsoft .NET Framework - what is known as the .NET Compact Framework. Likewise, since the TinyCLR has an even smaller footprint and is designed for devices with limited resources and functionality, SPOT developers have an even more compact framework to use.

While many things have been removed - TinyCLR has no support for WinForms, database access, files, or XML - it retains critical items not available for other microcontroller environments like threading, synchronization objects, RSA and TEA cryptography, and real-time debugging. It also has a whole new set of classes unique to the SPOT environment like the InputPort, OutputPort, and InterruptPort classes that we'll take a look at.

Currently the TinyCLR compiler only supports C# development (you can't even develop in unmanaged code), but as the platform expands and gains popularity, expect VB.NET and C++ to come along as well.

A HelloWorld SPOT Application

The simplest way to get a feel for the similarities of SPOT development and other managed development is to look at an introductory "Hello World" kind of application. Let's take a look at one that's similar to a desktop program, but shows some TinyCLR uniqueness.

Just like the Full and Compact Frameworks, assembly execution starts in a static method called Main. In the example in Listing 1, Main creates a class instance and then calls a method on that instance. The construct is no different than any other managed application.

The class method then outputs some text through the Debug class, which ends up back in Visual Studio's Output window. Just to show the Thread class, between Debug outputs the Thread class is used to stall execution. For Compact Framework developers this sample may be refreshing, as the Compact Framework 1.0 can't send data back to Studio. Otherwise this code is no different than what would be done in the other frameworks.

Finally the sample does something unique to TinyCLR that's easy for anyone who has done any development, managed or otherwise, to understand. It throws an Exception (which isn't the unique part) that's caught back in Main, and the Exception handler uses the Microsoft.SPOT.Debug class to dump both the current stack and the current heap - two extremely useful debugging tools - to the debug the window.

As the example in Listing 1 shows, if you're familiar with developing against either the Full Framework or the Compact Framework you'll be quite comfortable doing development against TinyCLR.

Using the SPOT Processor's Microcontroller Features

Since the SPOT processor is designed to go into applications that traditionally use other 8-, 16- and 32-bit microcontrollers, it only makes sense that most of the uniqueness that SPOT classes have are related to the workhorse functionality of microcontrollers: interrupt handling and digital I/O.

The TinyCLR has four classes that encapsulate these basic functionalities. I/O is handled with the InputPort, OutputPort, and TristatePort classes. Interrupts are handled using the InterruptPort class.

As the names suggest, the InputPort is used for digital input and the OutputPort is used for digital output. The TristatePort is used when a line must be used for input and output as well as needing a high impedance (high-Z) state. All three support turning on optional internal pull-up or pull-down resistors in the processor. Listings 2 and 3 are short code snippets demonstrating the use of InputPort and OutputPort respectively. Of interest is the CPU class that contains an enumeration for every pin on the processor.

Since a TristatePort is inherently more complex than simple input or output, the code to use it is also a bit more complex, though not overwhelming. The most important aspect to note is that setting the TristatePort.Active property to the value already set (setting it true when already true or false when already false) will throw an exception, so to be safe your code must always check the property before setting it. Listing 4 is a short snippet showing the use of the TristatePort.

The final area that we'll look at is interrupt handling, which is one of the most common features used in microcontroller and embedded applications. When your application needs to be "notified" when the state of a digital line changes without having to poll it constantly, you set up an interrupt. In the TinyCLR this is done with an InterruptPort. The SPOT processor supports both edge and level interrupts and can be used in conjunction with the processor's internal pull up/down resistors. Listing 5 offers an example of setting up an interrupt and EventHandler that will get called with every interrupt event.

Conclusion

The TinyCLR running on the SPOT processor offers OEMs and developers a highly advanced operating environment. Coupled with the industry-leading Rapid Application Development features of Microsoft Visual Studio 2005, it's possible to deliver stable and robust blue-collar, function-specific embedded solutions in a very short time. In a world where time-to-market and reliability are two major factors in product success, these technologies provide a window of opportunity for a whole new generation of developers to move into embedded computing.

More Stories By Chris Tacke

Chris Tacke is a partner with OnWard Technology, a company specializing in smart sensors and SPOT development, and cofounder of OpenNETCF.org, an open source initiative for the .NET Compact Framework. Chris currently lives in Maryland with his wife Erin and two children, Olivia and Garrett.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
SYS-CON Events announced today that Datanami has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Datanami is a communication channel dedicated to providing insight, analysis and up-to-the-minute information about emerging trends and solutions in Big Data. The publication sheds light on all cutting-edge technologies including networking, storage and applications, and the...
SYS-CON Events announced today that EnterpriseTech has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. EnterpriseTech is a professional resource for news and intelligence covering the migration of high-end technologies into the enterprise and business-IT industry, with a special focus on high-tech solutions in new product development, workload management, increased effi...
SYS-CON Events announced today that MobiDev, a client-oriented software development company, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MobiDev is a software company that develops and delivers turn-key mobile apps, websites, web services, and complex software systems for startups and enterprises. Since 2009 it has grown from a small group of passionate engineers and business...
SYS-CON Events announced today that GrapeUp, the leading provider of rapid product development at the speed of business, will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Grape Up is a software company, specialized in cloud native application development and professional services related to Cloud Foundry PaaS. With five expert teams that operate in various sectors of the market acr...
SYS-CON Events announced today that Ayehu will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara California. Ayehu provides IT Process Automation & Orchestration solutions for IT and Security professionals to identify and resolve critical incidents and enable rapid containment, eradication, and recovery from cyber security breaches. Ayehu provides customers greater control over IT infras...
Artificial intelligence, machine learning, neural networks. We’re in the midst of a wave of excitement around AI such as hasn’t been seen for a few decades. But those previous periods of inflated expectations led to troughs of disappointment. Will this time be different? Most likely. Applications of AI such as predictive analytics are already decreasing costs and improving reliability of industrial machinery. Furthermore, the funding and research going into AI now comes from a wide range of com...
In this presentation, Striim CTO and founder Steve Wilkes will discuss practical strategies for counteracting fraud and cyberattacks by leveraging real-time streaming analytics. In his session at @ThingsExpo, Steve Wilkes, Founder and Chief Technology Officer at Striim, will provide a detailed look into leveraging streaming data management to correlate events in real time, and identify potential breaches across IoT and non-IoT systems throughout the enterprise. Strategies for processing massive ...
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organi...
SYS-CON Events announced today that Cloud Academy named "Bronze Sponsor" of 21st International Cloud Expo which will take place October 31 - November 2, 2017 at the Santa Clara Convention Center in Santa Clara, CA. Cloud Academy is the industry’s most innovative, vendor-neutral cloud technology training platform. Cloud Academy provides continuous learning solutions for individuals and enterprise teams for Amazon Web Services, Microsoft Azure, Google Cloud Platform, and the most popular cloud com...
SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
SYS-CON Events announced today that TMC has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo and Big Data at Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Global buyers rely on TMC’s content-driven marketplaces to make purchase decisions and navigate markets. Learn how we can help you reach your marketing goals.
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that IBM has been named “Diamond Sponsor” of SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California.
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
We build IoT infrastructure products - when you have to integrate different devices, different systems and cloud you have to build an application to do that but we eliminate the need to build an application. Our products can integrate any device, any system, any cloud regardless of protocol," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held November 1-3, 2016, at the Santa Clara Convention Center in Santa Clara, CA
Multiple data types are pouring into IoT deployments. Data is coming in small packages as well as enormous files and data streams of many sizes. Widespread use of mobile devices adds to the total. In this power panel at @ThingsExpo, moderated by Conference Chair Roger Strukhoff, panelists looked at the tools and environments that are being put to use in IoT deployments, as well as the team skills a modern enterprise IT shop needs to keep things running, get a handle on all this data, and deliver...
The current age of digital transformation means that IT organizations must adapt their toolset to cover all digital experiences, beyond just the end users’. Today’s businesses can no longer focus solely on the digital interactions they manage with employees or customers; they must now contend with non-traditional factors. Whether it's the power of brand to make or break a company, the need to monitor across all locations 24/7, or the ability to proactively resolve issues, companies must adapt to...
SYS-CON Events announced today that Enzu will exhibit at SYS-CON's 21st Int\ernational Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enzu’s mission is to be the leading provider of enterprise cloud solutions worldwide. Enzu enables online businesses to use its IT infrastructure to their competitive advantage. By offering a suite of proven hosting and management services, Enzu wants companies to focus on the core of their ...