Embedded System Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Embedded System Programming

Description:

Introduction to Device Drivers. What are device drivers? ... Recognising device drivers ... Character Device Drivers. Data is a serial stream. No random access ... – PowerPoint PPT presentation

Number of Views:125
Avg rating:3.0/5.0
Slides: 16
Provided by: cd780
Category:

less

Transcript and Presenter's Notes

Title: Embedded System Programming


1
Embedded System Programming
  • Introduction to Device Drivers

2
What are device drivers?
  • Software interfaces to hardware resources in the
    kernel
  • Mirrors variety of hardware resources
  • Can change constantly
  • Will require reconfiguration
  • Different interfaces into the same devices
  • Require kernel resident programs
  • Uses module interface

3
Split level kernel
User programs and applications
Application level
Kernel level
Process mgment
Memory mgment
File systems
Device Control
Networking
Kernel parts
Multi-tasking
Files Dirs
Connectivity
features
V Memory
TTYS devs
software
Fs types
Networks
Memory Mang.
Achture code
Character Devices
hardware
Block Dvc
If drivers
Hardware level
Disks CDs
Console S Ports
Network Interfaces
CPU
RAM
4
Types of device driver
  • There are some general types or characteristics
    of device drivers
  • Character devices
  • Serial data stream
  • Block devices
  • Accessed via blocked data stream
  • Network interfaces
  • Although serial, has no mapping into file system

5
Recognising device drivers
  • Apart from network devices most drivers appear
    like file in the Unix system
  • ls l /dev
  • crw-r--r-- 1 root root 10, 134 Jun7 1996 apm_bios
  • brw-rw---- 1 root floppy 2, 0 May 14 1996 fd0

File Name
Device type
Minor number
Major number
6
Character Device Drivers
  • Data is a serial stream
  • No random access
  • Even a block devices can be a character one!
  • Printers

7
Block Devices
  • Data is read in blocks
  • Block size depends upon the device
  • Random access is supported
  • Files systems can only be mounted block devices
  • Block devices can have character interfaces
  • fsck works on character raw interface to file
    system

8
Network Interfaces
  • Network interfaces act in some ways like a serial
    character orientated device, however they dont
    exist in the file system
  • For example eth0 is queried through the ifconfig
    command
  • Weirdly, network devices can support block
    features for example network mounted file systems

9
Character Block Device number assignment
  • Character devices
  • 1 Memory
  • 4 Terminal
  • 6 Parallel interfaces
  • 7 Vitual consoles
  • 9 SCSI tapes
  • 10 Bus mice
  • 12 QIC02 Tape
  • 13 PC speaker driver
  • Block devices
  • 1 RAM disk
  • 2 Floppy disk
  • 3 IDE disk
  • 8 SCSI disk
  • 11 SCSI CD-ROM
  • 13XT 8-bit hard disk

10
Loadable modules
  • Historically there has been a split between
    monolithic kernels
  • All code is contained in the kernel, fixed at
    build or boot time
  • This means that kernel can be fast and efficient
  • And Micro kernels
  • Small lightweight kernel that load features in at
    run time, when required
  • The kernel is smaller, easier to port, the feaure
    list of more flexible
  • Linux loadable modules gives a compromise
    position
  • Mainly monolithic kernel but can load modules in
    when needed
  • The use of modules for devices is clearly
    important

11
Kernel Modules
  • The provision of kernel modules allows code to be
    introduced into a running kernel.
  • This requires the kernel to be built with this
    capability, it also requires the commands
  • Insmod and rmmod (plus lsmod, depmod and
    modprobe)
  • Modules can be loaded on demand automatically.

12
Module programming
  • The 2.6 kernel has changed the way module
    programming is handled.
  • We will look at this later on for the moment we
    will deal with 2.4
  • Modules under 2.4 are just ordinary unlinked
    object files (cc o)
  • Although they must link with the kernel and can
    bring it down, so they are rather special.

13
Module programs
  • Requires header files
  • These will include others
  • Needs an init_module and cleanup_module function
  • The return value is important
  • Only return 0.
  • Use of printk

14
Using macros
  • Use of init exit macros
  • Use of __init and __initdata

15
Features of kernel programming
  • Dont use libraries only kernel code
  • Printk not printf
  • Set use of headers
  • /usr/include/asm /usr/include/linux
  • Beware of namespace pollution
  • Code shares names with the kernel
  • Use static
Write a Comment
User Comments (0)
About PowerShow.com