+ All Categories
Home > Design > Training Lecture

Training Lecture

Date post: 06-May-2015
Category:
Upload: iuui
View: 2,212 times
Download: 1 times
Share this document with a friend
Description:
EDK
145
EDK Training at University of Toronto Processor IP Team November 2003
Transcript
Page 1: Training Lecture

EDK Training atUniversity of TorontoProcessor IP Team

November 2003

Page 2: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 2

Table of ContentsIntroduction and Overview Page 3PowerPC and MicroBlaze Page 11Processor IP Page 19Creating a Simple MicroBlaze System with

XPS with Base System Builder Page 49Creating a Simple MicroBlaze System with

XPS without Base System Builder Page 79Adding I/O Peripherals to a System Page 96Software Development with the EDK and XPS Page 110Device Drivers & Software Infrastructure Page 119

Page 3: Training Lecture

Introduction andOverview

Page 4: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 4

Programmable Logic Evolution

1985

XC2000-XC3000 XC4000, Virtex® Virtex-II Pro™

1992 2000 2002

Dev

ice

Com

plex

ity

Virtex-II

2004

• FPGA Fabric• Block RAM• SelectIO• XCITE

Technology• DCM• Embedded

Multipliers• PowerPC• RocketIO

•• FPGA FabricFPGA Fabric•• Block RAMBlock RAM•• SelectIOSelectIO•• XCITEXCITE

TechnologyTechnology•• DCMDCM•• EmbeddedEmbedded

MultipliersMultipliers•• PowerPCPowerPC•• RocketIORocketIO

• FPGA Fabric• Block RAM• SelectIO• XCITE

Technology• DCM• Embedded

Multipliers

•• FPGA FabricFPGA Fabric•• Block RAMBlock RAM•• SelectIOSelectIO•• XCITEXCITE

TechnologyTechnology•• DCMDCM•• EmbeddedEmbedded

MultipliersMultipliers• FPGA Fabric• Block RAM•• FPGA FabricFPGA Fabric•• Block RAMBlock RAM• FPGA Fabric•• FPGA FabricFPGA Fabric

Glue Logic

Block Logic

System Platform

Platform

Page 5: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 5

Xilinx Virtex-II Pro FPGASetting the Standard in Programmable Logic

High performance truedual-port RAM - 10 Mb SelectIO™- Ultra

Technology - 1200 I/O

Advanced FPGA Logic -125,000 logic cells

Embedded XtremeDSPFunctionality - 556 multipliers

RocketIO™ High-speedSerial Transceivers - 24

PowerPC™ Processors400+ MHz Clock Rate - 4

XCITE Digitally ControlledImpedance - Any I/O

DCM™ Digital ClockManagement - 12

130 nm, 9 layer copper in 300 mm wafer technology

Page 6: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 6

Virtex-II Pro Revolution

• Up to 4 PowerPC 405 Processors– Industry standard– 420 DMIPS at 300 MHz

• Up to 24 Serial Transceivers– 622 Mbps to 3.125 Gbps

Built on the Success of Virtex-II Fabric

TM

Page 7: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 7

RocketIO™ SerDesLeading-Edge High-Speed Serial

• Multi-Rate– 3.125, 2.5, 2.0, 1.25, 1.0 Gbps– 2 - 24 transceivers

• Multi-Protocol– 1G, 10 G Ethernet (XAUI)– PCI Express– Serial ATA– InfiniBand– FibreChannel– Serial RapidIO– Serial backplanes…

• Key Features– Embedded 8B/10B Coding– 4-Level Pre-Emphasis– Programmable Output Swing– AC & DC Coupling– Channel bonding

SerialOut

On-ChipReference

Clock

TX Clock Generator

RX Clock Generator

De-Serializer

Serializer

Receive

Buffer

Transmitter

Receiver

FIFO8B/10B

Encode

10B/8B

Decode

Elastic

Buffer

SerialIn

Transmit

BufferTXDATA

8-32b Wide

TXDATA

8-32b Wide

RXDATA8-32b Wide

RXDATA8-32b Wide

Page 8: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 8

Virtex-II Pro Device FamilyCovers the Entire Design Spectrum

Page 9: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 9

Embedded Development Kit (EDK)

• All encompassing design environmentfor Virtex-II Pro PowerPCTM and MicroBlazebased embedded systems in Xilinx FPGAs

• Integration of mature FPGA andembedded tools with innovativeIP generation and customizationtools

• Delivery vehicle for Processor IP

Page 10: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 10

Compiler/Linker

(Simulator)

C/C++ Code

Debugger

Data2BlockRAM

Bitstream

ChipScope Tools

Xilinx PlatformStudio (XPS)

Standard Embedded SWDevelopment Flow

Standard FPGA HWDevelopment Flow

RTOS, Board Support Package

Synthesizer

Place & Route

Simulator

VHDL/Verilog

codein on-chipmemory

?codein off-chip memory

?

Download to Board & FPGA

Download to FPGA

EDK System DesignComprehensive Tool Chain

Object Code

Page 11: Training Lecture

PowerPC andMicroBlaze

Page 12: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 12

D-Side On-ChipMemory (OCM)

I-Cache(16KB)

D-Cache(16KB)

MMU(64 Entry TLB)

Execution Unit(32x32 GPR,ALU, MAC)

Fetch & Decode

Timers and

Debug Logic

Pro

cess

or

Lo

cal B

us

(PL

B)

JTAGInstruction

Trace

I-Side On-Chip Memory (OCM)

PowerPC 405

• 5-stage data path pipeline• 16KB D and I Caches• Embedded Memory

Management Unit• Execution Unit

– Multiply / divide unit– 32 x 32-bit GPR

• Dedicated on-chip memoryinterfaces

• Timers: PIT, FIT, Watchdog• Debug and trace support• Performance:

– 450 DMIPS at 300 MHz– 0.9mW/MHz Typical Power

Page 13: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 13

What is MicroBlaze?

• It’s a soft processor, around 900 LUTs

• RISC Architecture• 32-bit, 32 x 32 general purpose registers

