FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... ·...

22
FPGA based embedded processor MOTIVATION With rising gate densities of FPGA devices, many FPGA vendors now offer a processor that either exists in silicon as a hard IP or can be incorporated within the programmable device as a soft IP. The purpose of having a processor co-exist with conventional digital logic components is to provide flexibility of combining software and hardware based control in one chip. Many algorithms that are difficult to code in HDL and have update time requirements in milliseconds can use the processor inside the FPGA. A whole suite of tools, consisting of compilers and assemblers help the designer code in C or C++. The motivation of this chapter is to introduce the use of FPGA embedded processors and to integrate custom digital logic with FPGA-based processors. Recent advances in semiconductor technology facilitate the integration of many million gates on a single chip and result in the integration of Systems on Chip (SoC).Typical examples of SoC applications can be found in the multimedia domain and in intelligent transport systems. In those applications, generally, large amounts of data must be processed in parallel. However, performing such processing by software running on a high-performance processor or only by hardware is not efficient except for a few specific cases.An optimal combination of hardware and software and an optimal system partitioning into hardware and software is most desirable. That is why one must learn what is Hardware– Software Task Partitioning and how it is achieved. To perform the functions with the I/O system, the operating system must be able to communicate with I/O devices and to prevent user programs from accessing the I/O devices directly. That is why one must learn what is interfacing and how it is achieved between various I/O devices. The electronics industry has entered the era of multimillion gate chips,and there is no turning back. This technology promises new levels of integration on a single chip, called the System-on-a-Chip (SoC) design, but also presents significant challenges to the chip designer. Processing cores on a single chip, may number well into the high tens within the next decade, given the current rate of advancements.Interconnection networks in such an environment are, therefore,

Transcript of FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... ·...

Page 1: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

FPGA based embedded processor

MOTIVATION

With rising gate densities of FPGA devices, many FPGA vendors now offer a processor that either exists in silicon as a hard IP or can be incorporated within the programmable device as a soft IP. The purpose of having a processor co-exist with conventional digital logic components is to provide flexibility of combining software and hardware based control in one chip. Many algorithms that are difficult to code in HDL and have update time requirements in milliseconds can use the processor inside the FPGA. A whole suite of tools, consisting of compilers and assemblers help the designer code in C or C++. The motivation of this chapter is to introduce the use of FPGA embedded processors and to integrate custom digital logic with FPGA-based processors.

Recent advances in semiconductor technology facilitate the integration of many million gates on a single chip and result in the integration of Systems on Chip (SoC).Typical examples of SoC applications can be found in the multimedia domain and in intelligent transport systems. In those applications, generally, large amounts of data must be processed in parallel. However, performing such processing by software running on a high-performance processor or only by hardware is not efficient except for a few specific cases.An optimal combination of hardware and software and an optimal system partitioning into hardware and software is most desirable. That is why one must learn what is Hardware–Software Task Partitioning and how it is achieved.

To perform the functions with the I/O system, the operating system must be able to communicate with I/O devices and to prevent user programs from accessing the I/O devices directly. That is why one must learn what is interfacing and how it is achieved between various I/O devices.

The electronics industry has entered the era of multimillion gate chips,and there is no turning back. This technology promises new levels of integration on a single chip, called the System-on-a-Chip (SoC) design, but also presents significant challenges to the chip designer. Processing cores on a single chip, may number well into the high tens within the next decade, given the current rate of advancements.Interconnection networks in such an environment are, therefore,

Page 2: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

becoming more and more important. Currently, on-chip interconnection networks are mostly implemented using buses. For SoC applications, design reuse becomes easier if standard internal connection buses are used for interconnecting components of the design. Design teams developing modules intended for future reuse can design interfaces for the standard bus around their particular modules.That is why one must learn what is Design Re-use Using On-chip Bus Interface & Customized Micro controller and how it is done.

Robots are complex electromechanical systems where several electric drives are used to control the movement of articulated structures. The design of axis control systems for robots can be greatly facilitated by the Electric Drives library in MATLAB, which can model complete axes including motor drives, speed reducers, mechanical model of the arm, and controllers in the same diagram. That is why one must learn how robot axis position control is achieved.

