Embedded Basics
Overview Introduction to Embedded Systems What is an embedded system? What are some of their characteristics? What is the required skill set? Software Development Process Waterfall vs Agile Tips and Tricks for writing embedded software 20 common tips and tricks to improve software
Introduction to Embedded Systems What is an embedded system? - An embedded system is a microprocessor used as a component in another piece of technology - The end product is not by definition a computer such as a laptop or desktop - Examples include
Introduction to Embedded Systems What are some of their characteristics? Resource constrained compared to traditional computer Limited Memory (RAM and ROM) Processor clock (8 MHz to 48 MHz typical) Bus Bandwidth ( 8 bit, 16 bit and 32 bit) Power Consumption Real-time response often critical or time guaranteed in safety critical applications ( must respond within x ms) Interacts with environment through the use of sensors, displays, etc Reliable ( the goal anyways)
Introduction to Embedded Systems What is the required skill set? Digital Electronics Communication interfaces Sensors Programming languages (C/C++, Java, etc) Algorithms Real-time programming Debugging skills Project management etc Tight coupling between software/hardware requires an understanding of both to be successful!
Software Development Process Waterfall Development Process Time spent early in the design cycle (Requirements) can lead to greater economy later Emphasis on documentation Difficult to perfectly move through one stage, changes result in scrapping time and work done Need a magic 8 ball to properly predict challenges that could affect design and requirements
Software Development Process Used to provide an iterative development process which adds flexibility to the design process Feedback is used at the end of each release as the primary control mechanism Basic functionality is developed first allowing critical components and primary functionality to be tested and adjusted Each iteration involves planning, requirements analysis, design, coding and testing
#1 Flowchart First, Implement Second
#2 Write Lasagna not Spaghetti Code!
#3 Use State Machines to Control Program Flow - Actions dictate program flow - Event driven - Easy to follow and implement - Program flow controlled by decision making - Continuous conditional checking
#4 Take Advantage of Modularity
#5 Limit Function Complexity Many methods to measure complexity Cyclomatic Complexity Kolmogorov complexity Function points
#6 Avoid using Assembly Language
#7 Don t use goto statements - Poor program structure - Difficult to follow and maintain - Results in spaghetti code! - Good program structure - Easier to follow and maintain - Results can be spaghetti code!
#8 Use for(;;) or while(1) - For(;;) is always considered to be true with no expressions - For(;expression;) behaves like a while loop - Typically used to seeing for(i=0; i<val; i++); - Any none zero value is considered to be true - While(expression);
#9 Use the appropriate conditional statement for the job - If / else - If / else if / else - Switch - While - Do while
#10 Use #pragma statements sparingly
#11 Use Descriptive Naming Conventions Don t use abbreviations but the whole descriptive word! If you use abbreviations then create a lookup table Call it what it is and don t be cryptic! (Use long variable names) Use broad terms first then get specific Choose naming conventions and be consistent! Develop a coding standard to keep track of your conventions so that future you or maintainer can understand
#12 Keep Interrupt Service Routines Simple Concurrent Interrupts Real-time response Avoid loops and complex calculations Do minimum of what needs to be done and return. Another task or module can handle processing Clear and re-enable interrupts ASAP
#13 Avoid the Use of Global Variables Encapsulate variables Use data hiding Object oriented design Prevents data corruption Reduces reentrancy issues Use static to declare local variables Use static to declare private functions
#14 Errors aren t always as they seem
#15 Use Processor Example Code to Experiment with Peripherals
#16 Document the Code Thoroughly Function Inputs Function Outputs Function use and behavior Related Functions Plenty of comments on what it does Maintainers and future self will thank you Use tools like Doxygen to generate documentation from code comments
#17 Use a Source Code Repository and Commit Frequently SVN is used to provide a method of source control. Completed modules are checked into SVN which then assigns a version control number to the software. This keeps the code constantly under revision control and allows for a method to examine changes in the code base between revisions. It can also prevent the code from being accessed if it has been checked out.
#18 Good Programmers don t necessarily write fewer lines of code Good Programmers.. Write structured, maintainable code Document their code in a clear manner Recognize and reuse design patterns Are passionate about writing code (find it fun) Never stop learning and honing skills Enjoy challenges Thoroughly test their work Are humble and adapt to change easily Strive for perfection but identify limits
#19 Stay on Top of Developing Technologies
#20???????????????? Audience Tips
Questions Contact Info Jacob Beningo jacob@beningo.com www.beningo.com EDN Blog: http://www.edn.com/electronics-blogs/4375394/embedded-basics