Course: Introduction to Embedded Linux C Programming
Duration: 5 Days
Course Background
The C programming language is over 40 years old. It is a testament to the genius of the gifted researchers at Bell Labs who developed it that it is still very widely used. C programming is a mainstay of embedded systems programming. In an age where traditional analog systems have. laregely, been replaced by digital systems capable of capturing and processing analog inputs digitally and controlling analog outputs digitally knowing how to program in C is an essential skill. The genius of C is that it is both a high level programming language, and yet, one that is very close to assembler.
Course Prerequisites and Target Audience
A basic knowledge of programming and working with PC tools is assumed e.g. simple shell programming, JavaScript programming or web programming with PHP. A knowledge of binary, octal and hexadecimal number systems would be helpful.
Course Overview
The course discusses C programming in the context of implementing C applications for Embedded Linux Systems as well as applications running on Linux
workstations/industrial computer e.g. where an embedded Linux system is acquiring data and sending it over some communications link (e.g. ethernet or RS485) to another
application running on a workstation or larger industrial computer, or is receiving commands and instructions from the larger machine. This course is a prelude to a more advanced course that explores more advanced algorithms and data
structures as well as multi-tasking and inter-process communication.
The course will use a typical Linux distribution e.g. Ubuntu on the workstation, and an appropriate Linux distribution running on either a RaspberryPi or BeagleBone Black
as the embedded target platform. Various techniques for compiling and downloading code onto the embedded target platform will be explored including the use of
the NFS distributed file system to access executables compiled on the workstation using a suitable cross compiler toolchain or downloading executable files from the development
machine to the target board using a file transfer protocol such as TFTP.
The development environment used will be Eclipse CDT. In addition the basic use of make and makefiles will also be covered.
Course Benefits
Students successfully completing this course will have a sound understanding of C programming. You will understand the basic C data types, arrays and pointers.
You will have a good appreciation of data structures and their uses, and the use of pointers to data structures and arrays of data structures.
You'll learn how to use arrays to implement circular buffers and how to use them, and how to use arrays to implement stacks, and the uses of software stacks.
You will also be introduced to basic techniques of memory management and programming with dynamic data structures - and to circular buffers and stacks and linked lists.
You'll also learn techniques for implementing interrupt handler code in C, multi-module programming including applications containing a
mixture of C and assembly language modules, and techniques for manipulating hardware registers and special function registers in C. In addition the course will
provide an introduction to basic network programming, fileio, serial communications over RS232/RS485 and basic GPIO.
Course Outline
- C basic data types
- Integer types
- Floating point types
- Pointers (pointer arithmetic, pointer derefencing)
- Arrays
- The relationship between arrays and pointers
- Enums
- Programming constructs
- if - else statements
- switch statements
- while loops and do - while loops
- for loops
- goto statements
- Functions in C
- Function prototypes
- Understanding C's call by value mechanism for passing arguments
- Implementing functions
- Calling functions
- Using pointers to pass values by reference
- Passing arrays to functions
- Understanding C's return value mechanism
- Using pointers to return values by reference
- Data Structures
- Defining data structures
- Accessing and manipulating the elements of a data structure
- Pointers to data structures
- The arrow (->) operator
- Using a pointer to traverse an array of data structures
- Advanced topics
- Pointers to pointers
- Function pointers
- const and static keywords - their meanings and uses
- casts and casting
- Using void * pointers
- Data structures containing pointers to data structures
- Data structures containing function pointers
- Function pointers and table driven programming
- Bit fields in data structures
- Unions
- Using arrays to implement circular buffers and stacks
- Modules as data structures and interfaces
- Dynamic data structures and their uses
- Singly linked lists
- Doubly linked lists
- Overview of the C standard library
- putc, putchar, getc, getchar
- printf, scanf
- String manipulation functions ( strcpy, strcat, ... )
- Embedded Linux System Oriented Topics
- Installing an ARM cross compiler toolchain.
- Defining bit oriented data structures
- Compiler specific features
- Linkers and libraries
- Overview of Kernel Space code, User Space code and system calls
- Basic file i/o
- The abstraction of devices as files
- Basic programming of RS232 / RS485 serial communications
- Timers and their uses
- Network programming
- An intensive overview of TCP/IP
- IPv4 and IPv6 compared
- Implementing a simple UDP socket application
- Implementing a simple TCP socket application
- GPIO programming
- An introduction to memory mapping
- Using memory mapping to access GPIO ports from user space