PREREQUISITES

A basic understanding of :

What Hardware and Software mean. How memory and processors work along with the meaning of interfacing. On-chip bus interface is required. A robot axis is required.

SUGGESTED TIME

12 hrs

LEARNING OBJECTIVES

In this module we will be learning about:

FPGA Fabric Immersed Processors Soft and Hard Processors Tool Flow for Hardware–Software Co-design Interfacing Processor with Peripherals Different types of On-chip Interfaces Design Re-use Using On-chip Bus Interface

Page 3: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Motor Drive as a Peripheral Creating a Customized Micro-controller Robot Axis Position Control.

READING MATERIAL

Hardware–Software Task Partitioning

Introduction

Figure Task update rates

The digital system designer identifies tasks and their update time requirements. What is shown in the figure is a robot controller task pyramid which is made up of tasks that need microsecond or millisecond update time. In the hypothetical robot control system, a processor is allocated the task of robot joint trajectory computation, which requires 10–100 ms update time. The processor propelled by a timer interrupt, updates the trajectory profile every 10–100 ms. The task of

Page 4: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

motor current and power device PWM control is the function of hardware logic (designed using HDL) since it needs to update every 50 μs.

FPGA Fabric Immersed Processors

A new dimension has been added to the use of FPGA devices with the ability to support processor logic.

It has given designers the leverage to partition their designs either for single-threaded software flow or to use concurrent digital logic. A quick browsing of the internet reveals that several 8- and 32-bit proprietary processors are offered by prominent FPGA vendors alongside recognised processors. A reason for using the time tested, established processor is to reduce the learning curve of designers and build confidence in their use. Most major vendors of field programmable devices offer processors, for use with their respective devices. The table above shows a partial list of vendors and the processors they provide.

Partial list of contemporary FPGA-based processors

Page 5: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Soft Processors

Soft processors exist as synthesized netlists integrated into the FPGA using logic block resources of a certain FPGA. FPGA vendors provide soft processors which serve 8-bit and 32-bit applications. A small footprint of the 8-bit processor is placed on the FPGA device and it uses the FPGA embedded memory for program and data memory storage. In the figure below, we observe the block diagram of PicoBlaze, an 8-bit soft controller from Xilinx. The PicoBlazeTM controller which is made up of an 8-bit input and an 8-bit output port also supports interrupt. The embedded block RAM of the FPGA is used as a location for program and data memory for the PicoBlaze. The PicoBlazeTM assembler procures the program file and generates the coefficient (.coe) file, loaded in the embedded memory of the FPGA.

Page 6: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Two of the popular 32-bit proprietary soft processors are NIOS® from Altera and MicroBlaze from Xilinx which figure among the 32-bit soft processors. A portion of the FPGA resources is utilised by these processors. The residual part of the FPGA can be used for assimilating other digital logic.

Realising an 8-bit soft controller on a FPGA

In the next diagram we display a MicroBlaze 32-bit soft processor, which is a reduced instruction set computer (RISC) based engine with a 32 * 32-bit LUT RAM-based register file with separate instructions for data and memory access. It gives support to both on-chip block RAM and external memory for program/data memory. All peripherals are executed on the FPGA fabric and interface to the MicroBlazeTM utilising the onchip peripheral bus (OPB) or processor local bus (PLB). The MicroBlaze processor choices include instantiation of additional hardware to implement IEEE 754 single precision floating point standards. Since this option is included, it can support floating point addition, subtraction, multiplication, division and comparison.

Page 7: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

In the table it was indicated that the soft processors can be specially tailored by adding a barrel shifter or adjusting the size of the data and instruction cache. Additional processors can also be appended to offer a multi-processing option. Depending on the results of software profiling, certain resource intensive software algorithms can be shifted to the hardware fabric as coprocessors or as custom peripherals.

MicroBlaze block diagram

