Agenda
Traditional Embedded System Design Embedded Processor in FPGAs Design Flow with FPGAs Conclusion
Embedded Systems
Computing Systems inside a specific device application Embedded System = Embedded Processor + Peripherals + Software Must Work in Real Time ! Usually Responds to External Stimulus
Incoming Call on a Cell Phone
Design Flow
System Specification Algorithm Modeling HW/SW Partitioning Processor System Specification Selection Peripheral Algorithm Modeling Design Custom IP HW/SW Partitioning Design HW/SW HW Integration System HW Validation RTOS Selection Data Flow & Control Flow Development Driver Development SW Integration Verify using Emulation/Simulation Model
Nios II CPU
Debug
FPGA
6 Copyright 2005 Altera Corporation
irq[31..0]
Interrupt Controller
Data Cache
Fast 4X Faster
150 100 50
Economy 50% Smaller Standard 10% Smaller Over 2X Faster
0 0
Results Based on Stratix II FPGA Copyright 2005 Altera Corporation
500
1000
CPU Core Size (Logic Elements)
1500
2000
Nios II /s Standard
5 Stage 3 Cycle Static Configurable None 1200 1400 Up to 256
Nios II /e Economy
None Emulated In Software None None None 600 700
250 3 1
Nios II/s
90 DMIPS @ 175MHz 800 LEs 4K Icache, No Dcache Stratix 2S10-C5 67 DMIPS @ 135MHz 1200 LEs 4K Icache, No Dcache Stratix 1S10-C5 62 DMIPS @ 125MHz 1200 LEs 2K Icache, No Dcache Cyclone 1C4-C6
Nios II/e
28 DMIPS @ 190MHz 400 LEs No Icache, No Dcache Stratix 2S10-C5 22 DMIPS @ 150MHz 550 LEs No Icache, No Dcache Stratix 1S10-C5 20 DMIPS @ 140MHz 550 LEs No Icache, No Dcache Cyclone 1C4-C6
Stratix
Cyclone
* FMax Numbers Based Reference Design Running From On-Chip Memory (Nios II/f 1.15 DMIPS / MHz)
11
Off-Chip
SRAM CFI Flash
Parallel l/O JTAG UART LCD Display Ethernet Port System ID Peripheral Interface to User Logic Interface to Altera IP
12
Timer n
SPI 0
SPI n
GPIO n
DMA 0
DMA n
Switch PIO
Transfer Types
Slave Transfers Master Transfers Streaming Transfers Latency-Aware Transfers Burst Transfers
Read
LED PIO
PIO-32
UserDefined Interface
ROM
(with Monitor)
UART
Timer
14
15
16
User-Defined Custom Peripherals What if I need to add a peripheral not included with the Nios II system?
user wants to add own peripheral to perform some kind of proprietary Expand or accelerate system capabilities
17
Custom Instructions
Augment Nios II Instruction Set
Mux User Logic Into ALU Path of Processor Pipeline
18
SOPC Builder
LE
M4K
M512
Synthesis
I/O
- Translate Design into Device Specific Primitives - Optimization to Meet Required Area & Performance Constraints - Spectrum, Synplify, Quartus II
Timing Analysis
- Verify Performance Specifications Were Met - Static Timing Analysis
20
Web-Based IP Deployment
21
22
23
24
25
26
27
Project Directories
Hardware
HDL Source & Netlist db - Quartus project database
Software
Application source code Library files
Simulation
Testbench Automatically generated test memory and vectors
28
RTL Simulation
Nios II SOPC Builder Automatically Creates Simulation Models Plus:
ModelSim Project Testbench Simulation Scripts
Simulation TestBench
Ethernet MAC/PHY Dev board SRAM Dev board FLASH Compact FLASH SDRAM
Nios II Processor
Address (32)
Tri-State Bridge
Tri-State Bridge
SDRAM Controller
On Chip ROM)
On Chip RAM
Clock
Reset
User Device
User Peripheral
30
User Device
31
32
33
35
Hardware Development
Software Development
Nios II IDE
C Header files Custom Library Peripheral Drivers
Generate
Hardware Configuration File Executable Code
User Code
Quartus II
Altera PLD
On-Chip Debug
Software Trace Hard Breakpoints SignalTap II
Libraries RTOS
GNU Tools
37
39
Nios II IDE
Terminal window
40
Note: C++ files must have extension .cpp In-line assembly code offset by asm();
41
42
43
Drivers Directory
- contains all device drivers DO NOT DELETE !
44
45
46
Project Properties
Both Application and System Library have Properties pages
47
48
Software Compilation
To compile a software application, highlight your project and select Build Project from the Projects menu
49
50
51
Gives a consistent POSIX-like API, regardless of underlying hardware Make programming as familiar as possible to software engineers who may not be familiar with the specific peripheral architectures
ANSI C (through the Newlib library) UNIX style interface (i.e. POSIX like) Altera extensions where standards dont exist or were inappropriate (watch for the alt_* extension)
52
53
User Program
HAL API _exit() close() closedir() fstat() getpid() gettimeofday() ioctl() isatty() kill() lseek() open() opendir read() readdir() rewinddir() sbrk() settimeofday() stat() usleep() wait() write()
HAL API
Device Driver Device Driver Device Driver
54
/dev
/mnt
/dev/jtag_uart0
/dev/lcd0
/mnt/rozipfs
/mnt/rozipfs/myfile1
Device names match those set in SOPC builder. Can only access nodes, not directories. All paths must be absolute (no current directory)
/mnt/rozips/myfile21
55
UNIX Style:
fd = open (/dev/lcd0, O_WRONLY); write (fd, msg, strlen(msg));
Existing code (outside the Nios world) uses these interfaces. Porting is now much easier. Use of existing standards means theres nothing new to learn.
56 Copyright 2005 Altera Corporation
system.h
system.h
Contains macro definitions for system parameters, including peripheral configuration, for instance:
Hardware configuration of the peripheral Base address IRQ priority (if any) Symbolic name for peripheral
Does not include: static information, function prototypes, or device structures (unlike the old excalibur.h) Located in the syslib project directory Rarely necessary to include it explicitly in your application code, which improves rebuild time
58
system.h - example
Defines system settings and peripheral configurations:
Replaces excalibur.h (from Nios)
/* * system configuration * */ #define ALT_SYSTEM_NAME "std_1s10ES" #define ALT_CPU_NAME "cpu" #define ALT_CPU_ARCHITECTURE "altera_nios2" #define ALT_DEVICE_FAMILY "STRATIX" #define ALTERA_NIOS_DEV_BOARD_STRATIX_1S10_ES #define ALT_STDIN "/dev/jtag_uart" #define ALT_STDOUT "/dev/jtag_uart" #define ALT_STDERR "/dev/jtag_uart" #define ALT_CPU_FREQ 50000000 #define ALT_CPP_CONSTRUCTORS #define ALT_IRQ_BASE NULL
. . .
/* * button_pio configuration * */ #define BUTTON_PIO_NAME "/dev/button_pio" #define BUTTON_PIO_TYPE "altera_avalon_pio" #define BUTTON_PIO_BASE 0x00920830 #define BUTTON_PIO_IRQ 2 #define BUTTON_PIO_HAS_TRI 0 #define BUTTON_PIO_HAS_OUT 0 #define BUTTON_PIO_HAS_IN 1 #define BUTTON_PIO_CAPTURE 1 #define BUTTON_PIO_EDGE_TYPE "ANY" #define BUTTON_PIO_IRQ_TYPE "EDGE" #define BUTTON_PIO_FREQ 50000000
. . .
59 Copyright 2005 Altera Corporation
HAL References
Each HAL project references library routines and drivers for the components included in your Nios II system
60
61
63
Interrupts
HAL API for ISRs - Functions
alt_irq_register()
Associates interrupt with your ISR function.
alt_irq_disable_all()
Disables all IRQs
alt_irq_enable_all()
Enables all IRQs
alt_irq_interruptible()
Used in ISR function body. Allows ISR to be interrupted by higher priority IRQs.
alt_irq_non_interruptible()
Used to make ISRs uninterruptible (default behavior).
64 Copyright 2005 Altera Corporation
id == irq number (0 to 31) context == void pointer to data produced by or consumed by ISR.
65
Keep it simple. Use ISR to trigger execution of slow processing tasks outside of interrupt context Do NOT perform these tasks within ISR References: Exception Handling Chapter in Nios II Software Developers Handbook
66
68
69
70
71
72
73
Basic Debug
Run Controls Stack View Active Debug Sessions
Memory View
Variables Registers Signals
Copyright 2005 Altera Corporation
74
Disconnect Terminate Suspend Resume Run last Configuration Debug last Configuration
Copyright 2005 Altera Corporation
75
76
77
78
79
80
81
82
83
Nios II Console
Allows for hardware breakpoints and trace data
2 HWBPs and 16 Frames of OnChip Trace Included
84
Provider
Altera
Description
Features
IDE / Debugger JTAG Target Connection, H/W Breakpoints, Data Triggers, On-Chip Trace, FS2 Trace Probe IDE / Debugger JTAG Target Connection, H/W Breakpoints, Data Triggers, On-Chip Trace , FS2 Trace Probe Debugger Supports FS2 ISA-Nios/T
** code|lab
ATI Mentor
Watchpoint
ISA-Nios/T
* Included in Nios II Development Kits ** Evaluation Version Included in Nios II Development Kits
85 Copyright 2005 Altera Corporation
Nios II IDE
2 2 On-Chip 16 Frames No No Altera USB/B Blaster Included
86
87
Custom Instruction
Add your logic to the ALU Stalls the CPU while running the Instruction
Copyright 2005 Altera Corporation
89
91
Creates Interface
Connect to Existing HDL or board component Map into Nios II Memory Space Can be Inside or Outside Nios II System
I/O Nios II CPU Avalon I/O I/O I/O Interface to User Logic External User Peripheral Nios II CPU Avalon I/O I/O I/O I/O Internal User Peripheral
92
93
94
Summary
Processors Peripherals Optimized Interconnect SOPC Builder Nios II IDE On-Chip Processor Debug SignalTap II Logic Analyzer Concept to System in Minutes FPGA > HardCopy Structured ASIC
96