• Supported in Virtex/E/II/IIPro, Spartan-III/II/E

Machine StatusReg

ProgramCounter

Data B

us Controller

RegisterFile

32 x 32bit

r0r1

r31

Addressside

LMB

Data Side LMB

InstructionBuffer

Instruction Bus C

ontroller

Control Unit

Multiply

Multiply

Add /Subtract

Shift /Logical Multiply

Processor

Page 14: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 14

More on MicroBlaze ...• Harvard Architecture

• Configurable instruction cache, data cache• Non-intrusive JTAG debug

• Support for 2 buses:– LMB (Local Memory Bus) - 1 clock cycle latency, connects to

BRAM– OPB (On-chip Peripheral Bus) - part of the IBM

CoreConnectTM standard, connects to other peripheral“Portable” IP between PPC and MB

• Big endian, same as PowerPC PPC405

Page 15: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 15

MicroBlaze Interrupts andExceptions

• Interrupt handling– 1 Interrupt port

• 32+ interrupts and masking supported through interruptcontroller(s)

• Exception handling– No exceptions generated in Virtex-II versions– One in Virtex/E and Spartan-II versions for MUL

instruction

Page 16: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 16

Software Tools

• GNU tool chain

• GCC - GNU Compiler Collection• GDB - The GNU debugger

– Source code debugging– Debug either C or assembly code

• XMD - Xilinx Microprocessor Debug utility– Separate Process

– Provides cycle accurate program execution data– Supported targets: simulator, hardware board

Page 17: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 17

Software - XMD• Interfaces GDB to a “target”• Allows hardware debug without a ROM monitor or reduces

debug logic by using xmd-stub (ROM monitor)• Offers a variety of simulation targets

– Cycle accurate simulator– Real hardware board interface via UART or MDM

• Includes remote debugging capability

XMDGDB MDM

UART

SIM

Page 18: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 18

• JTAG debug using BSCAN

• Supports multiple MicroBlazes• Software non-intrusive debugging

• Read/Write access to internal registers• Access to all addressable memory

• Hardware single-stepping• Hardware breakpoints - configurable (max 16)

• Hardware read/write address/data watchpoints– configurable (max 8)

MicroBlaze Debug Module

Page 19: Training Lecture

Processor IP

Hardware and Software

Page 20: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 20

Example MicroBlaze System

MicroBlaze

LMB_BRAMIF_CNTLR

OPB_V20

OPB_TIMER OPB_EMC

SYS_Clk /SYS_Rst

JTAG Debug OPB_INTC

P160SRAM

External to FPGA

BRAMBLOCK

OPB_MDM

OPB_GPIOOPB_UART

LITE

LMB_V10

OPB_ETHERNET

Serial Port

User LED P160Ethernet PHY

OPB_DDR

External to FPGA

DDRSDRAM

LMB_BRAMIF_CNTLR

LMB_V10

I-Side LMB D-Side LMB

D-Side OPBI-Side OPB

Page 21: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 21

Example PPC405 System

Jtag

PPC405

PLB_V34

PLB2OPBBRIDGE

OPB_V20

PROC_SYSRESET

JTAG

DCMRef_Clk

SYS_Rst_n

PLB_DDR

PLB_BRAMIF_CNTLR

DCR_V29

BRAMBLOCK

OPB2PLBBRIDGE

DCR_INTC(critical)

DCR_INTC(non-critical)

Serial Port

User Input/Output

OPB_ETHERNETOPB_GPIOOPB_UART16550

External PHY

Page 22: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 22

Processor IP (HW/SW)Infrastructure (includes Device Drivers)• MicroBlaze CPU

• LMB2OPB Bridge

• PLB Arbiter & Bus Structure (PLB_V34)• OPB Arbiter & Bus Structure (OPB_V20)

• DCR Bus Structure (DCR_V29)

• PLB2OPB Bridge• OPB2PLB Bridge

• OPB2OPB Bridge - Lite

• OPB2DCR Bridge• System Reset Module

• BSP Generator (SW only)

• ML3 VxWorks BSP (SW only)• Memory Test Utility (SW only)

OPB IPIF Modules (includes Device Drivers)• PLB IPIF

– OPB IPIF-Slave Attachment– OPB IPIF-Master Attachment– IPIF-Address Decode– IPIF-Interrupt Control– IPIF-Read Packet FIFOs– IPIF-Write Packet FIFOs– IPIF-DMA– IPIF-Scatter Gather– IPIF-FIFOLink

• PLB IPIF– PLB IPIF-Slave Attachment– PLB IPIF-Master Attachment– IPIF-Address Decode– IPIF-Interrupt Control– IPIF-Read Packet FIFOs– IPIF-Write Packet FIFOs– IPIF-DMA– IPIF-Scatter Gather– IPIF-FIFOLink

Page 23: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 23

Processor IP (HW/SW)Memory Interfaces (includes Device Drivers &

Memory Tests)• PLB EMC (Flash, SRAM, and ZBT)• PLB BRAM Controller• PLB DDR Controller• PLB SDRAM Controller• OPB EMC (Flash, SRAM, and ZBT)• OPB BRAM Controller• OPB DDR Controller• OPB SDRAM Controller• OPB SystemACE• LMB BRAM Controller

Peripherals (includes Device Drivers & RTOSAdapt. Layers)

• OPB Single Channel HDLC Controller• OPB<->PCI Full Bridge• OPB 10/100M Ethernet• OPB 10/100M Ethernet - Lite• OPB ATM Utopia Level 2 Slave• OPB ATM Utopia Level 2 Master

Peripherals (continued)• OPB IIC Master & Slave• OPB SPI Master & Slave• OPB UART-16550• OPB UART-16450• OPB UART - Lite• OPB JTAG UART• OPB Interrupt Controller• OPB TimeBase/Watch Dog Timer• OPB Timer/Counter• OPB GPIO• PLB 1G Ethernet• PLB RapidIO• PLB UART-16550• PLB UART-16450• PLB ATM Utopia Level 2 Slave• PLB ATM Utopia Level 2 Master• PLB ATM Utopia Level 3 Slave• PLB ATM Utopia Level 3 Master• DCR Interrupt Controller

