25
Lab2: I/O Handling

Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lab2: I/O Handling

Page 2: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 1

Goal of the lab

•  Learn how to access different I/O devices

•  Write programs that interact with I/O devices

•  Write driver routines

Page 3: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 2

Computer system

Page 4: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 3

Simplification

•  In the lab we will use –  Switches/Buttons –  LED –  7-Segment display

Page 5: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Computer System

CONTROL BUS

DATA BUS

ADDRESS BUS

MicroBlaze microprocessor

Memory

SWITCHES LEDS 7SEGMENT DISPLAYS

PUSH BUTTONS TIMER1 TIMER2 INTERRUPT

CONTROLLER

FPGA

Page 6: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 5

Memory mapped vs. Isolated I/O

•  Memory mapped –  Same address space shared among memory and I/O –  Same instructions used to access memory and I/O

•  Isolated I/O –  Different address space for memory and I/O –  Different instructions –  More control signals

MicroBlaze

Memory mapped I/O

Page 7: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 6

Minnesmappad och isolerad I/O

Memory mapped: I/Os are addressed by reading or writing to specific memory addresses Cost: reduced address space

Isolated: I/Os are addressed by specific functions, more memory for the processor Cost: more instructions, increased complexity

Page 8: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 7

I/O devices

•  Contain a set of registers •  Status/Control registers •  Data registers

Page 9: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 8

SWITCHES

16 switches are interfacing the microprocessor through an I/O module •  one control and one data register •  both registers are 32bit wide •  control register gives a bit level control for the data flow

direction of each of the bits of the data registers •  data register stores the state of the switches

•  Input only

Page 10: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 9

SWITCHES

shuffle

Data register

Control register

ADDRESS BUS

DATA BUS

I/O module

Page 11: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 10

LEDs

16 LEDs are interfacing the microprocessor through an I/O module •  one control and one data register •  both registers are 32bit wide •  control register gives a bit level control for the data

flow direction of each of the bits of the data registers

•  data register stores the state of the switches

•  Output only

Page 12: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 11

LEDS

shuffle

Data register

Control register

ADDRESS BUS

DATA BUS

Page 13: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 12

7-SEGMENT DISPLAYS

•  Output device •  Contains 8 data registers •  Each data register is 32bit wide •  One data register keeps the data to be displayed on one of

the 8 seven segment displays

Page 14: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 13

7-segment display

•  7 input signals •  One signal controls the state of one segment

Data register

shuffle

a b c d e f g

Page 15: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 14

7- SEGMENT DISPLAYS

Data Register

8

Data Register

7

Data Register

6

Data Register

5

Data Register

4

Data Register

3

Data Register

2

Data Register

1

7SEGMENT DISPLAYS

ADDRESS BUS

DATA BUS

Page 16: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 15

Driver routines

•  Software interface to hardware devices •  Operating system can invoke driver routines •  Programmers can invoke driver routines without needing to

know precise details of the hardware being used

Write driver routines for the 7-SEGMENT DISPLAYS device

Page 17: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 16

Pushbutton

•  Produces a logic ‘1’ when pressed •  Produces a logic ’0’ when released

Page 18: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 17

PUSH BUTTONS

5 pushbuttons are interfacing the microprocessor through an I/O module •  one control and one data register •  both registers are 32bit wide •  control register gives a bit level control for the data flow

direction of each of the bits of the data registers •  data register stores the state of the pushbuttons •  Input only

Page 19: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 18

PUSH BUTTONS

Data register

Control register

ADDRESS BUS

DATA BUS

shuffle

Page 20: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 19

PUSH BUTTONS

Data register

Control register

ADDRESS BUS

DATA BUS

shuffle

Page 21: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 20

CPU - I/O communication

•  Programmed I/O –  CPU has to wait for completion of each I/O operation

•  Interrupt-driven I/O –  CPU can execute other code during I/O operation

Page 22: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 21

Programmed I/O

•  Polling –  CPU repeatedly checks if the device I/O is ready –  Many clock cycles are wasted

Check if any of the push buttons is pressed or released

Page 23: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 22

Bouncing

•  Problem with the push buttons •  Tendency of any two metal contacts in an electronic device

to generate multiple signals as the contacts close or open

Pressing a button

expected

bouncing

time

Page 24: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 23

Debouncing

•  Delays •  If the state has changed, read the state after some delay •  The delay is of order of milliseconds

Pressing a button

20ms no samples

Without delays

With delays

Page 25: Lab2: I/O Handling · 2017. 1. 19. · Lab2: I/O Handling . Lund University / Electrical and Information Technology / 1 Goal of the lab ... Isolated: I/Os are addressed by specific

Lund University / Electrical and Information Technology / 24