EmbeddedRelated.com
Books

More to C - Advanced Programming with C in Linux and on Raspberry Pi

Johnson, Andrew 2017

This guide builds on the original 'C' Here guide and it is recommended that you obtain a copy of that guide if you haven’t already got a basic knowledge of C programming, or another programming language (available on Amazon in Book and Kindle form - ISBN-13: 978-1546967941 or Lulu item code 23199004). This guide should be most useful to those who are doing lower-level programming – such as working with embedded systems, micro controllers or similar architectures. Similarly, anyone with a limited knowledge of C wanting to work on things like Device Drivers for Networking and USB should also find this guide of use in describing the C language features which facilitate lower level system access. The main topics covered in this guide are Structures and Unions, Binary (raw) File I/O, Dynamic Memory Allocation,Linked Lists, Access to Bits and Bytes, Logic Operations, Modules and Makefiles, Elementary aspects of system programming.


Why Read This Book

You will learn the C language features and idioms that are most useful for low‑level and systems programming on Linux and Raspberry Pi, with practical emphasis on accessing hardware and handling binary data. The book translates language concepts (structures, unions, pointers, file I/O, memory mapping) into patterns you can reuse when writing firmware, user‑space device interfaces, or lightweight drivers.

Who Will Benefit

Embedded and systems programmers with basic C and Linux familiarity who want to move from application code to low‑level firmware, device interfaces, and Raspberry Pi hardware projects.

Level: Intermediate — Prerequisites: Basic C programming (variables, control flow, functions), comfortable using Linux command line and an editor/IDE; recommended to have the author’s introductory 'C' Here guide or equivalent basic C knowledge.

Get This Book

Key Takeaways

  • Use structures, unions and bitfields to model hardware registers and packed binary formats safely and portably.
  • Perform binary (raw) file I/O and parse/emit on‑disk and on‑wire binary formats with attention to alignment and endianness.
  • Manage dynamic memory and pointers in low‑level contexts to avoid leaks and corruption in long‑running embedded processes.
  • Access device resources from user space using memory‑mapped I/O (mmap), ioctl patterns, and raw device file handling.
  • Debug and profile low‑level C on Linux/Raspberry Pi using gcc, gdb, Valgrind, and runtime checks for concurrency and resource issues.

Topics Covered

  1. 1. Introduction and how this book fits with 'C' Here
  2. 2. Revisiting C fundamentals for systems programming
  3. 3. Structures, unions and bitfields for hardware modeling
  4. 4. Pointers, address arithmetic and safe indirection
  5. 5. Dynamic memory management in long‑running processes
  6. 6. Bitwise operations, packing, and endianness
  7. 7. Binary (raw) file I/O and parsing binary formats
  8. 8. Memory‑mapped I/O (mmap) and direct device access
  9. 9. User‑space device access: opening devices, ioctl and character devices
  10. 10. Interfacing common buses on Raspberry Pi: GPIO, SPI, I2C (user‑space examples)
  11. 11. Concurrency: threads, signals and race avoidance in C
  12. 12. Debugging, testing and tooling for low‑level C (gdb, Valgrind, static analysis)
  13. 13. Cross‑compilation and deploying to Raspberry Pi
  14. 14. Practical examples: small drivers, file format handlers, and hardware utilities
  15. 15. Appendices: compiler flags, useful libraries and reference snippets

Languages, Platforms & Tools

CShell (bash)Python (for brief examples/scripts)Linux (x86_64)Raspberry Pi (ARM Linux / Raspbian)gcc / cross‑arm toolchainsmakegdbValgrindstraceWiringPi / libgpiod (user‑space GPIO libraries)scp/rsync for deployment

How It Compares

Compared with Linux Device Drivers (Corbet et al.), this book focuses less on kernel internals and more on C language techniques for user‑space device access and hardware interfacing; compared to Raspberry Pi hardware guides (e.g., Derek Molloy), it emphasizes advanced C idioms and binary handling rather than electronics fundamentals.

Related Books

Bryant, Randal, O'Hallaron,...