Page 24: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 24

System Infrastructure

• Hardware IP– Common PowerPC and MicroBlaze peripherals– Peripherals are common across bus types– Parameterize for optimal functionality, optimal FPGA usage– IP Interface (IPIF) provides common hardware blocks

• Software IP (Device Drivers)– Common across processors and operating systems

Page 25: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 25

The Benefits of Parameterization

• Significantly increases performance or saves area• Only include what you need• This can only be accomplished in a programmable system

Resources F MAX

NUM_MASTERS PROC_INTERFACE DYNAM_PRIORITY PARK REG_GRANTS LUTs MHz1 N N N N 11 2952 N N N N 18 2234 N N N N 34 1934 Y N N N 59 1564 N Y N N 54 1694 N N Y N 83 1594 N N N Y 34 2014 Y Y Y Y 146 1458 Y Y Y Y 388 112

Parameter Values

Example: OPB Arbiter

Difference:>4x in size>30% in speed

Page 26: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 26

Full IP Interface (IPIF)

Bus AttachmentLayer

Bus/Core HWIndependent

Layer

ScatterGather

MasterAttachment

DMA

InterruptController

Read FIFOIP

Core from

Xilinx, 3rd party or custom

er

Addr Decode

Write FIFO

MU

X

SlaveAttachment

Processor B

us (OP

B or P

LB

)

• Consists of 8 modules– Each module is selectable and

parameterizable

• Automatically configures a coreto the processor bus

– Xilinx IP Cores

– 3rd Party IP Cores– Customer proprietary cores and

external devices

• OPB & PLB supported– Bus independent IP Cores and

associated Device Drivers

• IPIF will be added to otherLogiCOREs

IPIC

Page 27: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 27

Buses and Arbiters

• PLB– Arbitration for up to 16 masters– 64-bit and 32-bit masters and slaves

– IBM PLB compliant

• OPB– Includes arbiter with dynamic or fixed priorities and bus parking

– Parameterized I/O for any number of masters or slaves– IBM OPB compliant

• DCR– Supports one master and multiple slaves– Daisy chain connections for the DCR data bus

– Required OR function of the DCR slaves’ acknowledge signal

• LMB– MicroBlaze single-master Local Memory Bus

Page 28: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 28

Bridges

• PLB to OPB– Decode up to 4 different address ranges– 32-bit or 64-bit PLB slave, 32-bit OPB master

– Burst and non-burst transfers, cache-line transactions

• OPB to PLB– 64-bit PLB master, 32-bit OPB slave

– Burst and non-burst transfers, cache-line transactions– BESR and BEAR

• OPB (slave) to DCR (master)– Memory mapped DCR control

• OPB to OPB– Allows further OPB partitioning

Page 29: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 29

More System Cores

• Processor System Reset– Asynchronous external reset input is synchronized with clock– Selectable active high or active low reset

– DCM Locked input

– Sequencing of reset signals coming out of reset:• First - bus structures come out of reset

• Second - Peripheral(s) come out of reset 16 clocks later

• Third - the CPU(s) come out of reset 16 clocks after the peripherals

• JTAG Controller– Wrapper for the JTAGPPC primitive.

– Enables the PowerPC’s debug port to be connected to the FPGA JTAG chain

• IPIF User Core Templates– Convenient way to add user core to OPB or PLB

Page 30: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 30

Timer / Counter

• Supports 32-bit OPB v2.0 bus interface

• Two programmable interval timers with interrupt,compare, and capture capabilities

• Programmable counter width

• One Pulse Width Modulation (PWM) output

Page 31: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 31

Watchdog Timer / Timebase• Supports 32-bit bus interfaces

• Watchdog timer (WDT) with selectable timeout periodand interrupt

• Two-phase WDT expiration scheme

• Configurable WDT enable: enable-once or enable-disable

• WDT Reset Status (was the last reset caused by theWDT?)

• One 32-bit free-running timebase counter with rolloverinterrupt

Page 32: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 32

Interrupt Controller• Number of interrupt inputs is configurable up to the width

of the data bus width• Interrupt controllers can be easily cascaded to provide

additional interrupt inputs

• Master Enable Register for disabling the interrupt requestoutput

• Each input is configurable for edge or level sensitivity

– rising or falling, active high or active low• Output interrupt request pin is configurable for edge or

level generation

Page 33: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 33

UART 16550 / 16450 / Lite

• Register compatible with industry standard 16550/16450

• 5, 6, 7 or 8 bits per character• Odd, even or no parity detection and generation

• 1, 1.5 or 2 stop bit detection and generation• Internal baud rate generator and separate RX clock input

• Modem control functions• Prioritized transmit, receive, line status & modem control

interrupts

• Internal loop back diagnostic functionality• Independent 16 word transmit and receive FIFOs

Page 34: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 34

IIC

• 2-wire (SDA and SCL) serial interface

• Master/Slave protocol• Multi-master operation with collision detection and

arbitration

• Bus busy detection• Fast Mode 400 KHz or Standard Mode 100 KHz operation

• 7 Bit, 10 Bit, and General Call addressing• Transmit and Receive FIFOs - 16 bytes deep

• Bus throttling

Page 35: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 35

SPI

• 4-wire serial interface (MOSI, MISO, SCK, and SS)

• Master or slave modes supported• Multi-master environment supported (requires tri-state

drivers and software arbitration for possible conflict)

• Multi-slave environment supported (requires additionaldecoding and slave select signals)

• Programmable clock phase and polarity• Optional transmit and receive FIFOs

• Local loopback capability for testing

Page 36: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 36

Ethernet 10/100 MAC

• 32-bit OPB master and slave interfaces

• Media Independent Interface (MII) for connection toexternal 10/100 Mbps PHY Transceivers

• Full and half duplex modes of operation

• Supports unicast, multicast, broadcast, and promiscuousaddressing

• Provides auto or manual source address, pad, andFrame Check Sequence

Page 37: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 37

