Session Title

Download Report

Transcript Session Title

Fundamentals of Embedded
Software Design
Day 4: Organizing and Developing
Reusable Code
November 21, 2013
Jacob Beningo, CSDP
1
© Jacob Beningo 2013
All Rights Reserved
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
2
© Jacob Beningo 2013
All Rights Reserved
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
3
© Jacob Beningo 2013
All Rights Reserved
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?
4
© Jacob Beningo 2013
All Rights Reserved
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
5
© Jacob Beningo 2013
All Rights Reserved
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
6
© Jacob Beningo 2013
All Rights Reserved
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
7
© Jacob Beningo 2013
All Rights Reserved
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
8
© Jacob Beningo 2013
All Rights Reserved
Application Protocol Interface
Digital Input / Output API’s
Serial Peripheral Interface
EEPROM
9
© Jacob Beningo 2013
All Rights Reserved
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
10
© Jacob Beningo 2013
All Rights Reserved
Modularity and Code Organization
• Examples
Main Application
Main Application
EEPROM
Application
EEPROM
Application
EEPROM Driver
EEPROM Driver
Freescale Part
Microchip Part
11
© Jacob Beningo 2013
All Rights Reserved
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
12
© Jacob Beningo 2013
All Rights Reserved
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
13
© Jacob Beningo 2013
All Rights Reserved
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
14
© Jacob Beningo 2013
All Rights Reserved
Module Coupling
• What is module coupling and why do we care?
Main.c
EEPROM_App.c
Sensor.c
15
Filter.c
EEPROM.c
SPI.c
Dio.c
© Jacob Beningo 2013
All Rights Reserved
Module Coupling
• Examples
Main Application
Main Application
EEPROM
Application
Flash Application
EEPROM
Application
EEPROM Driver
Flash Driver
EEPROM Driver
16
© Jacob Beningo 2013
All Rights Reserved
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
17
© Jacob Beningo 2013
All Rights Reserved
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
18
© Jacob Beningo 2013
All Rights Reserved
Questions
Contact Info
Jacob Beningo
[email protected]
www.beningo.com
Jacob_Beningo
Beningo Engineering
JacobBeningo
Embedded Basics
© 2013 Jacob Beningo, All Rights Reserved