Baremetal C Programming for Embedded Systems Class 5: Writing Portable Code February 27, 2015 Jacob Beningo, CSDP
Course Overview C Concepts for Embedded Systems Baremetal Scheduling Techniques Driver Design Techniques Design Patterns for Firmware Writing Portable Code
Session Overview Why Write Portable Code? API Design An EEPROM Example
Benefits of Portable Code Easily moved from one MCU to the next Proven and tested Decreases development time Decreases costs Familiarity which makes maintenance easier
Hardware Abstraction Layer
API’s 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 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
API’s Digital Input / Output (Gpio) Serial Peripheral Interface EEPROM
EEPROM Overview
EEPROM Configuration Header Definitions
EEPROM Configuration Source Definitions
EEPROM Driver Header Definitions
EEPROM Driver Initialization
EEPROM Driver Write Status Register
EEPROM Driver Read Status Register
Portable Code Tips Avoid the use of #pragma Keep modules as de-coupled as possible One “function” per module Create an API Keep configuration separate from implementation Use only standard C concepts (bit field ex.) Encapsulation and data hiding
Course Review Use of static and volatile A Review of C Concepts Scheduling Techniques Methods of Accessing Memory Circular Buffers Driver Design GPIO, SPI, External EEPROM
Additional Resources Download Course Material for Updated C Doxygen Templates (Feb 2015) Example drivers source code Microcontroller API Standard EDN Embedded Basics Articles Embedded Bytes Newsletter From www.beningo.com under - Blog and Articles > Software Techniques > CEC Baremetal C Programming
Jacob Beningo Newsletters P.O. Box 400 Embedded Bytes Linden, Michigan 48451 www.beningo.com Newsletters Embedded Bytes http://bit.ly/1BAHYXm Training MicroPython Bootloaders Low Power Design Real-time Software C/C++ Embedded : jacob@beningo.com : 810-844-1522 : Jacob_Beningo : Beningo Engineering : JacobBeningo : Embedded Basics Jacob Beningo Principal Consultant 18