100 likes | 247 Views
Representing and Manipulating Hardware in Standard C and C++. by Dan Saks. Overview. This presentation was about hardware manipulation using ANSI C and ANSI C++ common idioms for controlling devices make code more portable. Aids for Embedded Programming. Features provided by C and C++
E N D
Representing and Manipulating Hardware in Standard C and C++ by Dan Saks
Overview • This presentation was about • hardware manipulation using ANSI C and ANSI C++ • common idioms for controlling devices • make code more portable
Aids for Embedded Programming • Features provided by C and C++ • bitwise operators and bitfields • const qualifier • volatile qualifier • type sig_atomic_t • Feature provided by C++ • Class concept (encapsulation of hardware)
I/O Architectures • Presentation was especially about memory mapped i/o architectures (ex. Motorola) • C and C++ are best at MMIO • Port I/O was tackled at the end
Basic Techniques • How to represent a register • use the correspondent type (eg. one byte => char) • How to assign an adres to a variable in C/C++ • not possible • solution: declare a pointer with the specified adres • How to change bits in a register • use masks • Use structs when registers are physically colocated
Compiler optimizations • Several compiler optimizations are based on variables • distinction `standard` variable and `device` variable is not made by compiler • compiler could alter program making it incorrect • use the keyword `volatile` • for a volatile variable the compiler will not make optimizitions
More Advanced Topics • Access the register on a per bit base • use a struct • often big/little endian problems • Classes • public functions are used to read/write values • overhead can be eliminated thanks to inlining • the object encapsulates exact position/structure of register • Write-only registers
More Advanced Topics • Port I/O • no standard C or C++ solution • rely on ASM or language extensions • Interrupt Handling • als no standard C or C++ solution • rely on ASM or language extensions • sig_atomic_t: use it in asynchronous environments (as environments where interrupts occur)
Conclusion • Tutorial was ... • interesting for C/C++ programmers • not groundbreaking in terms of new concepts • interesting part (use of classes) not seen in depth