ECE243

29
1 ECE243 I/O Hardware

description

ECE243. I/O Hardware. ECE243. Basic Components. MULTIPLEXER. In2. In1. MUX. out. select. DECODER. out. in. 0. decoder. 0. 10. 1. 2. 0. Example: a 2->4 decoder. Can be used to match a specific value: eg., in==2?. in. out. decoder match 2. 10. 1. 2. TRI STATE INTERFACE. - PowerPoint PPT Presentation

Transcript of ECE243

Page 1: ECE243

1

ECE243

I/O Hardware

Page 2: ECE243

2

ECE243

Basic Components

Page 3: ECE243

3

MULTIPLEXER

select out

0 In1

1 In2MUX

In1 In2

out

select

Page 4: ECE243

4

DECODER• Example: a 2->4 decoder

In(1) In(0) Out(3)

Out(2) Out(1)

Out(0)

0 0 0 0 0 1

0 1 0 0 1 0

1 0 0 1 0 0

1 1 1 0 0 0

decoder

2

0

10 010

inout

Can be used to match a specific value: eg., in==2?

decodermatch 22

10 1

inout

Page 5: ECE243

5

TRI STATE INTERFACE • aka tri-state buffer

• used for attaching to shared wires– eg a bus

• Z = “high impedence”– ie no impact on outgoing wire

Enable In Out

1 0 0

1 1 1

0 0/1 Z

enableoutin

Dev0 Dev1

What if: 0 1?

Page 6: ECE243

6

PULL DOWN LINE • normally made with a pull-up resistor

• resistor connected to power – pulls the line ‘up’ to 1 by default

• devices can pull the line ‘down’ to 0– like pulling the stop wire on a TTC bus

Vdd

DEV DEV

0 0

Page 7: ECE243

7

PASS TRANSISTOR

Enable In Out

1 0 0

1 1 1

0 0/1 Z

In Out

Enable==

Page 8: ECE243

8

D/Q Flip Flop • eg., rising edge triggered• Like posing for a picture

– Set-up time• say cheese and hold the pose

– Hold-time • like taking a long exposure shot at night

• Q is set to D’s value – when clk goes from low to high

• D must be stable for setup-time seconds– before the clock edge

• D must remain stable for hold-time seconds – after clock edge

DQ

clk

inout

clockD

clk

Q

Setup time hold time

Page 9: ECE243

9

REGISTER• stores an N-bit value

• is composed of N flip flops

• value is read/written in parallel

Register

in

out

clock

N

N

DQ

clk DQ

clk

In(0)In(N-1)

Out(N-1) Out(0)

=

Page 10: ECE243

10

SHIFT REGISTER• stores an N-bit value

• composed of N flip flops

• value is read/written 1-bit at a time (serial)

Shift Reg.

in

out

clock

1

1D

Qclk D

Qclk

In

=D

Qclk

Page 11: ECE243

11

ECE243

I/O Implementation

Page 12: ECE243

12

NIOS Bus

• addr: only upper 30 bits: A31-A2• byte enable: four wires, be3-be0

– encodes two things: A1,A0 and word/halfword/byte– each wire indicates whether that byte is valid

• ME: master enable: one wire– do nothing if zero (avoid interpreting transient values)

• Ack: device sets this to one to ack processor request• IRQ: set to one to request an interrupt

Address A31-A2DataOut Do31-Do0DataIn Di31-Di0ByteEnable be3-be0R/!WMEACKIRQ IRQ31-IRQ0

3032

32411

132

CPU

Page 13: ECE243

13

BYTE-ENABLE Examples

a31-a2 a1-a0 be3-be0 di31-di0

Ldw 0b100001 00

Ldb 0b100001 00

Ldb 0b101011 01

Ldb 0b100101 10

Ldb 0b101001 11

Ldh 0b110101 00

Ldh 0b110001 10

Page 14: ECE243

14

STEPS for a LOAD (protocol):1) CPU:

– set addr, byte-enable, R/!W to 1;– then set ME to 1

2) dev/mem:– set DataIn to value– set ACK to 1

3) CPU– read DataIn lines– set ME to 0

4) dev/mem:– set ACK to 0

Page 15: ECE243

15

STEPS for a store1) CPU:

– set addr, byte-enable, DataOut, R/!W to 0;– then set ME to 1

2) dev/mem:– use DataOut values to update state– set ACK to 1

3) CPU– set ME to 0

4) dev/mem:– set ACK to 0

Page 16: ECE243

16

Timing Diagram: Read

ME

DataOut31-0

DataIn31-0

Address31-2

ByteEnable3-0

Ack

Page 17: ECE243

17

Timing Diagram: Write

ME

DataOut31-0

DataIn31-0

Address31-2

ByteEnable3-0

Ack

Page 18: ECE243

18

IMAGINARY I/O DEVICE .equ MYDEVICE, 0xffabc0

0(MYDEVICE): 8bit input register

4(MYDEVICE): 8bit output register

Note: 0xffabc0 >> 2 = 0x3feaf0

0xffabc4 >> 2 = 0x3feaf1

Page 19: ECE243

19

READING A DEVICE REG:.equ MYDEVICE, 0xffabc0

movia r8, MYDEVICE

ldwio r9,0(r8)

Addr A31-a2

R/!W

Data

BE3-0

ME

ACK

BUS

register

from outside world

Page 20: ECE243

20

WRITING A DEVICE REG:.equ MYDEVICE, 0xffabc0

movia r8, MYDEVICE

stwio r9,4(r8)

Addr A31-a2

R/!W

Data

BE3-0

ME

ACK

BUS

en register

to outside world

Page 21: ECE243

21

PARALLEL INTERFACE• RECALL:

.equ JP1, 0x10000060

0(JP1): DR data in/out (8 bits)

4(JP1): DDR data direction register, each bit configures data pin as in or out (8 bits)

0 means inp, 1 means out

0x10000060 >> 2 = 0x4000018

0x10000064 >> 2 = 0x4000019

Page 22: ECE243

22

PARALLEL INTERFACEJP1portA: 0(0x10000060): DR # 0x10000060 >> 2 = 0x4000018 4(0x10000060): DDR # 0x10000060 >> 2 = 0x4000019

Addr A31-a2

R/!W

Data (bit5)

BE3-0

ME

ACK

D Q

DDR bit5

EN

D Q

DR reg bit5

EN

Vdd

pin5

Page 23: ECE243

23

Serial Interface• Problem: single pin, but read/write bytes• Solution: use shift registers

shift register

input register (8bits)

rcv clock Input line from outside world

/8

/1

shift register

input register (8bits)

send clock output line to outside world

/8

/1

Serial Input:

Serial Output:

Page 24: ECE243

24

Serial Interface: RS232

UART UARTCPU

send

receive

ground

Control lines

bus

motherboard External DeviceRs-232 (serial) cable

clock clock

Page 25: ECE243

25

SYNCHRONIZATION:• each side has its own clock

• this causes problems:– clocks may not be exactly same speed

• ie., there is a frequency difference

– clocks may be out-of-sync • ie., there is a phase difference

• hardware has to handle these difficulties

Page 26: ECE243

26

SERIAL TRANSMISSION1. Both sides agree on a configuration:

– baud rate (bits per second)– number of bits per group (7 or 8)

• is the MS-bit a parity bit? (odd or even)

– number of stop bits (1, 2…)• normally one’s

2. Can then send frames of bits– start bit: normally a zero– frame: 1 start bit + bit group + stop bits– expect a new bit every period

• period = 1 / baud-rate

Page 27: ECE243

27

PARITY:• Even parity:

– the number of bits that are one is even• Odd parity:

– the number of bits that are one is odd• Parity bit:

– a bit that is added to ensure even or odd parity– typically the MSbit

• Ex: what is the parity bit for _1001110– even parity: – odd parity:

• Parity bit can be used to detect errors– Eg., if expecting even parity and get odd parity

Page 28: ECE243

28

EXAMPLE CONFIGURATION:– Baud rate: 1Kbaud = 1000 bits/s– #bits = 8 (includes parity bit)– parity? = yes, even– # stop bits = 2

• send ascii char: 011 0110 – assume sends LSbit first

Page 29: ECE243

29

EFFECTIVE DATA RATE• of 1k bits/s, some are wasted:

– start bits, stop bits, parity bits

• Effective data rate: – the bit rate of non-wasted bits

• Ex: what is the eff data rate from prev slide?