Hard Processors There are many standard processors and microcontrollers which are available as hard IP inside the FPGA. The AVR microcontroller offered by the Atmel family and the PowerPC processor as part of Xilinx Virtex FPGAs are a few that can be named. The design chain for programming and debugging the FPGA-based processor system is quite comparable to their previous model as stand-alone processors.

Page 8: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Tool Flow for Hardware–Software Co-design When a system needs to be co-designed, hardware as well as software tasks need to be independently coded and tested. Figure below indicates the software flow which joins the source and the library files to come up with an executable file for the processor to use. The program and data code can be located either in the internal memory of the FPGA device or if the program code is sizeable, an external memory device is used. The program is stored within the memory of the FPGA device as shown in Fig. 10.4. The hardware design flow takes the electronic design interchange format (EDIF) files of the soft processor and combines them with the user written custom digital code and formulates a complete system netlist after synthesis.

Hardware–software design flow

Interfacing

Page 9: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Interfacing Memory to the Processor

The use of a processor needs a memory, where the instructions are stored. As analysed in the earlier module, many FPGAs provide on-chip embedded memory. The size of this memory is based on the density of the FPGA device which is being used. 360 kbits of memory are obtainable for the Xilinx 500 k gate FPGA. During the usage of this onboard memory, a local memory bus (LMB) controller is configured to read and write to/from this memory. The onboard memory satisfies the conditions for small codes that are meant for the PicoBlazeTM processor or assembly coded codes for the 32-bit processors. While using this bus, memory can be accessed much faster and can be handled by the memory controller. In the case of larger programs, the compiled code requires to be stored in an external memory chip. Show below is the linker script settings should be modified for either using an external double data rate synchronous dynamic random access memory (DDR SDRAM) or internal FPGA memory to store program code, stack or heap.

Linker script settings for determining the type of memory to be used with a MicroBlaze soft processor

Interfacing Processor with Peripherals

Page 10: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

From the perspective of the digital design, the shared bus interface approach is like the peripherals that are interfaced to a processor using tracks on a PCB. Many backplane bus standards that provide basic interfacing capabilites for peripherals have developed over time. A signal has address, data and control bus are used by interconnect buses. Many proprietary interface bus standards are present, with comparable interfacing methodology. The physical backplane bus standards and system-on-chip buses used for interfacing processor and peripherals are indicated in the tables.

The hardware-software synergy available by use of a FPGA-based processor carries weight only if customized coprocessors or peripherals are part of the design. Or else it is much more straight forward and economical to go for a microcontroller or digital signal processor implementation. There are several procedures for connecting user defined custom logic to a FPGA processor. One method of doing this is to use industry standard interconnect buses. The use of standard buses enhances the re-use of IP core since the bus interface logic gives the front-end connection to the IP core.

Page 11: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Processor connected to different peripherals on a PCB

Now, let us look at the partial list of physical backplane bus standards:

1. IBM PC bus brought by IBM 2. Multibus brought by Intel 3. Multibus II brought by Intel 4. VME bus brought by Motorola 5. STD bus, IEEE 488 bus brought by HP 6. Q-bus brought by DE Corp 7. Unibus brought by DE Corp.

Page 12: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

The System on Chip buses are given below:

1. AMBA, ARM 2. Wishbone, Silicore 3. OPB core connect bus, IBM 4. Fast serial link, Xilinx 5. Avalon bus, Altera.

Types of On-chip Interfaces

On-chip processor peripheral interface topology can be categorised into point-to-point, cross bar switch and shared bus interfaces. Point-to-Point

The point-to-point interface made up of a link which is used exclusively between the communicating devices, for instance the fast simplex link (FSL). This point-to-point connection gives a unidirectional, non-arbitrated channel to perform fast communication between the MicroBlazeTM processor and custom hardware module. The MicroBlaze can be structured so as to support multiple FSL links to read and write data or control signals to a peripheral.

Cross Bar Switch