Ethernet 10/100 MAC (cont)

• Simple DMA and Scatter/Gather DMA architecture forlow processor and bus utilization, as well as a simplememory-mapped direct I/O interface

• Independent 2K to 32K transmit and receive FIFOs

• Supports MII management control writes and reads withMII PHYs

• Supports VLAN and Pause frames

• Internal loopback mode

Page 38: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 38

1 Gigabit MAC

• 64-bit PLB master and slave interfaces

• GMII for connection to external PHY Transceivers• Optional PCS function with Ten Bit Interface (TBI) to

external PHY devices

• Option PCS/PMA functions with SerDes interface toexternal transceiver devices for reduced signal count

• Full duplex only• Provides auto or manual source address, pad, and

Frame Check Sequence

Page 39: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 39

1 Gigabit MAC (cont)

• Simple DMA and Scatter/Gather DMA architecture forlow processor and bus utilization, as well as a simplememory-mapped direct I/O interface

• Independent, depth-configurable TX and RX FIFOs

• Supports MII management control writes and reads withMII PHYs

• Jumbo frame and VLAN frame support

• Internal loopback mode

Page 40: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 40

Single Channel HDLC

• Support for a single full duplex HDLC channel

• Selectable 8/16 bit address receive address detection,receive frame address discard, and broadcast addressdetection

• Selectable 16 bit (CRC-CCITT) or 32 bit (CRC-32) framecheck sequence

• Flag sharing between back to back frames

• Data rates up to OPB_Clk frequency

Page 41: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 41

Single Channel HDLC (cont)

• Simple DMA and Scatter/Gather DMA architecture forlow processor and bus utilization, as well as a simplememory-mapped direct I/O interface

• Independent, depth-configurable TX and RX FIFOs

• Selectable broadcast address detection and receiveframe address discard

• Independent RX and TX data rates

Page 42: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 42

ATM Utopia Level 2

• UTOPIA Level 2 master or slave interface

• UTOPIA interface data path of 8 or 16 bits• Single channel VPI/VCI service and checking in received

cells

• Header error check (HEC) generation and checking• Parity generation and checking

• Selectively prepend headers to transmit cells, pass entirereceived cells or payloads only, and transfer 48 byteATM payloads only

Page 43: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 43

ATM Utopia Level 2 (cont)

• Simple DMA and Scatter/Gather DMA architecture forlow processor and bus utilization, as well as a simplememory-mapped direct I/O interface

• Independent, depth-configurable TX and RX FIFOs

• Interface throughput up to 622 Mbps (OC12)• Internal loopback mode

Page 44: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 44

OPB-PCI Bridge

• 33/66 MHz, 32-bit PCI buses

• Full bridge functionality– OPB Master read/write of a remote PCI target (both single and burst)– PCI Initiator read/write of a remote OPB slave (both single and multiple)

• Supports up to 3 PCI devices with unique memory PCImemory space

• Supports up to 6 OPB devices with unique memory OPBmemory space

• PCI and OPB clocks can be totally independent

Page 45: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 45

System ACE Controller

• Used in conjunction with System ACE CompactFlashSolution to provide a System ACE memory solution.

• System ACE Microprocessor Interface (MPU)– Read/Write from or to a CompactFlash device– MPU provides a clock for proper synchronization

• ACE Flash (Xilinx-supplied Flash Cards)– Densities of 128 MBits and 256 Mbits– CompactFlash Type 1 form factor

• Supports any standard CompactFlash module, or IBM microdrives up to 8Gbits, all with the same form factor.

• Handles byte, half-word, and word transfers

Page 46: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 46

GPIO

• OPB V2.0 bus interface with byte-enable support

• Supports 32-bit bus interface• Each GPIO bit dynamically programmable as input or

output

• Number of GPIO bits configurable up to size of data businterface

• Can be configured as inputs-only to reduce resourceutilization

Page 47: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 47

Memory Controllers

• PLB and OPB interfaces

• External Memory Controller– Synchronous Memory (ZBT)

– Asynchronous Memory (SRAM, Flash)• Internal Block Memory (BRAM) Controllers

• DDR and SDRAM

Page 48: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 48

• Device drivers are provided for eachhardware device

• Device drivers are written in C and aredesigned to be portable acrossprocessors

• Device drivers allow the user to selectthe desired functionality to minimize therequired memory

• BSPs are automatically generated byEDK tools

Board SupportPackage (BSP)

Boot Code

Initialization Code

Eth

ern

et 1

0/10

0D

evic

e D

rive

r

UA

RT

165

50D

evic

e D

rive

r

IIC M

aste

r &

Sla

veD

evic

e D

rive

r

AT

M U

top

ia D

evic

eD

rive

r

Per

iph

eral

n, n

+1…

Dev

ice

Dri

vers

RTOS Adaptation Layer

Device Drivers and BoardSupport Packages (BSPs)

Page 49: Training Lecture

Creating a SimpleMicroBlaze Systemwith XPSwith Base System Builder Wizard

Page 50: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 50

Design Flow

• Design Entry with Xilinx Platform Studio using theBase System Builder Wizard

• Generate system netlist with XPS• Generate hardware bitstream with XPS• Download and sanity check design with XPS and

XMD

Page 51: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 51

Simple MicroBlaze SystemBlock Diagram

External to FPGA

MicroBlaze

LMB_BRAMIF_CNTLR

OPB_V20

SYS_Clk /SYS_Rst

JTAG Debug

BRAMBLOCK

OPB_MDM OPB_UARTLITE

LMB_V10

Serial Port

LMB_BRAMIF_CNTLR

LMB_V10

I-Side LMB D-Side LMB

D-Side OPBI-Side OPB

Page 52: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 52

Start Xilinx Platform Studio

Page 53: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 53

Create A New Project• Select File from the Tools

menu

• Select the New Projectsubmenu and the BaseSystem Builder submenu

• Browse to the location wherethe project is to be located

• Click OK to start creating theproject

Page 54: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 54

Selecting The Board

• Select Xilinx as the BoardVendor

