First Technology Transfer

Standard and Advanced Technical Training, Consultancy and Mentoring

Course RPI104 RaspberryPi Advanced C Programming

Duration: 5 Days

Intended Audience

Because of the large material the course aims to cover the course will, ideally, follow a boot-camp format. If this is not possible then the course can be tailored to e.g. a standard very intensive 9am - 5.30 pm 5 day course.

This course is for those who already have a reasonable understanding of C programming on a Linux platform, and are looking to extend their programming skills and advance their knowledge of embedded Linux. As with the other courses in the RaspberryPi curriculum the intention is to equip teachers and experimenters with practical skills, that go a bit beyond purely academic data structures and algorithms type courses. Trying to envisage a scenario where those who have completed this course will be developing projects, teaching materials, examples and demonstrations to inspire / impress their students and colleagues this course includes not only writing C code for the RaspberryPi, but also code for Microchip controller based target boards (the course fill concentrate on PIC16 and PIC18 boards, and Arduino boards. If their is sufficient demand variants, or extensions covering PIC24, dsPIC , PIC32, ARM CortexM3 boards and Atmel AVR32 boards can be made available).

Course Overview

The goals of this course are to introduce more advanced C programming techniques, programming using the Linux Posix C API, and programming networking applications using the sockets API, programming USB applications using libusb, I2C programming, and use of memory mapping to program the RaspberryPi GPIO.

The course emphasises the implementation of disciplined and well structured code and the design of modules with clean interfaces. Topics include:

  • Advanced use of dynamic data structures and algorithms for manipulating them.
  • Structured interrupt handling
  • Implementation of simple schedulers and operating systems
  • Working with embedded operating systems
  • Understanding standard techniques for inter-process communication, and their uses.
  • Finite state machines, statecharts, and their uses
  • Introduction to Advanced algorithms and research-oriented approaches to developing software

In addition the course will also include some more advanced examples programming using PIC16/PIC18 based microcontrollers and the Arduino, including multi-tasking without an operating system, and the implementation of command-response protocols running over RS232 or USB for controlling small embedded systems targets from the RaspberryPi.

An important purpose of RPI104 is to "teach the teachers". To this end, as well as regular programming labs the course will include labs in which students are required to develop "teaching materials and their associated labs". This is why this course follows the intensive "Boot Camp" format. The "develop labs and teaching materials" sections will take place in the early evening "breakout" sessions. These will be group sessions involving groups of 3 to 4 students. This course will be a "dual mode" course. Code will be developed on the PC and will be compiled and tested on the PC, but also cross-compiled for an ARM processor target and downloaded and run on the RaspberryPi. The course will teach both command line compiling and the use of make and Makefiles as well as programming using the Eclipse IDE (Integrated Development Environment). Debugging and Unit testing techniques will also be introduced.

Each attendee will be given a RaspberryPi and a Microchip evaluation board or an Arduino development kit, to take with them after the course. If there is sufficient demand FTT will set up a forum for teachers and experimenters to discuss and follow up on various issues and topics raised on this course.

Course Benefits

You'll learn how to write larger and more complex structure C programs and be introduced to the world of data structures and algorithms. You will learn how to program the Linux Posix API. Code will be tested on both the RaspberryPi and Linux running on a PC. You will also learn how to build applications involving both a RaspberryPi and an embedded target board.

After taking this course you will be able to:

  • Write programs which interact with the Linux system
  • Access and modify file data, permissions and ownership
  • Exploit concurrency through processes and threads
  • Develop client/server applications that communicate across a network
  • Write graphical applications using libraries and toolkits
  • Communicate efficiently between processes
  • Write and distribute software to run on a variety of platforms

There will be an (optional) one day exploration session and post-course party on the Saturday following the course. An opportunity to explore and try out ideas and get started on that project you have been itching to have a go at.

Course Contents

  • Intensive overview of essential C concepts and idioms
    • Data types, data structures, pointers and arrays
    • Using pointers to search collections of data
  • Arrays and buffers
    • Circular buffers
    • Polygonal buffers
    • I/O vectors
  • Linked Lists in depth
    • Singly linked and doubly linked lists
    • Using lists to implements FIFO queues and LIFO queues (stacks)
    • Using lists of linked lists
    • Using linked list nodes containing void * pointers to implement heterogeneous collections of data
    • Using linked lists to implement resizeable arrays
  • Binary trees, their uses and their relations
    • Basic binary trees
    • Self-balancing binary trees (AVL, Red-Black, Splay)
    • Heaps and their uses
    • Huffman encoding
    • Priority queues
  • Error detection
    • CRC checksums (16 bit and 32 bit)
  • Implementing simple memory management schemes
  • Implementing simple flash memory file systems
  • State Machines and Statecharts
    • Event driven programming
    • Basic FSMs
    • Pattern matching
    • Parsing
    • State driven hardware and communication protocols
    • Implementing FSMs using switch statements
    • Implementing FSMs using a table driven approach
    • Limitations of FSMs
    • Extended FSMs and hierarchical FSMs
    • Extending FSMs by adding variables and conditional transitions
    • Nesting state machines (push down automata)
  • Statecharts
    • Hierachical FSMs and extended FSMs (simple statecharts)
    • Orthogonal statecharts and concurrency
    • Active objects - linking multi-tasking, message passing and event driven programming
  • Getting Started - Hello Posix
    • Receiving command line arguments
    • Accessing environment variables
    • Reading and writing stdin and stdout
    • How to detect and handle system call errors
  • Multiprocessing
    • The memory model and life cycle of a process
    • Creating processes with fork
    • Executing programs with exec
    • Waiting for process termination
    • Returning and retrieving exit status
  • Multithreading
    • The memory model and life cycle of a thread
    • Creating threads with the pthreads API
    • Waiting for thread termination
    • How are threads and processes different?
    • Synchronising access to shared data
    • When to use multiple processes and threads
  • Basic I/O
    • Low-level input and output
    • Reading and writing files
    • Changing file attributes
    • Managing files and directories
  • Interprocess Communication
    • Pipes
    • Message queues
    • Shared Memory
    • Semaphores
  • Signals
    • What are signals for?
    • Sending signals
    • Ignoring and catching signals
    • Writing signal handlers
  • Working with the Linux Security Model
    • Changing file permissions and ownerships
    • Accessing the user account database
    • Setting user identity of a process
  • Network Communication
    • TCP/IP fundamentals
    • Client/server programming
    • Connection-oriented sockets
    • Connectionless sockets
    • Name resolution
    • IPv6 Socket Programming
    • Unix Domain Socket Programming
  • Basic operating systems and multi-tasking concepts
    • Task structures
    • Task life cycle
    • Task management
    • Task data structures
    • Task queues
    • Message queues
    • Semaphores (counting, binary, mutex)
    • Monitors
    • Pipes
    • Memory management services
    • Signals
    • Timers
    • Device drivers
  • Standard Inter-Process Communication Idioms
    • Producer - Consumer
    • Monitors
    • Readers and Writers
    • Workcrew
  • RaspberryPi socialising with small microcontroller target boards
    • PIC16/PIC18 and Arduino - more advanced C programming examples
    • Understanding and using the Microchip USB library
    • Understanding and using the Microhip TCP/IP library
    • Design and implementation of communication micro-protocols