190 likes | 240 Views
Fundamentals of Embedded Software Design. Day 4: Organizing and Developing Reusable Code. November 21, 2013 Jacob Beningo, CSDP. Course Overview. Introduction to Embedded Systems Developing a Software Architecture A Review of C Programming Techniques Organizing and Developing Reusable Code
E N D
Fundamentals of Embedded Software Design Day 4: Organizing and Developing Reusable Code November 21, 2013Jacob Beningo, CSDP
Course Overview • Introduction to Embedded Systems • Developing a Software Architecture • A Review of C Programming Techniques • Organizing and Developing Reusable Code • Writing a Memory Mapped Driver for a Timer
Session Overview • Software Design Goals • Software Architecture Goals • Application Protocol Interface (API’s) • Modularity and Code Organization • Code Coupling • Object Oriented Design Techniques • The end result
Software Design Goals • The software design cycle problem • Tight/shrinking budgets • Shortened development cycles • Feature creep • Intense competition • Software bugs • Customer feature expectations • What can be done to speed up the development cycle? • How much time is spent developing and validating drivers?
Software Design Goals • Write software that is reusable! • This can be done through • Designing and using a layered software architecture. • Defining and using API’s • Modularity • Decreasing module coupling • Following object oriented design techniques
Software Architecture Goals • Many different ways to organize code • Break the code up into different layers (but keep it simple!) • Driver Layer • Contains MCU peripheral drivers • Generic initialization functions • MCU start-up and copy down • Might contain board support package drivers for external chips
Software Architecture Goals • Application Layer • Product features • Scheduler • Applications for drivers • Ex. External EEPROM configuration application • Ex. Button response behavior • Configuration Layer • Configuration for drivers • Configuration for applications • Application settings
Application Protocol Interface Application Programming Interfaces • Critical to creating reusable software • Defines a common interface that can be used from one project to the next • Identifies useful peripheral features (think driver and application layer) • If adhered to at a driver level application code can be reused and ported with ease Example API’s and Standards • Linux Kernel • AUTOSAR • Arduino Libraries • Custom • etc
Application Protocol Interface Digital Input / Output API’s Serial Peripheral Interface EEPROM
Modularity and Code Organization • Characteristics of Modular Code • Header and Source files are dedicated to a specific function • Digital I/O • SPI Communication • Sensor Interfacing • Etc • Modules can be interchangeable • Swap a Microchip Spi Driver for a Freescale Spi Driver • Use ANSI standard coding techniques • Not all language features are supported by all compilers so use standard techniques! • Separates interface (.h) from the implementation (.c) • Easier to design and maintain • Breaks the problem up into smaller manageable pieces
Modularity and Code Organization • Examples Main Application Main Application EEPROM Application EEPROM Application EEPROM Driver Freescale Part EEPROM Driver Microchip Part
Modularity and Code Organization • How to decide what functions go together? • Software architecture diagrams will naturally hint at modules • Decompose the layers in the architecture • Decompose those layers into independent features and functionality
Modularity and Code Organization • What effects how the source code is organized? • Compiler • Forces a separation of header and source files? • Allow creation of folders and subfolders? • Architecture Decisions • Application • Hardware
Modularity and Code Organization • How should the code be organized? • Separate header and source files • Separate the individual layers • Drivers • Application • Task Schedulers • Protocol Stacks • Configuration • Supporting Files and docs • It should be easy to find a module! • File system organization should match! • Allows for layers to be easily swapped
Module Coupling • What is module coupling and why do we care? Main.c EEPROM_App.c Sensor.c Filter.c EEPROM.c Dio.c SPI.c
Module Coupling • Examples Main Application Main Application EEPROM Application Flash Application EEPROM Application EEPROM Driver Flash Driver EEPROM Driver
Object Oriented Design • Modules should look like black boxes • Exposed interfaces • Implementation hidden • Data hiding • Variables local to the module • LIMITED USE OF GLOBAL VARIABLES • Limited dependencies on other modules • Use interface to set and read variables
The End Result • Modular Software is simpler • Easier to test • Easier to debug • Ease of configuration • Loosely coupled allowing a change in one module to minimally affect other modules • Can be reused in future projects, thus saving • Future development costs • Time to market
Questions Contact Info Jacob Beningo jacob@beningo.com www.beningo.com Jacob_Beningo Beningo Engineering JacobBeningo Embedded Basics