Download Altera NIOS II Processor-Embedded Systems-Lecture 05 Slides-Electrical and Computer Engineering and more Slides Embedded Systems in PDF only on Docsity!
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Embedded Systems
Altera NIOS II Software Development: Part I
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Overview
- NIOS II programs and associated projects
- Applications
- User libraries
- Board support packages (BSPs)
- Programming a NIOS II system
- User programs
- C standard library
- Hardware abstraction layer (HAL) and HAL layers
- Device drivers
- HAL Architecture and Services
- Developing Programs Using the HAL
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
NIOS II Programs
- Each NIOS II program consists of:
- an application project,
- optional user library projects, and
- a board support package (BSP) project
- The build process creates an Executable and Linking Format File ( .elf) which runs on a NIOS II processor.
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
NIOS II Software Project Types: Application
Project
- A NIOS II C/C++ application project consists of a collection of source code, plus a makefile
- A typical characteristic of an application is that one of the source files contains function main()
- An application includes code that calls functions in libraries and BSPs
- The makefile contains commands to:
- compile the source code
- link it with a BSP and one or more optional libraries
- create one .elf file
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Overview of the Hardware Abstraction Layer
- The HAL provides a simple device driver interface for programs to connect to the underlying hardware
- The HAL application program interface (API) is integrated with the ANSI C standard library
- The HAL API allows access to devices and files using familiar C library functions - printf(), fopen(), fwrite(), etc.
- The HAL serves as a device driver package for NIOS II processor systems - provides a consistent programming interface to the peripherals in a NIOS II system
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
HAL Architecture and Services
- Integration with the newlib ANSI C standard library
- Provides the familiar C standard library functions
- Device drivers
- Provides access to each device in the system
- The HAL API
- Provides a consistent, standard interface to HAL services, such as device access, interrupt handling, and alarm facilities
- System initialization
- Performs initialization tasks for the processor and the runtime environment before main()
- Device initialization
- Initializes each device in the system before main() runs
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Layers of a HAL-Based System
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
HAL Generic Device Models
- The HAL provides generic device models for classes of peripherals found in embedded systems - timers, Ethernet MAC/PHY chips, and I/O peripherals that transmit character data, etc.
- Generic device models allow programs to use a consistent API, regardless of the underlying hardware
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Developing Programs Using The HAL
- NIOS II Development Flows
- The NIOS II Embedded Design Suite (EDS) provides two distinct development flows for creating NIOS II programs - NIOS II Software Build Tools (SBT for Eclipse or command line) - NIOS II Integrated Development Environment (IDE)
- HAL BSP Settings
- Every NIOS II board support package (BSP) has settings that determine the BSP’s characteristics
- For example, HAL BSPs have settings to identify the hardware components associated with standard devices such as stdout
- Defining and manipulating BSP settings is an important part of NIOS II project creation
- BSP settings can be modified with the NIOS II BSP Editor, with command-line options, or with Tcl scripts
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
The NIOS II HAL Project Structure
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
The NIOS II HAL Project Structure
- Every HAL-based NIOS II program consists of two NIOS II projects - Your application-specific code is contained in one project (the user application project), and - it depends on a separate BSP project (the HAL BSP).
- The application project contains all the code you develop
- The executable image for your program ultimately results from building both projects
- With the NIOS II Software Build Tools for Eclipse, the tools create the HAL BSP project when you create your application project
- The BSP project depends on the SOPC Builder system, defined by a SOPC Information File ( .sopcinfo ) - The SOPC file is created using the SPOC Builder tool within the Altera Quartus software
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
The system.h System Description File
- The system.h file provides a complete software description of the NIOS II system hardware
- The system.h file describes each peripheral in the system and provides: - The hardware configuration of the peripheral - The base address - Interrupt request (IRQ) information (if any) - A symbolic name for the peripheral
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
The HAL and GNU Toolchain Type
Definitions and Data Widths
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
UNIX-Style Interface
- The HAL API provides a number of UNIX-style functions - The UNIX-style functions provide a familiar development environment for new NIOS II programmers - Can ease the task of porting existing code to run in the HAL environment
- The HAL uses these functions primarily to provide the system interface for the ANSI C standard library - For example, the functions perform device access required by the C library functions defined in stdio.h.
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Available UNIX-style Functions
- _exit()
- close()
- fstat()
- getpid()
- gettimeofday()
- ioctl()
- isatty()
- kill()
- lseek()
- open()
- read()
- sbrk()
- settimeofday()
- stat()
- usleep()
- wait()
- write()
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
File System Functions
- The HAL provides infrastructure for UNIX-style file access
- You can access files in a HAL-based file system by using
- The C standard library file I/O functions in the C library (for example fopen(), fclose(), and fread()), or
- The UNIX-style file I/O provided by the HAL
- HAL-provided functions
- close()
- fstat()
- ioctl()
- isatty()
- lseek()
- open()
- read()
- stat()
- write()
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Starting the NIOS SBT for Eclipse
- From the Start Menu, select Altera->NIOS II EDS 9.1->NIOS II 9.1 Software Build Tools for Eclipse
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
NIOS II SBT for Eclipse
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
NIOS II SBT for Eclipse
- Select File->New->NIOS II Application and BSP from Template
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
NIOS II SBT for Eclipse
- Select File->New->NIOS II Application and BSP from Template
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
NIOS II SBT for Eclipse
Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-
Alternate output using Character Output to a
Device
#include <stdio.h> #include <string.h> int main (void) { char* msg = "hello world"; FILE* fp; fp = fopen ("/dev/jtag_uart", "w"); if (fp!=NULL) { fprintf(fp, "%s",msg); fclose (fp); } return 0; }