Professional Documents
Culture Documents
1
Busses: the glue that connects the pieces
C
Assembly
Software Central Machine Code
ISA Hardware
Processing
Unit
ldr (read)
bl (int) str (write)
System Buses
AHB/APB
Interrupts
Internal &
GPIO/INT Timers USART DAC/ADC External
Memory
Internal
External
2
Today…
3
Memory-Mapped I/O (MMIO)
• How?
– Let’s say that red, green, and blue pushbuttons are mapped to
memory address 0xB0000003 at bits 0, 1, and 2, respectively
– When pushed, we will read a ‘1’ from the corresponding bit
– When released, we will read a ‘0’ from the corresponding bit
– Must mask (and perhaps shift) to select target bits for reading
int isBlueButtonPressed() {
return (*((uint32_t *)PBS_REG) & 0x00000004) >> 2;
}
5
Writing register bits with MMIO
• How?
– Let’s say that red, green, and blue LEDs are mapped to memory
address 0xB0000004 at bits 0, 1, and 2, respectively
– Writing a ‘1’ (‘0’) to the corresponding bit turns on (off) the LED
• const
– Makes variable value or pointer parameter unmodifiable
– const x = 32;
• register
– Tells compiler to locate variables in a CPU register if possible
– register int x;
• static
– Preserve variable value after its scope ends
– Does not go on the stack
– static int x;
• volatile
– Opposite of const
– Can be changed in the background
– volatile int I;
7
Today…
8
AMBA: Advanced Microcontroller Bus Architecture
9
Busses: the glue that connects the pieces
C
Assembly
Software Central Machine Code
ISA Hardware
Processing
Unit
ldr (read)
bl (int) str (write)
System Buses
AHB/APB
Interrupts
Internal &
GPIO/INT Timers USART DAC/ADC External
Memory
Internal
External
10
Actel SmartFusion system/bus architecture
11
Advanced Microcontroller Bus Architecture (AMBA)
- Advanced/AMBA High-performance Bus (AHB)
- Advanced Peripheral Bus (APB)
AHB APB
• High performance • Low power
• Pipelined operation • Latched address/control
• Burst transfers • Simple interface
• Multiple bus masters • Suitable of many
• Split transactions peripherals
12
AMBA: Advanced Microcontroller Bus Architecture
13
APB: a simple bus that is easy to work with
• Low-cost
• Low-power
• Low-complexity
• Low-bandwidth
• Non-pipelined
14
Notation
15
APB
APB States:
IDLE:
PSELx = 0;
PENABLE = 0;
Transfer = OFF;
SETUP:
PSELx = 1;
PENABLE = 0;
Transfer = START;
ACCESS:
PSELx = 1;
PENABLE = 1;
Transfer = ON;
16
APB bus state machine
• IDLE
– Default APB state
• SETUP
– When transfer required
– PSELx is asserted Setup phase begins
with this rising edge
– Only one cycle
• ACCESS
– PENABLE is asserted
– Addr, write, select, and
write data remain stable
– Stay if PREADY = L
– Goto IDLE if PREADY = H
and no more data
– Goto SETUP is PREADY = H
and more data pending Setup Access
Phase Phase
17
APB Master-Slave Interface
18
APB Master
19
APB Slave
20
APB Write transfer Signals direction
22
APB bus signals in action
• PCLK
– Clock
• PADDR
– Address on bus
• PWRITE
– 1=Write, 0=Read
• PWDATA
– Data written to the I/O
device. Supplied by the bus
master/processor.
23
APB bus signals
• PSEL
– Asserted if the current bus
transaction is targeted to
this device
• PENABLE
– High during entire
transaction other than the
first cycle.
• PREADY
– Driven by target. Similar to
ACKNOWLEDGE signal.
Indicates if the target is
ready to do transaction.
Each target has it’s own
PREADY
24
A write transfer with no wait states
Setup Access
Phase Phase
25
A write transfer with no wait states
26
A write transfer with wait states
27
APB Multiple Write Transfers
28
A read transfer with no wait states
Setup Access
Phase Phase
29
A read transfer with wait states
30
APB Multiple Read Transfers
31
APB Back to Back Transfers
32
Error response
33
Error response
34
Failing write transfer
35
Failing read transfer
36
APB 2.0 and 3.0 add-ons
37
Write strobes
• The write strobe signals ‘PSTRB’ enable sparse data transfer on the write
data bus
• Each write strobe signal corresponds to one byte of the write data bus
• When asserted HIGH, a write strobe indicates that the corresponding byte
lane of the write data bus contains valid information
• There is one write strobe for each eight bits of the write data bus, so
PSTRB[n] corresponds to PWDATA[(8n+7):(8n)]
• For read transfers the bus master must drive all bits of PSTRB LOW
38
Protection unit support
• To support complex system designs, it is often necessary for both the interconnect
and other devices in the system to provide protection against illegal transactions
• For the APB interface, this protection is provided by the PPROT[2:0] signals
39
Example setup
D1
D2
41
Design
What ifawe
device
wantwhich writes
to have to a of
the LSB register whenever
this register
any address
control in its range is written
an LED?
PWDATA[31:0] PREADY
PWRITE
32-bit Reg
PENABLE D[31:0]
Q[31:0]
EN
PSEL
C LED
PADDR[7:0]
PCLK
PWRITE D[31:0]
Q[31:0]
EN
PENABLE C
PSEL
D[31:0]
Q[31:0]
PCLK
EN
The key thing here is that each slave device has its own read data (PRDATA) bus!
Recall that “R” is from the initiator’s viewpoint—the device drives data when read.
44
Let’s say we want a device that provides data from
a switch on a read to any address it is assigned.
(so returns a 0 or 1)
PREADY
PRDATA[31:0]
PWRITE
PENABLE
Switch1
PSEL
PADDR[7:0]
PCLK
45
Device provides data from switch A if address
0x00001000 is read from. B if address 0x00001004
is read from
PREADY
PRDATA[31:0]
PWRITE
PENABLE
PSEL Switch1
PADDR[7:0] Switch2
PCLK
46
All reads read from register, all writes write…
PWDATA[31:0] PREADY
PRDATA[31:0]
PWRITE
32-bit Reg
PENABLE
D[31:0]
Q[31:0]
PSEL EN
C
PADDR[7:0]
PCLK
PREADY
• PRESETn
– Active low system reset signal
– (needed for stateful peripherals)
48
Verilog!
assign PSLVERR = 0;
assign PREADY = 1;
// regA is updated with APB slave interface register read and write always blocks
49
Actel/Microsemi implementation of CoreAPB3
50
Today…
51
AHB-Lite supports single bus master and provides high-
bandwidth operation
52
AHB-Lite bus master/slave interface
• Global signals
– HCLK
– HRESETn
• Master out/slave in
– HADDR (address)
– HWDATA (write data)
– Control
• HWRITE
• HSIZE
• HBURST
• HPROT
• HTRANS
• HMASTLOCK
• Slave out/master in
– HRDATA (read data)
– HREADY
– HRESP
53
AHB-Lite signal definitions
• Global signals
– HCLK: the bus clock source (rising-edge triggered)
– HRESETn: the bus (and system) reset signal (active low)
• Master out/slave in
– HADDR[31:0]: the 32-bit system address bus
– HWDATA[31:0]: the system write data bus
– Control
• HWRITE: indicates transfer direction (Write=1, Read=0)
• HSIZE[2:0]: indicates size of transfer (byte, halfword, or word)
• HBURST[2:0]: indicates single or burst transfer (1, 4, 8, 16 beats)
• HPROT[3:0]: provides protection information (e.g. I or D; user or handler)
• HTRANS: indicates current transfer type (e.g. idle, busy, nonseq, seq)
• HMASTLOCK: indicates a locked (atomic) transfer sequence
• Slave out/master in
– HRDATA[31:0]: the slave read data bus
– HREADY: indicates previous transfer is complete
– HRESP: the transfer response (OKAY=0, ERROR=1)
54
Key to timing diagram conventions
• Timing diagrams
– Clock
– Stable values
– Transitions
– High-impedance
• Signal conventions
– Lower case ‘n’ denote
active low (e.g. RESETn)
– Prefix ‘H’ denotes AHB
– Prefix ‘P’ denotes APB
55
Basic read and write transfers with no wait states
Pipelined
Address
& Data
Transfer
56
Read transfer with two wait states
57
Write transfer with one wait state
58
Wait states extend the address phase of next transfer
Address stage of
the next transfer
is also extended
59
MMIO: Memory-Mapped I/O review
60
Burst transfer
• The main advantage of burst mode over single mode is that the burst
mode typically increases the throughput of data transfer.
• Any bus transaction is typically handled by an arbiter, which decides
when it should change the granted master and slaves.
• In case of burst mode, it is usually more efficient if you allow a master to
complete a known length transfer sequence.
• The total delay in a data transaction can be typically written as a sum of
initial access latency plus sequential access latency.
• Here the sequential latency is same in both single mode and burst mode,
but the total initial latency is decreased in burst mode, since the initial
delay (usually depends on FSM for the protocol) is caused only once in
burst mode. Hence the total latency of the burst transfer is reduced, and
hence the data transfer throughput is increased.
• It can also be used by slaves that can optimize their responses if they
know in advance how many data transfers there will be.
• The typical example here is a DRAM which has a high initial access
latency, but sequential accesses after that can be performed with fewer
wait states.
61
Transfers can be of four types (HTRANS[1:0])
• IDLE (b00)
– No data transfer is required
– Slave must OKAY w/o waiting
– Slave must ignore IDLE
• BUSY (b01)
– Insert idle cycles in a burst
– Burst will continue afterward
– Address/control reflects next transfer in
burst
– Slave must OKAY w/o waiting
– Slave must ignore BUSY
• NONSEQ (b10)
– Indicates single transfer or first transfer of
a burst
– Address/control unrelated to prior
transfers
• SEQ (b11)
– Remaining transfers in a burst
– Addr = prior addr + transfer size
62
A four beat burst with master busy and slave wait
Master busy
indicated by
HTRANS[1:0]
63
Controlling the size (width) of a transfer
64
Controlling the burst beats (length) of a transfer
• Incremental burst
• Wrapping bursts
– 4 beats x 4-byte words wrapping
– Wraps at 16 byte boundary
– E.g. 0x34, 0x38, 0x3c, 0x30,…
65
A four beat wrapping burst (WRAP4)
66
A four beat incrementing burst (INCR4)
67
An eight beat wrapping burst (WRAP8)
68
An eight beat incrementing burst
(INCR8) using half-word transfers
69
An undefined length incrementing burst (INCR)
70
Multi-master AHB-Lite
requires a multi-layer interconnect
• AHB-Lite is single-master
• Multi-master operation
– Must isolate masters
– Each master assigned to layer
– Interconnect arbitrates slave
accesses
71
unaligned data transfers
72
AXI features
73
74
Architecture
75
Key Features of AXI Protocol
76
Channel Definition
77
Flexible Interconnect
78
Basic AXI Transactions
79
AXI Transaction Handshake Dependencies
80
AXI Channel Handshaking
81
AXI Signals
82
AHB/AXI Burst Transfer
83
AHB/AXI Burst Transfer
84
85