<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Barr Code &#187; realtime</title>
	<atom:link href="http://embeddedgurus.com/barr-code/tag/realtime/feed/" rel="self" type="application/rss+xml" />
	<link>http://embeddedgurus.com/barr-code</link>
	<description>A Blog by Michael Barr</description>
	<lastBuildDate>Wed, 18 Apr 2012 19:33:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Trends in Embedded Software Design</title>
		<link>http://embeddedgurus.com/barr-code/2012/04/trends-in-embedded-software-design/</link>
		<comments>http://embeddedgurus.com/barr-code/2012/04/trends-in-embedded-software-design/#comments</comments>
		<pubDate>Wed, 18 Apr 2012 19:27:41 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[outsourcing]]></category>
		<category><![CDATA[processors]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=732</guid>
		<description><![CDATA[In many ways, the story of my career as an embedded software developer is intertwined with the history of the magazine Embedded Systems Design. When it was launched in 1988, under the original title Embedded Systems Programming (ESP), I was finishing high school. Like the vast majority of people at that time, I had never [...]]]></description>
			<content:encoded><![CDATA[<p>In many ways, the story of my career as an embedded software developer is intertwined with the history of the magazine <a href="http://www.eetimes.com/electronics-blogs/4216468/Embedded-Systems-Design-magazine-archive?Ecosystem=embedded" title="Embedded Systems Design Magazine" target="_blank">Embedded Systems Design</a>.  When it was <a href="http://www.ganssle.com/misc/firstesp.pdf" title="First Issue of Embedded Systems Programming" target="_blank">launched in 1988</a>, under the original title Embedded Systems Programming (ESP), I was finishing high school.  Like the vast majority of people at that time, I had never heard the term &#8220;embedded system&#8221; or thought much about the computers hidden away inside other kinds of products.  Six years later I was a degreed electrical engineer who, like many EEs by that time in the mid-90&#8242;s, had a job designing embedded software rather than hardware.  Shortly thereafter I discovered the magazine on a colleague&#8217;s desk, and became a subscriber and devotee.</p>
<p><strong>The Early Days</strong></p>
<p>In the early 1990s, as now, the specialized knowledge needed to write reliable embedded software was mostly not taught in universities.  The only class I&#8217;d had in programming was in FORTRAN; I&#8217;d taught myself to program in assembly and C through a pair of hands-on labs that were, in hindsight, my only formal education in writing embedded software.  It was on the job and from the pages of the magazine, then, that I first learned the practical skills of writing device drivers, porting and using operating systems, meeting real-time deadlines, implementing finite state machines, the pros and cons of languages other than C and assembly, remote debugging and JTAG, and so much more.</p>
<p>In that era, my work as a firmware developer involved daily interactions with Intel hex files, device programmers, tubes of EPROMs with mangled pins, UV erasers, mere kilobytes of memory, 8- and 16-bit processors, in-circuit emulators, and ROM monitors.  Databooks were actual books; collectively, they took up whole bookshelves.  I wrote and compiled my firmware programs on an HP-UX workstation on my desk, but then had to go downstairs to a lab to burn the chips, insert them into the prototype board, and test and debug via an attached ICE.  I remember that on one especially daunting project eight miles separated my compiler and device programmer from the only instance of the target hardware; a single red LED and a dusty oscilloscope were the extent of my debugging toolbox.</p>
<p>Like you I had the Internet at my desk in the mid-90s, but it did not yet provide much useful or relevant information to my work other than via certain FTP sites (does anyone else remember FTPing into <a target="_blank" href="http://en.wikipedia.org/wiki/Ibiblio">sunsite.unc.edu</a>? or Gopher?).  The rest was mostly blinking headlines and dancing hamster; and Amazon was merely the world&#8217;s biggest river.  There was not yet an <a href="http://embedded.com" target="_blank">Embedded.com</a> or <a href="http://eetimes.com" target="_blank">EETimes.com</a>.  To learn about software and hardware best practices, I pursued an MSEE and CS classes at night and traveled to the Embedded Systems Conferences.</p>
<p>At the time, I wasn&#8217;t aware of any books about embedded programming.  And every book that I had found on C started with &#8220;Hello, World&#8221;, only went up in abstraction from there, and ended without ever once addressing peripheral control, interrupt service routines, interfacing to assembly language routines, and operating systems (real-time or other).  For reasons I couldn&#8217;t explain years later when Jack Ganssle asked me, I had the gumption to think I could write that missing book for embedded C programmers, got a contract from O&#8217;Reilly, and did&#8211;ending, rather than starting, mine with &#8220;Hello, World&#8221; (via an RS-232 port).</p>
<p>In 1998, a series of at least three twists of fate spanning four years found me taking a seat next to an empty chair at the speaker&#8217;s lunch at an Embedded Systems Conference.  The chair&#8217;s occupant turned out to be Lindsey Vereen, who was then well into his term as the second editor-in-chief of the magazine.  In addition to the book, I&#8217;d written an article or two for ESP by that time and Lindsey had been impressed with my ability to explain technical nuances.  When he told me that he was looking for someone to serve as a technical editor, I didn&#8217;t realize it was the first step towards my role in that position.  </p>
<p><strong>Future Trends</strong></p>
<p>Becoming and then staying involved with the magazine, first as technical editor and later as editor-in-chief and contributing editor, has been a highlight of my professional life.  I had been a huge fan of ESP and of its many great columnists and other contributors in its first decade.  And now, looking back, I believe my work helped make it an even more valuable forum for the exchange of key design ideas, best practices, and industry learning in its second decade.  And, though I understand the move away from print towards online publishing and advertising, I am nonetheless saddened to see the magazine come to an end.</p>
<p>Reflecting back on these days long past reminds me that a lot truly has changed about embedded software design.  Assembly language is used far less frequently today; C and C++ much more.  EPROMs with their device programmers and UV erasers have been supplanted by flash memory and bootloaders.  Bus widths and memory sizes have increased dramatically.  Expensive in-circuit emulators and ROM monitors have morphed into inexpensive JTAG debug ports.  ROM-DOS has been replaced with whatever Microsoft is branding embedded Windows this year.  And open-source Linux has done so well that it has limited the growth of the RTOS industry as a whole&#8211;and become a piece of technology we all want to master if only for our resumes.</p>
<p>So what does the future hold?  What will the everyday experiences of embedded programmers be like in 2020, 2030, or 2040?  I see three big trends that will affect us all over those timeframes, each of which has already begun to unfold.</p>
<p><strong>Trend 1: Volumes Finally Shift to 32-bit CPUs</strong></p>
<p>My first prediction is that inexpensive, low-power, highly-integrated microcontrollers&#8211;as best exemplified by today&#8217;s <a href="http://en.wikipedia.org/wiki/ARM_Cortex-M" title="ARM Cortex M" target="_blank">ARM Cortex-M</a> family&#8211;will bring 32-bit CPUs into even the highest volume application domains.  The volumes of 8- and 16-bit CPUs will finally decline as these parts become truly obsolete.</p>
<p>Though you may be programming for a 32-bit processor already, it&#8217;s still true that 8- and 16-bit processors still drive CPU chip sales volumes.  I&#8217;m referring, of course, to microcontrollers such as those based on 8051, PIC, and other instruction set architectures dating back 30-40 years.  These older architectures remain popular today only because certain low-margin, high-volume applications of embedded processing demand squeezing every penny out of BOM cost.  </p>
<p>The limitations of 8- and 16-bit architectures impact the embedded programmers in a number of ways.  First, there are the awkward memory limitations resulting from limited address bus widths&#8211;and the memory banks, segmenting techniques, and other workarounds to going beyond those limitations.  Second, these CPUs are much better at decision making than mathematics&#8211;they lack the ability to manipulate large integers efficiently and have no floating-point capability.  Finally, these older processors frequently lack modern development tools, are unable to run larger Internet-enabled operating systems, such as Linux, and don&#8217;t feature the security and reliabiltiy protections afforded by an MMU.</p>
<p>There will, of course, always be many applications that are extremely cost-conscious, so my prediction is not that they will disappear completely, but that the overall price (including BOM cost as well as power consumption) of 32-bit micro controllers, with their improved instruction set architectures and transistor geometries, will win on price.  That will put the necessary amount of computing power into the hands of some designers and make our work easier for all of us.  It also helps programmers accomplish more in less time.</p>
<p><strong>Trend 2: Complexity Forces Programmers Beyond C</strong></p>
<p>My second prediction is that the days of the C programming language&#8217;s dominance in embedded systems are numbered.</p>
<p>Don&#8217;t get me wrong, C is a language I know and love.  But, as you may know firsthand, C is simply not up to the task of building systems requiring over a million lines of code.  Nonetheless, the demanded complexity of embedded software has been driving our systems towards more than a million lines of code. At this level of complexity, something has to give.</p>
<p>Additionally, our industry is facing a crisis: the average age of an embedded developer is rapidly increasing and C is generally not taught in universities anymore.  Thus, even as the demand for embedded intelligence in every industry continues to increase, the population of skilled and experienced C programmers is on the decline.  Something has to give on this front too.</p>
<p>But what alternative language can be used to build real-time software, manipulate hardware directly, and be quickly ported to numerous instruction set architectures?  It&#8217;s not going to be C++ or Ada or Java, for sure&#8211;as those have already been tried and found lacking.  A new programming language is probably not the answer either, across so many CPU families and with so many other languages already tried.</p>
<p>Thus I predict that tools that are able to reliably generate those millions of lines of C code automatically for us, based on system specifications, will ultimately take over.  As an example of a current tool of this sort that could be part of the trend, I direct your attention to Miro Samek&#8217;s dandy open source <a href="http://state-machine.com/qp/index.php" title="State Machine Frameworks for Embedded Systems" target="_blank">Quantum Platform (QP) framework for event-driven programs</a> and his (optional) free <a href="http://state-machine.com/qm/index.php" title="UML Modeling Tool" target="_blank">Quantum Modeler (QM) graphical modeling tool</a>.  You may not like the idea of auto-generated code today, but I guarantee that once you push a button to generate consistent and correct code from an already expressive statechart diagram, you will see the benefits of the overall structure and be ready to move up a level in programming efficiency.</p>
<p>I view C as a reasonable common output language for such tools (given that C can manipulate hardware registers directly and that every processor ever invented has a C compiler).  Note that I do expect there to be continued demand for those of us with the skills and interest to fine tune the performance of the generated code or write device drivers to integrate it more closely to the hardware. </p>
<p><strong>Trend 3: Connectivity Drives Importance of Security</strong></p>
<p>We&#8217;re increasingly connecting embedded systems&#8211;to each other and to the Internet.  You&#8217;ve heard the hype (e.g., &#8220;Internet of things&#8221; and &#8220;ubiquitous computing&#8221;) and you&#8217;ve probably already also put TCP/IP into one or more of your designs.  But connectivity has a lot of implications that we are only starting to come to terms with.  The most obvious of these is security.</p>
<p>A connected device cannot hide for long behind &#8220;security through obscurity&#8221; and, so, we must design security into our connected devices from the start.  In my travels around our industry I&#8217;ve observed that the majority of embedded designers are largely unfamiliar with security.  Sure some of you have read about encryption algorithms and know the names of a few.  But mostly the embedded community is shooting in the dark as security designers, within organizations that aren&#8217;t of much help.  And security is only as strong as the weakest link in the chain.</p>
<p>This situation must change.  Just as Flash memory has supplanted UV-erasable EPROM, so too will over-the-net patches and upgrades take center stage as a download mechanism in coming years and decades.  We must architect our systems first to be secure and then to accepted trusted downloads so that our products can keep up in the inevitable arms race against hackers and attackers.</p>
<p><strong>And That&#8217;s a Wrap</strong></p>
<p>Whatever the future holds, I am certain that embedded software development will remain an engaging and challenging career.  And you&#8217;ll still find me writing about the field at http://embeddedgurus.com/barr-code and http://twitter.com/embeddedbarr.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2012/04/trends-in-embedded-software-design/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Building Reliable and Secure Embedded Systems</title>
		<link>http://embeddedgurus.com/barr-code/2012/03/building-reliable-and-secure-embedded-systems/</link>
		<comments>http://embeddedgurus.com/barr-code/2012/03/building-reliable-and-secure-embedded-systems/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 10:49:45 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=710</guid>
		<description><![CDATA[In this era of 140 characters or less, it has been well and concisely stated that, &#8220;RELIABILITY concerns ACCIDENTAL errors causing failures, whereas SECURITY concerns INTENTIONAL errors causing failures.&#8221; In this column I expand on this statement, especially as regards the design of embedded systems and their place in our network-connected and safety-concious modern world. [...]]]></description>
			<content:encoded><![CDATA[<p><em>In this era of 140 characters or less, it has been well and concisely stated that, &#8220;RELIABILITY concerns ACCIDENTAL errors causing failures, whereas SECURITY concerns INTENTIONAL errors causing failures.&#8221;  In this column I expand on this statement, especially as regards the design of embedded systems and their place in our network-connected and safety-concious modern world.</em></p>
<p>As the designers of embedded systems, the first thing we must accomplish on any project is to make the hardware and software work.  That is to say we need to make the system behave as it was designed to.  The first iteration of this is often flaky; certain uses or perturbations of the system by testers can easily dislodge the system into a non-working state.  In common parlance, &#8220;expect bugs.&#8221;  </p>
<p>Given time, tightening cycles of debug and test can get us past the bugs and through to a shippable product.  But is a debugged system good enough?  Neither reliability nor security can be tested into a product.  Each must be designed in from the start.  So let&#8217;s take a closer look at these two important design aspects for modern embedded systems and then I&#8217;ll bring them back together at the end.</p>
<p><strong>Reliable Embedded Systems</strong></p>
<p>A product can be stable yet lack reliability.  Consider, for example, an anti-lock braking computer installed in a car.  The software in the anti-lock brakes may be bug-free, but how does it function if a critical input sensor fails?</p>
<p>Reliable systems are robust in the face of adverse run-time environments.  Reliable systems are able to work around errors encountered as they occur to the system in the field&#8211;so that the number and impact of failures are minimized.  One key strategy for building reliable systems is to eliminate single-points-of-failure.  For example, redundancy could be added around that critical input sensor&#8211;perhaps by adding a second sensor in parallel with the first.</p>
<p>Another aspect of reliability that is under the complete control of designers (at least when they consider it from the start) are the &#8220;fail-safe&#8221; mechanisms.  Perhaps a suitable but lower-cost alternative to a redundant sensor is detection of the failed sensor with a fall back to mechanical braking.</p>
<p><a href="http://en.wikipedia.org/wiki/Failure_mode_and_effects_analysis" title="Failure Modes and Effects Analysis" target="_blank">Failure Mode and Effect Analysis</a> (FMEA) is one of the most effective and important design processes used by engineers serious about designing reliability into their systems.  Following this process, each possible failure point is traced from the root failure outward to its effects.  In an FMEA, numerical weights can be applied to the likelihoods of each failure as well as the seriousness of consequences.  An FMEA can thus help guide you to a cost effective but higher reliability design by highlighting the most valuable places to insert the redundancy, fail-safes, or other elements that reinforce the system&#8217;s overall reliability.</p>
<p>In certain industries, reliability is a key driver of product safety.  And that is why you see these techniques and FMEA and other design for reliability processes being applied by the designers of safety-critical automotive, medical, avionics, nuclear, and industrial systems.  The same techniques can, of course, be used to make any type of embedded system more reliable.</p>
<p>Regardless of your industry, it is typically difficult or impossible to make your product as reliable via patches.  There&#8217;s no way to add hardware like that redundant sensor, so your options may reduce to a fail-safe that is helpful but less reliable overall.  Reliability cannot be patched or tested or debugged into your system.  Rather, reliability must be designed in from the start.</p>
<p><strong>Secure Embedded Systems</strong></p>
<p>A product can also be stable yet lack security.  For example, an office printer is the kind of product most of us purchase and use without giving a minute of thought to security.  The software in the printer may be bug-free, but is it able to prevent a would-be eavesdropper from capturing a remote electronic copy of everything you print, including your sensitive financial documents?</p>
<p>Secure systems are robust in the face of persistent attack.  Secure systems are able to keep hackers out by design.  One key strategy for building secure systems is to validate all inputs, especially those arriving over an open network connection.  For example, security could be added to a printer by ensuring against buffer overflows and encrypting and digitally signing firmware updates.</p>
<p>One of the unfortunate facts of designing secure embedded systems is that the hackers who want to get in only need to find and exploit a single weakness.  Adding layers of security is good, but if even any one of those layers remains fundamentally weak, a sufficiently motivated attacker will eventually find and breach that defense.  But that&#8217;s not an excuse for not trying.</p>
<p>For years, the largest printer maker in the world apparently gave little thought to the security of the firmware in its home/office printers, even as it was putting tens of millions of tempting targets out into the world.  Now <a href="http://events.ccc.de/congress/2011/Fahrplan/track/Hacking/4780.en.html" title="Print Me If You Dare" target="_blank">the security of those printers has been breached by security researchers</a> with a reasonable awareness of embedded systems design.  Said one of the lead researchers, &#8220;We can actually modify the firmware of the printer as part of a legitimate document. It renders correctly, and at the end of the job there&#8217;s a firmware update. &#8230; In a super-secure environment where there&#8217;s a firewall and no access &#8212; the government, Wall Street &#8212; you could send a résumé to print out.&#8221;</p>
<p>Security is a brave new world for many embedded systems designers.  For decades we have relied on the fact that the microcontrollers and Flash memory and real-time operating systems and other less mainstream technologies we use will protect our products from attack.  Or that we can gain enough &#8220;security by obscurity&#8221; by keeping our communications protocols and firmware upgrade processes secret.  But we no longer live in that world.  You must adapt.</p>
<p>Consider the implications of an <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5504804" title="Experimental Security Analysis of a Modern Automobile" target="_blank">insecure design of an automotive safety system that is connected to another Internet-connected computer in the car via CAN</a>;  or the insecure design of an <a href="http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4531149&amp;isnumber=4531132" title="Pacemakers and Implantable Cardiac Defibrillators: Software Radio Attacks and Zero-Power Defenses" target="_blank">implanted medical device</a>; or the insecure design of <em>your</em> product.</p>
<p>Too often, the ability to upgrade a product&#8217;s firmware in the field is the very vector that&#8217;s used to attack.  This can happen even when a primary purpose for including remote firmware updates is motivated by security.  For example, as I&#8217;ve learned in my work as an <a href="http://netrino.com/images/cv-barr.pdf" title="Expert Witness Resume" target="_blank">expert witness</a> in numerous cases involving reverse engineering of the techniques and technology of satellite television piracy, much of that piracy has been empowered by the same software patching mechanism that allowed the broadcasters to perform security upgrades and electronic countermeasures.  Ironically, had the security smart cards in those set-top boxes had only masked ROM images the overall system security may have been higher.  This was certainly not what the designers of the system had in mind.  But security is also an arms race.</p>
<p>Like reliability, security must be designed in from the start.  Security can&#8217;t be patched or tested or debugged in.  You simply can&#8217;t add security as effectively once the product ships.  For example, an attacker who wished to exploit a current weakness in your office printer or smart card might download his hack software into your device and write-protect his sectors of the flash today so that his code could remain resident even as you applied security patches.</p>
<p><strong>Reliable and Secure Embedded Systems</strong></p>
<p>It is important to note at this point that reliable systems are inherently more secure.  And that, vice versa, secure systems are inherently more reliable.  So, although, design for reliability and design for security will often individually yield different results&#8211;there is also an overlap between them.  </p>
<p>An investment in reliability, for example, generally pays off in security.  Why?  Well, because a more reliable system is more robust in its handling of all errors, whether they are accidental or intentional.  An anti-lock braking system with a fall back to mechanical braking for increased reliability is also more secure against an attack against that critical hardware input sensor.  Similarly, those printers wouldn&#8217;t be at risk of fuser-induced fire in the case of a security breach if they were never at risk of fire in the case of any misbehavior of the software.</p>
<p>Consider, importantly, that one of the first things a hacker intent on breaching the security of your embedded device might do is to perform a (mental, at least) <a href="http://www.fault-tree.net/papers/ericson-fta-tutorial.pdf" title="Fault Tree Analysis" target="_blank">fault tree analysis</a> of your system.  This attacker would then target her time, talents, and other resources at one or more single points of failure she considers most likely to fail in a useful way.  </p>
<p>Because a fault tree analysis starts from the general goal and works inward deductively toward the identification of one or more choke points that might produce the desired erroneous outcome, attention paid to increasing reliability such as via FMEA usually reduces choke points and makes the attacker&#8217;s job considerably more difficult.  Where security can break down even in a reliable system is where the possibility of an attacker&#8217;s intentionally induced failure is ignored in the FMEA weighting and thus possible layers of protection are omitted.</p>
<p>Similarly, an investment in security may pay off in greater reliability&#8211;even without a directed focus on reliability.  For example, if you secure your firmware upgrade process to accept only encrypted and digitally signed binary images you&#8217;ll be adding a layer of protection against an inadvertently corrupted binary causing an accidental error and product failure.  Anything you do to improve the security of communications (i.e., checksums, prevention of buffer overflows, etc.) can have a similar effect on reliability.</p>
<p><strong>The Only Way Forward</strong></p>
<p>Each year it becomes increasingly important for all of us in the embedded systems design community to learn to design reliable and secure products.  If you don&#8217;t, it might be your product making the wrong kind of headlines and your source code and design documents being poured over by lawyers.  It is no longer acceptable to stick your head in the sand on these issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2012/03/building-reliable-and-secure-embedded-systems/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Embedded Software Training in a Box</title>
		<link>http://embeddedgurus.com/barr-code/2011/05/embedded-software-training-in-a-box/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/05/embedded-software-training-in-a-box/#comments</comments>
		<pubDate>Fri, 06 May 2011 15:40:02 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Efficient C/C++]]></category>
		<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[RTOS Multithreading]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=614</guid>
		<description><![CDATA[I am beaming with pride. I think we have finally achieved the holy grail of firmware training: Embedded Software Training in a Box. Priced at just $599, the kit includes Everything-You-Need-to-Know-to-Develop-Quality-Reliable-Firmware-in-C, including software for real-time safety-critical systems such as medical devices. In many ways, this product is the culmination of about the last fifteen years [...]]]></description>
			<content:encoded><![CDATA[<p><img align="right" src="http://netrino.com/images/BootCampKit.jpg" alt="Embedded Software Training in a Box" />I am beaming with pride. I think we have finally achieved the holy grail of firmware training: <a href="http://netrino.com/Boot-Camp-Box">Embedded Software Training in a Box</a>. Priced at just $599, the kit includes Everything-You-Need-to-Know-to-Develop-Quality-Reliable-Firmware-in-C, including software for real-time safety-critical systems such as medical devices.</p>
<p>In many ways, this product is the culmination of about the last fifteen years of my career. The knowledge and skills imparted in the kit are drawn from my varied experiences as:</p>
<ul>
<li>An embedded software developer working on real products from consumer electronics to medical devices,</li>
<li>An author (you get copies of <a href="http://netrino.com/Embedded-Systems/Books">all three of my books</a> and the most relevant of <a href="http://netrino.com/Embedded-Systems/How-To">my sixty-odd articles</a>),</li>
<li>As a speaker at the <a href="http://esc.eetimes.com">Embedded Systems Conferences</a> since 1998,</li>
<li>Developer of the <a href="http://netrino.com/Boot-Camp">Embedded Software Boot Camp</a> training materials,</li>
<li>As a former technical editor and editor-in-chief of <a href="http://embedded.com">Embedded Systems Design</a> magazine.</li>
</ul>
<p>This kit also&#8211;at long last&#8211;answers the question I&#8217;ve been receiving from around the world since I first started writing articles and books about embedded programming: &#8220;Where/How can I learn to be a great embedded programmer?&#8221; I believe the answer is now as easy as: &#8220;<a href="http://netrino.com/Boot-Camp-Box">Embedded Software Boot Camp in a Box</a>!&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/05/embedded-software-training-in-a-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Beer and Boards at ESC Silicon Valley</title>
		<link>http://embeddedgurus.com/barr-code/2011/04/beer-and-boards-at-esc-silicon-valley/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/04/beer-and-boards-at-esc-silicon-valley/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 00:52:05 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=609</guid>
		<description><![CDATA[It really looks like I&#8217;ve picked the wrong year to miss ESC Silicon Valley (due to a schedule conflict). (The last time I wasn&#8217;t at ESC, it was 1997 and White Zombie was still together. The first thing I&#8217;d really liked to have seen is Steve Wozniak&#8216;s keynote speech. The second thing I&#8217;m really sad [...]]]></description>
			<content:encoded><![CDATA[<p>It really looks like I&#8217;ve picked the wrong year to miss <a href="http://esc.eetimes.com/siliconvalley/">ESC Silicon Valley</a> (due to a schedule conflict). (The last time I wasn&#8217;t at ESC, it was 1997 and <a href="http://en.wikipedia.org/wiki/White_Zombie_(band)">White Zombie</a> was still together.  The first thing I&#8217;d really liked to have seen is <a href="http://en.wikipedia.org/wiki/Steve_Wozniak">Steve Wozniak</a>&#8216;s keynote speech. The second thing I&#8217;m really sad to miss is the just announced &#8220;Beer and Boards&#8221; party/giveaway.</p>
<p><a href="http://esc.eetimes.com/siliconvalley/boards_beer">Beer and Boards</a> sounds really fun. Here&#8217;s how it works: Every &#8220;All Access&#8221; attendee will get to choose one of three free development kits to take home:</p>
<ul>
<li><a href="http://focus.ti.com/lit/ug/swru270a/swru270a.pdf">TI CC2540DK-MINI Bluetooth Low Energy Kit</a></li>
<li><a href="http://www.element14.com/community/groups/xl-star">XL_STAR MMA8451 Accelerometer Kit</a></li>
<li><a href="http://www.em.avnet.com/ctf_shared/evk/df2df2usa/xlx-s6-lx9-microboard-pb020411.pdf">Xilinx Spartan-6 FPGA LX9 MicroBoard Kit</a></li>
</ul>
<p>Once you select your preferred kit you will receive information on the time and place for the relevant Beer and Boards party, at which you will get to drink free beer at a special meet-and-greet with one of your kit&#8217;s designers to talk about your new kit and its capabilities. Three boards spread out over three days.</p>
<p>Nerds drinking beer! I love it. What will they think of next?</p>
<p>Before you register for this year&#8217;s ESC, be sure to check out my earlier post <a href="http://embeddedgurus.com/barr-code/2011/03/save-big-on-embedded-systems-conference-registration/">Save Big on Embedded Systems Conference Registration</a>. Also, remember to use the promo code BARR20 to save an additional 20% off registration and be entered to win a free seat at a future <a href="http://netrino.com/Boot-Camp">Embedded Software Boot Camp</a> or one of 20 free copies of the <a href="http://netrino.com/Coding-Standard">Embedded C Coding Standard</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/04/beer-and-boards-at-esc-silicon-valley/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What NHTSA/NASA Didn&#8217;t Consider re: Toyota&#8217;s Firmware</title>
		<link>http://embeddedgurus.com/barr-code/2011/03/what-nhtsanasa-didnt-consider-re-toyotas-firmware/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/03/what-nhtsanasa-didnt-consider-re-toyotas-firmware/#comments</comments>
		<pubDate>Wed, 02 Mar 2011 23:10:54 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=548</guid>
		<description><![CDATA[In a blog post yesterday (Unintended Acceleration and Other Embedded Software Bugs), I wrote extensively on the report from NASA&#8217;s technical team regarding their analysis of the embedded software in Toyota&#8217;s ETCS-i system. My overall point was that it is hard to judge the quality of their analysis (and thereby the overall conclusion that the [...]]]></description>
			<content:encoded><![CDATA[<p>In a blog post yesterday (<a href="/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/">Unintended Acceleration and Other Embedded Software Bugs</a>), I wrote extensively on the report from NASA&#8217;s technical team regarding their analysis of the embedded software in Toyota&#8217;s ETCS-i system. My overall point was that it is hard to judge the quality of their analysis (and thereby the overall conclusion that the software isn&#8217;t to blame for unintended accelerations) given the large number of redactions.</p>
<p>I need to put the report down and do some other work at this point, but I have a few other thoughts and observations worth writing down.</p>
<p><strong>Insufficient Explanations</strong></p>
<p>First, some of the explanations offered by Toyota, and apparently accepted by NASA, strike me as insufficent.  For example, at pages 129-132 of <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NASA_FR_Appendix_A_Software.pdf">Appendix A</a> to the NASA Report there is a discussion of <a href="http://en.wikipedia.org/wiki/Recursion">recursion</a> in the Toyota firmware. &#8220;The question then is how to verify that the indirect recursion in the ETCS-i does in fact terminate (i.e., has no infinite recursion) and does not cause a stack overflow.&#8221; </p>
<blockquote><p>
&#8220;For the case of stack overflow, [redacted phrase], and therefore a stack overflow condition cannot be detected precisely. It is likely, however, that overflow would cause some form of memory corruption, which would in turn cause some <strong>bad behavior</strong> that would then cause a watchdog timer reset. Toyota relies on this assumption to claim that stack overflow does not occur because no reset occurred during testing.&#8221; (emphasis added)
</p></blockquote>
<p>I have written about what really happens during stack overflow before (<a href="http://embeddedgurus.com/barr-code/2010/03/firmware-specific-bug-4-stack-overflow/">Firmware-Specific Bug #4: Stack Overflow</a>) and this explains why a reset may not result and also why it is so hard to trace a stack overflow back to that root cause. (From page 20, in NASA&#8217;s words: &#8220;The system stack is limited to just 4096 bytes, it is therefore important to secure that no execution can exceed the stack limit. This type of check is normally simple to perform in the absence of recursive procedures, which is standard in safety critical embedded software.&#8221;)</p>
<p>Similarly, &#8220;Toyota designed the software with a high margin of safety with respect to deadlines and timeliness. &#8230; [but] documented no formal verification that all tasks actually meet this deadline requirement.&#8221; and &#8220;All verification of timely behavior is accomplished with CPU load measurements and other measurement-based techniques.&#8221; It&#8217;s not clear to me if the NASA team is saying it buys those Toyota explanations or merely wanted to write them down. However, I do not see a sufficient explanation in this wording from page 132:</p>
<blockquote><p>
&#8220;The [worst case execution time] analysis and recursion analysis involve two distinctly different problems, but they have one thing in common: Both of their failure modes would result in a CPU reset. &#8230; These potential malfunctions, and many others such as concurrency deadlocks and CPU starvation, would <strong>eventually</strong> manifest as a spontaneous system reset.&#8221; (emphasis added)
</p></blockquote>
<p>Might not a <a href="http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-7-deadlock/">deadlock</a>, starvation, <a href="http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-8-priority-inversion/">priority inversion</a>, or infinite recursion be capable of producing a bit of &#8220;bad behavior&#8221; (perhaps even unintended acceleration) before that &#8220;eventual&#8221; reset? Or might not a stack overflow just corrupt one or a few important variables a little bit and that result in bad behavior rather than or before a result? These kinds of possibilities, even at very low probabilities, are important to consider in light of NASA&#8217;s calculation that the U.S.-owned Camry 2002-2007 fleet alone is running this software a cumulative one billion hours per year.</p>
<p><strong>Paths Not Taken</strong></p>
<p>My second observation is based upon reflection on the steps NASA might have taken in its review of Toyota&#8217;s ETCS-i firmware, but apparently did not. Specifically, there is no mention anywhere (unless it was entirely redacted) of: </p>
<ul>
<li><a href="http://www.netrino.com/Embedded-Systems/How-To/RMA-Rate-Monotonic-Algorithm">rate monotonic analysis</a>, which is a technique that Toyota could have used to validate the critical set of tasks with deadlines and higher priority ISRs (and that NASA could have applied in its review),</li>
<li><a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatic complexity</a>, which NASA might have used as an additional winnowing tool to focus its limited time on particularly complex and hard to test routines,</li>
<li><a href="http://www.fda.gov/MedicalDevices/DeviceRegulationandGuidance/GuidanceDocuments/ucm089543.htm">hazard analysis and mitigation</a>, as those terms are defined by FDA guidelines regarding software contained in medical devices, nor</li>
<li>any discussion or review of Toyota&#8217;s specific software testing regimen and bug tracking system.
</ul>
<p>Importantly, there is also a complete absence of discussion of how Toyota&#8217;s ETCS-i firmware versions evolved over time. Which makes and models (and model years) had which versions of that firmware? (Presumably there were also hardware changes worthy of note.) Were updates or patches ever made to cars once they were sold, say while at the dealer during official recalls or other types of service?</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/03/what-nhtsanasa-didnt-consider-re-toyotas-firmware/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Unintended Acceleration and Other Embedded Software Bugs</title>
		<link>http://embeddedgurus.com/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/</link>
		<comments>http://embeddedgurus.com/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 19:09:54 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Coding Standards]]></category>
		<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[ethics]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[outsourcing]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[standards]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=517</guid>
		<description><![CDATA[Last month, NHTSA and the NASA Engineering and Safety Center (NESC) published reports of their joint investigation into the causes of unintended acceleration in Toyota vehicles. NASA&#8217;s multi-disciplinary NESC technical team was asked, by Congress, to assist NHTSA by performing a review of Toyota&#8217;s electronic throttle control and the associated embedded software. In carefully worded [...]]]></description>
			<content:encoded><![CDATA[<p>Last month, <a href="http://www.nhtsa.dot.gov">NHTSA</a> and the <a href="http://www.nasa.gov/offices/nesc/home/index.html">NASA Engineering and Safety Center (NESC)</a> published reports of their joint investigation into the causes of unintended acceleration in Toyota vehicles. NASA&#8217;s multi-disciplinary NESC technical team was asked, by Congress, to assist NHTSA by performing a review of Toyota&#8217;s electronic throttle control and the associated embedded software. In carefully worded concluding statement, NASA stated that it &#8220;found no electronic flaws in Toyota vehicles capable of producing the large throttle openings required to create dangerous high-speed unintended acceleration incidents.&#8221; (The official reports and a number of supporting files are available for download at <a href="http://www.nhtsa.gov/UA">http://www.nhtsa.gov/UA</a>.)</p>
<p>The first thing you will notice if you join me in trying to judge the technical issues for yourself are the redactions: pages and pages of them. In parts and entirely for unexplained reasons, this report on automotive electronics reads like the public version of a CIA Training Manual. I&#8217;ve observed that approximately 193 of the 1,061 pages released so far feature some level of redaction (via black boxes, which obscure from a single number, word, or phrase to a full table, page, or section). The redactions are at their worst in NASA&#8217;s <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NASA_FR_Appendix_A_Software.pdf">Appendix A</a>, which describes NASA&#8217;s review of Toyota&#8217;s embedded software in detail. More than half of all the pages with redactions (including the vast majority of fully redacted tables, pages, and sections) are in that Appendix.</p>
<p>Despite the redactions, we can still learn some interesting facts about Toyota&#8217;s embedded software and NASA&#8217;s technical review of the same.  The bulk of the below outlines what I&#8217;ve been able to make sense of in about two days of reading.  Throughout, my focus is on embedded software inside the electronic throttle control, so I&#8217;m leaving out considerations of other potential causes, including EMI (which NASA also investigated).  First a little background on the investigation.</p>
<p><strong>Background</strong></p>
<p>Although the inquiry was taken to examine unintended acceleration reports across all Toyota, Scion, and Lexus models, NASA focused its technical inquiry almost entirely on Toyota Camry models equipped with the <em>Electronic Throttle Control System, Intelligent</em> (ETCS-i). The Camry has long been among the top cars bought in the U.S., so this choice probably made finding relevant complaint data and affected vehicles easier for NHTSA. (BTW, NASA says the voluntary complaint database shows both that unintended accelerations were reported before the introduction of electronic throttle control and that press coverage and Congressional hearings can increase the volume of complaints.)</p>
<p>According to a press release by the company made upon publication of the NHTSA and NASA reports, Toyota&#8217;s ETCS-i has been installed in &#8220;more than 40 million cars and trucks sold around the world, including more than 16 million in the United States.&#8221; Undoubtedly, ETCS-i has also &#8220;made possible significant safety advances such as vehicle stability control and traction control.&#8221; But as with any other embedded system there have been refinements made through the years to both the electronics and the embedded software. </p>
<p>Though Toyota apparently made available, under agreed terms and via its attorneys, schematics, design documents, and source code &#8220;for multiple Camry years and versions&#8221; (Appendix A, p. 9) as well as many of the Japanese engineers involved in its design and evolution, NASA only closely examined one version. In NASA&#8217;s words, &#8220;The area of emphasis will be the 2005 Toyota Camry because this vehicle has a consistently high rate of reported &#8216;UA events&#8217; over all Toyota models and all years, when normalized to the number of each model and year, according to NHTSA data.&#8221; (p. 7) Except as otherwise stated, everything else in this column concerns the electronics and firmware found in that year, make, and model.</p>
<p><strong>Event Data Recorders</strong></p>
<p>Event Data Recorder (EDR) is the generic term for the automotive equivalent of an aircraft black box <a href="http://en.wikipedia.org/wiki/Flight_data_recorder">flight data recorder</a>. EDRs were first installed in cars in the early 1990s and have increased in use as well as sophistication in the years since. Generally speaking, the event data recorder is an embedded system residing within the airbag control module located in the front center of the engine compartment. The event data recorder is connected to other parts of the car&#8217;s electronics via the CAN bus and is always monitoring vehicle speed, the position of the brake and accelerator pedals, and other key parameters. </p>
<p>In the event of an impossibly high (for the vehicle operating normally) acceleration or deceleration sensor reading, Toyota&#8217;s latest event data recorders save the prior five 1Hz samples of these parameters in a non-volatile memory area. Once saved, an event record can be read over the car&#8217;s On-Board Diagnostics (OBD) port (or, in the event of a more severe accident, directly from the airbag control module) via a special cable and PC software. If the airbag actually deploys, the event record will be permanently locked. The last 2 or 3 (depending on version) lesser &#8220;bump&#8221; records are also stored, but may be overwritten in a FIFO manner.</p>
<p>This investigation of Toyota&#8217;s unintended acceleration marked the first time that anyone from NHTSA had ever read data from a Toyota event data recorder. (Toyota representatives apparently testified in Congress that there had previously just been one copy of the necessary PC software in the U.S.) As part of this study, NHTSA validated and used tools provided by Toyota to extract historical data from 52 vehicles involved in incidents of unintended acceleration, with acknowledged bias toward geographically reachable recent events. After reviewing driver and other witness statements and examining said black box data, NHTSA concluded that 39 of these 52 events were explainable as &#8220;pedal misapplications.&#8221; That&#8217;s a very nice way of saying that whenever the driver reported &#8220;stepping on the brake&#8221; he or she had pressed the accelerator pedal by mistake. Figure 5 of a <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NHTSA-Toyota_EDR_field_inspection.pdf">supplemental report describing these facts</a> portrays an increasing likelihood of such incidents with driver age vs. the bell curve of Camry ownership by age.</p>
<p>Note that no record is apparently ever made, in the event data recorder or elsewhere, of any events or state changes within the ETCS-i firmware. So-called &#8220;Diagnostic Trouble Codes&#8221; concerning sensor and other hardware failures are recorded in non-volatile memory and the presence of one or more such codes enables the &#8220;Check Engine&#8221; light on the dashboard. But no logging is done of significant software faults, including but not limited to watchdog-initiated resets. </p>
<p><strong>Engine Control Module</strong></p>
<p>ETCS-i is a collection of components and features that was changed in the basic engine design when Toyota switched from mechanical to electronic throttle control. (Electronic throttle control is also known as &#8220;throttle-by-wire&#8221;.) Toyota has used two different types of pedal sensors in the ETCS-i system, always in a redundant fashion. The earlier design, pre-2007, using potentiometers was susceptible to current leakage via growth of <a href="http://nepp.nasa.gov/whisker/">tin whiskers</a>. Though this type of failure was not known to cause sudden high-speed behaviors, it did seem to be associated with a higher number of warranty claims. The newer pedal sensor design uses <a href="http://en.wikipedia.org/wiki/Hall_effect_sensor">Hall effect sensors</a>.</p>
<p>Importantly, the brakes are not a part of the ETCS-i system. In the 2005 Camry, Toyota&#8217;s brake pedal was mechanically controlled. (It may still be.) It appears this is one of the reasons the NASA team felt comfortable with their conclusion that driver reports of wide open throttle behavior that could not be stopped with the brakes were not caused by software failures (alone). &#8220;The NESC team did not find an electrical path from the ETCS-i that could disable braking.&#8221; (<a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NASA-UA_report.pdf">NASA Report</a>, p. 15) It is clear, though, that power assisted brakes lose the enabling vacuum pressure when the throttle is wide open and the driver subsequently pumps the brakes; thus any system failure that opened the throttle could indirectly make bringing the vehicle to a stop considerably harder.</p>
<p>The Engine Control Module at the heart of the ETCS-i consists of a Main-CPU and a Sub-CPU located within a pair of ASICs. The Sub-CPU contains a set of A/D converters that translates raw sensor inputs, such as voltages VPA and VPA1 from the accelerator pedal, into digital position values and sends them to the Main-CPU via a serial interface. In addition, the Sub-CPU monitors the outputs of the Main-CPU and is able to reset (in the manner of a watchdog timer) the Main-CPU.</p>
<p>The Main-CPU is reported to be a <a href="http://america2.renesas.com/docs/files/U14559EJ2V0UM00.pdf">V850E1</a> microcontroller, which is &#8220;a 32-bit RISC CPU core for ASIC&#8221; designed by Renesas (nee NEC). The V850E1 processor has a 64MB program address space, which is part of an overall 4GB linear address space. The Main-CPU also keeps tabs on the Sub-CPU and can reset it if anything is found wrong.</p>
<p>NASA reports that the embedded software in the Main-CPU is written (mostly) in ANSI C and compiled using a <a href="http://www.ghs.com">GreenHills</a> C compiler (Appendix A, p. 14). Furthermore, an <a href="http://en.wikipedia.org/wiki/OSEK">OSEK</a>-compliant real-time operating system with fixed-priority preemptive scheduling is used to manage a redacted (but apparently larger than ten, based on the size of the redaction) number of real-time tasks. The actual firmware development (design, coding and unit testing) was outsourced to <a href="http://www.globaldenso.com/en/">Denso</a> (p. 19). Toyota apparently performed integration testing and ran several commercial and in-house static analysis tools, including <a href="http://www.programmingresearch.com/qac_main.html">QAC</a> (p. 20). The code was written in English, with Japanese comments and design documents, and follows a proprietary Toyota naming convention/coding standard that predates but half overlaps with the 1998 version of <a href="http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx">MISRA-C</a>.</p>
<p><strong>Are There Bugs in Toyota&#8217;s Firmware?</strong></p>
<p>In the NASA Report&#8217;s executive summary it is made clear that &#8220;because proof that the ETCS-i caused the reported UAs was not found does not mean it could not occur.&#8221; (NASA Report, p. 17) The report also states that NASA&#8217;s analysis was time-limited and top-down, remarking &#8220;The Toyota Electronic Throttle Control (ETC) was far more complex than expected involving hundreds of thousands of lines of software code&#8221; and that this <a href="http://www.nhtsa.gov/staticfiles/nvs/pdf/NHTSA-Toyota_peer_review.pdf">affected the quality of a planned peer review</a>.</p>
<p>It&#8217;s stated that &#8220;Reported [Unintended Accelerations (UAs)] are rare events. Typically, the reporting of UAs is about 1/100,000 vehicles/year.&#8221; But there are millions of cars on the road, and so NHTSA has collected some &#8220;831 UA reports for Camry&#8221; alone. &#8220;Over one-half of the reported events described large (greater than 25 degrees) high-throttle opening UAs of unknown cause&#8221; (NASA Report, p. 14), the causes of which are never fully explained in these reports.</p>
<p>The NASA apparently identified some lesser firmware bugs themselves, saying &#8220;[our] logic model verifications identified a number of potential issues. All of these issues involved unrealistic timing delays in the multiprocessing, asynchronous software control flow.&#8221; (Appendix A, p. 11)  NASA also spent time simulating possible <a href="http://embeddedgurus.com/barr-code/2010/02/firmware-specific-bug-1-race-condition/">race conditions</a> due to worrisome &#8220;recursively nested interrupt masking&#8221; (pp, 44-46); note, though, that simulation success is not a sufficient proof of lack of races. As well, the NASA team seems to recommend &#8220;reducing the amount of global data&#8221; (p. 38) and eliminating &#8220;dead code&#8221; (p. 40). </p>
<p>Additionally, the redacted text in other parts of Appendix A seems to be obscuring that:</p>
<ul>
<li>&#8220;<a href="http://gcc.gnu.org/">The standard gcc compiler</a> version 4&#8243; generated a redacted number of warnings (probably larger than 100) about the code, in 11 different warning categories. (p. 25)</li>
<li>&#8220;<a href="http://www.coverity.com/">Coverity</a> version 4.2&#8243; generated a redacted number of warnings (probably larger than 154) about the code, in 10 different warning categories. (p. 27)</li>
<li>&#8220;<a href="http://www.grammatech.com/products/codesonar/">Codesonar</a> version 3.6p1&#8243; generated a redacted number of warnings (probably larger than 136) about the code, in 10 different warning categories.</li>
<li>&#8220;<a href="http://spinroot.com/uno/">Uno</a> version 2.12&#8243; generated a redacted number of warnings (probably larger than 72) about the code, in 9 different warning categories.</li>
<li>The code contained at least 347 deviations from a subset of 14 of the <a href="http://www.misra-c.com/Activities/MISRAC/tabid/160/Default.aspx">MISRA-C rules</a>.</li>
<li>The code contained at least 243 violations of a subset of 9 of the 10 &#8220;<a href="http://spinroot.com/p10">Power of 10&#8211;Rules for Developing Safety Critical Code</a>,&#8221; which was published in IEEE Computer in 2006 by NASA team member Gerard Holzmann.</li>
</ul>
<p>It looks to me like Figure 6.2.3-1 of the NASA Report (p. 30) shows that UA complaints filed with NHTSA increased in the year of introduction of electronic throttle control for the vast majority of Toyota, Scion, and Lexus models&#8211;and that complaint counts have remained higher but generally declined over time since those transitions years. Such a complaint data pattern is perhaps consistent with firmware bugs. (Note to NHTSA: It would be helpful to see this same chart normalized by number of vehicles sold by model year and with the rows sorted by the year of ETC introduction. It would also be nice to see a chart of ETCS-i firmware versions and updates, which vehicles they apply to, and the dates on which each was put into new production vehicles or distributed through dealers.)</p>
<p><strong>Final Thoughts</strong></p>
<p>I am not privy to all of the facts considered by the NHTSA or NASA review teams and thus cannot say if I agree or disagree with their overall conclusion that embedded software bugs are not to blame for reports of unintended acceleration in Toyota vehicles. How about you? If you&#8217;ve spotted something I missed in the reports from NHTSA or NASA, please send me an e-mail or leave a comment below. Let&#8217;s keep the conversation going.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2011/03/unintended-acceleration-and-other-embedded-software-bugs/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Embedded Software Boot Camp in a Box</title>
		<link>http://embeddedgurus.com/barr-code/2010/12/embedded-software-boot-camp-in-a-box/</link>
		<comments>http://embeddedgurus.com/barr-code/2010/12/embedded-software-boot-camp-in-a-box/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 11:59:48 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Efficient C/C++]]></category>
		<category><![CDATA[RTOS Multithreading]]></category>
		<category><![CDATA[education]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[netrino]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=449</guid>
		<description><![CDATA[Whether you are new to embedded software development in C or looking for ways to improve your skills, the Embedded Software Boot Camp in a Box will provide you the hands-on education you need. Exercises are based around an ARM processor board (shown below), the MicroC/OS-II real-time operating system, and the IAR Embedded Workbench compiler/debugger, [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you are new to embedded software development in C or looking for ways to improve your skills, the <a href="http://www.netrino.com/Boot-Camp-Box">Embedded Software Boot Camp in a Box</a> will provide you the hands-on education you need.  Exercises are based around an ARM processor board (shown below), the <a href="http://micrium.com/page/products/rtos/os-ii">MicroC/OS-II</a> real-time operating system, and the <a href="http://www.iar.com/ewarm">IAR Embedded Workbench</a> compiler/debugger, all of which are included in the box.</p>
<div id="attachment_457" class="wp-caption aligncenter" style="width: 390px"><a href="http://embeddedgurus.com/barr-code/files/2010/12/str9121.jpg"><img src="http://embeddedgurus.com/barr-code/files/2010/12/str9121.jpg" alt="STR912-SK" title="ARM Processor Board" width="380" height="310" class="size-full wp-image-457" /></a><p class="wp-caption-text">Learn Embedded Programming on an ARM Processor</p></div>
<p><a href="http://www.netrino.com">Netrino</a>’s popular <a href="http://www.netrino.com/Boot-Camp">Embedded Software Boot Camp</a> (see <a href="http://www.netrino.com/Training-Calendar">upcoming dates</a>), on which this kit is based, is an intense in-person training experience that requires attendees to be able to check out of normal work and life routines for a week—sometimes also travelling a great distance.  The <a href="http://www.netrino.com/Boot-Camp-Box">Embedded Software Boot Camp in a Box</a> is a way to learn the same skills at your own pace.  You’ll do the same exercises and have access to the same materials, just won’t have a “drill instructor” or the clock to prod you. </p>
<p>Here’s how you&#8217;ll use the <a href="http://www.netrino.com/Boot-Camp-Box">Embedded Software Boot Camp in a Box</a> to learn embedded programming:</p>
<ul>
<li>Read the 350 page “Field Manual” book, which contains the slides from the in-person Boot Camps, in order.
<li>If you want to dig deeper, watch the video of <a href="http://www.michaelbarr.info">Michael Barr</a>&#8216;s acclaimed &#8220;How to Prioritize RTOS Tasks and Why it Matters&#8221; lecture on DVD, or read the three books and numerous articles provided as PDFs on the USB drive.
<li>As you read, you will come to slides titled “Exercise: …”.  These slides mark the best points to attempt each exercise.
<li>In all there are ten programming exercises: one to test your compiler/debugger/board setup; two concerning hardware interfacing in C; six concerning multithreaded programming with uC/OS-II; and one capstone project to build a scuba dive computer.  These involve hardware interactions such as blinking LEDs, debouncing pushbuttons, reading A/D converters, working with programmable timer/counters, and generating audio tones via <a href="http://www.netrino.com/Embedded-Systems/How-To/PWM-Pulse-Width-Modulation">PWM</a> signals.
<li>Detailed instructions for each exercise can be found in the printed “Exercise Manual”.
<li>Solutions for each of the exercises are provided on the USB drive.
<li>After you finish with the included exercises, you&#8217;ll know your way around most of your ARM processor board and be ready to explore the rest of its hardware (RS-232, CAN, Ethernet, USB, etc.) on your own.
</ul>
<p>For more details or to order your kit now, browse on over to <a href="http://www.netrino.com/Boot-Camp-Box">http://www.netrino.com/Boot-Camp-Box</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2010/12/embedded-software-boot-camp-in-a-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firmware-Specific Bug #10: Jitter</title>
		<link>http://embeddedgurus.com/barr-code/2010/12/firmware-specific-bug-10-jitter/</link>
		<comments>http://embeddedgurus.com/barr-code/2010/12/firmware-specific-bug-10-jitter/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 11:56:26 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[RTOS Multithreading]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=421</guid>
		<description><![CDATA[Some real-time systems demand not only that a set of deadlines be always met but also that additional timing constraints be observed in the process. Such as managing jitter. An example of jitter is shown in Figure 1. Here a variable amount of work (blue boxes) must be completed before every 10 ms deadline. As [...]]]></description>
			<content:encoded><![CDATA[<p>Some real-time systems demand not only that a set of deadlines be always met but also that additional timing constraints be observed in the process. Such as managing jitter.</p>
<p>An example of jitter is shown in Figure 1. Here a variable amount of work (blue boxes) must be completed before every 10 ms deadline. As illustrated in the figure, the deadlines are all met. However, there is considerable timing variation from one run of this job to the next. This jitter is unacceptable in some systems, which should either start or end their 10 ms runs more precisely.</p>
<p><a href='http://eetimes.com/ContentEETimes/Images/Design/Embedded/2010/1110/1110esdBarr03.gif'>Jitter Figure 1</a></p>
<p>If the work to be performed involves sampling a physical input signal, such as reading an analog-to-digital converter, it will often be the case that a precise sampling period will lead to higher accuracy in derived values. For example, variations in the inter-sample time of an optical encoder&#8217;s pulse count will lower the precision of the velocity of an attached rotation shaft.</p>
<p><em>Best Practice</em>: The most important single factor in the amount of jitter is the relative priority of the task or ISR that implements the recurrent behavior. The higher the priority the lower the jitter. The periodic reads of those encoder pulse counts should thus typically be in a timer tick ISR rather than in an RTOS task. </p>
<p>Figure 2 shows how the interval of three different 10 ms recurring samples might be impacted by their relative priorities. At the highest priority is a timer tick ISR, which executes precisely on the 10 ms interval. (Unless there are higher priority interrupts, of course.) Below that is a high-priority task (TH), which may still be able to meet a recurring 10-ms start time precisely. At the bottom, though, is a low priority task (TL) that has its timing greatly affected by what goes on at higher priority levels. As shown, the interval for the low priority task is 10 ms +/- approximately 5 ms.</p>
<p><a href='http://eetimes.com/ContentEETimes/Images/Design/Embedded/2010/1110/1110esdBarr04.gif'>Jitter Figure 2</a></p>
<p><a href="/barr-code/2010/11/firmware-specific-bug-9-incorrect-priority-assignment/">Firmware-Specific Bug #9</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2010/12/firmware-specific-bug-10-jitter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Firmware-Specific Bug #9: Incorrect Priority Assignment</title>
		<link>http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-9-incorrect-priority-assignment/</link>
		<comments>http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-9-incorrect-priority-assignment/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 12:50:03 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[RTOS Multithreading]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=419</guid>
		<description><![CDATA[Get your priorities straight! Or suffer the consequence of missed deadlines. Of course, I&#8217;m talking here about the relative priorities of your real-time tasks and interrupt service routines. In my travels around the embedded design community, I&#8217;ve learned that most real-time systems are designed with ad hoc priorities. Unfortunately, mis-prioritized systems often &#8220;appear&#8221; to work [...]]]></description>
			<content:encoded><![CDATA[<p><em>Get your priorities straight! Or suffer the consequence of missed deadlines. Of course, I&#8217;m talking here about the relative priorities of your real-time tasks and interrupt service routines. In my travels around the embedded design community, I&#8217;ve learned that most real-time systems are designed with ad hoc priorities. </em></p>
<p>Unfortunately, mis-prioritized systems often &#8220;appear&#8221; to work fine without discernibly missing critical deadlines in testing. The worst-case workload may have never yet happened in the field or there is sufficient CPU to accidentally succeed despite the lack of proper planning. This has lead to a generation of embedded software developers being unaware of the proper technique. There is simply too little feedback from non-reproducible deadline misses in the field to the original design team—unless a death and a lawsuit forces an investigation.</p>
<p><em>Best Practice</em>: There is a science to the process of assigning relative priorities. That science is associated with the &#8220;rate monotonic algorithm,&#8221; which provides a formulaic way to assign task priorities based on facts. It is also associated with the &#8220;rate monotonic analysis,&#8221; which helps you prove that your correctly-prioritized tasks and ISRs will find sufficient available CPU bandwidth between them during extreme busy workloads called &#8220;transient overload.&#8221; It&#8217;s too bad most engineers don&#8217;t know how to use these tools.</p>
<p>There&#8217;s insufficient space in this column for me to explain why and how RMA works. But I&#8217;ve written on these topics before and recommend you start with &#8220;<a href="http://www.netrino.com/Embedded-Systems/How-To/RMA-Rate-Monotonic-Algorithm">Introduction to Rate-Monotonic Scheduling</a>&#8221; and then read my column &#8220;<a href="http://embeddedgurus.com/barr-code/2010/08/3-things-every-programmer-should-know-about-rma/">3 Things Every Programmer Should Know About RMA</a>.&#8221;</p>
<p>Please know that if you don&#8217;t use RMA to prioritize your tasks and ISRs (as a set), there&#8217;s only one entity with any guarantees: the one highest-priority task or ISR can take the CPU for itself at any busy time—barring priority inversions!—and thus has up to 100% of the CPU bandwidth available to it. Also note that there is no rule of thumb about what percentage of the CPU bandwidth you may safely use between a set of two or more runnables unless you do follow the RMA scheme.</p>
<p><a href="/barr-code/2010/11/firmware-specific-bug-8-priority-inversion/">Firmware-Specific Bug #8</a></p>
<p><a href="/barr-code/2010/12/firmware-specific-bug-10-jitter/">Firmware-Specific Bug #10</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-9-incorrect-priority-assignment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firmware-Specific Bug #8: Priority Inversion</title>
		<link>http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-8-priority-inversion/</link>
		<comments>http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-8-priority-inversion/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 15:42:15 +0000</pubDate>
		<dc:creator>Michael Barr</dc:creator>
				<category><![CDATA[Firmware Bugs]]></category>
		<category><![CDATA[RTOS Multithreading]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[rtos]]></category>
		<category><![CDATA[safety]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://embeddedgurus.com/barr-code/?p=414</guid>
		<description><![CDATA[A wide range of nasty things can go wrong when two or more tasks coordinate their work through, or otherwise share, a singleton resource such as a global data area, heap object, or peripheral&#8217;s register set. In the first part of this column, I described two of the most common problems in task-sharing scenarios: race [...]]]></description>
			<content:encoded><![CDATA[<p>A wide range of nasty things can go wrong when two or more tasks coordinate their work through, or otherwise share, a singleton resource such as a global data area, heap object, or peripheral&#8217;s register set. In the first part of this column, I described two of the most common problems in task-sharing scenarios: race conditions and non-reentrant functions. But resource sharing combined with the priority-based preemption found in commercial real-time operating systems can also cause priority inversion, which is equally difficult to reproduce and debug.</p>
<p>The problem of priority inversion stems from the use of an operating system with fixed relative task priorities. In such a system, the programmer must assign each task it&#8217;s priority. The scheduler inside the RTOS provides a guarantee that the highest-priority task that&#8217;s ready to run gets the CPU—at all times. To meet this goal, the scheduler may preempt a lower-priority task in mid-execution. But when tasks share resources, events outside the scheduler&#8217;s control can sometimes prevent the highest-priority ready task from running when it should. When this happens, a critical deadline could be missed, causing the system to fail.</p>
<p>At least three tasks are required for a priority inversion to actually occur: the pair of highest and lowest relative priority must share a resource, say by a mutex, and the third must have a priority between the other two. The scenario is always as shown in the figure below. First, the low-priority task acquires the shared resource (time t1). After the high priority task preempts low, it next tries but fails to acquire their shared resource (time t2); control of the CPU returns back to low as high blocks. Finally, the medium priority task—which has no interest at all in the resource shared by low and high—preempts low (time t3). At this point the priorities are inverted: medium is allowed to use the CPU for as long as it wants, while high waits for low. There could even be multiple medium priority tasks.</p>
<p><a href="http://embeddedgurus.com/barr-code/files/2010/11/FiveMoreBugs_fig2.gif"><img src="http://embeddedgurus.com/barr-code/files/2010/11/FiveMoreBugs_fig2-300x243.gif" alt="Priority Inversion" title="Priority Inversion" width="300" height="243" class="aligncenter size-medium wp-image-415" /></a></p>
<p>The risk with priority inversion is that it can prevent the high-priority task in the set from meeting a real-time deadline. The need to meet deadlines often goes hand-in-hand with the choice of a preemptive RTOS. Depending on the end product, this missed deadline outcome might even be deadly for its user!</p>
<p>One of the major challenges with priority inversion is that it&#8217;s generally not a reproducible problem. First, the three steps need to happen—and in that order. And then the high priority task needs to actually miss a deadline. One or both of these may be rare or hard to reproduce events. Unfortunately, no amount of testing can assure they won&#8217;t ever happen in the field.[5]</p>
<p><em>Best Practice</em>: The good news is that an easy three-step fix will eliminate all priority inversions from your system.<br />
Choose an RTOS that includes a priority-inversion work-around in its mutex API. These work-arounds come by various names, such as priority inheritance protocol and priority ceiling emulation. Ask your sales rep for details.<br />
Only use the mutex API (never the semaphore API, which lacks this work-around) to protect shared resources within real-time software.</p>
<p>Take the additional execution time cost of the work-around into account when performing the analysis to prove that all deadlines will always be met. Note that the method for doing this varies by the specific work-around.<br />
Note that it&#8217;s safe to ignore the possibility of priority inversions if you don&#8217;t have any tasks with consequences for missing deadlines.</p>
<p><em>Footnotes</em></p>
<p>[5] Barr, Michael and Dave Stewart. &#8220;Introduction to Rate Monotonic Scheduling,&#8221; Beginner&#8217;s Corner, Embedded Systems Programming, February 2002. Available online at www.embedded.com/showArticle.jhtml?articleID=9900522.</p>
<p><a href="/barr-code/2010/11/firmware-specific-bug-7-deadlock/">Firmware-Specific Bug #7</a></p>
<p><a href="/barr-code/2010/11/firmware-specific-bug-9-incorrect-priority-assignment/">Firmware-Specific Bug #9</a></p>
]]></content:encoded>
			<wfw:commentRss>http://embeddedgurus.com/barr-code/2010/11/firmware-specific-bug-8-priority-inversion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