• Select Virtex-II MultimediaFF896 Development Board asthe Board Name

• Select Board Revision 1

• Click Next to continue to thenext step

Page 55: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 55

Select the Processor

• This board has a Virtex-IIFPGA which does not containa PowerPC processor

• Click Next to continue to thenext step

Page 56: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 56

Configuring The Processor• Select On-chip H/W debug

module such that a ROMmonitor is not required

• Select 64KB of Local Data andInstruction Memory (BRAM)

• There is no need to selectcaches when using internalBRAM

• Click Next to continue to thenext step

Page 57: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 57

Configuring I/O Interfaces

• The board has a serial portand it is default behavior tobuild the hardware with it

• Since it is used as standardI/O it is not necessary to beinterrupt driven

• Click Next to continue to thenext step

Page 58: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 58

Adding Internal Peripherals

• Other peripherals can beadded at this point, such as atimer counter.

• Click Next to continue to thenext step

Page 59: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 59

System Summary

• The system has been createdand is ready to be generated

• Review the details of thesystem and backup ifnecessary to make changes

• Click the Generate button tocreate the data files for XPS

Page 60: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 60

Base System BuilderFinished

• The Base System BuilderWizard in XPS has completed

• The data files for XPS havebeen generated such that thesystem will be contained in anXPS project

• Click the Finish button to exitthe wizard & return to XPS

Page 61: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 61

Generating Hardware NetList

• Select the Toolsmenu

• Select the GenerateNetlist submenu

• Wait for thegeneration tocomplete

Page 62: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 62

Generating Hardware Bitstream

• Select the Toolsmenu

• Select theGenerateBitstreamsubmenu

• Wait for thebitstreamgeneration tocomplete

Page 63: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 63

Adding Software Source Files

• Select processor inSystem tab

• Select the Tools menu• Select the Add Program

Sources submenu• Navigate to the source

file and select it.

Page 64: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 64

Setting Compile Options

• Select the Options menu

• Select the CompilerOptions submenu

• Set the optimization tonone

• Set the debug options tocreate symbols fordebugging

Page 65: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 65

Setting Up Standard I/O

• Select the System tab

• Double click on themicroblaze_0

• The dialog box illustratedis displayed

• Select the opb_uartlite_0for the STDIN andSTDOUT peripheral andclick the OK button

Page 66: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 66

Assigning Drivers To Devices

• Assigning a driver to a devicecauses the driver to be compiledinto the library & linked with theapplication

• Double click on the device inthe System tab of the XPSproject

• The latest version of the driver isdisplayed by default

• Choose the appropriateInterface Level of the driver

Page 67: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 67

Setting Memory Options

• Double click on theprocessor instance in theSystem tab

• Select the Details tab

• Change the program startaddress or stack size

• Add other options to thepreprocessor, assembler,or linker

Page 68: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 68

Setting Library Options

• Double click on theprocessor instance in theSystem tab

• Select the Others tab

• Add or change options forlibrary compilation

• Add other options forapplication compilation

Page 69: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 69

Generating Libraries In XPS

• A Library containing the devicedrivers and the startup code isbuilt for an application to belinked against

• The Library helps separateBoard Support Packagedevelopment from applicationdevelopment

• Libraries will automatically bebuilt if they don’t exist when theapplication is built

Page 70: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 70

Compiling The Software

• Select the Tools menu

• Select the CompileProgram Sourcessubmenu

• Wait for the compile tocomplete

Page 71: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 71

Updating the Bitstream

• Select the Tools menu

• Select the UpdateBitstream submenu

• The hardware bitstreamis updated to containthe contents of thesoftware elf file

Page 72: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 72

Downloading The Hardware

• Make sure that theboard power is onand the parallel podis connected

• Select the Toolsmenu

• Select the Downloadsubmenu

• Wait for the downloadto complete

Page 73: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 73

Running XMD• Select the Tools

menu

• Select the XMDsubmenu

• Type “mbconnectmdm” to connectXMD to theMicroBlazeprocessor.

Page 74: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 74

Testing Memory• Type “mrd 0x1000 2” to read 2

memory locations starting ataddress 0x1000

• Type “mwr 0x10000x12345678” to write tomemory location 0x1000

• Perform writes to location0x1004 also

• Type “mrd x1000 2” to read 2memory locations and verifythe values that were written

Page 75: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 75

Starting The GNU Debugger(GDB)

• Select the Tools menu• Select the Software

Debugger submenu

Page 76: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 76

Target Selection & Download

• In GDB, select theRun menu andchoose the Runmenu item

• Wait for the TargetSelection dialog boxto be displayed

• Enter the data in thedialog box and clickOK

Page 77: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 77

Stepping in GDB

• The debugger isready, the programcounter is at abreakpoint at line 5 ofthe source file

• Select the Controlmenu

• Select the Stepsubmenu

Page 78: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 78

Watching A Variable With GDB

• Double click on thevariable count such that itis selected

• Right click and select inthe submenu to Addcount to Watch

• A dialog box is displayedwhich contains thevariable count and it’scontents

Page 79: Training Lecture

Creating a SimpleMicroBlaze Systemwith XPSwithout Base System Builder Wizard

Page 80: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 80

Design Flow

• Design Entry with Xilinx Platform Studio• Generate system netlist with XPS• Generate hardware bitstream with XPS• Download and sanity check design with XPS and

XMD

Page 81: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 81

Start Xilinx Platform Studio

Page 82: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 82

Create A New Project

• Select New Project from theTools menu

• Enter all the projectinformation

• Click OKon this dialog box.

• Click Yes on the next dialogbox to start with an emptyMHS file

Page 83: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 83

Adding New Cores

• Select theProjectmenu

• Select theAdd/EditCoressubmenu

Page 84: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 84

Adding Bus Structures

• Select the Bus ConnectionsTab

• Select thelmb_v10_v1_00_a bus &opb_v20_v1_10_b bus andclick the Add button

• Select thelmb_v10_v1_00_a bus andclick the Add button

Page 85: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 85

Adding Basic Peripherals

• Select the Peripheralstab

