EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O...
Transcript of EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O...
![Page 1: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/1.jpg)
EECS 388: Embedded Systems
4. I/O Interface
Heechul Yun
1
![Page 2: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/2.jpg)
Agenda
• Memory mapped I/O
• I/O interfaces
2
![Page 3: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/3.jpg)
Input/output (I/O) Devices
3
![Page 4: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/4.jpg)
Input/output (I/O) Devices
4
![Page 5: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/5.jpg)
Input and Output (I/O) Interfaces
5
CPUCore
MemoryDevices
I/OControllers
Interconnect
Computer
Input devices(e.g. sensor)
Output devices(e.g., motor)
OtherComputers
External:GPIO, UART, USB, I2C, SPI, CAN, ATA, PCI, WiFi, Ethernet, …
Internal:AXI, TileLink, …
![Page 6: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/6.jpg)
How Does CPU Talk to Devices?
• CPU talks to device controllers
– Via memory mapped I/O
6
CPUCore
MemoryDevices
I/OControllers
Interconnect
Computer
Input devices(e.g. sensor)
Output devices(e.g., motor)
OtherComputers
![Page 7: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/7.jpg)
Memory Mapped I/O
• Parts of physical memory space are mapped to hardware controllers (peripherals)
– Mapped to control registers and buffers
• Reading/writing from/to the memory mapped regions in peripheral specific ways
7
![Page 8: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/8.jpg)
Memory Mapped I/O
• Via system bus (CPU – memory or I/O device)
8
Address Signals
Data Signals
Control Signals
AddressDecoder
ControlCircuitry
Data,Status, and
Control Registers
I/O Device
I/O Interface
Bus{
}
![Page 9: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/9.jpg)
9
Memory Map ofSiFive FE310
CPU: 32 bit RISC-VClock: 320 MHzSRAM: 16 KB (D)Flash: 4MB
Memory mapped I/O regions
![Page 10: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/10.jpg)
10
Memory Map ofSiFive FE310
GPIO registers are mapped at0x10012000 – 0x10012FFF
![Page 11: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/11.jpg)
Memory Mapped I/O: Example
11
![Page 12: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/12.jpg)
12
Memory Map ofSiFive FE310
UART0 registers are mapped at0x10013000 – 0x10013FFF
![Page 13: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/13.jpg)
Volatile in C
13
a4 = 0x10013000
Branch to .L17 if a5 < zero
a5 = *a4
![Page 14: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/14.jpg)
Volatile in C
14
Is this correct?
a4 = 0x10013000
Branch to .L17 if a5 < zero
a5 = *a4
![Page 15: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/15.jpg)
Input and Output (I/O) Interfaces
15
CPUCore
MemoryDevices
I/OControllers
Interconnect
Computer
Input devices(e.g. sensor)
Output devices(e.g., motor)
OtherComputers
External:GPIO, UART, USB, I2C, SPI, CAN, ATA, PCI, WiFi, Ethernet, …
Internal:AXI, TileLink, …
![Page 16: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/16.jpg)
External I/O Interfaces
16HiFive1 Rev B Pinout
![Page 17: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/17.jpg)
General Purpose I/O (GPIO)
• Programmable digital input/output pins
• Use voltage levels to represent digital signals
– 5V = logic 1 (for 5V CPUs)
– 0V = logic 0
• Can be configured as
– Input or output
• Useful to interact withexternal devices
17
![Page 18: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/18.jpg)
3V VDD
Example: Turn on an LED
• Assume a GPIO pin can draw up to 18mA, and when the LED is on, it has a voltage drop of 2V
• Ohm’s law: 𝐼 × 𝑅 = 𝑉
• What registor is needed?
18
![Page 19: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/19.jpg)
3V VDD
Example: Turn on an LED
• Assume a GPIO pin can draw up to 18mA, and when the LED is on, it has a voltage drop of 2V
• Ohm’s law: 𝐼 × 𝑅 = 𝑉
• What registor is needed?
I = V / R = 1 / R < 18mA
R > 1V/18mA
= 1000mV/18mA= 56 ohm
19
![Page 20: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/20.jpg)
Serial vs. Parallel
• Serial communication
– use single line
20
01001001
010010010 1 0 0 1 0 0 1
Sender Receiver
![Page 21: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/21.jpg)
Serial vs. Parallel
• Parallel communication
– use multiple lines
21
01001001
01001001
Sender Receiver
01001001
![Page 22: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/22.jpg)
Serial vs. Parallel Interfaces
• Serial interfaces– RS-232: serial communication standard– USB: universal serial bus– I2C: inter-integrated circuit– SPI: serial peripheral interface bus– SATA: serial ATA– …
22
SATA USB RS-232I2C
![Page 23: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/23.jpg)
Serial vs. Parallel Interfaces
• Parallel interfaces
– Parallel ATA: advanced technology attachment
– SCSI: small computer system interface
– PCI: peripheral component interface
– …
23
PCI SCSI PATA Parallel port
![Page 24: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/24.jpg)
Serial vs. Parallel Interfaces
• Are parallel interfaces better?++ better performance for the same clock speed
--- synchronization among the wires at high speed
• Serial interfaces are increasingly popular for external i/o (e.g., USB, SATA, PCIe, …)
• Parallel interfaces are dominant for internal interconnect within chip where clock synchronization is easier (e.g., AXI, TileLink, ..)
24
![Page 25: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/25.jpg)
Synchronous vs. Asynchronous
• Synchronous communication– Requires a common shared clock– Higher throughput, low overhead. – All parallel communications are synchronous – Synchronization difficulties.
• Asynchronous communication– No shared clock.– Asynchronous start/stop – Self clocked w.r.t. agreed up on speed– High overhead
25
![Page 26: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/26.jpg)
RS-232
• Asynchronous serial communication standard from 1960s, but still widely used
26This Photo by Unknown Author is licensed under CC BY-SA
![Page 27: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/27.jpg)
UART
• Universal asynchronous receiver/transmitter
• Convert parallel data to serial data (vice versa)
• Can be configured to implement various serial protocol (e.g., RS-232)
• Require at least TX and RX lines to function
27
![Page 28: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/28.jpg)
UART Speed (Baudrate)
• Both sender and receiver must use agreed upon transmission speed (baudrate)
• Up on detecting the start bit, the receiver sample 8 more times before stop
28
![Page 29: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/29.jpg)
Point-to-Point vs. Bus
• Point-to-point– 1:1 communication
• Bus– Shared among multiple devices
– Need an arbitration mechanism
– Master• An entity who initiates the data transfer
– Slave• An entity who cooperates with the master
29
![Page 30: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/30.jpg)
I2C
• Inter-integrated circuit protocol (I2C), by NXP• Synchronous serial communication protocol• Use two wires (SCL - clock, SDA - data)• Multi-master, multi-slave support• Use 7bit ID. Connect up to 127 devices.• Half duplex, relatively slow
30
This Photo by Unknown Author is licensed under CC BY-SAThis Photo by Unknown Author is licensed under CC BY-SA
![Page 31: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/31.jpg)
SPI
• Serial peripheral interface (SPI), by Motorola
• Synchronous serial communication protocol
• Use 4 lines, full-duplex, (relatively) fast
• Single master, multi-slave
• No start/stop bits
• Good for fast, short distance communication
31
This Photo is licensed under CC BY-SA
![Page 32: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/32.jpg)
USB
• Universal serial bus• One host, multiple devices, can form a tree• Use two wires for single differential signal
– Reduce noise caused by electromagnetic interference
• Device needs to process the protocol messages
32
https://commons.wikimedia.org/wiki/File:USB_signal_example.svg#/media/File:USB_signal_example.svg
![Page 33: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/33.jpg)
I/O Considerations
• Digital vs. analog
• Serial vs. parallel
• Wired vs. wireless
• Speed (throughput, latency)
• Real-time/QoS guarantees
• Power/Electrical requirements
• Reliability, Security
33
![Page 34: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/34.jpg)
Summary
• Memory mapped I/O– Parts of physical memory space are mapped to
hardware controllers (peripherals)
– Reading/writing from/to the memory mapped regions in peripheral specific ways
• I/O interfaces– GPIO, UART, SPI, I2C, USB, …
– Serial vs parallel
– Asynchronous vs synchronous
34
![Page 35: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/35.jpg)
Quiz
• Suppose you are sending data over a UART channel at a baud rate of 115200 bps. How long does it take to send a single 8 bit character over the channel?
35
![Page 36: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/36.jpg)
Quiz
• How many CPU cycles would be needed to execute the busy-wait loop in the worst-case? Assume that that the CPU is running at 1 MHz and the baud rate is set at 9600 bps?
36
a4 = 0x10013000
Branch to .L17 if a5 < zero
a5 = *a4
![Page 37: EECS 388: Embedded Systemsheechul/courses/eecs388/W4.ioif.pdf · EECS 388: Embedded Systems 4. I/O Interface Heechul Yun 1. Agenda •Memory mapped I/O •I/O interfaces 2. Input/output](https://reader034.fdocuments.in/reader034/viewer/2022043007/5f9510a75879c022ff145c92/html5/thumbnails/37.jpg)
Acknowledgements
• Some slides are based on the material originally developed by
– Edward A. Lee and Prabal Dutta (UCB) for EECS149/249A
– Rodolfo Pellizzoni (U. Waterloo) for ECE224
37