An Introduction to Embedded Software Architecture and Design Class 4: From Architecture to Implementation December 4, 2014 Jacob Beningo, CSDP
Course Overview Introduction to Embedded Software Architecture Software Architecture using UML Understanding Embedded Software Architectures From Architecture to Implementation Software Architecture of a UAV and Review
Session Overview Review of the Example Problem Architecture to Design Design to Implementation Tips and Tricks
An Example Problem Review Remote firmware updates System requires periodic firmware updates in the field without the use of specialized hardware Must blink an led in this mode Seamless ability to switch between app and update mode System requires the ability to be updated via UART simulates radio connectivity
Architecture to Design Software Architecture Provides us different views of software in regards to User interactions with the system Environmental conditions Timing System states Etc Relate to requirements of the system Does NOT provide low level details
Architecture to Design
Architecture to Design What is included in the design phase? Detailed planning of the software to the lowest levels! Such as ….. Flowcharting Function definitions Variable naming Task declarations API’s
Architecture to Design Flow Charts Most common design element Consists of Entry point Conditionals Actions Exit point Keep them simple! Highlight enum and const
Architecture to Design Flowcharting of the boot-loader
Architecture to Design API’s Critical to creating reusable software Defines a common interface that can be used from one project to the next Identifies useful peripheral features If adhered to code can be reused and ported with ease Examples include ….
Architecture to Design API’s continued Digital Input / Output API’s EEPROM
Architecture to Design Operating System Selection What did the architecture dictate? Polling Interrupt Driven (Event-driven) Cooperative Scheduling Real-time Operating System Hybrid systems
Architecture to Design Coding Standards Design stage is the perfect time to pick a coding standard! Sets the tone for how the firmware should look and feel Sets the do’s and don’t Sets the best practices to follow Hopefully verifiable by tools
Design to Implementation Implementation is easy! Architecture for the general roadmap Design for the detailed flowcharts and layout What could possibly go wrong?
Design to Implementation Bootloader Implementation // When the checksum has completed and the timer has expired for waiting for a // programming tool to respond, perform the branch checks. if((Checksum_Complete == TRUE) && (StartUpTmr == EXPIRED)) { if((*ResetVector != 0xFFFF) && // Does app reset vector exist? (Status != 'B') && // EEPROM status set? (Boot_ToolPresent != TRUE) && // Tool present? (Checksum_Valid != FALSE)) // Checksum valid? App_LoadImage(); } else Boot_LoadImage();
Design to Implementation Tip #1 Limit Function Complexity Cyclomatic Complexity Kolmogorov complexity Function points
Design to Implementation Tip #2 – Use Assertions
Design to Implementation Tip #3 – Document 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
Design to Implementation Tip #4 – 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
Design to Implementation Tip #5 – 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
Additional Resources Download Course Material for Edraw UML Templates Updated C Doxygen Templates Misc Papers and Websites for further reading From www.beningo.com under - Blog and Articles > Software Techniques > CEC Software Architecture Materials
Jacob Beningo Newsletters P.O. Box 400 Embedded Monthly Linden, Michigan 48451 www.beningo.com Newsletters Embedded Monthly Low Power Design http://eepurl.com/2xJFr Training Bootloaders Embedded Software C/C++ : jacob@beningo.com : 810-844-1522 : Jacob_Beningo : Beningo Engineering : JacobBeningo : Embedded Basics Jacob Beningo Principal Consultant