• Select the bram_block,lmb_bram_if_cntlr,microblaze, andopb_mdm and click theAdd button.

• Select thelmb_bram_if_cntlr andclick the Add button.

Page 86: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 86

Change The Memory Map

• Edit the BaseAddress and HighAddress for thelmb_bram_if_cntlrand opb_mdmperipherals

Page 87: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 87

Setting Bus Masters & Slaves

• Select the BusConnectionstab

• Set the mastersand slaves onthe buses byclicking on theboxes with an‘s’ and ‘M’

Page 88: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 88

Setting MicroBlaze Parameters• Select the Parameters

tab• Select microblaze_0 IP

instance

• Select theC_DEBUG_ENABLED andC_NUMBER_OF_PC_BRK

parameters and clickthe Add button

• Edit the parametervalues

Page 89: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 89

Setting MDM Parameters

• Select theopb_mdm_0 IPinstance

• Select theC_USE_UARTparameter andclick the Addbutton

• Edit the parametervalue

Page 90: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 90

Setting LMB Parameters

• Select the lmb_v10_0IP instance

• Select theC_EXT_RESET_HIGHparameter and click theAdd button

• Edit the parametervalue

• Repeat for lmb_v10_1IP instance

Page 91: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 91

Setting OPB Parameters

• Select the opb_v20_0IP instance

• Select theC_EXT_RESET_HIGHparameter and click theAdd button

• Edit the parametervalue

Page 92: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 92

Connecting The Clock

• Select the Ports tab

• Select the LBM_Clkand OPB_Clk ports onthe lmb_v10_0,lmb_v10_0 andopb_v20_0 IPinstances and clickthe Add button

Page 93: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 93

Connecting The Reset

• Select the SYS_Rstports of thelmb_v10_0,lmb_v10_1, andopb_v20_0 IPinstances and clickthe Add button

Page 94: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 94

Connecting The Reset (2)• Select the

lmb_v10_0,lmb_v10_1, andopb_v20_0 instanceson the left side andclick the Connectbutton

• Enter sys_rst for thenet name in thedialog box and clickthe OK button

Page 95: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 95

Completing the Add/Edit

• Click the OK button to set all the itemschanged in the Add/Edit Cores dialog box

Page 96: Training Lecture

Adding I/OPeripherals to aSystem

Page 97: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 97

Adding A UartLite

• Select the Projectmenu

• Select the Add/EditCores submenu

• Select the opb_uartliteand click Add

• Edit the Base Addressand High Address ofthe uartlite

Page 98: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 98

Setting UartLite Parameters

• Select the Parameterstab

• Select the C_CLK_FREQand C_USE_PARITYparameters and click theAdd button

• Edit the parameter values

Page 99: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 99

Put UartLite On the OPB

• Select the BusConnections tab

• Click on the box to markthe UartLite as a slave onthe OPB bus

Page 100: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 100

Connecting UartLite I/O

• Select the Ports tab

• Select the RX andTX ports ofopb_uartlite_0 andclick the Add button

• Edit the net namesto be tx and rx forthe opb_uartlite_0

• Click OK on thedialog box

Page 101: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 101

Adding A Timer

• Select the Projectmenu

• Select the Add/EditCores submenu

• Select the opb_timerand click Add

• Edit the Base Addressand High Address ofthe timer

Page 102: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 102

Setting Timer Parameters

• Select the Parameterstab

• Select theC_ONE_TIMER_ONLYparameters and click theAdd button

• Edit the parameter value

Page 103: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 103

Put Timer On the OPB

• Select the BusConnections tab

• Click on the box to markthe Timer as a slave onthe OPB bus

Page 104: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 104

Adding an InterruptController

• Select the Projectmenu

• Select the Add/EditCores submenu

• Select the opb_intcand click Add

• Edit the Base Addressand High Address ofthe intc

Page 105: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 105

Put Intc On the OPB

• Select the BusConnections tab

• Click on the box to markthe Intc as a slave on theOPB bus

Page 106: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 106

Connect Intc to MicroBlaze• Select Ports tab

• Add Interrupt inputof MicroBlaze andIrq output of Intc

• Highlight both ofthese and pressConnect

• Name the net,select Internal,and press OK

Page 107: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 107

Connect Intc to MicroBlaze

Page 108: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 108

Connect Timer to Intc• Select Ports tab

• Add Interruptoutput of Timerand Intr input ofIntc

• Highlight both ofthese and pressConnect

• Name the net,select Internal,and press OK

Page 109: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 109

Connect Timer to Intc

Page 110: Training Lecture

SoftwareDevelopment withthe EDK and XPS

Page 111: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 111

Compiler/Linker

(Simulator)

C/C++ Code

Debugger

Data2BlockRAM

Bitstream

ChipScope Tools

Xilinx PlatformStudio (XPS)

Standard Embedded SWDevelopment Flow

Standard FPGA HWDevelopment Flow

RTOS, Board Support Package

Synthesizer

Place & Route

Simulator

VHDL/Verilog

codein on-chipmemory

?codein off-chip memory

?

Download to Board & FPGA

Download to FPGA

EDK System DesignComprehensive Tool Chain

Object Code

Page 112: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 112

Building Software in XPS

• XPS is an Integrated Development Environment(IDE) similar to other products with the primarydifference being it allows the user to buildhardware and software.

• The GNU tools (compiler, linker, etc.) includingGDB are used by XPS for software development.

• The GNU tools are not native Windows tools suchthat they execute within a Xygwin (Xilinx Cygwin)environment.

Page 113: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 113

XPS Project DirectoryStructure

• A project within XPS is a directory that containsmultiple subdirectories.

• The code subdirectory is created by the user andcontains application source code.

• The include files, drivers, and libraries are locatedin a directory based on the instance name of themicroprocessor in the project.

Page 114: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 114

XPS Example ProjectDirectory

Page 115: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 115

Library Generation

• XPS compiles device drivers and C run-time CRTinto a single library that is then linked with a userapplication program.

• Libgen is the tool executed from within XPS orfrom a command line, that copies the librarysource files and device driver source files to theproject directory to build the library.

