CprE 211 Introduction To Microcontrollers Lecture 15 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CprE 211 Introduction To Microcontrollers Lecture 15

Description:

Student questions example. Polling Ask students for questions, raise hands, gather information ... is extremely simple consisting of only a data register ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 16
Provided by: rsr1
Category:

less

Transcript and Presenter's Notes

Title: CprE 211 Introduction To Microcontrollers Lecture 15


1
CprE 211 Introduction To MicrocontrollersLecture
15
  • Nathan VanderHorn
  • Fall 2005

2
Input Output Programming
  • Communication with external devices
  • How does the processor know an external device is
    requesting communication we will focus on two
    methods
  • Polling keep checking the status of external
    devices
  • Interrupt external device signals processor
    that service is requested
  • Student questions example
  • Polling Ask students for questions, raise
    hands, gather information
  • How many questions?
  • Order in which to service questions?
  • Interrupt Student interrupts lecture with
    question
  • Service question immediately
  • What happens if a question interrupts the current
    question
  • Interrupts can be more difficult

3
Methods for I/O Programming
  • Sampling
  • Simple devices in which the device is always
    ready to accept or provide data
  • The interface is extremely simple consisting of
    only a data register
  • Examples are temp sensors, motor control port
  • Polling
  • Requires data and status/control registers
  • Status is read by the microcontroller and denotes
    status of device
  • Control is written by microcontroller to indicate
    the characteristics of communication baud rate,
    operation mode etc.
  • Interrupt
  • Device interrupts the microcontroller when
    service is needed
  • Control is passed to the device if interrupts are
    enabled
  • Software handles the operations to be performed

4
Communication Examples
  • Keyboard
  • Processor ? keyboard data ready? read-data?
  • Keyboard ? processor data ready
  • Hard disk
  • Processor ? disk seek sector, seek track,
    read/write block
  • Disk ? processor data-ready, error conditions
    bad block
  • Printer
  • Processor ? printer data-sent, print, font,
    resolution?
  • Printer ? processor printing done, error
    conditions out of paper, toner

5
Dealing with I/O
  • Should we include instructions for communications
    with external devices?
  • Is there enough uniformity between I/O devices to
    agree on a single set of instructions to
    communicate with them?
  • How about the I/O devices we have not even
    foreseen yet?
  • Hard to develop an instruction set to control
    todays and tomorrows devices!
  • Necessity for a generic method to communicate
    with all devices

6
Memory Mapped I/O
Peripherals
  • How should the Processor communicate with the I/O
    devices
  • Will every device communicate in the same way?
  • Need a generic method for accessing external
    devices

Keyboard
Bus
Mouse
Processor
Printer
A/D converter
Other Device
7
Memory Mapped I/O
  • Generic control
  • Make the interface between the I/O device
    processor soft
  • Develop each devices control as a unique data
    structure
  • Specify a place in memory for these control and
    data registers

8
Keyboard Example
  • Getchar() gets an ASCII byte from the keyboard
    and puts it into r3
  • Assume r13? 0xF000 0000
  • Assembly code for Getchar()
  • poll
  • lwz r4, 0(r13)
  • andi. r4, r4, 1
  • beq poll
  • getchar
  • lbz r3, 4(r13)

Processor
Keyboard
Data register
0xF000 0004
0xF000 0000
Control Register
R
9
Polling
  • We have just seen how polling works with a
    keyboard example
  • Is it efficient to poll?
  • Sometimes yes sometimes no
  • Depends upon the application

10
Why Interrupt I/O
  • Polling is what we have seen
  • main ()
  • while(1)
  • PollKeyboard()
  • Polling the keyboard
  • Read port to see if a key is pressed
  • Must poll every n ms, the minimal time period a
    key is pressed otherwise keystroke is lost
  • If the program has tasks to do
  • main ()
  • task1()
  • PollKeyboard()
  • task2()
  • PollKeyboard()
  • Overhead polling frequency polling overhead
  • Difficulty Hard to mix polling with a normal
    process

11
Generic Programming Model with Interrupts
start
Interrupt
Interrupt
Interrupt
Initialize
ISR for task 1
ISR fortask 2
ISR fortask 3
Wait for events
I-return
I-return
I-return
Processing
Memory
How to support interrupt programming? How to
write interrupt-based C and Assembly code?
12
Understanding Interrupts
  • Normal control flow
  • Exception control flow
  • Exception and Interrupts
  • Hardware implementation of interrupts
  • Machine level interrupt programming

13
Normal Control Flow
  • In a processor, the program counter (PC) takes a
    sequence of values
  • a0, a1, , an-2, an-1
  • where each ak is the address of an instruction
    Ik.
  • Control transfer each transition from ak to
    ak1
  • Flow of control, or control flow sequence of
    control transfers
  • Smooth control flow Ik and Ik1 are adjacent
    in memory
  • Changes to smooth flow Ik1 not adjacent to Ik
  • Branches
  • Calls, returns

14
Exceptional Control Flow (ECF)
  • Abrupt changes in control flow not caused by
    program statements and variables Ik1 is
    external to the program
  • Hardware timer goes off at regular intervals
  • I/O request completes, e.g., A/D conversion, disk
    I/O
  • Packets arrive at network adapter
  • Instruction attempts divide by zero
  • Virtual memory page fault occurs
  • Memory access violation
  • Exceptions occur at all levels in a computer
    system hardware, operating system, user

15
Exceptions
  • DEFINITION an abrupt change in the control flow
    in response to some change in the processors
    state
  • Event change in processors state, where state
    is encoded in various bits and signals inside the
    processor
  • Event might be related or unrelated to current
    instruction
  • Implementation details vary from system to system
Write a Comment
User Comments (0)
About PowerShow.com