Embedded Systems Design - July 2008 - (Page 36) 20 years ago ever an unrecoverable error could exist, tions pass, enabling us to change the The existing software foundation way exceptions are handled in one will influence your design a great deal, as a check is made. If an error occurs, the system-wide exception handler is called. central procedure. monitors and kernels generally provide From this basic method we can no error handling at all other than rebuild a system in which each exception The actual exception processing porting that an error occurred during a is assigned a unique error code to identi- can be approached in several ways. system call. UNIX, on the other hand, fy the line that caused the exception. Us- During the debug and implementation provides a rich set of tools through ing the exception handler is as simple as phases, the programmer needs to which complex error-handling systems a normal function call: know what exception occurred and be can be built. When a serious fault ocable to examine the state of the system curs, the state of the system is written to at the exact moment the exception octhe disk in the form of a core file and sys_fault( SYS_CRASH_001, err ); curred. The best way to do signals are sent to parent this is to print a crash reprocesses to alert them Any project will require exception-handling port that gives the excepto the error condition. tion condition, then freeze As comfortable as tailored to its environment; the point is to the UNIX tools may be, build a method that allows the programmer the system by returning to the debugger/monitor. the most common envito easily incorporate error handling into the After the project has ronments for embedded been completed and applications are kernels project during implementation. shipped to the field, it’s usuand monitors. Accordally highly undesirable for ingly, the examples here the system to freeze when an exception are for a kernel-based system. occurs. Exceptions in a production The field SYS_CRASH_001 is a mode may best be handled by recording THE EXCEPTION HANDLER unique number within the system and the exception and automatically restartAn exception is, by definition, an anomforms a unique exception ID (a long ining the system (advanced exception hanalous condition. In practice, this term teger, in this example). Implementers of dling is discussed later). The crash recovers a wide variety of sins. Let’s say a a project can build a central file, similar port can subsequently be retrieved to message is posted to a message queue to the following, listing exception IDs through a kernel call. If it’s posted sucand keep track of their use in the system: determine the cause of the exception. Any project will require exception cessfully, the kernel returns a message to handling tailored to its environment; the the caller that no error occurred. But /* qpost, sys_chk_msg() */ point is to build a methodology that alwhat if the message queue is full or the #define SYS_CRASH_001 0x0001 lows the programmer to easily incorporequest specifies a nonexistent message /* bad indx, sys_prcs_msg() */ rate error handling into a project during queue? Exceptions aren’t limited to ker#define SYS_CRASH_002 0x0002 implementation. It should provide a nel calls; they can be defaults at the end /* qpend, sys_snd_msg() */ means of isolating the problem, locating of a case statement (to represent an in#define SYS_CRASH_003 0x0003 it within the source code during debugvalid parameter) or other program flowging, and checking the system during type problem. The err field represents additional production to determine the errors that One simple approach to exception information that the user desires to have occurred but were recovered from. handling is to establish a rigorous pass to the exception handler; for kerListings 1 and 2 illustrate a simple methodology at the beginning of the nel errors, this could be the error reexception handler that formats the crash project. A central handler can easily be turned from the kernel call. For softreport shown in Figure 1 and checks a used throughout the system, as repreware flow errors, such as the default of front panel switch to determine how to sented by the following pseudocode: a case, it could be the value used in the handle the exception. Listing 2 is called case. upon an exception to build a stack frame The methodology defined thus far err = system_operation(); that meets the definition in Listing 1 offers the following: if( err ) sys_fault(); and call the csys_ fault() procedure else with a pointer to the stack frame. The { A consistent approach to invoking crash report can be either sent to the exceptions. normal_processing(); screen or appended to a crash file. In the } The ability to identify (through the first case, the handler jumps to the deID code) the exact line of code that bugger (debug mode); in the second, the caused the exception condition. This simple example demonstrates a handler executes a warm boot (producconsistent approach for checking and A single hook—in this case, sys_ tion mode). handling anomalous conditions. Wherfault()—through which all excep- • • • 36 JULY 2008 | embedded systems design | www.embedded.com http://www.embedded.com
Table of Contents Feed for the Digital Edition of Embedded Systems Design - July 2008 Embedded Systems Design - July 2008 Contents #Include Parity Bit Programming Pointers Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design Building a Power Supply for Discontinuous Transmission Wireless Networks An Exception Primer Advertising Index Break Points Marketplace Embedded Systems Design - July 2008 Embedded Systems Design - July 2008 - Embedded Systems Design - July 2008 (Page Cover1) Embedded Systems Design - July 2008 - Embedded Systems Design - July 2008 (Page Cover2) Embedded Systems Design - July 2008 - Embedded Systems Design - July 2008 (Page 1) Embedded Systems Design - July 2008 - Embedded Systems Design - July 2008 (Page 2) Embedded Systems Design - July 2008 - Contents (Page 3) Embedded Systems Design - July 2008 - Contents (Page 4) Embedded Systems Design - July 2008 - Contents (Page 5) Embedded Systems Design - July 2008 - Contents (Page 6) Embedded Systems Design - July 2008 - #Include (Page 7) Embedded Systems Design - July 2008 - #Include (Page 8) Embedded Systems Design - July 2008 - Parity Bit (Page 9) Embedded Systems Design - July 2008 - Programming Pointers (Page 10) Embedded Systems Design - July 2008 - Programming Pointers (Page 11) Embedded Systems Design - July 2008 - Programming Pointers (Page 12) Embedded Systems Design - July 2008 - Programming Pointers (Page 13) Embedded Systems Design - July 2008 - Programming Pointers (Page 14) Embedded Systems Design - July 2008 - Programming Pointers (Page 15) Embedded Systems Design - July 2008 - Programming Pointers (Page 16) Embedded Systems Design - July 2008 - Programming Pointers (Page 17) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 18) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 19) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 20) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 21) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 22) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 23) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 24) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 25) Embedded Systems Design - July 2008 - Interactive C-code Cleaning Tool Supports Multiprocessor SoC Design (Page 26) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 27) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 28) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 29) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 30) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 31) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 32) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 33) Embedded Systems Design - July 2008 - Building a Power Supply for Discontinuous Transmission Wireless Networks (Page 34) Embedded Systems Design - July 2008 - An Exception Primer (Page 35) Embedded Systems Design - July 2008 - An Exception Primer (Page 36) Embedded Systems Design - July 2008 - An Exception Primer (Page 37) Embedded Systems Design - July 2008 - An Exception Primer (Page 38) Embedded Systems Design - July 2008 - An Exception Primer (Page 39) Embedded Systems Design - July 2008 - An Exception Primer (Page 40) Embedded Systems Design - July 2008 - An Exception Primer (Page 41) Embedded Systems Design - July 2008 - An Exception Primer (Page 42) Embedded Systems Design - July 2008 - An Exception Primer (Page 43) Embedded Systems Design - July 2008 - Advertising Index (Page 44) Embedded Systems Design - July 2008 - Break Points (Page 45) Embedded Systems Design - July 2008 - Break Points (Page 46) Embedded Systems Design - July 2008 - Marketplace (Page 47) Embedded Systems Design - July 2008 - Marketplace (Page 48) Embedded Systems Design - July 2008 - Marketplace (Page Cover3) Embedded Systems Design - July 2008 - Marketplace (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.