The cross bar switch comprises an interconnection fabric, configured depending on the connections between various sections of the design. This is normally done at the time of design synthesis. The transfer rate of a crossbar switch is much more than that of a shared bus mechanism. However the crossbar switch needs more interconnection logic and routing resources as compared to a shared bus system.

Shared Bus

Shared buses are akin to their older backplane bus counterparts. The shared bus interface describes an address for the slave or peripheral device. The address bus initiating from the microprocessor carries the address of the slave device to which the microprocessor wants to communicate. An address decoder in each slave device decides if that particular slave is being addressed. The microprocessor master device writes to or reads the bank of registers within the slave device.

Page 13: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Every one of these registers in the slave device has a unique address sent by the master device. A typical read and write to a particular register in the slave device is indicated in the timing diagrams of read and write cycles.

The peripheral logic regularly updates the feedback/status registers and reads the configuration registers. When a peripheral requires immediate attention, it produces an interrupt for the microprocessor. When there is only one interrupt generating peripheral in the system, it is linked to the interrupt port of the microprocessor. But in case there are many peripherals that can probably interrupt the processor, then there is an interrupt controller peripheral that directs the interrupt signal to the microprocessor depending on the pre-assigned priorities of the interrupts.

The shared bus comprises:

a unidirectional Address Bus a bi-directional Data Bus control signals

-write/read enable -acknowledge

System control signals — clock, reset.

Wishbone Interface

In the Wishbone there are three kinds of interconnections: the point-to-point, shared bus and the crossbar switch. The interface defines the connection between the processor (master) and the wishbone slave. The figure below pictures the interconnections which consist of address, data and handshaking signals. The handshaking mechanism is utilized to regulate the data transfer rate. The acknowledge [ACK_0] signal is compulsory, on the other hand error [ERR_o] and retry [RTY_o] are optional handshaking signals. The signals which are defined for the point-to-point connection are also used in the shared bus interface. The following operations: single read/write, block read/write, and read-modify-write are supported by Wishbone. All the signals between master and slave have to be

Page 14: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

either inputs or outputs, but not bi-directional (using tri-state logic). Address and data bus widths can be altered to suit the application. 8, 16, 32 and 64 bits are the possible widths that are supported.

Wishbone interface configured for a point-to-point connection

Avalon Switch Matrix

The Avalon switch fabric is an interconnect technology operated by Altera. It is produced using the system on a programmable chip (SOPC) builder tool of Altera. It provides up to a 128-bit address and data path. Various multiple masters are supported like built-in address decoding, peripheral transfer support, read and write transfers and fixed and variable length transfers. The FPGA switch fabric enables a faster configurable interconnect used to make memory mapped

Page 15: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

connections between master and slave devices. The figure indicates a sample configuration of an Altera NIOS® processor.

Interconnection of Avalon Bus using interconnection fabric

OPB Bus Interface

The on-chip peripheral bus (OPB) maybe termed a shared bus architecture. It is part of the CoreConnect architecture developed by IBM which is used for integrating on-chip “cores”. Even though the specifications allow for a 32- or 64-bit wide address and data bus, the FPGA adaptation by Xilinx uses 32-bit as the word size. The OPB bus system utilizes master-slave architecture. The master which is generally a part of the microprocessor can introduce a transaction by specifying a slave address. The slave reacts to the requests from the master. Both the OPB as well as the MicroBlaze soft processor use big-endian form of data, where bit 0 is the most significant bit and bit 31 is the least significant. The signals interchanged between an OPB master and slaves are indicated in figure.

Page 16: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

The OPB bus read cycle is made up of the OPB_RNW signal that becomes high along with the OPB_SELECT signal. The address from where the OPB master (the processor here) wishes to read from, is sent on the OPB_ABUS and after a latency of four cycles, the data from the peripheral are available on the OPB_DATA bus.

The write cycle of the OPB operates in a fashion very much like the read cycle. Rather than the OPB_RNW becoming higher along with OPB_SELECT, the address and data bus contents are put on their respective buses. A transfer acknowledge signal from the slave shows the completion of the write cycle.

OPB bus interface signals for master and slave devices