Page 116: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 116

Command Line Builds

• XPS generates a single make file, system.make,that can be used to build the hardware or softwarefrom the command line of a Xygwin window.

• This make file could be used to create a buildenvironment for software development groups thatbuild from the command line.

Page 117: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 117

Xilinx Microprocessor Debugger (XMD)

• Interfaces GDB to a “target”• Supports script interface for built-in commands• Allows debug with or without a ROM monitor

– MDM target for true JTAG– UART target for ROM monitor (xmd-stub)– SIM target for instruction set simulator

XMDGDB MDM

UART

SIM

Page 118: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 118

• JTAG debug using BSCAN

• Software non-intrusive debugging• Read/Write access to internal registers

• Access to all addressable memory• Hardware single-stepping

• Hardware breakpoints - configurable (max 16)• Hardware read/write address/data watchpoints

– configurable (max 8)

Microprocessor DebugModule (MDM)

Page 119: Training Lecture

Device Drivers &SoftwareInfrastructure

Page 120: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 120

Device Drivers for FPGADesigns

• Hardware is parameterizable– Capabilities and features may change every build

• FPGA space is limited– User needs flexible driver architecture– Internal memory solution as well as external memory solution

• Processor may change– Portability of driver is key

Page 121: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 121

Device Driver Goals

• Portability/Reusability– Drivers are to be portable across many different

RTOSs, microprocessors, and toolsets– Minimize development effort

• Out-of-the-box solution for customers

Page 122: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 122

Driver Design Considerations

Programming Languages• Assembly Language

– Minimized to allow maximum portability between microprocessors– Only boot code, which executes prior to the C/C++ runtime system, is

typically necessary to be assembly language– Located in separate source files to help isolate it, as opposed to in-line

assembly language in the C source code

• C Programming Language– The C programming language is the most utilized language for embedded

systems– In order to support the largest number of customers, the first

implementation utilizes the C programming language

Page 123: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 123

Driver DesignConsiderations

• Object Oriented Design– Emphasize data abstraction, data hiding, and encapsulation in

addition to greater potential for code reuse and ease ofmaintenance

– Provides an easier transition from non-object orientedlanguages such as C to more object oriented languages suchas C++ and Java

• Delivery Format– Delivered to customers in source code format, allowing it to be

built and optimized for a wide range of microprocessors usingcustomer selected tools

Page 124: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 124

Device Driver Architecture

• Component based objectoriented design implementedin ANSI C

• A device driver supportsmultiple instances of a device

• Layered device driverarchitecture to allow userselectable features and size

Layer 0 (Low Level)Drivers

Layer 1 (High Level)Drivers

Layer 2 Drivers(RTOS Adapters)

Page 125: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 125

Device Driver Architecture(continued)

• Source code is provided• Layer 0 and Layer 1 are OS-independent

• Device drivers in all layers have common characteristics• Primitive data types for portability (Xuint8, Xuint16,

Xuint32, etc.), in xbasic_types.h

• Isolation of I/O accesses for portability (XIo_In8(),XIo_Out8(), etc.), in xio.h

• Coding and documentation conventions

Page 126: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 126

Layer 0, Low Level Drivers

• Interface contained in <driver>_l.h file• Designed for a small system, typically for internal memory

of an FPGA.

• Small memory footprint• No error checking performed

• Supports primary device features only, not comprehensive• Polled I/O, blocking functions

Page 127: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 127

Layer 1, High Level Drivers

• Interface contained in <driver>.h file• Designed to allow a developer to utilize all features of a

device• Larger memory footprint• Robust error checking such as asserting input arguments

• Supports configuration parameters in <driver>_g.c• Interrupt driven I/O, non-blocking functions

– Interrupt service routines are provided

Page 128: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 128

Layer 2 Drivers,RTOS Adapters

• Interface contained in <driver>_adapter.h file.• Converts the Layer 1 device driver interface to an

interface that matches the device driver scheme of theRTOS.

• Contains calls specific to the RTOS

• Can use RTOS features such as memory management,threading, inter-task communication, etc.

Page 129: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 129

RTOS IndependentDevice Drivers

• Driver– Responsible for interfacing to the device (peripheral).

It encapsulates communication to the device– Designed to be portable across processor

architectures and operating systems

• Adapter– Integrates the driver into an operating system

– Satisfies the "plug-in" requirements of the operatingsystem

– Needs to be rewritten for each OS

Page 130: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 130

RTOS Support

• Xilinx supports VxWorks 5.4/5.5 for PowerPC in-house• 3rd party support includes MontaVista Linux (PPC), ATI

Nucleus, uCos, ucLinux• VxWorks integration:

– All device drivers can be used directly by the application– Some device drivers tightly integrated into VxWorks

• UARTs to standard and file I/O• Ethernet to network stack (Enhanced Network Driver)• Interrupt controller• System ACE into VxWorks filesystem interface

• Automatic Tornado BSP generation using EDK

Page 131: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 131

Naming Conventions• A common name is used for all external identifiers of the

device driver– <driver_name>_FunctionName();– <driver_name>_DataType;

• A common name is used for all source files of the devicedriver for ease of use– <driver_name>_l.h low level driver interface definition– <driver_name>.h high level driver interface definition– <driver_name>.c primary source file– <driver_name>_g.c configuration table source file– <driver_name>_intr.c interrupt processing source file

Page 132: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 132

Multiple Instance Details

• Multiple instances of a single device (such as an EthernetMAC) typically exist in a system

• A single device driver handles all instances of the device

• A layer 1 device driver uses a data type that is passed asthe first argument to each function of the driver. The datatype contains information about each device instancesuch as the base address

Page 133: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 133

Example Layer 0 DeviceDriver API

• Each function of Layer 0 uses the base address of thedevice as the first argument

• No state information is kept by the driver and the usermust manage multiple instances of the device

• void XEmac_mSetControlReg(Xuint32 BaseAddress, Xuint32 Mask)• void XEmac_SendFrame(Xuint32 BaseAddress, Xuint8 *FramePtr, int Size)• int XEmac_RecvFrame(Xuint32 BaseAddress, Xuint8 *FramePtr)

