Chapter4 Embedded Interfaces
Chapter4 Embedded Interfaces
Chapter4 Embedded Interfaces
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Outlines
• Custom interfaces
• GPIO
• Communication
• Human machine
interfaces
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Hardware: system view
EMBEDDED
INPUT OUTPUT
SYSTEM
DEVICE DRIVERS
Analog Environment
MCU
INPUT DEVICES
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded development trend
• Interconnection
– IoT/M2M
– Diversified communication physical means
• Distribution/decentralization
– More modules to co-work
– Higher parallelism
• Human machine interface
– Behavior recognition
– More intelligent
• Customizability
– Configurable hardware
– Universal ports
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Devices have different data Rates
different I/O techniques used
+ sensors, actuators, SSD, router
Embedded
2/16 Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Interface Performance Measures
• Latency
delay between service request and service
completion
» includes both software and hardware delays
for real-time systems
» guarantee must be made for worst-case latency
• Bandwidth (or throughput)
maximum rate at which data can be processed
• Priority
determines service order when more than one
request is pending
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Synchronizing SW w/ I/O Devices
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Synchronization Mechanisms
• Blind cycle
SW waits a fixed amount of time for the I/O to complete
» then samples input or produces another output
• Busy waiting
check I/O status flag once per iteration (previous example)
» waits for flag to indicate I/O done state
• Interrupt
I/O requests SW to become active
• Periodic polling
timer based interrupt requests software activity
» 6812 TCNT timer both more accurate and energy efficient than a cycle
counting software timer
• Direct Memory Access (DMA)
I/O device transfers data to/from controller memory
» memory used as a mailbox to facilitate communication
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Scalable Embedded I/O Bus Architectures
- Device I/O interfaces and Drivers for
Real-time Systems | Coursera
https://www.coursera.org/lecture/real-time-mission-
critical-systems-design/scalable-embedded-i-o-bus-
architectures-sGxqA
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
I/O Basics
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Device Drivers
• Part of kernel
– Compiled with OS, Dynamically loaded into OS
• Accept abstract R/W requests from device-independent layer ;
• Initialize device, Manage power, and log
• Check & translate input parameters
– e.g., convert linear block number into the head, track, sector and cylinder
number for disk access
• Check device status & Control sequence of commands
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
CPU Bus I/O
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
I/O Register operations
I/O Registers are NOT like normal memory
Device events can change their values (e.g., status registers)
Reading a register can change its value (e.g., error condition
reset)
For example, can't expect to get same value if read twice
Some are readonly (e.g., receive registers)
Some are writeonly (e.g., transmit registers)
Sometimes multiple I/O registers are mapped to same address
Selection of one based on other info (e.g., read vs. write or extra control
bits)
Cache must be disabled for memory-mapped addresses – why?
When polling I/O registers, should tell compiler that value can
change on its own and therefore should not be stored in a register
volatile int *ptr; (or int volatile *ptr;)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Parallel vs. Serial Digital Interfaces
Parallel $$$$
– Multiple parallel data lines
– Hi Speed
– Ex: PCI, ATA, CF cards
Serial convenient
– minimal data lines
– Low Power, length
– Ex: USB, SATA, SD (secure digital),
I2C, SPI, CAN, PCI-Express
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Serial vs. Parallel
TX
Serial MCU 1 RX MCU 2
signal
Data[0:7]
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Why Serial Communication?
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Simple Serial Port
Receive
Buffer Register
0 1 2 3 4 5 6 7
0 1 2 3 4 5 6 7
Receive
Shift Register
Transmit
Shift Register 0 1 2 3 4 5 6 7
Transmit 0 1 2 3 4 5 6 7
Hold Register
Processor Peripheral
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Protecting Against Data Loss
How can data be lost?
If the transmitter starts to send the next byte before the
receiver has had a chance to process/read the current byte
If the next byte is loaded at the transmitter end before the
current byte has been completely transmitted
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
FIFO Buffer FIFO Buffer
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
Clock Clock
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
Processor Peripheral
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
What is RS-232?
So far, we’ve talked about clocks being synchronized and using the
clock as a reference for data transmission
Fine for short distances (e.g., within chips on the same board)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Types of Serial Communications
Synchronous communication
Data transmitted as a steady stream at regular intervals
All transmitted bits are synchronized to a common clock signal
The two devices initially synchronize themselves to each other, and
then continually send characters to stay synchronized
Faster data transfer rates than asynchronous methods, because it does
not require additional bits to mark the beginning and end of each data
byte
Asynchronous communication
Data transmitted intermittently at irregular intervals
Each device uses its own internal clock resulting in bytes that are
transferred at arbitrary times
Instead of using time as a way to synchronize the bits, the data format is
used
Data transmission is synchronized using the start bit of the word, while
one or more stop bits indicate the end of the word
Asynchronous communications slightly slower than synchronous
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Sync vs. Async
Synchronous communications
Requires common clock (SPI)
Whoever controls the clock controls communication speed
Asynchronous communications
Has no clock (UART)
Speed must be agreed upon beforehand (the baud-rate configuration
accomplishes that)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
RS232 – Bits and Serial Bytes
7 6 5 4 3 2 1 0
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
RS-232 Signal Levels
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Serial Port Connector
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded Real-Time Systems
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Handshaking
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Interfacing Serial Data to Microprocessor
Processor has parallel buses for data need to convert serial data to
parallel (and vice versa)
Standard way is with UART
UART Universal asynchronous receiver and transmitter
Chip Reg
Select
Tx Clock
R/W
Control
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: tien.phamvan1@hust.edu.vn C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596