System Programming and Device Drivers
System Programming and Device Drivers
xxxx
System Programming using C 4 0 0 4 100
COURSE OBJECTIVES
This course is meant to give them a broad exposure to the understanding of various concepts
of System Programming.
The course will provide the students with
(i) the concept of advanced Embedded C Language,
(ii) the knowledge of microcontroller architecture,
(iii) the methodology to write Program for chosen microcontroller, and
(iv) the skill to use basic technique for debugging in Linux environment and
(v) basic understanding of system programming.
Experiments will run in synchronism with the lectures to support the methods and techniques
taught in the lectures. Through the experiments, the students will
(i) learn how to use Linux commands and programming environment,
(ii) gain confidence to do system programming in Linux environment, and learn how
to test and debug the developed programs.
Learning Outcome of students are
(i) Perform advanced C programming using linked list, Function pointers, arrays,
sorting, etc.,
(ii) 2. Basic scripting in Linux environment
(iii) 3. Demonstrate programming using Linux System calls
(iv) 4. Demonstrate various debugging techniques when the program throws error
(v) 7. Plan and execute projects simple system programming projects.
Project
1. Developing event-based project using Linux IPC and synchronization
mechanism.
2. Developing message queue-based project using message queue and
synchronization mechanism.
COURSE OUTCOMES :
On completion of the course the student will be able to
CO1. Write System programs in Linux environment.
CO2. Design and Implement simple system projects
Text Books:
Advanced Embedded C Programming
The C Language Programming, Brian W. Kernighan • Dennis M. Ritchie, 1998.
Linux System Programming
Linux System Programming, Robert Love, 2013.
Advanced Microcontroller Programming
Discovering the STM32 Microcontroller, Geoffrey Brown, 2012.
Reference Books:
Advanced Embedded C Programming
1. THE FIRMWARE HANDBOOK, Jack Ganssle, 2004..
2. C Programming for Embedded Systems, Kirk Zurell, 2000.
3. Making Embedded Systems, Elecia White, 2011.
Linux System Programming
1. Beginning Linux Programming, Neil Matthew & Richard Stones, 2008.
2. Hands-On System Programming with Linux, Kaiwan N Billimoria, 2018.
Advanced Microcontroller Programming
1. Mastering STM32, Carmine Noviello, 2016.
2. ARM Cortex M4 Cookbook, Dr. Mark Fisher, 2016.
3. RM0090, Reference manual, STM32F405/415, STM32F407/417,
STM32F427/437 and STM32F429/439 advanced Arm®-based 32-bit MCUs.
4. PM0214 Programming manual STM32 Cortex-M4 MCUs and MPUs
programming manual.
1. Create a read process and control process. The read process should read the thermostat sensor
value and perform the temperature calculation, based on the temperature value and set
temperature value, the control process should turn on and off the compressor motor. Pipes
should be used for the communication between read process and control process.
2. Create 3 processes, one process maintains state machine to send command to control the valves
and motor, second process to control the motor, third process to control the valve. The motor
should rotate in forward or backward direction based on the command. Use pipes the send
command between processes.
3. Create 3 processes, one process reads the angle sensor, second process reads the proximity
sensor and three process sends command through serial port to control the speed of the motor
based on the sensor values. Use message queues to pass information between the processes.
4. Create 4 processes, one process controls the heater based on the user input and thermostat value,
second process controls the light and monitors door, third process controls fan motor and turn
table motor and fourth process read the thermostat reading. Use message queues as inter process
communication mechanism between processes.
5. Create 5 processes, one process controls the various solenoidal valves, second process controls
2 motors, third process controls light, relays and buzzer, fourth process reads sensor, switch
values and user inputs. Fifth processes control whole functionalities of the devices.
6. Create 4 processes, one process read the current time and place it in the shared memory. Second
process reads the temperature sensor value and place it in the shared memory. Third process
reads the humidity sensor value and place it in the shared memory. Fourth process plays video
or current time with temperature and humidity value based on the user selection.
7. Create 4 processes, one reads the input values from the user related to rate and time. Second
process performs calculation based on rate and time and controls the pump direction and speed.
Third process read the pressure sensor value. Use message queues as inter process
communication between processes.
8. Create 3 processes, one reads the pressure sensor value on request, second process controls the
pump and third process to perform calculation and display the result in the screen. Use message
queue and signal as an inter process communication between process
9. Create 3 processes, one process receives the input from the user, second process controls various
motors in sequence and third process performs certain calculations periodically. Use
semaphores, message queues, signals and shared memory as an inter process communication
between the processes.
10. Create 3 processes, one process writes the captured image into a jpg file format, second
processes write the recorded videos into 3pg file format, third process reads jpg or 3pg files and
displays it in the screen.
11. Create 3 processes, one process handles the key input, second process handles audio player
functionalities and third process handles photo frame functionalities. Use message queues,
interrupt and signal as inter process communication. Use <--, -->, ^, v, backspace keys to
provide inputs.
12. Create an application to read the records through serial communication port after handshaking
and write the records in the file. Implement a logic to sort the table based on the parameters.
13. Create a runtime thread to update the run time parameters in the shared memory.
Create a charging thread to update the total charging hours in the shared memory.
Create a battery thread to update the total battery usage hours in the shared memory.
Create a sensor1 thread to update the sensor event with date and time in the shared memory.
Create a sensor2 thread to update the threshold limit exceed event with date and time in the
shared memory.
Create an event log thread to read the various shared memory location and update the event log
file.
Create a display thread to display the event log in the screen on request from the user.
Use mutex for synchronization of shared resource access.
14. Create an application to read the information from the configuration file and then perform the
device operation.
Configuration File:
1. Select Required Cycles (Cycle1 to Cycle 15, each cycle will perform certain sequence of
operation related to pump, fluid, volume and pressure)
2. Configure the pump speed, duration, volume, concentration and flow rate.
3. Door close/open duration for each cycle
4. Fluid drain duration, etc
15. Create a file manager application for Linux environment.
16. Create an application to write the health parameter in the file and send it to online server to get
the prescription based on the health condition.
17. Create 2 processes, one is server process, and another is client process. Both accessing the
shared memory, use semaphore as a synchronization mechanism.
18. Implementing alarm system which provides audio and visual warning based on the multiple
sensor values.
Create 5 process, one process reads sensor1 value, second process reads sensor 2 value, third
process reads sensor 3 value, fourth process performs the limit check and generates visual and
audible alarm based on sensor values. Alarms priority are categorized as low, medium and high
alarms. Visual alarm color and audible alarm tone is based on alarm priority.
19. Create a manager process which performs health check of another 5 processes. In case any of
the process malfunctions, the manager process should restart the malfunction process. Use
message queue and signals as a inter process communication.
20. Create 2 process, one process reads 2 bytes of sensor value and update the circular buffer, the
second process reads the circular buffer update the head and tail information in the shared
memory. Use semaphore to synchronize between write and read operation from the circular
buffer.
21. Implement speed alert application to regulate vehicle speed-based road wet condition.
Create 3 processes, one read the sensor value to identify the wet condition, the second process
provides visual and audible warning to reduce the speed of the engine, the third process should
reduce the speed of the engine.
Use message queue as a inter process communication between process.
22. Create a traffic management system to control the traffic in the signal based on the information
from the nearby signals.
23. Create an internet speed test application using Linux Networking Program.
24. Create 2 processes, one process receives command from the server. Second process controls the
motor connected to motor driving board which control the AC, DC and Stepper Motors.
25. Implement networking application to control the home appliances.
Create 2 processes, one process receives command from the server. Second process based on
command, sends control signal to home device connected through.
26. Create a server application to receive and store the video images in the file system.
27. Create a client application to send the working state of the primary system to redundant system.
In redundant system run the server application, and when the primary system fails, the
redundant system quickly takes up the functionalities of primary system.
28. Create a server application in the PC to retrieve the trip information from the vehicle and store
it in a file. Create a client application to send the trip information to the server.
Seventh Semester- L T P Credits Total Marks
SCSA xxxx Linux Kernel & Device Driver
4 0 0 4 100
Programming
COURSE OBJECTIVES
This course is meant to give them a broad exposure to the understanding of various concepts
of Linux Kernel and Device Driver Programming.
The course will provide the students with
(vi) The core concepts of operating systems
(vii) the knowledge of Linux Kernel architecture and device driver framework,
(viii) the methodology to write Programs for chosen embedded devices, and
(ix) the skill to use basic techniques for debugging in Linux device drivers and
(x) basic understanding of Linux based embedded system design.
Experiments will run in synchronism with the lectures to support the methods and techniques
taught in the lectures. Through the experiments, the students will
(iii) learn how to setup environment for developing and debugging device drivers,
(iv) gain confidence to write/customise Linux device drivers, debug and test them
using a target platform.
Learning Outcome of students are
(i) Understanding of complex Linux Kernel framework and extending this knowledge
to understand any type of operating system
(ii) Writing device drivers for simple embedded devices
(iii) Basic scripting to building the Linux Kernel and Device Drivers
(iv) Demonstrate end-end data flow from device to application
(v) Demonstrate various debugging techniques when the system crashes due to a
malfunctioning Kernel or Device Driver
(vi) Plan and execute simple device driver development projects.
Pre-requisites
1. Advanced C Programming
2. Basic Linux utilities
3. Comfortable with Linux text editors (Vim, Gedit, etc.)
4. Experience with major Linux distribution (Ubuntu, Debian, etc.)
5. Free course from Linux Foundation: A Beginner’s Guide to Linux Kernel Development
(LFD103)
6. Free course from Linux Foundation: Introduction to Linux (LFS101)
UNIT 1 INTRODUCTION TO THE LINUX KERNEL 9Hrs.
Preliminaries - UNIX Vs Linux, Types of Kernels, Versions, Kernel
repository, Object-Oriented approach in Linux Kernel, Important Kernel
tasks, User-Space and Kernel-Space.
Lab work
6. Browsing/searching the Kernel source code
7. Booting a target development board over ethernet
8. Add a new system call
9. Code walkthrough for system initialisation code in Kernel
10. Create your first module and send it for review
Lab work
8. Implement a module that registers as an I2C driver
9. Modify the Device Tree to list the I2C device
10. Get the driver called when the device is enumerated at boot time
11. Configure the pin-mux for the I2C bus to communicate with the driver
12. Extend the driver to communicate with a I2C device
13. Extend the driver to communicate with user space
14. Extend the driver to implement ioctls
15. Demonstrate driver binding using udev
16. Write a module to gather memory statistics
17. Write a module to create a private memory cache
18. Write a module to setup a memory pool
19. Write a module to check the memory allocation limits
Disk caches and swapping – Caches, Page cache basics, what is swapping,
Swap areas, swapping pages In and Out, Controlling swappiness, The swap
cache, Reverse mapping, OOM Killer
Signals - What are Signals? Available signals, System calls for signals,
Sigaction, Signals and threads, How the Kernel installs signal handlers, How
the Kernel sends signals, How the Kernel invokes signal handlers, Real time
signals
Lab work
4. Write module to get the current CPU ID
5. Create threads in Kernel and run them in different CPUs
6. Write a Kernel module to launch a user process
7. Write a program to simulate CFS
8. Write a program to defragment memory
9. Write a module to manipulate signals installed from user process
the misc Subsystem - What the misc kernel subsystem is useful for? API of
the misc kernel subsystem (both the kernel side and user space side)
GPIO Subsystem - API of the GPIO kernel subsystem (both the kernel side
and user space side)
Lab work
3. Create a module to handle input events
4. Create a platform driver and hook it to the misc subsystem
5. Write a program to communicate with the GPIO port
6. Create a module to register a simple interrupt handler
7. Make a process sleep and wake-up from a module
8. Handle a variable from 3 simple modules using mutex
9. Handle a variable from 3 simple modules using Semaphore
10. Compute the average time slices of a process
11. Write a program to examine and modify the scheduling policies and
priority
12. Write a basic PCI driver
13. Write interrupt example programs from LDD3
Memory Technology Devices - What are MTD Devices? NAND vs. NOR vs.
eMMC, Flash filesystems
Block Drivers - What are Block Drivers? Buffering, Registering a block
driver, gendisk structure, Request handling
Lab work
1. Write a simple block driver
2. Code walkthrough for an example USB driver
3. Code walkthrough for an example Network driver
4. Write SNULL driver example from LDD3
5. Write DMA driver example from LDD3
COURSE OUTCOMES :
On completion of the course the student will be able to
CO3. Write device drivers for simple devices used in Linux based embedded systems.
CO4. Design and implement simple embedded applications
Text Books:
Linux Device Drivers (LDD), 3rd Edition
Linux Kernel Development, 3rd Edition, Robert Love
Reference Books:
Linux System Programming, 2nd Edition, Robert Love
The Linux Programming Interface, Michael Kerrisk
Linux Kernel Documentation