Design Re-use Using On-chip Bus Interface

Introduction

Page 17: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

On many occasions, standard digital components are re-used for other applications. Creating a design that is suitable to an on-chip bus interface is one method of re-using a design. Different IP cores developed independently can be joined together and tested by standardizing the IP core interfaces. Several re-usable digital designs22 that are obtainable from the public domain are compatible with on-chip interfaces. The list of peripherals referred to in table do not contain the motor controller and Quadrature encoder interface as microcontroller peripherals. Moreover these peripherals are not found in a FPGA vendor supplied peripheral library. When this occurs a custom peripheral for motor control is needed.

List of peripherals needed for the robot controller

Motor Drive as a Peripheral

The robot motor drive logic can be crafted as a custom peripheral that interfaces with the system-on-chip bus. Such a peripheral can be duplicated or cloned multiple times on a single FPGA chip without disturbing the performance of each individual drive (thanks to the independent concurrent threads that a FPGA device can support!). In the following module we will study more on how to create HDL code for robot motor drive control.

Page 18: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Details for robot motor drive peripheral

Design of Custom Peripheral

A peripheral is an independent device that is used to off-load the processor from processes that need repeated attention. First the peripheral takes input from the processor and then interrupts the processor once a given task is completed. Frequently used on-chip microcontroller peripherals include timers, UART and interrupt controllers. The availability of high-density FPGA devices, which have built-in processors, has made incorporation of custom peripherals possible. A FPGA-based processor system is configurable to make a customized microcontroller. Extra user defined peripherals can be incorporated into the processor. The design of a custom peripheral is such that it needs a bus interfacing logic and the custom code of the user peripheral. Depending on the timing diagram of the read and write cycles of the particular bus protocol, a finite state machine is designed to interface a custom peripheral device.

Page 19: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

A typical port map of the slave device consists of these signals:

Bus to slave peripheral

- Address bus

- Data bus

- Clock

- Read/Write

Slave peripheral to bus

- Data bus

- Transfer acknowledge

- Time out suppression

The finite state machine would have idle, selected, read/write, transfer acknowledge and then the idle state would be repeated. The peripheral interface logic consists of the shaded section shown below.

Page 20: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

Interface logic for connecting a peripheral to a chip interconnect bus

Creating a Customized Microcontroller

The FPGA gives the flexibility of creating a customized application-oriented microcontroller. The programming flow of these processors is very much like that used for programming a microcontroller-based system. A high-level programming interface like C is used. The architecture for a microcontroller designed for motor control is shown below. This architecture reveals a 16-bit CPU, SPI, ADC and timer/counter interfaces. There is a proprietary internal bus inside the controller that connects the processor with different peripherals.

Page 22: FPGA based embedded processor - INFLIBNET Centreeacharya.inflibnet.ac.in/data-server/eacharya... · custom peripherals. MicroBlaze block diagram Hard Processors There are many standard

(a) Architecture of a microcontroller for control applications; (b) architecture of a FPGA-based system on chip customised for motor control application

By using the field programmable device if a comparable architecture for multi-motor control were to be produced, then the architecture would not change much. An FPGA based hard or soft CPU is selected, and various pre-designed peripherals that are available, are assembled to form a system around a given interconnect bus. If the program memory conditions are high, an external memory device is connected using a memory controller IP. The typical environment of a single-chip controller is made up of general purpose input output (GPIO) devices, a communications terminal such as the UART and memory. To achieve equivalency with the microcontroller environment, let us build a similar FPGA-based system.

· UART: In this example the standard input and output port (STDIN and STDOUT) are configured for RS232_DCE. This makes sure that the program outputs using the print command are exhibited on the serial port. An interrupt is generated when any valid character is in the receive FIFO and the interrupt stays.

· Timer: The timer provides an interrupt for real-time processing.

· SPI bus: Provides communication with off-chip ADC and DAC chips.

· Interrupt controller: For managing multi-source interrupts.

The one peripheral not there in the IP library is the motor drive peripheral. A customized peripheral examined in the previous section needs to be created.