Embedded Systems

Embedded Systems

Embedded Systems Altera NIOS II Software Development: Part I Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-1 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-2 1 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-3 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-4 2 NIOS II Software Project Types: User Library Project • A user library project is a collection of source code compiled to create a single library archive file (.a) – Libraries often contain reusable, general purpose functions that multiple application projects can share – A collection of common arithmetical functions is one example • A user library does not contain a main() function Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-5 NIOS II Software Project Types: BSP Project • A NIOS II BSP project is a specialized library containing system-specific support code • A BSP provides a software runtime environment customized for one processor in an SOPC Builder system • The NIOS II EDS provides tools to modify settings that control the behavior of the BSP • A BSP contains the following elements: – Hardware abstraction layer – Newlib C standard library – Device drivers – Optional software packages – Optional real-time operating system Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-6 3 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-7 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-8 4 Layers of a HAL-Based System Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-9 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-10 5 HAL Device Model Classes • Character-mode devices – Hardware peripherals that send and/or receive characters serially, such as a UART. • Timer devices – Hardware peripherals that count clock ticks and can generate periodic interrupt requests. • File subsystems – A mechanism for accessing files stored in physical device(s) • Ethernet devices – Devices that provide access to an Ethernet connection for a networking stack • Direct memory access (DMA) devices – Peripherals that perform bulk data transactions from a data source to a destination • Flash memory devices – Nonvolatile memory devices that use a special programming protocol to store data Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-11 HAL Peripherals • All peripherals must have a header file that defines the peripheral’s low-level interface to hardware • Therefore, all peripherals support the HAL to some extent • However, some peripherals might not provide device drivers • If drivers are not available, use only the definitions provided in the header files to access the hardware • Some peripherals provide functions that are not based on the HAL generic device models – For example, Altera provides a general-purpose parallel I/O (PIO) core for use with the NIOS II processor system – The PIO peripheral does not fit in any class of generic device models provided by the HAL, and so it provides a header file and a few dedicated functions only – User pushbuttons and LEDs are examples of these Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-12 6 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-13 The NIOS II HAL Project Structure Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-14 7 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-15 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-16 8 Excerpts from a system.h File Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-17 Data Widths and the HAL Type Definitions • For embedded processors such as the NIOS II processor, it is often important to know the exact width and precision of data • Because the ANSI C data types do not explicitly define data width, the HAL uses a set of standard type definitions instead • The ANSI C types are supported, but their data widths are dependent on the compiler’s convention • The header file alt_types.h defines the HAL type definitions Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-18 9 The HAL and GNU Toolchain Type Definitions and Data Widths Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson Lecture 5-19 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-20 10 Available UNIX-style Functions • _exit() • open() • close() • read() • fstat() • sbrk() • getpid() • settimeofday() • gettimeofday() • stat() • ioctl() • usleep() • isatty() • wait() • kill() • write() • lseek() Electrical & Computer Engineering – Embedded Systems Dr. Jeff Jackson

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us