CS 4448 - Fall 1998
Object-Oriented Programming and Design
Talk 11.4
by
Mike Wingert

USING OBJECT ORIENTED METHODOLOGIES WITH EMBEDDED SYSTEMS AND REAL-TIME APPLICATIONS br> by
...


CS4448 PRESENTATION



Referencing
EMBEDDED C++ SLASHES CODE SIZE
 AND BOOSTS EXECUTION
Mike Haden, Compiler Engineering Manager
Green Hills Software

DEFINITIONS
• EMBEDDED SYSTEM
A dedicated, self-contained, microprocessor-based system including hardware and software designed into a product most often for purposes of control.
­ Dedicated => Handles one application (typical)
­ Self Contained => Microprocessor, ROM/RAM, I/O devices, ...
­ Software => Firmware=non-volatile; minimal RAM ; minimal OS
­ Hardware => Cost sensitive; difficult to change, extend
­ Control => Performance is often critical
­ Product => Error handling, safety, &  reliability issues; power
• REAL-TIME APPLICATION
An event (clock, interrupt, ...) driven system required to respond and perform concurrent tasks in a very precise and timely manner
­ Most often controls devices external to the computer system

WHAT'S THE PROBLEM?
• PRODUCT COST
	Feature rich compilers produce memory hog solutions.  
	High volume, price competitive products require cost minimization of all components especially CPU and memory.

• SYSTEM PERFORMANCE
	Many embedded systems have use low-cost microprocessors with short instructions, few registers, and no floating point unit.
	  e.g. Intel 8051: 8 bits, 12 MHz 
	
• SUITABILITY OF TOOLS
	Many existing tools do not allow turning-off of high overhead components such as type checking and multiple inheritance.
	Most do not support ROMable builds. 

PRODUCTS FROM NEC
	NEC Semiconductor Application Engineering Division reports the following typical embedded code sizes:

	Application		Current KB	Future KB
	Camera			48-64		96-256
	Rice Cooker		16-48		64
	Cellular Phone		384+		768+
	Printer			32-64		64-128
	Television		16-48		32-96
	VCR			192-256		320+
	HDD			32-64		64-128

					Source: Embedded C++, P. Plauger

WHO ARE THE C++ CULPRITS?
• Multiple inheritance & virtual base classes
		linear hierarchy more appropriate for embedded aps
• New-style casts
		static_cast, reinterpret_cast, const_cast, dynamic_cast
• Mutable specifiers
		allows casting of data members so they can be modified
• Namespaces
		used with multiple large libraries
• Run-time type identification
		useful to programmers with little knowledge of the code
• Exceptions
		the leading offender when it comes to bloated code
• Templates
		often used incorrectly with little benefit and great overhead

ARE OBJECTS ROMABLE?
	C linkers for embedded systems allow const static data to be kept in ROM.  This means that all non-varying data known at compile time can be specified by static initializers, compiled to be stored in ROM and left there.

	In well designed C++ code, most data is encapsulated in objects.  Objects belong to classes and most classes have constructors.  The natural OO equivalent to const initialized data is a const object.  A const static object that has a constructor must be stored in RAM for its constructor to initialize it.  Thus the C++ object must occupy expensive RAM.

	For objects to be ROMable, the class must (1) have no constructor, (2) have no virtual functions, (3) have no base classes, and (4) have no private or protected members.

WHAT IS THE SOLUTION?
• New Compilers and Libraries
- EC++ by Green Hills Software, CAD-UL, Cygnus, ...
- Dinkum Standard Template & Abridged Libraries
- Lint-like utilities and test suites

• New Standards
	A group of companies have requested ISO/IEC WG21 and ANSI J11 to produce a non-normative ISO Technical Report.

• Embedded System Programmer Education
	Tutorials, seminars, books (Saks, Xcc Software)
	
SOME RESULTS
	
	Cygnus Solutions has compared use of the Dinkum EC++ Library with a subset of libstdc++:

	File		Dinkum		libstdc++
	a000091		 37,077		 45,662
	a000092		 39,237		104,542
	a000094j	 38,020		101,654
	s00002a		113,533		157,062
	s00004a		 71,788		115,242
					

					Source: Embedded C++, P. Plauger

FURTHER READING
	
	C++ in Embedded Systems: Myth and Reality
	Dominic Herity, Embedded Systems Programming, 2/98

	Designing Real-Time Systems with UML
	Bruce powel Doublass, Embedded Systems Programming, 3-5/98

	Embedded C++
	P.J. Plauger, Embedded Systems Programming, 10/97
	
	www.embedded.com
	www.dinkumware.com
	www.caravan.net


Copyright © University of Colorado. All rights reserved.
Revised: November 20, 1998