Yann DOUZE
Polytech’Paris UPMC – E2i3
UE CoDesign
C1 : Présentation du NIOS II
Qu’est ce qu’un « Soft » processeur ?
� Un processeur décrit dans un langage HDL (VHDL, Verilog) et qui peut être implémenter dans un FPGA
� On peut implémenter plusieurs processeurs en parallèle sur le même FPGA (MPCore : Multi Processeur Core)
� On peut utiliser le reste des ressources du FPGA pour accélérer ou customiser le processeur.
� Egalement appelé « Softcore »
Avantage d’un SoftCore ?
�High Level of Design Reuse
�Réduction du risque d'obsolescence
� Simplifie la mise à jour ou les modifications
�Davantage d'options de mise en œuvre
�Plus faible latence entre le processeur et les composants du FPGA.
4
What is Nios II?
� Altera’s Second Generation Soft-Core 32 Bit RISC Microprocessor� Developed Internally By Altera
� Harvard Architecture
� Royalty-Free
FPGA
- Nios II Plus All Peripherals Written In HDL
- Can Be Targeted For All Altera FPGAs
- Synthesis Using Quartus II Integrated Synthesis
Ava
lon
Sw
itch
Fab
ric UART
GPIO
Timer
SPI
SDRAMController
On-ChipROM
On-ChipRAM
Nios IICPUDebug C
ach
e
5
32-BitNios II
ProcessorROM
(with Monitor)
On-Chip Off-Chip
Address (32)
Read
Write
Data In (32)
Data Out (32)
IRQ
IRQ #(6)
Avalo
n Sw
itch Fab
ric
Nios II Processor
Standard Reference Design Block Diagram
Tri-StateBridge
Leve
l Sh
ifte
r
16MB Compact FLASH
SDRAMController
8MB FLASH
1MB SRAMEthernet
MAC/PHY32MB
SDRAM
Tri-StateBridge
Compact Flash PIOs
Button PIO7-SegmentLED PIO
LCD PIOLED PIO
General Purpose
Timer
Periodic Timer
UART
8 LEDsExpansion Header J12
2 Digit Display
4 Momentary
buttons
Reconfig PIO
JTAG_UART
6
Nios II Versions
� Nios II Processor Comes In Three ISA Compatible Versions
� Software� Code is Binary Compatible
� No Changes Required When CPU is Changed
− FAST: Optimized for Speed
− STANDARD: Balanced for Speed and Size
− ECONOMY: Optimized for Size
7
Binary Compatibility / Flexible Performance
Nios II /fFast
Nios II /sStandard
Nios II /eEconomy
Pipeline 6 Stage 5 Stage None
H/W Multiplier & Barrel Shifter 1 Cycle 3 Cycle
EmulatedIn Software
Branch Prediction Dynamic Static None
Instruction Cache Configurable Configurable None
Data Cache Configurable None None
Logic Usage (Logic Elements)
1400 - 1800 1200 – 1400 600 – 700
CustomInstructions Up to 256
8
Custom Peripheral Integration
9
Custom Peripheral Structure
10
C2H Hardware Accelerator Block
� Custom Peripheral automatically generated from ANSI C function and integrated into Avalon Switch Fabric
ProgramMemory
CPU
DataMemory
ArbiterArbiter
DataMemory
ArbiterArbiter
C2HAccelerator
C2HAccelerator
11
Nios II Custom Instructions� Augment Nios II Instruction Set.
� A custom instruction written in HDL or schematic format can easily be added in parallel with the Nios II ALU, providing extended capabilities to the processor.
Objectif du C/TP11. Créer votre système autour du NiosII :
SOPC : System On Programmable Chip
2. Exécuter du code C sur ce système.
Cyclone IIFPGA ChipCyclone IIFPGA Chip
…………
[LEDR17…LEDR0][LEDG7…LEDG0]
Host Computer
USB-Blaster Interface
JTAG UART Interface
JTAG Debug Module
NIOS II Processor
Avalon Switch Fabric
SRAMInterface
SRAMChip
Timer
Switches and Key parallel input
interface
………..
[SW17..SW0] [KEY3..KEY0]
Red and Green LEDs parallel
output interface
7 segments parallel output interface
………….....
HEX7 HEX0
API Nios II� Pour lire la valeur d’un registre dans le périphérique SWITCH:
sw=IORD_ALTERA_AVALON_PIO_DATA(SWITCH_BASE);
� Pour écrire dans un registre du périphérique LEDR :
IOWR_ALTERA_AVALON_PIO_DATA(LEDR_BASE,sw);
� LEDR_BASE et SWITCH_BASE correspondent aux adresses des périphériques LEDR et SWITCH.Voir system.h dans NiosII_training_project_syslib ���� Debug ����
System Description ���� System.h
API Nios II� Lorsque un périphérique comporte plusieurs registres, comme le
périphérique SEVEN_SEG, il faut rajouter un offset à l’adresse SEVEN_SEG_BASE afin d’écrire dans les différents registres du périphérique.
IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_BASE + 0, SevenSeg[0] );
IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_BASE + 4, SevenSeg[1] );
IOWR_ALTERA_AVALON_PIO_DATA(SEVEN_SEG_BASE + 8, SevenSeg[2] );
Voir le code de2_sevensegs.vhd
C2 : Custom Peripheral
Yann DOUZE
Polytech’Paris UPMC – E2i3
UE CoDesign
2
Custom Peripheral Integration
3
Custom Peripheral Structure
Principaux signaux du bus Avalon
Nom Largeur Direction Description
ReadRead_n
1 Entrée Demande de lecture.
WriteWrite_n
1 Entrée Demande d’écriture.
address 1-32 entrée Bus d’adresse.
readdata 8,16,32,64,128,256,512,1024
Sortie Bus de données pour la lecture.
writedata 8,16,32,64,128,256,512,1024
Entrée Bus de données pour l’écriture.
chipselect 1 Entrée Bit de sélection du composant. Si actif, le composant à le contrôle sur le bus de données.
Signaux PWM
Génération de PWM
DIV
pwm_out
DUTY
TP2 : Périphérique avalon_pwm
avalon_pwm
Interface avec le Bus Avalon
address
writedata
chipselect
write_n
readdata
DIV
DUTY
Partie opérative
pwm_out
clkReset_n
Entité de l’IP PWMentity avalon_pwm is
port (
clk : in std_logic;
writedata : in std_logic_vector (31 downto 0);
chipselect : in std_logic;
write_n : in std_logic;
address : in std_logic;
reset_n : in std_logic;
readdata : out std_logic_vector (31 downto 0);
out_port : out std_logic_vector (7 downto 0) );
end entity;
Partie opérativesignal div : unsigned (31 downto 0);signal duty : unsigned (31 downto 0);signal counter : unsigned (31 downto 0);signal pwm_on : std_logic;
…..divider: process (clk, reset_n)beginif reset_n = '0' thencounter <= (others => '0');
elsif clk'event and clk = '1' thenif counter >= div thencounter <= (others => '0');
elsecounter <= counter + 1;
end if;end if;
end process;
duty_cyle: process (clk, reset_n)beginif reset_n = '0' thenpwm_on <= '1';
elsif clk'event and clk = '1' thenif counter >= duty thenpwm_on <= '0';
elsif counter = 0 thenpwm_on <= '1';
end if;end if;
end process;out_port <= (others=> pwm_on);
Interface avec le bus avalonreaddata <= std_logic_vector(div) when address = '0' else
std_logic_vector(duty);registers: process (clk, reset_n)beginif reset_n = '0' thendiv <= (others => '0');duty <= (others => '0');
elsif clk'event and clk = '1' thenif chipselect ='1' and write_n = '0' thenif address = '0' thendiv (31 downto 0) <= unsigned(writedata (31 downto 0));
elseduty (31 downto 0) <= unsigned(writedata (31 downto 0));
end if;end if;
end if;end process;
Insertion dans le système Nios II
Nios II System
CPU : Nios II
Bus Avalon
avalon_pwm
LEDsVertes
Altera_avalon_pwm.h et pwm.cAltera_avalon_pwm.h, déclaration des fonctions qui permettent de lire ou écrire dans
DIV et DUTY :
#include <io.h>
#define IORD_ALTERA_AVALON_PWM_DIVIDER(base) IORD(base, 0)
#define IOWR_ALTERA_AVALON_PWM_DIVIDER(base, data) IOWR(base, 0, data)
#define IORD_ALTERA_AVALON_PWM_DUTY(base) IORD(base, 1)
#define IOWR_ALTERA_AVALON_PWM_DUTY(base, data) IOWR(base, 1, data)
Pwm.c, utilisation des fonctions qui permettent d’écrire dans les registres DIV et DUTY :
IOWR_ALTERA_AVALON_PWM_DIVIDER(AVALON_PWM_INST_BASE,0xFF;
IOWR_ALTERA_AVALON_PWM_DUTY(AVALON_PWM_INST_BASE,0xFF);