Page 134: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 134

Example Layer 1 DeviceDriver API

• Each function of Layer 1 uses an instance pointer asthe first argument

• XStatus XEmac_Initialize(XEmac *InstancePtr, Xuint16 DeviceId)• XStatus XEmac_Start(XEmac *InstancePtr)• XStatus XEmac_Stop(XEmac *InstancePtr)• void XEmac_Reset(XEmac *InstancePtr)• XStatus XEmac_SelfTest(XEmac *InstancePtr)

Page 135: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 135

Example Layer 1 Device DriverAPI For FIFO Interrupt Support

• XStatus XEmac_FifoSend(XEmac *InstancePtr, Xuint8 *BufPtr, Xuint32ByteCount);

• XStatus XEmac_FifoRecv(XEmac *InstancePtr, Xuint8 *BufPtr, Xuint32*ByteCountPtr);

• void XEmac_SetFifoRecvHandler(XEmac *InstancePtr, void *CallBackRef,XEmac_FifoHandler FuncPtr);

• void XEmac_SetFifoSendHandler(XEmac *InstancePtr, void *CallBackRef,XEmac_FifoHandler FuncPtr);

• void XEmac_IntrHandlerFifo(void *InstancePtr); /* interrupt handler */

Page 136: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 136

Device Driver & SystemConfiguration

• xparameters.h contains important system parametersused by the drivers & the BSP

• Parameters for each device may include a device ID, abase address, an interrupt identifier, and any deviceunique parameters

• This file is the best place to start when trying tounderstand a system

• Libgen automatically generates xparameters.h

Page 137: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 137

Example xparameters.h File

• The following example is for a system that has anEthernet MAC device at address 0x60000000. The nameof the hardware instance is opb_ethernet.

#define XPAR_XEMAC_NUM_INSTANCES 1#define XPAR_OPB_ETHERNET_BASEADDR 0x60000000#define XPAR_OPB_ETHERNET_HIGHADDR 0x60003FFF#define XPAR_OPB_ETHERNET_DEVICE_ID 0#define XPAR_OPB_ETHERNET_ERR_COUNT_EXIST 1#define XPAR_OPB_ETHERNET_DMA_PRESENT 3#define XPAR_OPB_ETHERNET_MII_EXIST 1

Page 138: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 138

Device Driver ConfigurationSpecifics

• Constants describing each device instance are contained inxparameters.h

• These constants are also inserted into a configuration table foreach device driver contained in the <driver_name>_g.c

• The device driver looks up information for the specific instanceof the device when it is initialized

• The data type definition for the configuration data is containedin the <driver_name>.h file

• Libgen generates the <driver_name>_g.c file for each devicedriver

Page 139: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 139

Device Driver ConfigurationExample

• typedef struct{

Xuint16 DeviceId;Xuint32 BaseAddress;Xboolean HasCounters;Xuint8 IpIfDmaConfig;Xboolean HasMii;

} XEmac_Config;• XEmac_Config XEmac_ConfigTable[] =

{{

XPAR_OPB_ETHERNET_DEVICE_ID,XPAR_OPB_ETHERNET_BASEADDR,XPAR_OPB_ETHERNET_ERR_COUNT_EXIST,XPAR_OPB_ETHERNET_DMA_PRESENT,XPAR_OPB_ETHERNET_MII_EXIST

}};

Fromxemac.hsource file

Fromxemac_g.csource file

Page 140: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 140

Interrupt Processing• Layer 1 device drivers provide interrupt driven I/O

• The device driver provides an interrupt handler that must beconnected to the interrupt source by the application

• The device driver interrupt handler performs device specificdetails such as register reads & writes and calls a userspecified handler (or callback) to process events and data

• The user application must setup the application callback to becalled by the device driver interrupt handler

• The application callback can perform processing in aninterrupt context or signal non-interrupt driven processing toperform the processing

Page 141: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 141

Interrupt Processing Example• When using MicroBlaze, XPS automatically connects the interrupt controller

in the system to the exception vector of the processor so that the interruptcontroller’s interrupt handler gets called when an interrupt occurs

• The following code illustrates setting an application callback for the EthernetMAC device driver, connecting the Ethernet MAC device driver interrupthandler to the interrupt controller, and enabling the MicroBlaze interrupts

XEmac_SetFifoSendHandler(InstancePtr, InstancePtr, SendHandler);XEmac_SetFifoRecvHandler(InstancePtr, InstancePtr, RecvHandler);

XIntc_Connect(&InterruptController, XPAR_OPB_INTC_OPB_ETHERNET_IP2INTC_IRPT_INTR,

(XInterruptHandler)XEmac_IntrHandlerFifo, InstancePtr);

microblaze_enable_interrupts();

Page 142: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 142

Error Processing

• Device driver functions which detect errors return a data typeof XStatus to indicate the detailed error condition

• The error details are contained in xstatus.h• Device driver functions use asserts to indicate errors during

runtime.• Errors detected during interrupt processing are returned to the

application via an asynchronous callback function.

Page 143: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 143

Assert Details

• Device drivers use Assert to validate input arguments

• The default is for asserts to be used by device drivers• Asserts can be disabled when the libraries are generated by

using the -DNDEBUG symbol

• The default behavior of Assert is to loop forever after calling auser defined function if defined

• The user can setup a function to be called when an assert iscalled.

void XAssertSetCallback(XAssertCallback Routine);

Page 144: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 144

Device Drivers In The EDKInstall Directory

This illustration showsthe directories of adevice driver (emac) inthe EDK install area.

Note that there is anexamples directory thatcontains examplesource files for using adevice driver.

Page 145: Training Lecture

Implementing Processor Systems on Xilinx FPGAs Page 145

Writing An Application To Use ADevice Driver

• Always start with an example provided in the device driverdirectory of the EDK install to save time

• Choose the example best fits your application, such as polled,interrupts, or DMA, and copy code snippets from the example


Recommended