Documente Academic
Documente Profesional
Documente Cultură
Nios II UART
Cache
On-Chip Timer
ROM
SPI
On-Chip SDRAM
RAM Controller
FPGA
I/O Flash
CPU
SDRAM
I/O
I/O I/O I/O
DSP
I/O FPGA
CPU DSP
Flash
FPGA
SDRAM
CPU is a Critical
Solution: ReplaceControl Function
External Devices
Required forProgrammable
with System-Level Logic
Integration
Copyright © 2005 Altera Corporation
6
FPGA Hardware Design Flow
with Quartus II and SOPC Builder
10/100 Ethernet
MAC/PHY &
RJ-45 Connector
CPU Reset Expansion
Prototype
8 MB Flash Connectors
(40 I/O pins each)
16 MB SDRAM
1MB SRAM
Configuration Controller
Compact Flash Buttons LEDs 7 Segment (MAX 7128AE)
(Connector Mounted on Back)
Configuration Control
Copyright © 2005 Altera Corporation
8
Standard Design Block Diagram
Ethernet 1MB 8MB 16MB Compact 32MB
MAC/PHY SRAM FLASH FLASH SDRAM
Nios II Processor
Compact
Address (32) Tri-State Tri-State SDRAM
Flash
Level Shifter
Bridge Bridge Controller
Read PIOs
32-Bit
Avalon Switch Fabric
Write
Nios II
Processor Data In (32) UART
General
Data Out (32) ROM Periodic
Purpose
(with Monitor) Timer
Timer
Reconfig
PIO
IRQ
Expansion 4
2 Digit
On-Chip Off-Chip 8 LEDs Header Momentary
Display
J12 buttons
Exception
Controller
Control
Interrupt Registers
irq[31..0] Controller ctl0 to ctl4
Data
Master
Port
Data
Custom Arithmetic Cache
Custom Instruction Logic Unit
I/O Signals Logic
Software
Code is Binary Compatible
No Changes Required When CPU is Changed
Logic Usage
1400 - 1800 1200 – 1400 600 – 700
(Logic Elements)
Custom
Instructions Up to 256
Supported through
www.niosforum.com
Hardware Executable
Configuration Code
Synthesis & Compiler,
File
Fitter Verification Linker, Debugger
& Debug
JTAG,
Serial, or
User Design Ethernet
User Code
Other IP Blocks Libraries
On-Chip
Altera Debug RTOS
Quartus II FPGA Software Trace
Hard Breakpoints GNU Tools
SignalTap® II
Libraries
to run with the Nios II IDE RTOS
GNU Tools
File Viewer
List of Open Window
Projects
(for C code,
C++, and
assembly*)
Terminal
window
Application Project
- contains application
source code
Drivers Directory
- contains all device
drivers – DO NOT
DELETE !
/dev /mnt
/mnt/rozipfs/myfile1
system.h
References:
Exception Handling Chapter in “Nios II Software Developer’s
Handbook”
Basic Debug
• Run Controls
• Stack View
• Active Debug
Sessions
Double-click to
add breakpoints
Memory View
•Variables
•Registers
•Signals
Step Return
Step Over
Step Into
Step with Filters
Disconnect
Terminate
Suspend
Resume
Nios II Processor
Compact
Address (32) Tri-State Tri-State SDRAM
Flash
Bridge Bridge Controller
Avalon Switch Fabric
Read PIOs
32-Bit
Write
Nios II
Processor Data In (32)
On Chip On Chip Custom
User Device
Data Out (32)
ROM) RAM Instruction
UART
IRQ
User User
IRQ #(6) Defined Defined
Peripheral Interface
User Device
User Included
Clock Reset Peripheral
Not Included
Copyright © 2005 Altera Corporation
104
User Additions to Nios II TestBench
A B C D E
clk
A B C D E F G H
clk
Tsu
readn
readdata readdata
A B C D
clk
address,be_n address, be_n
writedata writedata
writen
chipselect
A B C D E F G
clk
address,be_n address, be_n
writedata writedata
writen
chipselect
Master Master
Master Clock Domain 1
Clock Domain 2
Clock Domain 1
CDX
CDX
Arbiter
Arbiter
Arbiter
Arbiter CDX
Slave Slave
Clock Domain 3 Clock Domain 2
Concentrate Effort on
Peripheral Functionality!
Copyright © 2005 Altera Corporation
132
New Component Editor
I/O I/O
Nios II Nios II
CPU I/O CPU I/O
Avalon
Avalon
I/O I/O
I/O I/O
off-chip peripherals
Base interface type
on data sheet
Interface to
User Logic
Off Chip
Tri-State
Avalon
Bridge
Nios II Peripheral
Processor
FPGA
Avalon
Processor Base + 0x1 bb
8 Base + 0x2 cc
8 Bit
Peripheral Base + 0x3 dd
Base + 0x4 ee
Avalon
Processor
Base + 0x8
64
64 Bit
Base + 0x16 ff ee dd cc bb aa 99 88
Memory
?? ?? ?? ?? ?? ?? ?? ??
Fill in fields
Add component to
SOPC Builder portfolio
Can add parameterizing
capability to component
Application Examples
Data Stream Processing (eg. Network Applications)
Application Specific Processing (eg. MP3 Audio Decode)
Software Inner Loop Optimization
dataa
result
datab 32 Combinatorial
32
32
clk
clk_en
Multi-Cycle done
reset
start
n
Extended
8
a readra
b 5 Internal readrb
5 Register File writerc
c
5
Copyright © 2005 Altera Corporation
153
Custom Instructions
Integrated Into Nios II Development Tools
SOPC Builder design tool handles op-code assignment
Generates C and assembly-language macros
Port list
All Custom Instruction Modules need these ports
Port names must match exactly
dataa[31..0]
result[31..0]
Custom
reada Logic writec
c[4..0]
a[4..0]
a_swap = ALT_CI_BSWAP(a);
return 0;
}
Two Examples:
r = Nios II processor
custom 0, r6, r7, r8
register
custom 3, c1, r2, c4
c = Custom instruction
internal register
result_slow
result_slow == aa ** b;
b; /*
/* Takes
Takes 266
266 clock
clock cycles
cycles */*/
result_fast
result_fast == ALT_CI_fpmult(a,b);
ALT_CI_fpmult(a,b); /*
/* Takes
Takes 66 clock
clock cycles*/
cycles*/
Significantly
SignificantlyFaster!
Faster!
Typical Flow
Profile Code
Identify Critical Inner Loop
Create Custom Instruction Logic
Replace One or All Instructions in Inner Loop
Import Custom Instruction Logic into Design
Call Custom Instruction from C or Assembly
0x408
Result
DataB
0x404
DataA
0x400
L0 Custom L0
L1 Peripheral
Custom Instruction
Nios Clock Cycles
custom REG
---
---
REG
Next Instr
Result
Custom Instruction
custom REG
Nios Clock Cycles
custom
custom
REG
custom
custom
Next Instr
Result
xor/shift
xor/shift
reg
////reset
resetcrc
crc CRC
Control
Custom Instruction
ALT_CI_CRC(0xFFFF,1);
ALT_CI_CRC(0xFFFF,1);
DataA(31-0) Data in
////run crc
run crc CRC Reg Result(15-0)
ALT_CI_CRC(word,0);
ALT_CI_CRC(word,0);
DataB(0) Init / nRun
System
Arbiter Determines
Control Bottleneck DMA Bus
DMA Arbiter
Arbitor Which Master Has
direction Access To Shared
Bus
System Bus
I/O I/O
Program Data
1 2
Slaves Memory Memory
System
Switch
Fabric
Arbiter Arbiter
# Bytes # Bytes
Direction
Control Port
Avalon Avalon
Arbiter
I/O I/O
1 2 Data
Program
Memory
Memory
1
DMA
DMA
Processor Accelerator
Avalon
Switch
Fabric Arbiter
Arbiter Arbiter
Arbiter
25,000,000
20,000,000
Clock Cycles
15,000,000
10,000,000 27 530
Times Times
Faster Faster
5,000,000
0
Software Only Custom Hardware
Instruction Accelerator
control
Avalon
Streaming readdata
Slave
dataavailable
Peripheral
Readyfordata
endofpacket
control
Custom
Avalon
writedata
Master
Peripheral readdata
waitrequest
SPI DMA
1 share
PCI DMA
2 shares
Copyright © 2005 Altera Corporation
182
Set Arbitration Priority
View => Show Arbitration Priorities
Master A Shares = 4
Master A Master B
Master B Shares = 2
Arbiter
Slave
Master A
Master B
Zero Skew
Buffer
Zero Skew
Buffer PLL
CLK in
(50 MHz)
Address
MAX® EPM7128 Configures FPGA from MAX
Flash
Upon power up or press of Reset Config
MAX Device Loads User Image into FPGA
If This Fails MAX Device Loads Safe Image
Failure includes no user image present
Upon press of Safe Config
MAX Device Loads Safe Image into FPGA
Copyright © 2005 Altera Corporation
189
Flash Memory Configuration
8 MB Flash
Safe FPGA
Image & S/W
0x700000
User FPGA Data
Image
0x600000
Stratix
0x500000
Address
0x400000
SRAM
0x300000 User
Software
0x200000
0x100000
0x000000
Copyright © 2005 Altera Corporation
190
Configuration of FPGA From Flash
0x1000000
Data
0xE00000
0xC00000
8 MB RAM Stratix
0xA00000
Nios II
0x800000
Data
0xE00000 Dynamic
Memory
0xC00000
8 MB RAM Stratix
Application
0xA00000 Code
Nios II
Start-up Code
0x800000
Address
Prepends Boot Copier to
Program Code SRAM
if Reset Address is in Flash and 8 MB Flash
Program Memory is in RAM
Flash Content
sof2flash
Bin2flash
elf2hex
nios2-flash-programmer