Ug 743810 750762
Ug 743810 750762
Developer Handbook
Updated for Intel® Quartus® Prime Design Suite: 22.1std
IP Version: 1.0.0
Contents
2
Contents
3
Contents
4
Contents
5
Contents
14. Revision History for Nios V Processor Software Developer Handbook....................... 334
6
743810 | 2022.10.31
Send Feedback
Install the latest release of the Intel Quartus® Prime software on the Windows*or
Linux* operating system. Following that, you can find the Nios V processor tools
package in the directory: <Intel Quartus Prime installation directory>
\niosv. You need to acquire the free license for the Nios V processor to compile the
design in Intel Quartus Prime software.
Related Information
• Nios® V Embedded Processor Design Handbook
Describes how to most effectively use the tools, recommends design styles,
and practices for developing, debugging, and optimizing embedded systems
using the Nios® V processor and Intel-provided tools.
• Nios® V Processor Reference Manual
Provides information about the Nios V processor performance benchmarks,
processor architecture, the programming model, and the core implementation.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
1. Overview of Nios® V Embedded Processor Development
743810 | 2022.10.31
Documentation Refer to the Related Information. Refer to the latest documentations according to
the Intel Quartus Prime Pro Edition software
and IP version.
Related Information
• Nios® V Processor Reference Manual
Provides information about the Nios V processor performance benchmarks,
processor architecture, the programming model, and the core implementation
(Intel Quartus Prime Standard Edition User Guide).
• Nios® V Embedded Processor Design Handbook
Describes how to most effectively use the tools, recommends design styles,
and practices for developing, debugging, and optimizing embedded systems
using the Nios® V processor and Intel-provided tools (Intel Quartus Prime
Standard Edition User Guide).
• Ashling* RiscFree* Integrated Development Environment (IDE) for Intel® FPGAs
User Guide
Describes the RiscFree integrated development environment (IDE) for Intel
FPGAs Arm-based HPS and Nios V core processor.
8
1. Overview of Nios® V Embedded Processor Development
743810 | 2022.10.31
Application • A Nios V processor C/C++ application project consists of a collection of source code,
including a CMakeLists.txt.
• The CMakeLists.txt compiles the source code and links the code with a BSP, and
one or more optional libraries to create one .elf file.
• An application project includes code that calls functions in libraries and BSPs.
• A typical characteristic of an application project is that one of the source files contains
function main().
User Library • 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. One example is a collection of common arithmetical functions.
• A user library does not contain a main() function.
Board Support Package (BSP) A BSP project contains the following elements:
• Hardware abstraction layer
• Device drivers
• Optional software packages
• Optional real-time operating system
Note: The toolchain provides the newlib C Library.
Related Information
• Configuring BSP Projects on page 26
For more information about configuring the BSP project.
• Configuring the Application Project on page 33
For more information about configuring the application project
9
1. Overview of Nios® V Embedded Processor Development
743810 | 2022.10.31
Note: Before importing the project to Ashling RiscFree IDE for Intel FPGAs, you need the
generated BSP package and application package.
Related Information
Ashling* RiscFree* Integrated Development Environment (IDE) for Intel® FPGAs User
Guide
The Nios V processor tools creates software projects for you. Each project is based on
a CMakeLists.txt.
Related Information
• CMake
• CMake commands
For more various actions the tool can perform.
10
743810 | 2022.10.31
Send Feedback
Related Information
• Getting Started with the Hardware Abstraction Layer on page 73
• Simple Placement Options on page 110
niosv-download Download the application .elf file into the Nios V processor.
Related Information
Nios V Processor Tools Reference on page 245
For more information about the command line utilities provided by the Nios® V
processor software build tools.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
2. Getting Started from the Command Line
743810 | 2022.10.31
2.2.1.1. niosv-bsp
Usage
Description
Create a BSP CMakeLists.txt that can compile the BSP library file. A
toolchain.cmake file is also created, and it contains toolchain options such as C
compiler, C++ compiler, and link flags to build the Nios V processor software projects.
CMakeLists.txt uses both files when generating the application project.
The default BSP Tcl scripts run unless specified otherwise during BSP creation. The
scripts are available in <Intel Quartus Prime installation directory>/
niosv/scripts/bsp-defaults folder.
Creates a new settings file and -c, --create niosv-bsp -c -s=<path to .qsys file> -t=<bsp
generate the BSP files in the BSP type> [OPTIONS] settings.bsp
directory.
Updates the existing settings file -u, --update niosv-bsp -u [OPTIONS] settings.bsp
and generate the BSP files in the
BSP directory.
Generates the BSP files in the BSP -g, --generate niosv-bsp -g [OPTIONS] settings.bsp
directory according to the existing
settings file.
Queries the BSP settings file. -q, --query niosv-bsp -q -E=<exported tcl script name>
Requires extra options to query [OPTIONS] settings.bsp
individual BSP settings.
-b, --bsp-dir=<bsp directory> The BSP directory. If not specified, this option is the current
directory which stores the settings file.
-t, --type=<bsp type> The type of BSP to create,. For example, hal or ucosii. This
option is required when using -c, --create function and
the BSP type names are case-insensitive.
-E, --export-as-tcl=<exported tcl script The exported Tcl script file name based on the queried BSP
name> project.
Related Information
• Nios V Processor Command Line Utilities on page 245
For more information about the rest of the provided Nios V Utilities options.
• Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
12
2. Getting Started from the Command Line
743810 | 2022.10.31
2.2.1.2. niosv-app
Usage
niosv-app [OPTIONS]
Description
The niosv-app utility is used to create an application project, and you must run
make manually to build the Executable and Linking Format File (.elf) for your
application.
Create application project which links niosv-app -a=<application directory> -b=<bsp directory>-
to a specified BSP s=<source files directory> [OPTIONS]
-L, --link-lib=<linked Links the application or library to the specified library directory. Can be specified
library directory> multiple times.
-e, --elf-name=<.elf output The name of the .elf output file. If omitted, the default .elf name is
file name> <application directory>.elf.
-s, --srcs=<source files Comma separated list of sources. Can be files or directories. Directories have
directory> direct descendant source files included. Specified sources are not copied. They
show up with relative path in the CMakeList.txt.
-p, --public-incs=<public Comma separated list of public include directories. This is for libraries to expose
includes directory> public includes (for dependents to #include).
Related Information
Nios V Processor Command Line Utilities on page 245
For more information about the rest of the provided Nios V Utilities options.
2.2.1.3. niosv-download
Usage
13
2. Getting Started from the Command Line
743810 | 2022.10.31
Description
Download .elf file to the only Nios V processor instance niosv-download ELF_file.elf
Download .elf file to the only Nios V processor instance, niosv-download -g ELF_file.elf
and run from entry point
Download .elf file to the Nios V processor which is located niosv-download ELF_file.elf -c 1 -d 2 -i 2
at cable 1, device 2 and instance 2
-c <cable number>, --cable=<cable number> To select the cable number that the device is connected.
Related Information
Nios V Processor Command Line Utilities on page 245
For more information about the rest of the provided Nios V Utilities options.
14
743810 | 2022.10.31
Send Feedback
Related Information
• Nios V Processor Design Example Scripts on page 331
For more information about example designs.
• Intel® FPGA Technical Training
Online training demonstrations located on the Embedded Design Curriculum
page of the Intel FPGA Technical Training website.
• Nios V Processor Embedded Design Handbook
• Ashling* RiscFree* Integrated Development Environment (IDE) for Intel® FPGAs
User Guide
The Nios V processor tools provides the following tools for software development:
• Nios V processor — specific port of the newlib C library
• Intel Hardware Abstraction Layer (HAL)
• Nios V processor software build tools — based on a scriptable development flow
that includes the following user interfaces:
— Nios V processor software build tools Graphical User Interface (GUI) —
Supports creating, modifying, building, running, and debugging Nios V
processor software programs. The GUI is based on the BSP Editor and the
RiscFree IDE for Intel FPGAs.
— Nios V processor software build tools Command Line Interface (CLI) —
Executes Nios V processor build tools commands and uses scripts (or other
tools) to combine the command utilities.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
To use the Nios V processor tools , you need a .qsys file for your system. The
development flow includes the following steps to create a Nios V processor software:
1. Generate a Board Support Package (BSP) for your system.
2. Generate and build your application software.
3. Iterate through one or both steps until your design is complete.
The BSP project is a parameterizable library, customized for the hardware capabilities
and peripherals in your system. When you create a BSP library file from the BSP
project, you create it with a specific set of parameter values.
The application project consists of your application source files and the application
CMakeLists.txt. The source files refer to the services provided by the BSP library
file.
Related Information
Performing External Tools Configuration
For more information about configuring juart-terminal in the Ashling RiscFree IDE
for Intel FPGAs.
You can accomplish most software development tasks using the Nios V processor
software build tools including creating, editing, building, running, and debugging
programs. The Nios V processor provides the following GUIs for software
development:
• BSP Editor in Platform Designer
• Ashling RiscFree IDE for Intel FPGAs
16
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Table 10. Summary of the Correlation Between GUI and the Command Line Features
Task GUI Command Line
Modifying an application • Any source code editor Any command line source code editor
• RiscFree IDE for Intel FPGAs
Modifying a user library • Any source code editor Any command line source code editor
• RiscFree IDE for Intel FPGAs
Generate an application RiscFree IDE for Intel FPGAs cmake and make
Generate a user library RiscFree IDE for Intel FPGAs cmake and make
You can use the BSP Editor to perform the following tasks:
• Create or modify a Nios V processor BSP project that has been integrated into
Platform Designer.
• Edit settings, linker regions, and section mappings, and to select software
packages and device drivers.
To launch the BSP Editor, click File ➤ Open... ➤ BSP Editor tab in the Platform
Designer. Select the BSP setting file to open.
You can modify, build, run, and debug an application or a user library with the Ashling
RiscFree IDE for Intel FPGAs.
The Nios V Command Shell is a command line environment initialized with the correct
settings to run Nios V command line tools.
For more information about launching the Nios V Command Shell, refer to the Nios V
Processor Command Line Utilities.
Related Information
niosv-shell on page 246
17
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
In the Nios V processor software build tools command line development flow, you can
create, modify, build, and run Nios V processor programs. Type the commands at a
command line or embedded in a script.
To debug your program, import your software projects to Ashling RiscFree IDE for
Intel FPGAs. You can then further edit, rebuild, run, and debug your imported project.
Each tool provides its own documentation in the form of help accessible from the
command line. To view the help menu, open theNios V Command Shell, and type the
following command: <name of tool> --help.
Note: Application file cannot be generated in Ashling RiscFree IDE for Intel FPGAs, you must
generate the application file using niosv-app utilities.
For more information about the Nios V processor tools and the Nios V Command Shell,
refer to Getting Started from the Command Line on page 11.
The Nios V processor command line tools described in this section are in the <Intel
Quartus Prime software installation directory>/niosv/bin directory.
niosv-bsp To create or update a BSP settings file and create the BSP files.
niosv-stack-report To report memory available for stack and heap from an .elf file.
For more information about the Nios V processor command line commands, refer to
the Nios V Processor Tools Reference.
File format conversion is sometimes necessary when passing data from one utility to
another. The file format conversion tools are in the <Intel Quartus Prime
software installation directory>/niosv/bin directory.
Related Information
File Format Conversion Tools Reference on page 251
For more information about the file format conversion tools.
18
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
You might require the following command line tools when building a Nios V processor-
based system. These command line tools are either provided by Intel in <Intel
Quartus Prime installation directory>/quartus/bin or acquired from
open-source tools.
juart-terminal Intel To monitor stdout and stderr, and to provide input to a Nios V
processor subsystem through stdin. This tool only applies to the
JTAG UART IP when it is connected to the Nios V processor.
cmake RiscFree IDE for Intel FPGAs To generate a project build-system using CMake.
make RiscFree IDE for Intel FPGAs To generate the project .elf file using GNU Make.
riscv32-unknown- RiscFree IDE for Intel FPGAs GNU RISC-V Embedded GCC toolchain commands.
elf-*
Related Information
• Nios® V Processor Embedded Design Handbook
For open-source tools installation guide.
• Other Command Line Utilities Tools Reference on page 253
• GNU RISC-V Embedded GCC Toolchain Reference on page 257
The purpose of the build tools is to create and build Nios V processor software
projects. A Nios V processor project build is based on CMakeLists.txt file with the
associated source files.
The Nios V processor software build tools creates the following types of projects:
• Nios V processor Application: A program running on the Nios V processor
implementing some desired functionality, such as control or signal processing.
• Nios V processor Board Support Package (BSP)
— A library providing access to hardware in the Nios V processor system, such as
UARTs and other I/O devices.
— Provides a software runtime environment customized for one processor in a
hardware system.
— Includes the operating system, and other basic system software packages
such as communications protocol stacks.
• User library: A library implementing a collection of reusable functions, such as
graphics algorithms.
19
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
The Nios V processor tools have nearly identical support for C/C++ applications and
libraries. For each case, the Nios V processor tools generate a CMakeLists.txt. The
CMakeLists.txt is used to build the application or user library.
When you create a CMakeLists.txt for an application or user library, provide the
Nios V processor tools with a list of source files. The BSP directory is mandatory for
applications.
For more information, refer to section Nios V Processor Software File Tree.
The Nios V processor tools examines the case-sensitive extension of each source file
to determine the programming language.
Table 13. Supported Programming Languages with the Corresponding File Extensions
Programming Language File extensions
C .c
Nios V processor assembly language; sources are built directly by the Nios V .s
processor assembler without preprocessing.
Related Information
Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
3.1.2.3.3. CMakeLists.txt
The Nios V software development flow generates CMakeLists.txt files and passses
the files to CMake to generate build files for Nios V processor software projects.
20
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Intel recommends you use the BSP Editor in Platform Designer to manage and
customize generated BSP files. As for the application or user library, you can use the
generated CMakeLists.txt or create your own CMakeLists.txt.
Run the commands below to generate single BSP with single application:
#Build App
cmake -B software/app/build -S software/app -G ”Unix Makefiles”
make -C software/app/build
21
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
app bsp
CMakeLists.txt CMakeLists.txt
main.c settings.bsp
build HAL
CMakeCache.txt alt_sys_init.c
CMakeFiles drivers
Makefile linker.h
cmake_install.cmake
linker.x
app.elf.objdump
memory.gbd
app.elf
summary.html
bsp
system.h
libhal2_bsp.a
toolchain.cmake
CMakeFiles
MakeFile
cmake_install.cmake
#Build App
cmake -B software/app/build -S software/app -G ”Unix Makefiles”
make -C software/app/build
22
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
make -C software/app1/build
make -C software/app2/build
Note: You can also build multiple application and single BSP using Ashling RiscFree IDE for
Intel FPGAs after generating multiple application files using Nios V Command Shell.
23
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
app1 bsp
CMakeLists.txt CMakeLists.txt
main.c settings.bsp
build HAL
CMakeCache.txt alt_sys_init.c
CMakeFiles drivers
Makefile linker.h
cmake_install.cmake linker.x
app.elf.objdump memory.gbd
app.elf summary.html
bsp system.h
libhal2_bsp.a toolchain.cmake
CMakeFiles
MakeFile
cmake_install.cmake
app2
CMakeLists.txt
main.c
build
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
app.elf.objdump
app.elf
bsp
libhal2_bsp.a
CMakeFiles
MakeFile
cmake_install.cmake
24
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
make -C software/bsp/build
Note: When BSP library file is built, it does not include _sw.tcl packages which defines
pre-compiled libraries. The libraries are exposed only to the Nios V processor
application via the CMake variable and linked in during the .elf creation.
bsp
CMakeLists.txt
settings.bsp
HAL
alt_sys_init.c
drivers
linker.h
linker.x
memory.gdb
settings.bsp
summary.html
system.h
toolchain.cmake
build
CMakeCache.txt
libhal2_bsp.a
CMakeFiles
cmake_install.cmake
Makefile
Hardware configuration • Obtain the hardware design on which the Nios V processor software
runs. You need to have the Platform Designer System File (.qsys) of
the Nios V processor-based system.
• You can obtain the .qsys file from:
— A Nios V processor design example, please refer to Nios V Design
Example Scripts for more information.
— Your design from Platform Designer
BSP configuration 1. Decide what features the BSP requires. (e.g., RTOS, specialized
software support, small memory footprint, etc)
2. Define BSP by specifying the components in the BSP and relevant
settings, then generate the settings.bsp file
3. Create a BSP CMakeLists.txt using the niosv-bsp utility
continued...
25
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Stage Description
Optional user library configuration 1. Include the custom software user library source files in a single
directory
2. Create a user library CMakeLists.txt using the niosv-app utility
Application project configuration 1. Develop the application code based on the hardware design. There
are some example codes in Nios V Design Example Scripts for your
reference.
2. Create an application CMakeLists.txt using the niosv-app utility
Software System Design • Developing with the Hardware Abstraction Layer (HAL)
• Programme the Nios V processor
• Writing exception handlers
• Optimize the application for performance and size
• Real-time operating system (RTOS) integration
If you change the hardware system, you must recreate, update, or regenerate the BSP
project to keep the library header files up to date. For information about how to keep
your BSP up to date with your hardware, refer to Revising your BSP.
Creating the BSP project populates the target directory with the BSP library file source
and build file. Some of these files are copied from other directories and are
overwritten when you recreate the BSP project.
26
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
The most basic tool for configuring BSPs is the BSP setting. Throughout this section,
many of the project modifications that you can make are based on BSP settings. In
each case, this section presents the names of the relevant settings, and explains how
to select the correct setting value. You can control the value of BSP settings several
ways: on the command line, or by directly adjusting the settings with the BSP Editor.
Another powerful tool for configuring a BSP is the software package. Software
packages add complex capabilities to your BSP. As when you work with BSP settings,
you can add and remove software packages on the command line, or with the BSP
Editor in Platform Designer. Intel recommends that you use the BSP Editor to
configure your BSP project.
For detailed information about how to manipulate BSP settings and add and remove
software packages with the BSP Editor, refer to Board Support Package Editor.
Note: Do not edit BSP files directly. Use the BSP Editor or Nios V processor utilities instead.
If you edit directly, you lose your edit as BSP files are overwritten and regenerated by
the BSP Editor.
Related Information
Board Support Package Editor on page 9
After you select Intel HAL or Micrium MicroC/OS-II RTOS, you cannot change the
operating system for this BSP project.
If you use the HAL environment, be aware of the following properties of this
environment:
• HAL BSP settings: The Settings tab in the BSP Editor shows a comprehensive
list of options.
• HAL setting modification: Modifying the HAL options modifies the system.h
file, which is used to compile the BSP library file.
• HAL initialization: The HAL is initialized during the execution of the C run-time
initialization (crt0) code block. After the crt0 code block runs, the HAL resources
are available for your application to use.
You can configure the HAL in the BSP Editor. The figure and Tcl script below shows how
you specify a jtag_uart to be used as the stdio device.
27
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Related Information
Settings Managed by Nios V Processor Board Support Package Editor on page 258
For more comprehensive list of BSP settings for HAL.
28
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
You can configure MicroC/OS-II with the BSP Editor. Figure Enabling MicroC/OS-II
Timers and Queues in BSP Editor shows how you enable the MicroC/OS-II timer and
queue code. Figure Configuring MicroC/OS-II for Four Timers in BSP Editor shows how
you specify a maximum of four timers for use with MicroC/OS-II. The MicroC/OS-II Tcl
script below performs the same MicroC/OS-II in these two figures.
29
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Related Information
Settings Managed by Nios V Processor Board Support Package Editor on page 258
For more comprehensive list of BSP settings for HAL.
Intel supplies several add-on software packages with the Intel Quartus Prime. The
operating system determines which software packages are available.
These software packages are available for your application to use, and can be
configured in the BSP Editor from the Software Packages tab. The Software
Packages tab allows you to insert and remove software packages in your BSP, and
control software package settings. The software package table at the top of this tab
lists each available software package. The table allows you to select the software
package version and enable or disable the software package.
The BSP Editor supports Tcl scripting. Tcl scripting in the BSP Editor is a simple but
powerful tool that allows you to easily migrate settings from one BSP to another. This
feature is especially useful if you have multiple software projects utilizing similar BSP
settings.
Tcl scripts in the BSP editor allow you to perform the following tasks:
• Regenerate the BSP from the command line
• Export a TCL script from an existing BSP as a starting point for a new BSP
• Recreate the BSP on a different hardware platform
You can configure a BSP either by importing your own manually created Tcl script, or
by using a Tcl script exported from the BSP Editor.
You can apply a Tcl script only at the time that you create the BSP.
BSP Editor export all settings including software packages, drivers, linker scripts
settings to the TCL script.
30
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
# Settings
set_setting
altera_avalon_jtag_uart_driver.enable_jtag_uart_ignore_fifo_full_error {false}
set_setting altera_avalon_jtag_uart_driver.enable_small_driver {false}
set_setting hal.enable_c_plus_plus {true}
set_setting hal.enable_clean_exit {true}
set_setting hal.enable_exit {true}
set_setting hal.enable_instruction_related_exceptions_api {false}
set_setting hal.enable_lightweight_device_driver_api {false}
set_setting hal.enable_reduced_device_drivers {false}
set_setting hal.enable_runtime_stack_checking {false}
set_setting hal.enable_sim_optimize {false}
set_setting hal.linker.allow_code_at_reset {true}
set_setting hal.linker.enable_alt_load {true}
set_setting hal.linker.enable_alt_load_copy_exceptions {false}
set_setting hal.linker.enable_alt_load_copy_rodata {false}
set_setting hal.linker.enable_alt_load_copy_rwdata {true}
set_setting hal.linker.enable_exception_stack {false}
set_setting hal.linker.exception_stack_memory_region_name {ram}
set_setting hal.linker.exception_stack_size {1024}
set_setting hal.log_flags {0}
set_setting hal.log_port {none}
set_setting hal.make.asflags {-Wa,-gdwarf2}
set_setting hal.make.cflags_debug {-g}
set_setting hal.make.cflags_defined_symbols {none}
set_setting hal.make.cflags_optimization {-O2}
set_setting hal.make.cflags_undefined_symbols {none}
set_setting hal.make.cflags_user_flags {none}
set_setting hal.make.cflags_warnings {-Wall -Wformat-security}
set_setting hal.make.cxx_flags {none}
set_setting hal.make.enable_cflag_fstack_protector_strong {false}
set_setting hal.make.enable_cflag_wformat_security {false}
set_setting hal.make.link_flags {none}
set_setting hal.make.objdump_flags {-Sdtx}
set_setting hal.max_file_descriptors {32}
set_setting hal.stderr {niosv_jtag_uart_ver2}
set_setting hal.stdin {niosv_jtag_uart_ver2}
set_setting hal.stdout {niosv_jtag_uart_ver2}
set_setting hal.sys_clk_timer {cpu}
set_setting hal.timestamp_timer {cpu}
set_setting hal.toolchain.ar {riscv32-unknown-elf-ar}
set_setting hal.toolchain.as {riscv32-unknown-elf-gcc}
set_setting hal.toolchain.cc {riscv32-unknown-elf-gcc}
set_setting hal.toolchain.cxx {riscv32-unknown-elf-g++}
set_setting hal.toolchain.enable_executable_overrides {false}
set_setting hal.toolchain.objdump {riscv32-unknown-elf-objdump}
set_setting hal.toolchain.prefix {riscv32-unknown-elf-}
set_setting intel_niosv_m_hal_driver.internal_timer_ticks_per_sec {1000}
# Software packages
# Drivers
set_driver intel_niosv_m_hal_driver cpu
set_driver altera_avalon_jtag_uart_driver niosv_jtag_uart_ver2
# User devices
31
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
The following example illustrates how to configure a new BSP with an imported Tcl
script. You import the Tcl script with the BSP Editor when you create a new BSP
settings file.
In this example, you create the Tcl script by hand, with a text editor. You can also use
a Tcl script exported from another BSP, as described in Exporting a Tcl Script.
Note: Do not attempt to import an Intel HAL Tcl script to a MicroC/OS-II BSP or vice versa.
Doing so can result in errors. Some BSP settings are OS-specific, making scripts from
different OSes incompatible.
32
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
For more information about commands that can appear in BSP Tcl scripts, refer to
Board Support Package Tcl Commands on page 285.
Related Information
Board Support Package Editor on page 9
Use the following tips to increase your efficiency in designing your application project:
• Source file inclusion—To add source files to your project, drag them from a file
browser, such as Windows Explorer, and drop them in the Project Explorer view
in the Ashling RiscFree IDE for Intel FPGAs.
From the command line with niosv-app, you may use the --srcs argument to
specify the source files in your application project command line option.
You can create and use your own user libraries in the Nios V processor toolss. The
Nios V processor tools enables you to create user libraries in the Nios V Command
Shell, as follows:
• Create the library using the niosv-app -l=libdir command. This command
generates a CMakeLists.txt file.
Configure the application project with the new library by running the niosv-app -
a=appdir --link-lib=libdir command to link library to application. The value
for the option specifies the path to the library's directory
After editing the BSP settings, and generating the BSP, you can build your project.
Below is the CLI flow to build the project once the BSP is generated:
1. Use niosv-app utility to generate and configure an application project.
2. Based in user interface:
a. CLI (Nios V Command Shell)
i. Use cmake command to generate a project build-system.
ii. Use make command to generate the project .elf file.
b. GUI (Ashling RiscFree IDE for Intel FPGAs)
i. Import the project to Ashling RiscFree IDE for Intel FPGAs
ii. Use the Build option to build the project.
33
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Note: You need to install the necessary open-source tools before running cmake and make.
For more information, refer to Other Utilities Tools.
Download the .elf file into a Nios V processor using one of the following method:
• niosv-download command in the Nios V Command Shell. Then, reset the Nios V
processor system to run your program.
• Debug As or Run As option using Ashling RiscFree IDE for Intel FPGAs
If you configured your application to use the stdin function via a JTAG UART
interface, you can use the juart-terminal application to communicate with your
target processor subsystem.
Characters you type in the shell are transmitted to the target. You can also configure
the juart-terminal in the Ashling RiscFree IDE for Intel FPGA.
Related Information
Performing External Tools Configuration
For more information about configuring juart-terminal in the Ashling RiscFree IDE
for Intel FPGAs.
This section describes how to debug a Nios V program using the Ashling RiscFree IDE
for Intel FPGAs. You can debug a Nios V processor program on Nios V processor
hardware such as a Nios V processor development board.
Note: Do not select Local C/C++ Application. Nios V processor projects can only be run
and debugged with Nios V processor run configurations.
Related Information
Ashling* RiscFree* Integrated Development Environment (IDE) for Intel® FPGAs User
Guide
For debugging purposes, it is useful to enable run-time stack checking, using the
hal.enable_runtime_stack_checking BSP setting. When properly used, this
setting enables the debugger to take control if Nios V processor detects a stack
collision has occurred in sbrk.
Related Information
Settings Managed by Nios V Processor Board Support Package Editor on page 258
For more comprehensive list of BSP settings for HAL.
34
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
This section discusses several designs and software architecture practices that can
help you avoid software project coherency. For example, a new version of a system
hardware project is not coherent with the previous version of the software project.
The safest software development practice for avoiding the software coherency problem
is to follow a strict hardware and software project hierarchy and to use Nios V utilities
to generate your application and BSP projects.
One best practice is structuring your application hierarchy with parallel application
projects and BSP project folders. In the following recommended directory structure, a
top-level hardware project folder includes:
• The Intel Quartus Prime project file.
• The Platform Designer-generated files.
• The Software Project Folder, which contains the following subfolders:
— Application project
— BSP project.
Project Folder
<system_name>.qsys
<system_name>.sof
The complete system generation process, from hardware to BSP and application
projects, must be repeated every time a change is made to the system in Platform
Designer. Therefore, defining all your settings in your niosv-bsp command Tcl script is
more efficient than using the BSP Editor to customize your project.
35
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
To implement this system generation process, Intel recommends that you use the
following checklists for handing off responsibility between the hardware and software
groups.
Note: This method assumes that the hardware and software engineering groups use the
same Intel Quartus Prime Software version.
Hardware project hand-off The hardware group provides copies of the <system_name>.qsys and
<system_name>.sof files. The software group copies these files to the software
group’s hardware project folder.
Create software project The software group creates the software application for the new hardware by
running the niosv-bsp and niosv-app utilities.
Build software project The software group runs cmake and make commands in its application project
directory to build the software application.
Reconfigure software project The hardware hands over the updated <system_name>.qsys and
<system_name>.sof files. The software group runs the niosv-app and
niosv-bsp command to reconfigure the group’s application and BSP projects.
Rebuild software project The software group runs cmake and make commands in its application project
directory to build the software application.
To hand off the project from the software group to the hardware group, follow this checklist:
Software project hand-off The software group builds and provides the hardware group with a copy of the
<app_name>.elf software binary. The hardware group then converts the
software binary into the relevant format according to Nios V processor boot
methods.
Many of the hardware and software coherency issues that arise during the creation of
the application software are problems of misplaced peripheral addresses. Because of
the flexibility provided by Platform Designer, almost any peripheral in the system can
be assigned an arbitrary address, or have its address modified during system creation.
Implement the following practices to prevent this type of coherency issue during the
creation of your software application:
• Peripheral and Memory Addressing —The Nios V processor tools automatically
generate a system header file, system.h, that defines a set of #define symbols
for every peripheral in the system. These definitions specify the peripheral name,
base address location, and address span.
36
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
To protect against coherency issues, access all system peripherals and memory
components with their system.h name and address span symbols. This method
guarantees successful peripheral register access even after a peripheral's addressable
location changes.
For example, if your system includes a UART peripheral named UART1 (located at
address 0x1000), access the UART1 registers using the system.h address symbol
(IOWR_32(UART1_BASE, 0x0,0x10101010)) rather than using its address
(IOWR_32(0x1000, 0x0,0x10101010)).
Related Information
• Overview of the Hardware Abstraction Layer on page 73
• HAL Peripheral Services on page 40
For information about configuring and using HAL services.
• Reducing Code Footprint in Embedded Systems on page 100
For information about increasing your application's performance, or minimizing
the code footprint.
The HAL BSP library is self-configuring to some extent to support the Nios V software
development flow. By design, the HAL attempts to enable as many services as
possible based on the peripherals present in the system hardware. This approach
provides your application with the least restrictive environment possible, a helpful
feature during the product development and board brings-up cycle.
The HAL is configured with a group of settings whose values are determined by Tcl
commands, which are called during the creation of the BSP project. Intel recommends
you create a separate Tcl file that contains your HAL configuration settings.
HAL configuration settings control the boot loading process and provide detailed
control over the initialization process, system optimization, and the configuration of
peripherals and services. For each of these topics, this section provides pointers to the
relevant material elsewhere in this section.
Your particular system may require a bootloader to configure the application image
before execution. For example, suppose your application image is stored in flash
memory and copied to volatile memory for performance. In that case, a bootloader
must configure the application image in the volatile memory. This configuration
process occurs before the HAL BSP library configuration routines execute and before
the crt0 code block executes. A bootloader implements this process.
37
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Related Information
• crt0 Initialization on page 38
• Nios® V Processor Configuration and Booting Solutions
The system initialization sequence begins when the system powers up. The
initialization sequence steps for FPGA designs that contain a Nios V processor are the
following:
1. Hardware reset event: The board receives a power-on reset signal, which resets
the FPGA.
2. FPGA configuration: The FPGA is programmed with a .sof file, from a
specialized configuration memory or an external hardware master.
3. System reset: The Platform Designer system, composed of one or more Nios V
processors and other peripherals, receives a hardware reset signal and enters the
components’ combined reset state.
4. Nios V processor: Nios V processor jumps to its preconfigured reset address and
begins running instructions found at this address.
5. Bootloader ( optional): Refer to bootloader section for more information.
6. crt0 execution: If you used a bootloader, the processor jumps to the _entry
symbol within the crt0 code. If you did not use a bootloader, the CPU starts from
the _reset symbol which jumps to the_entry symbol, which is the beginning of
the crt0 code.
38
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Note: Platform Designer determines the processors that have instruction caches
and configures these caches at system generation. The Nios V processor
tools insert the instruction-cache initialization code block if necessary.
2. Initializes data cache—If the processor has a data cache, this cache is
initialized. As with the instruction caches, this code is enabled if the processor has
a data cache.
3. Initializes exception vector (mtvec) and interrupt controller settings—The
exception vector and interrupt controller settings are initialized as configured in
the hardware design.
4. Set the global pointer—The global pointer register is initialized.
5. Sets the stack pointer—The stack pointer is initialized. You can configure the
stack pointer address.
6. Clears the .bss section—The .bss section is initialized to all zeros. You can set
the .bss section address.
7. Calls alt_load macros—If the application is designed to run from flash memory
(the .text section runs from flash memory), the remaining sections are copied to
volatile memory.
8. Jumps to alt_main()—The processor jumps to the alt_main() function, which
begins initializing the HAL BSP run-time library.
Note: If you use a third-party RTOS or environment for your BSP library file, the
alt_main() function can be different than the one provided by Intel.
If you use a third-party compiler or library, the C run-time initialization behavior may
differ from this description.
The crt0.S source file is generated when generating the Nios V processor BSP under
<bsp_dir>/HAL/src directory. The crt0 code includes initialization short-cuts only if
you perform hardware simulations of your design. You can control these optimizations
by the hal.enable_sim_optimize setting.
Related Information
• Settings Managed by Nios V Processor Board Support Package Editor on page 258
For more comprehensive list of BSP settings for HAL.
• Configuring the Boot Environment on page 37
For more information about Calls alt_load macros.
As for any other C program, the first part of the HAL's initialization is implemented by
the Nios V processor's crt0.S routine. After crt0.S completes the C run-time
initialization, it calls the HAL alt_main() function, which initializes the HAL BSP run-
time library and subsystems.
39
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
By default, the HAL configuration mechanism enables support for the C++
programming language. Disabling this feature reduces your application's code
footprint, as noted in Reducing Code Footprint in Embedded System. The Nios V
processor C++ language support depends on the GCC tool chain.
This section describes the core set of Intel-supplied, HAL-accessible peripherals and
the services they provide for your application. It also describes application design
guidelines for using the supplied service, and background and configuration
information, where appropriate.
Related Information
• Settings Managed by Nios V Processor Board Support Package Editor on page 258
For more comprehensive list of BSP settings for HAL.
• Developing Programs Using the Hardware Abstraction Layer on page 78
For more information about the HAL peripheral services.
40
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
The HAL provides two types of timer services, a system clock timer, and a timestamp
timer.
• The system clock timer is used to control, monitor, and schedule system events.
• The timestamp variant is used to make high performance timing measurements.
You can assign each of these timer services to the Nios V processor internal timer or
an Intel Avalon Timer peripheral.
Note: Nios V processor core includes a timer that provides both the system clock timer and
timestamp services.
Related Information
Embedded Peripherals IP User Guide: Interval Timer Core
The system clock timer resource is used to trigger periodic events (alarms), and as a
timekeeping device that counts system clock ticks. The default system clock timer in a
Nios V processor subsystem is the Nios V processor built-in internal timer. You may
configure the system clock timer to other timer peripherals in the Platform Designer
system.
Note: Only one system clock timer service may be identified in the BSP library. Only HAL
supplied routines access the timer.
The hal.sys_clk_timer setting controls the BSP project configuration for the
system clock timer. This setting configures one of the timers available in your Platform
Designer design as the system clock timer.
Intel provides separate APIs for application-level system clock functionality and for
generating alarms.
41
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Consider the following common issues and important points before you implement a
system clock timer:
• System Clock Resolution—The timer’s period value specifies the rate at which
the HAL BSP project increments the internal variable for the system clock counter.
If the system clock increases too slowly for your application, you can decrease the
timer's period in Platform Designer.
• Rollover—The internal, global variable that stores the number of system clock
counts (since reset) is a 64-bit unsigned integer. No rollover protection is offered
for this variable. Therefore, calculate when the rollover event occurs in your
system and plan the application accordingly.
• Performance Impact—Every clock tick causes the execution of an interrupt
service routine. Executing this routine leads to a minor performance penalty. If
your system hardware specifies a short timer period, the cumulative interrupt
latency impacts your overall system performance.
The alarm API allows you to schedule events based on the system clock timer, in the
same way an alarm clock operates. The API consists of the alt_alarm_start()
function, which registers an alarm, and the alt_alarm_stop() function, which
disables a registered alarm.
Consider the following common issues and important points before you implement an
alarm:
• Interrupt Service Routine (ISR) context—A common mistake is to program
the alarm call-back function to call a service that depends on interrupts being
enabled (such as the printf() function). This mistake causes the system to
deadlock, because the alarm call-back function occurs in an interrupt context,
while interrupts are disabled.
• Resetting the alarm—The callback function can reset the alarm by returning a
nonzero value. Internally, the alt_alarm_start() function is called by the call-
back function with this value.
• Chaining—The alt_alarm_start() function is capable of handling one or more
registered events, each with its own call-back function and number of system
clock ticks to the alarm.
• Rollover—The alarm API handles clock rollover conditions for registered alarms
seamlessly.
A good timer period for most embedded systems is 50 milliseconds. This value
provides enough resolution for most system events but does not seriously impact
performance nor roll over the system clock counter too quickly. Choosing a timer
period that is too short might overwhelm the Nios V processor to continuously
servicing the timer interrupt handler, and neglect other tasks.
The timestamp timer service provides applications with an accurate way to measure
the duration of an event in the system. The default timestamp timer in a Nios V
processor subsystem is the Nios V processor built-in internal counter. You may
alternatively configure the system clock timer to other timer peripherals in the
Platform Designer system.
Note: Only one timestamp timer service may be identified in the BSP library file. Only HAL
supplied routines access the timer.
42
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
The hal.timestamp_timer setting controls the BSP configuration for the timer. This
setting configures one of the timers available in the Platform Designer design as the
timestamp timer.
Intel provides a timestamp API. The timestamp API is very simple. It includes the
alt_timestamp_start() function, which makes the timer operational, and the
alt_timestamp() function, which returns the current timer count.
Consider the following common issues and important points before you implement a
timestamp timer:
• Timer Frequency—The timestamp timer decrements at the clock rate of the clock
that feeds it in the Platform Designer system. You can modify this frequency in
Platform Designer.
• Rollover—The timestamp timer has no rollover event. When the
alt_timestamp() function returns the value 0, the timer has run down.
• Maximum Time—The default Nios V processor internal timer have 64 bits
available to store the timer value. For Avalon timer peripherals, it can be 32 or 64
bits depending on the parametrization. Therefore, the maximum duration a
timestamp timer can count is [(1/timer frequency) × 2bits_value] seconds.
(bits_value = 32 or 64)
Related Information
HAL API Reference on page 186
For more information about the APIs that control the timestamp and system clock
timer services.
The HAL can support the stdio functions provided in the GNU newlib library. Using the
stdio library allows you to communicate with your application using functions such as
printf() and scanf().
Currently, Intel supplies two system components that can support the stdio library, the
UART and JTAG UART components. These devices can function as standard I/O
devices.
Make sure that you assign values individually for each of the stdin, stdout, and stderr
file variables that you use.
43
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
Depending on the function you use to read the file handle, an error code is returned,
specifying whether new data arrived.
The UART and JTAG UART components are initialized in blocking mode. However, each
component can be made non-blocking with the fnctl() or the ioctl() function, as
seen in the following open system call, which specifies that the device being opened is
to function in non-blocking mode:
The fnctl() system call shown in the example below specifies that a device that is
already open is to function in non-blocking mode.
The behavior of the UART and JTAG UART peripherals can also be modified with an
ioctl() function call. The ioctl() function supports the following parameters:
• For UART peripherals:
— TIOCMGET (reports baud rate of UART)
— TIOCMSET (sets baud rate of UART)
• For JTAG UART peripherals:
— TIOCSTIMEOUT (timeout value for connecting to workstation)
— TIOCGCONNECTED (find out whether host is connected)
44
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
if(errno != EWOULDBLOCK)
{
/* check other errnos */
}
}
else
{
/* process received characters */
}
If you have a custom device capable of character mode operation, you can create a
custom device driver that the stdio library functions can use.
Every flash memory device is queried by the HAL during system initialization to
determine the kind of flash memory and the functions to manage it. This process is
automatically performed by the alt_sys_init() function, if the device drivers are
not explicitly omitted and the small driver configuration is not set.
After initialization, you can query the flash memory for status information with the
alt_flash_get_flash_info() function. This function returns a pointer to an array
of flash region structures—C structures of type struct flash_region—and the number of
regions on the flash device.
For additional information about the struct flash_region structure, refer to the source
file HAL/inc/sys/alt_flash_types.h in the BSP project directory.
The HAL flash memory device model provides you with two flash access APIs, one
simple and one fine-grained. The simple API takes a buffer of data and writes it to the
flash memory device, erasing the sectors if necessary. The fine-grained API enables
you to manage your flash device on a block-by-block basis.
Both APIs can be used in the system. The type of data you store determines the most
useful API for your application. The following general design guidelines help you
determine which API to use for your data storage needs:
• Simple API—This API is useful for storing arbitrary streams of bytes if the exact
flash sector location is not important. Examples of this type of data are log or data
files generated by the system during run-time, which must be accessed later in a
continuous stream somewhere in flash memory.
• Fine-Grained API—This API is useful for storing units of data, or data sets, which
must be aligned on absolute sector boundaries. Examples of this type of data
include persistent user configuration values, FPGA hardware images, and
application images, which must be stored and accessed in each flash sector (or
sectors).
45
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
If you use flash memories in your system, be aware of the following properties of this
memory:
• Code Storage—If your application runs code directly from the flash memory, the
flash manipulation functions are disabled. This setting prevents the processor from
erasing the memory that holds the code it is running. In this case, the symbols
ALT_TEXT_DEVICE, ALT_RODATA_DEVICE, and ALT_EXCEPTIONS_DEVICE
must all have values different from the flash memory peripheral. (Note that each
of these #define symbols names a memory device, not an address within a
memory device).
• Small Driver—If the small driver flag is set for the software—the
hal.enable_reduced_device_drivers setting is enabled—then the flash
memory peripherals are not automatically initialized. In this case, your application
must call the initialization routines explicitly.
— Thread safety—Most of the flash access routines are not thread-safe. If you
use any of these routines, construct your application so that only one thread in
the system accesses these functions.
The HAL Direct Memory Access (DMA) model uses DMA transmit and receive channels.
A DMA operation places a transaction request on a channel. A DMA peripheral can
have a transmit channel, a receive channel, or both. This section describes three
hardware configurations for a DMA peripheral and shows how to activate each kind of
DMA channel using the HAL memory access functions.
The DMA peripherals are initialized by the alt_sys_init() function call and are
automatically enabled by the niosv-bsp command.
The following examples illustrate use of the DMA transmit and receive channels in a
system. The information complements the information available in Using DMA Devices.
Regardless of the DMA peripheral connections in the system, initialize a transmit
channel by running the alt_dma_txchan_open() function, and initialize a receive
DMA channel by running the alt_dma_rxchan_open() function. The following
sections describe the use model for some specific cases.
The HAL provides a wide variety of native devices support for Intel-supplied
peripherals. However, your system may require a device or peripheral that Intel does
not offer. In this case, one or both of the following two options is available for you:
• Obtain a device through Intel third-party program
• Incorporate your own device
Incorporating your own custom peripheral is a two-stage process. First you must
incorporate the peripheral in the hardware using Platform Designer, and then you
must develop a device driver.
46
3. Nios V Processor Software Development and Implementation
743810 | 2022.10.31
This section discusses exception handling with the Nios V processor internal interrupt
controller.
Consider the following common issues and important points before you use the HAL-
provided exception handler:
• Prioritization of interrupts: The Nios V processor does not prioritize its 16
platform interrupt, but the HAL exception handler assigns higher priority to lower
numbered interrupts. You must modify the interrupt request (IRQ) prioritization of
your peripherals in Platform Designer.
• Nesting of interrupts: The HAL infrastructure allows interrupts to be nested—
higher priority interrupts can preempt processor control from an exception handler
that is servicing a lower priority interrupt. However, Intel recommends that you
not nest your interrupts because of the associated performance penalty.
• Exception handler environment: When creating your exception handler, you
must ensure that the handler does not run interrupt-dependent functions and
services, because this can cause deadlock. For example, an exception handler
should not call the IRQ-driven version of the printf() function.
Related Information
Exception Handling on page 142
For information about the exception handler software routines, HAL-provided
services, and API.
In some very special cases, you can modify the existing HAL exception handler routine
or to insert your own interrupt handler for the Nios V processor. However, in most
cases you need not modify the interrupt handler routines for the Nios V processor for
your software application.
Consider the following common issues and important points before you modify or
replace the HAL-provided exception handler:
• Interrupt vector address: The interrupt vector address for each Nios V
processor is set by the Board Support Package (BSP) files. You can modify it
during BSP configuration in the BSP Editor.
• Modifying the exception handler: The HAL-provided exception handler is
robust, reliable, and efficient. Modifying the exception handler could break the
HAL-supplied interrupt handling API, and cause problems in the device drivers for
other peripherals that use interrupts, such as the UART and the JTAG UART.
You can modify the behaviour of the exception handler to increase overall
performance.
47
743810 | 2022.10.31
Send Feedback
Before reading this chapter, consider getting an introduction to the build tools from the
following references:
• Overview of Nios V Processor Embedded Development
• Getting Started from the Command Line
• Nios V Processor Tools
Depending on how you use the tools, you might also need to be familiar with the
following topics:
• Micrium MicroC/OS-II.
For more information, refer to MicroC/OS-II - The Real Time Kernel by Jean J.
Labrosse (CMP Books).
• Tcl scripting language.
Related Information
HAL BSP Settings on page 78
For more information about how to control BSP settings.
By default, the tools generate a basic BSP for a Nios V processor based system. If you
require more detailed control over the characteristics of your BSP, the BSP Editor
provides that control, as described in the remaining sections of this chapter.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
Each device driver manages a hardware component. By default, the HAL instantiates a
device driver for each component in your hardware system that needs a device driver.
In the Nios V software development environment, a device driver has the following
properties:
• A device driver is associated with a specific hardware component.
• A device driver might have settings that impact its compilation. These settings
become part of the BSP settings.
A software package is source code that you can optionally add to a BSP project to
provide additional functionality.
49
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The MicroC/OS-II source code resides in the UCOSII directory. The UCOSII directory
is contained in the BSP directory, like the HAL directory, and has the same structure
(src and inc directories).
Although this section describes tasks in terms of the BSP Editor command line flow,
you can also carry out most of these tasks from the BSP Editor user interface in
Platform Designer.
For details about the Nios V Command Shell and niosv-bsp, refer to the Getting
Started from the Command Line.
One common tool flow requirement is version control. When using version control, it is
important to know which files to add to your version control database. To ensure
reproducible results from software builds, Intel recommends placing the build scripts
50
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
(such as Platform Designer system script and BSP Tcl script) and application source
codes under version control. The build scripts incorporate all information on the
system and can be generated using the commands in the following table.
Export the BSP Tcl script niosv-bsp --query --export-as-tcl=<BSP Tcl script> settings.bsp
If you create a BSP by running your own script that calls niosv-bsp, you can put your
script under version control. If your script provides any BSP TCL scripts to niosv-
bsp(using the --script=<Tcl script> option), you must also put these TCL
scripts under version control. If you install a new release of Intel Quartus Prime
software and run your script to create a new BSP or to update an existing BSP, the
internal implementation of your BSP might change slightly due to improvements in
BSP Editor.
If you create a script that uses the command line tools niosv-bsp explicitly, or you
use these tools directly on the command line, you can create the BSP settings file in a
directory different from the directory where the generated BSP files reside. Intel
recommends you to keep the settings file with the other BSP files. You can rebuild the
project without the BSP settings file, but the settings file allows you to update and
query the BSP.
BSP CMakeLists.txt has only relative path references to project source files.
Therefore, you are free to copy, move, or rename the entire BSP. If you specify a
relative path to the Platform Designer system file when you create the BSP, you must
ensure that the .qsys file is still accessible from the new location of the BSP. This file
path is stored in the BSP settings file.
You must rebuild the BSP when copying, moving, or renaming a BSP before linking an
application with the BSP.
Another way to copy a BSP is to run the niosv-bsp --generate command to populate
an empty BSP directory and pass it the path to the BSP settings file of the BSP that
you want to copy.
If you rename or move a BSP, you must manually revise any references to the BSP
name or location in the application or user library CMakeLists.txt.
If you need to pass a BSP to another developer, save the processor subsystem as a
Platform Designer script and export the BSP settings as a BSP TCL script.
51
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
Export the BSP Tcl script niosv-bsp --query --export-as-tcl=<BSP Tcl script> settings.bsp
Related Information
Intel® Quartus® Prime Pro Edition User Guide: Platform Designer
For more information about creating and restoring a Platform Designer script.
This section describes several common scenarios in which the BSP Editor allows you to
control details of a memory usage.
Memory initialization files are used for HDL simulation, for Intel Quartus Prime
compilation of initializable FPGA on-chip memories, and for flash programming.
Memories that can be initialized include M512, M4K and M20K, but not MRAM.
The BSP Editor does not build the memory initialization files by default. You can
generate memory initialization using elf2hex command. For more information, refer
to File Format Conversion Tools Reference: elf2flash
If the default linker memory regions do not meet your needs, BSP Tcl commands let
you modify the memory regions as you prefer.
Suppose you have a memory region named onchip_ram. The following Tcl script
example separates the top 1024 bytes of onchip_ram to create a new region named
onchip_special.
52
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
For more information about an explanation of each Tcl command used in this example,
refer to the Board Support Package Tcl Commands .
If you pass this Tcl script to niosv-bsp, it runs after the default Tcl script runs and
sets up two memory regions named onchip_ram and onchip_special. Pass the Tcl
script to niosv-bsp as follows:
If you update your BSP without providing the --script option, your BSP reverts to
the default linker memory regions and the onchip_special memory region
disappears. To preserve it, please provide the --script option to your Tcl script.
For more information about using the --script argument, refer to the Calling a Custom
BSP Tcl Script.
53
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
To create your own section named special_section that is mapped to the linker
region named onchip_special, use the following niosv-bsp command:
When the niosv-bsp generates the linker script linker.x, the linker script has a
new section mapping. The order of section mappings in the linker script is determined
by the order in which the add_section_mapping command creates the sections. If
you use niosv-bsp, the default Tcl script runs before the --cmd option that creates
the special_section section.
If you update your BSP, you do not need to provide the add_section_mapping
command again because the default Tcl script only modifies section mappings for the
default sections (.entry, .exceptions, .text, .rodata, .rwdata, .bss, .heap,
and .stack).
This example works with any hardware design containing an on-chip memory named
on_chip_mem connected to a Nios V processor instruction manager.
The above Tcl script splits off 1 KB of RAM from the region named on_chip_mem,
gives it the name isrs_region, and then calls add_section_mapping to add
the .isrs section to isrs_region.
54
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
After cmake and make complete successfully, you can examine the object dump file,
<project_name>.objdump. The object dump file shows that the new .isrs section is
in the on_chip_mem. This object dump file excerpt shows a hardware design with an
on-chip memory whose address range is 0x00010000 to 0x00019fff.
SYMBOL TABLE:
00010000 l d .entry 00000000 .entry
00010020 l d .exceptions 00000000 .exceptions
00019c00 l d .isrs 00000000 .isrs
000102a0 l d .text 00000000 .text
00015cc0 l d .rodata 00000000 .rodata
00015cfc l d .rwdata 00000000 .rwdata
0001776c l d .init_array.00000 00000000 .init_array.00000
000191dc l d .bss 00000000 .bss
000192c0 l d .on_chip_mem 00000000 .on_chip_mem
If you examine the linker script file, linker.x, you can see that linker.x places
the new region isrs_region in MEMORY, adjacent to the on_chip_mem region.
55
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
If the default section mappings created by the default Tcl script do not meet your
needs, you can use a Tcl command to override the section mappings selectively.
To map the .stack and .heap sections into a memory region named ram_0, use the
following command:
The other section mappings (for example, .text) are still mapped to the default
linker memory region.
If you update your BSP, the default Tcl script overrides your section mappings
for .stack and .heap because they are default sections. To prevent your section
mappings from being changed, provide niosv-bsp --update with the
add_section_mapping command line options.
If you need to write a script that gets some information from the BSP settings file, use
the niosv-bsp --query utility. To maintain compatibility with future releases of the
Intel Quartus Prime software, avoid developing your own code to parse the BSP
settings file.
niosv-bsp --query --export-as-tcl=<BSP Tcl script> settings.bsp
This command exports the values of the BSP settings to a BSP Tcl script. By default,
the output of niosv-bsp --query is an ordered list of all settings values.
For more information about the niosv-bsp command line options, refer to the
Getting Started from the Command Line.
The BSP Editor creates an alt_sys_init.c file. By default, the BSP Editor assumes
that if a device is connected to the Nios V processor, and a driver is available, the BSP
must include the most recent version of the driver. However, you might want to use a
different version of the driver, or you might not want a driver at all (for example, if
your application accesses the device directly).
56
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The BSP Editor includes BSP Tcl commands to manage device drivers. With these
commands you can control which driver is used for each device. When the
alt_sys_init.c file is generated, it is set up to initialize drivers as you have
requested.
If you are using niosv-bsp, you can disable the driver for the uart0 device as
follows:
Use the --cmd option to call a Tcl command on the command line. Alternatively, you
can put the set_driver command in a Tcl script and pass the script to niosv-bsp or
with the --script option.
You replace the default driver for uart0 with a specific version of a driver as follows:
If you update your BSP, you must provide the original command line options again to
prevent the default Tcl script from choosing its own default device drivers.
The build tools offer several ways to control the details of your stdio device
configuration, such as the following:
If you update your BSP, you must provide the original command line options again to
prevent the default Tcl script from choosing its own default stdio devices.
57
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
You can specify the optimization and debug level for the application and BSP projects,
and any user library projects you might be using. Use the BSP Editor settings
hal.make.cflags_debug and hal.make.cflags_optimization to specify the
optimization and debug level for the whole project.
When your project is fully debugged and ready for release, you might want to
enable optimization and omit the symbol table, to achieve faster, smaller
executable code. To enable optimization and turn off the symbol table, edit the
BSP Editor settings as shown in the following example. The absence of a value in
hal.make.cflags_debug causes the compiler to omit generating a symbol
table.
• To configure the whole software project for release:
When creating a new BSP:
niosv-bsp --create --qsys=<Platform Designer system> --type=hal
--cmd=”set_setting hal.make.cflags_debug {none}” --cmd=”set_setting
hal.make.cflags_optimization {-O3}” settings.bsp
You can specify the RISC-V compiler using the hal.toolchain.prefix. By default, the
hal.toolchain.prefix is configured as riscv32-unknown-elf- which is provided by
the Ashling RiscFree IDE for Intel FPGAs.
58
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The BSP Editor manages copied files slightly differently from generated files. If a
copied file (such as a HAL source file) already exists, the tools check the file
timestamp against the timestamp of the file in the Intel Quartus Prime installation
directory. The tools do not replace the BSP file unless it differs from the distribution
file. The tools normally overwrite generated files, such as the system.h,
toolchain.cmake and CMakeLists.txt, and linker.x, unless you have disabled
generation of the individual file with the BSP Enable File Generation tab in the BSP
Editor.
Note: Avoid modifying BSP files. Use BSP settings, or custom device drivers or software
packages from the BSP Editor, to customize your BSP. Manual modification (without
using the BSP Editor) to the BSP files are destroyed upon BSP regeneration.
niosv-bsp --create
59
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The BSP settings file does not need to duplicate system information (such as base
addresses of devices), because the niosv-bsp utility has access to the .qsys file.
The niosv-bsp --create utility creates a new BSP settings file and generate the BSP
files. The niosv-bsp --update utility updates an existing BSP settings file and
regenerate the BSP files. The niosv-bsp --query utility reports the setting values in
an existing BSP settings file. The niosv-bsp --generate utility generates a BSP from
an existing BSP settings file.
niosv-bsp --create
niosv-bsp --query
BSP Settings
Tcl Script
(.tcl)
To understand how to build and modify Nios V C/C++ projects, understand the
difference between copied and generated files.
A copied file is installed with the Intel Quartus Prime software and copied to your BSP
directory when you create your BSP. The copied file does not replace the BSP file
unless it differs from the distribution file.
The niosv-bsp utility dynamically creates a generated file. Generated files reside in the
top-level BSP directory. BSP files are normally written every time niosv-bsp --create,
niosv-bsp --generate or niosv-bsp --update runs.
You can disable the generation of any BSP file in the BSP Editor. Otherwise, if you
modify a BSP file, the file is deleted when you regenerate the BSP.
60
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The BSP Editor places generated files in the top-level BSP directory, and copied files in
the HAL and drivers directories. If the MicroC/OS-II operating system is selected, the
BSP Editor creates an additional UCOSII directory.
alt_sys_init.c Generated File Used to initialize device driver instances and software
packages.
CMakeLists.txt Generated File Used to build the BSP by listing the files and directories
targeted by the build and other build settings.
linker.h Generated File Contains information about the linker memory layout.
system.h includes the linker.h file.
linker.x Generated File Contains a linker script for the GNU linker.
memory.gdb Generated File Contains memory region declarations for the GNU debugger.
settings.bsp Generated File Contains all BSP settings. This file is coded in XML.
system.h Generated File Contains the C declarations describing the BSP memory
map and other system information needed by software
applications.
toolchain.cmake Generated File Lists the compiler configurations for the build.
61
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
You control the characteristics of your BSP by manipulating BSP settings, using Tcl
commands, or combining them into Tcl scripts.
Tcl scripting gives you maximum control over the contents of your BSP. One advantage
of Tcl scripts over command line arguments is that a Tcl script can obtain information
from the hardware system or pre-existing BSP settings and then use it later in script
execution.
Any settings you specify in your script override the BSP default values. When you
update an existing BSP, you must include any scripts originally used to create it.
Otherwise, your project’s settings revert to the defaults.
When you use a custom Tcl script to create your BSP, you must include the script in
the set of files archived in your version control system.
The BSP Editor uses slave descriptors to refer to components connected to the Nios V
processor. A slave descriptor is the unique name of a hardware component's slave
port.
62
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
If a component has only one slave port connected to the Nios V processor, the slave
descriptor is the same as the component's name (for example, onchip_mem_0).
Suppose a component has multiple slave ports connecting the Nios V processor to
multiple resources in the component. In that case, the slave descriptor is the name of
the component followed by an underscore and the slave port name (for example,
onchip_mem_0_s1).
# Select a device connected to the processor as the default STDIO device.
# It returns the slave descriptor of the selected device.
# It gives first preference to devices with stdio in the name.
# It gives second preference to JTAG UARTs.
# If no JTAG UARTs are found, it uses the last character device.
# If no character devices are found, it returns "none".
# Procedure that does all the work of determining the stdio device.
proc choose_default_stdio {} {
set last_stdio "none"
set first_jtag_uart "none"
# Assume it is a JTAG UART if the module class name contains the string
# "jtag_uart". In that case, return the first one found.
if { [regexp .*jtag_uart.* $module_class_name] } {
if {$first_jtag_uart == "none"} {
set first_jtag_uart $slave_desc
}}
63
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
Every BSP is based on a Nios V processor in a hardware system. The BSP settings file
does not duplicate information available in the .qsys file, but it does contain system-
dependent settings that reference system information. Because of these system-
dependent settings, a BSP settings file can become inconsistent with its system if the
system changes.
You can revise a BSP at several levels. This section describes each level and guides
when to use it.
Related Information
• The Nios V Processor Embedded Project Structure on page 79
• Nios V Processor Software Development and Implementation on page 15
You can regenerate your BSP by using the niosv-bsp --generate command.
64
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
Note: To revert to the distributed BSP code, you must ensure that you have not disabled
generation on any BSP files
You can update your BSP by using the niosv-bsp --update command with the --
script option to define the BSP with a Tcl script. The Tcl script overrides the default
BSP settings.
65
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
You can recreate your BSP by using the niosv-bsp --create command with the --
script option to define the BSP with a Tcl script. The Tcl script overrides the default
BSP settings.
If you modify the underlying hardware design, the best practice is to create a new
BSP. Intel recommends modifying your BSP with the BSP Editor. Manually modifying a
large number of interrelated settings can be difficult.
66
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
bsp-linker-utils.tcl Helper Specifies memory regions and section mappings for linker script.
The BSP Editor uses the default Tcl scripts to specify default values for system-
dependent settings. System-dependent settings are BSP settings that reference
system information in the .qsys file.
The BSP Editor executes the default Tcl script before any user-specified Tcl scripts. As
a result, user input overrides settings made by the default Tcl script. You can pass
command line option (--script) to the default Tcl script to override the choices it
makes.
The default Tcl script consists of a top-level Tcl script named bsp-set-
defaults.tcl plus the helper Tcl scripts listed in the Default Tcl Script Components
table. The helper Tcl scripts do the real work of examining the processor subsystem
and choosing appropriate defaults.
67
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The script searches the processor subsystem file for a slave descriptor with the string
stdio in its name.
• If bsp-stdio-utils.tcl finds any such slave descriptors, the script chooses
the first as the default stdio device.
• If the script finds no such slave descriptor, the script looks for a slave descriptor
with the string jtag_uart in the component class name.
• If the script finds any such slave descriptors, the script chooses the first as the
default stdio device.
• If the script finds no slave descriptors fitting either description, the script chooses
the last character device slave descriptor connected to the Nios V processor.
• If bsp-stdio-utils.tcl does not find any character devices, there is no stdio
device.
68
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The script examines the .text section mapping and the Nios V processor reset agent
port. If the .text section is mapped to the same memory as the Nios V processor
reset agent port and the reset agent port is a flash memory device, the script assumes
that the alt_load() function is being used.
The alt_load() function is an early part of the software initialization and handles
the copying of sections on reset except the .text section. If it is necessary to copy
the .text section to other memory region, the BSP needs to provide a custom
bootloader code.
allow_code_at_reset 0 1
enable_alt_load 0 1
enable_alt_load_copy_rwdata 0 1
The script searches the processor subsystem to verify if the Nios V processor enabled
the following features:
• Memory Protection Unit (MPU)
• Memory Management Unit (MMU)
• Advanced exceptions settings:
— Illegal instruction exception
— Illegal memory access exception
— Slave access error exception
— Division error exception
— Imprecise illegal memory access exception
— Extra exception info
If any of the following features is enabled, the script enables the API for registering
handlers to service the instruction-related exceptions.
69
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The IsFlash property of the memory module (defined in the .qsys file) indicates
whether the .qsys file identifies the memory as a flash memory device.
The IsNonVolatileStorage property indicates whether the .qsys file identifies the
memory as a non-volatile storage device. The contents of a non-volatile memory
device are fixed and always present.
Note: You can initialize some FPGA memories when you configure the FPGA. They are not
considered non-volatile because the default Tcl script has no way to determine
whether they are actually initialized in a particular system.
Table 21. Memory Types Recognized when Making Decisions about Your Boot
Configuration
Memory Type Examples IsFlash IsNonVolatileStorage
The following sections describe each supported build configuration in detail. The
alt_load() facility is HAL code that optionally copies sections from the boot memory
to RAM. You can set an option to enable the boot copy. This option only adds the code
to your BSP if it needs to copy boot segments. The hal.enable_alt_load setting
enables alt_load() and there are settings for each of the three sections it can copy
(such as hal.enable_alt_load_copy_rodata). Enabling alt_load() also
modifies the memory layout specified in your linker script.
70
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The default Tcl script chooses this configuration when the memory associated with the
processor reset address is a flash memory and the .text section is mapped to a
different memory (for example, SDRAM).
Intel provides example bootloaders for QSPI flash memory in the <Intel Quartus
Prime software installation directory>/niosv/components/
bootloader folder, precompiled to Motorola S-record Files (.srec). You can use the
Intel-provided bootloader or provide your own.
alt_load() must copy the .rwdata section (either to another RAM or to a reserved
area in the same RAM as the .text RAM) if .rwdata needs to be correct after
multiple resets.
The default Tcl script chooses this configuration when the reset and .text memory
are the same.
In this boot configuration, when the processor core resets, by default the .rwdata
section is not reinitialized. Reinitialization would normally be done by a bootloader.
However, this configuration has no bootloader because the software is running out of
memory that is assumed to be preinitialized before start-up. If your software has
a .rwdata section that must be reinitialized at processor reset, turn on the
hal.linker.enable_alt_load_copy_rwdata setting in the BSP.
71
4. Nios V Processor Board Support Package Editor
743810 | 2022.10.31
The processor reset address points to an additional memory. Thus, the algorithms
used by the default Tcl script to select the appropriate boot configuration might make
the wrong choice. You need to explicitly control the individual BSP settings specified by
the default Tcl script.
72
743810 | 2022.10.31
Send Feedback
The HAL serves as a device driver package for Nios V processor systems, providing a
consistent interface to the peripherals in your system. The Nios V processor software
development tools extract system information from the Platform Designer System File
(.qsys). The Board Support Package (BSP) Editor generates a custom HAL BSP
specific to your hardware configuration. Changes in the hardware configuration
automatically propagate to the HAL device driver configuration, eliminating bugs that
emerge as a result of driver or IP configuration mismatch.
HAL device driver abstraction provides a clear distinction between application and
device driver software. This driver abstraction promotes reusable application code that
is resistant to changes in the underlying hardware. In addition, the HAL standard
makes it straightforward to write drivers for new hardware peripherals that are
consistent with existing peripheral drivers.
Related Information
• Driver Integration in the HAL API on page 116
• Developing with the Hardware Abstraction Layer on page 37
• HAL Peripheral Services on page 40
For information about configuring and using HAL services.
• Reducing Code Footprint in Embedded Systems on page 100
For information about increasing your application's performance, or minimizing
the code footprint.
• Creating Embedded Drivers for HAL Device Classes on page 120
In the Nios V processor software tools command line, you can create an example BSP
based on the HAL using the niosv-bsp utility.
You must base the HAL on a specific Platform Designer system. A Nios V processor
system consists of a Nios V processor core integrated with peripherals and memory.
Platform Designer generates Nios V processor systems.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
5. Overview of the Hardware Abstraction Layer
743810 | 2022.10.31
You can use an Intel provided example project for Nios V processor to develop your
Nios V processor system. You can re-target it to a different board later, or develop
your own custom Nios V processor.
Related Information
• Getting Started from the Command Line on page 11
For more information about creating a new project with the command line.
• Nios V Processor Design Example Scripts on page 331
For more information about how to base your project on an Intel-provided
example hardware system.
5.2.1. Services
The HAL provides the following 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—Instantiates and initializes each device in the system before
main() runs
User Program
newLib Library
HAL API
74
5. Overview of the Hardware Abstraction Layer
743810 | 2022.10.31
Related Information
• Developing Programs Using the Hardware Abstraction Layer on page 78
• Developing Device Drivers for the Hardware Abstraction Layer on page 116
For more information about the Hardware Abstraction Layer.
The HAL defines a set of functions that you use to initialize and access each class of
device. The API is consistent, regardless of the underlying implementation of the
device hardware.
For example, to access character-mode devices and file subsystems, you can use the
C standard library functions, such as printf() and fopen(). For application
developers, you need not write low-level routines just to establish basic
communication with the hardware for these classes of peripherals.
75
5. Overview of the Hardware Abstraction Layer
743810 | 2022.10.31
Each device model defines a set of driver functions necessary to manipulate the
particular class of device. If you are writing drivers for a new peripheral, you need
only provide this set of driver functions. As a result, your driver development task is
predefined and well documented.
In addition, you can use existing HAL functions and applications to access the device,
which saves software development effort. The HAL calls driver functions to access
hardware. Application programmers call the ANSI C or HAL API to access hardware,
rather than calling your driver routines directly.
Therefore, the usage of your driver is already documented as part of the HAL API.
Related Information
Redhat Website
Online documentation for newlib by Red Hat
76
5. Overview of the Hardware Abstraction Layer
743810 | 2022.10.31
Note: This list does not include peripherals supported by third-party vendors that is
compatible with Nios V processor.
As all peripherals vendors provide a header file that defines the peripheral's low level
hardware interface. You can use the definitions provided in the header to access the
hardware inside HAL.
Inevitably, some peripherals have features that does not map well to our general-
purpose HAL API. For these device, HAL API provides the UNIX-style ioctl() function
to access them.
For example, Intel provides a general-purpose parallel I/O core that can be use with
Nios V processor. However, this device does not fit into any generic device model class
provided by HAL. As such, it provides a header file and a few dedicated accessors
functions. ioctl() can be used to integrate its functionality into Nios V processor via
HAL.
For complete details regarding software support for a peripheral, refer to the
peripheral’s documentation.
Related Information
Embedded Peripherals IP User Guide
77
743810 | 2022.10.31
Send Feedback
Related Information
Applications versus Drivers on page 75
The BSP produces the system.h file, which contains the BSP settings for your project
and other HAL configuration settings you need to develop your software.
Note: Do not edit system.h. Use the Nios V processor tools to manipulate the system
settings.
For details about how to control BSP settings, refer the following documents in Related
Information.
Related Information
• Nios V Processor Board Support Package Editor on page 48
• Settings Managed by Nios V Processor Board Support Package Editor on page 258
• System Clock Driver on page 88
• Placement of the Heap and Stack on page 112
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Every HAL-based Nios V processor program consists of two parts of the project. Your
application-specific code is contained in one project (the user application project), and
it depends on a separate BSP project (the HAL BSP).
Related Information
• Revising Your BSP on page 63
For more information about how the Nios® V processor tools keep your BSP
up-to-date with your hardware system.
• Nios V Processor Software Development and Implementation on page 15
The system.h file describes each peripheral in the system and provides the following
details:
• The hardware configuration of the peripheral
• The base address
• Interrupt request (IRQ) information (if any)
• A symbolic name for the peripheral
79
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
The Nios V processor tools generates the system.h file for HAL BSP projects. The
contents of system.h depend on both the hardware configuration and the HAL BSP
properties.
Note: Do not edit system.h. Use Nios V processor tools facilities to manipulate system
settings.
80
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
char 8 bits.
short 16 bits.
long 32 bits.
int 32 bits.
The most commonly used functions are those that relate to file I/O.
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
81
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Note: This program sends characters to whatever device is associated with stdout when
the program is compiled.
When using the UNIX-style API, you can use the file descriptors stdin, stdout, and
stderr, defined in unistd.h, to access, respectively, the standard in, standard out,
and standard error character I/O streams. unistd.h is provided as part of the newlib C
library package.
82
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
6.6.4. /dev/null
All systems include the device /dev/null. Writing to /dev/null has no effect, and all
data is discarded. /dev/null is used for safe I/O redirection during system startup
and useful for applications that wish to sink unwanted data. The device is purely a
software construct. It does not relate to any physical hardware device in the system.
Related Information
Reducing Code Footprint in Embedded Systems on page 100
When Intel FPGA logging is enabled, your software can print extra messages to a
specified port with HAL function calls. The logging port, specified in the BSP, can be a
UART or a JTAG UART device. In its default configuration, Intel FPGA logging prints out
boot messages, which trace each step of the boot process.
Note: Avoid setting the Intel FPGA logging device to the device used for stdout or stderr.
If Intel FPGA logging output is sent to stdout or stderr, the logging output might
appear interleaved with the stdout or stderr output
Several logging options are available, controlled by C preprocessor symbols. You can
also choose to add custom logging messages.
Intel FPGA logging changes system behavior. The logging implementation is designed
to be as simple as possible, loading characters directly to the transmit register. It can
have a negative impact on software performance.
Intel FPGA logging functions are conditionally compiled. When logging is disabled, it
has no impact on code footprint or performance.
Note: The Intel FPGA reduced device drivers do not support Intel FPGA logging.
Logging is enabled by setting hal.log_port to a JTAG UART or a UART device. You can
find the hal.log_port in the BSP Editor. The setting allows the HAL to send log
messages to the specified device.
83
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
The build tools also set the ALT_LOG_PORT_TYPE and ALT_LOG_PORT_BASE values
in system.h to point to the specified device.
When logging is enabled without special options, the HAL prints out boot messages to
the selected port. For typical software that uses the standard alt_main.c (such as
the Hello World software example), the messages appear as in the following example.
Note: A write operation to the logging device stalls in ALT_LOG_PRINTF() until the
characters are read from the logging device’s output buffer. To ensure that the Nios V
processor application completes initialization, run the juart-terminal command from
the Nios V Command Shell to accept the logging output.
System clock log Purpose Prints out a message from the system clock interrupt handler at a specified interval.
This indicates that the system is still running. The default interval is every 1 second.
Preprocessor ALT_LOG_SYS_CLK_ON_FLAG_SETTING
symbol
Modifiers The system clock log has two modifiers, providing two different ways to specify the
logging interval.
• ALT_LOG_SYS_CLK_INTERVAL—Specifies the logging interval in system clock ticks.
The default is <clock ticks per second>, that is, one second.
• ALT_LOG_SYS_CLK_INTERVAL_MULTIPLIER—Specifies the logging interval in
seconds. The default is 1. When you modify
ALT_LOG_SYS_CLK_INTERVAL_MULTIPLIER, ALT_LOG_SYS_CLK_INTERVAL is
recalculated.
84
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Name Description
Write echo Purpose Every time alt_write() is called (normally, whenever characters are sent to
stdout), the first <n> characters are echoed to a logging message. The message
starts with the string "Write Echo:". <n> is specified with
ALT_LOG_WRITE_ECHO_LEN. The default is 15 characters.
Preprocessor ALT_LOG_WRITE_ON_FLAG_SETTING
symbol
JTAG startup log Purpose At JTAG UART driver initialization, print out a line with the number of characters in the
software transmit buffer followed by the JTAG UART control register contents. The
number of characters, prefaced by the string "SW CirBuf", might be negative,
because it is computed as (<tail_pointer> – <head_pointer>) on a circular buffer.
For more information about the JTAG UART control register fields, refer to the
Embedded Peripherals IP User Guide.
Preprocessor ALT_LOG_JTAG_UART_STARTUP_INFO_ON_FLAG_SETTING
symbol
Modifiers None
Sample Output JTAG Startup Info: SW CirBuf = 0, HW FIFO wspace=64 AC=0 WI=0 RI=0
WE=0 RE=1
JTAG interval log Purpose Creates an alarm object to print out the same JTAG UART information as the JTAG
startup log, but at a repeated interval. Default interval is 0.1 second, or 10 messages a
second.
Preprocessor ALT_LOG_JTAG_UART_ALARM_ON_FLAG_SETTING
symbol
Modifiers The JTAG interval log has two modifiers, providing two different ways to specify the
logging interval.
• ALT_LOG_JTAG_UART_TICKS—Logging interval in ticks. Default is
<ticks_per_second> / 10.
• ALT_LOG_JTAG_UART_TICKS_DIVISOR—Specifies the number of logs per second.
The default is 10. When you modify ALT_LOG_JTAG_UART_TICKS_DIVISOR,
ALT_LOG_JTAG_UART_TICKS is recalculated.
Sample Output JTAG Alarm: SW CirBuf = 0, HW FIFO wspace=45 AC=0 WI=0 RI=0 WE=0
RE=1
JTAG interrupt Purpose Prints out a message every time the JTAG UART near-empty interrupt triggers. Message
service routine contains the same JTAG UART information as in the JTAG startup log.
(ISR) log
Preprocessor ALT_LOG_JTAG_UART_ISR_ON_FLAG_SETTING
symbol
Modifiers None
Sample Output JTAG IRQ: SW CirBuf = -20, HW FIFO wspace=64 AC=0 WI=1 RI=0 WE=1
RE=1
Boot log Purpose Prints out messages tracing the software boot process. The boot log is turned on by
default when Intel FPGA logging is enabled.
Preprocessor ALT_LOG_BOOT_ON_FLAG_SETTING
symbol
Modifiers None
Note: An option’s modifiers are meaningful only when the option is enabled.
85
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Setting a preprocessor flag to 1 enables the corresponding option. Any value other
than 1 disables the option.
Several options have modifiers, which are additional preprocessor symbols controlling
details of how the options work. For example, the system clock log’s modifiers control
the logging interval.
Related Information
Embedded Peripherals IP User Guide
Note: You can use logging level -1 to turn off logging without changing the program
footprint. The logging code is still present in your executable image, as determined by
other logging options chosen. This is useful when you wish to switch the log output on
or off without disturbing the memory map.
This niosv-bsp command modify toolchain.cmake to use uart1 for log output,
and to add -DALT_LOG_FLAGS=2 when calling gcc to compile the program.
86
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
#include "sys/alt_log_printf.h"
If you want your custom logging message to be controlled by Intel FPGA logging
preprocessor options, use the appropriate Intel FPGA logging option preprocessor flags
from the ALT_LOG_FLAGS Logging Levels table or the Intel FPGA Logging Options and
Option Modifiers table.
soft_processor/altera_hal2/HAL/inc/sys/ alt_log_printf.h
soft_processor/altera_hal2/HAL/src/ alt_log_printf.c
soft_processor/intel_niosv_m/HAL/src/ alt_log_macro.S
Note: All file locations are relative to <Intel Quartus Prime installation
directory>/ip/altera folder.
These files implement the logging options listed in the Intel FPGA Logging Options and
Option Modifiers table. They also serve as examples of logging usage.
87
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
sopc_builder_ip/altera_avalon_jtag_uart/HAL/src/ altera_avalon_jtag_uart.c
sopc_builder_ip/altera_avalon_timer/HAL/src/ altera_avalon_timer_sc.c
soft_processor/altera_hal2/HAL/src/ alt_exit.c
soft_processor/altera_hal2/HAL/src/ alt_main.c
soft_processor/altera_hal2/HAL/src/ alt_write.c
soft_processor/intel_niosv_m/HAL/src/ crt0.S
Note: All file locations are relative to <Intel Quartus Prime installation
directory>/ip/altera folder.
A timer peripheral can behave as either a system clock or a timestamp, but not both.
For more information about where the HAL-specific API functions for accessing timer
devices are defined, refer to the sys/alt_alarm.h and sys/alt_timestamp.h
files.
For more information about how to control BSP settings, refer to the HAL BSP Settings
chapter.
The system clock measures time in clock ticks. If you are working with both hardware
and software, do not confuse the HAL system clock with the clock signal driving the
Nios V processor hardware. The period of a HAL system clock tick is much longer than
the hardware system clock. system.h defines the clock tick frequency.
88
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
At runtime, you can obtain the current value of the system clock by calling the
alt_nticks() function. This function returns the elapsed time in system clock ticks
since reset. You can get the system clock rate, in ticks per second, by calling the
function alt_ticks_per_second(). The HAL timer driver initializes the tick
frequency when it creates the instance of the system clock.
The standard UNIX function gettimeofday() is available to obtain the current time.
You must first calibrate the time of day by calling settimeofday(). In addition, you
can use the times() function to obtain information about the number of elapsed
ticks. The prototypes for these functions appear in times.h.
Related Information
• HAL API Reference on page 186
For more information about the UNIX-style functions.
• HAL BSP Settings on page 78
6.7.2. Alarms
You can register functions to be executed at a specified time using the HAL alarm
facility. A software program registers an alarm by calling the function
alt_alarm_start():
The function callback() is called after nticks have elapsed. The input argument
context is passed as the input argument to callback() when the call occurs. The
HAL does not use the context parameter. It is only used as a parameter to the
callback() function.
Your code must allocate the alt_alarm structure, pointed to by the input argument
alarm. This data structure must have a lifetime that is at least as long as that of the
alarm. The best way to allocate this structure is to declare it as a static or global.
alt_alarm_start() initializes *alarm.
The callback function can reset the alarm. The return value of the registered callback
function is the number of ticks until the next call to callback. A return value of zero
indicates that the alarm should be stopped. You can manually cancel an alarm by
calling alt_alarm_stop().
One alarm is created for each call to alt_alarm_start(). Multiple alarms can run
simultaneously.
89
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
*/
alt_u32 my_alarm_callback (void* context)
{
/* This function is called once per second */
return alt_ticks_per_second();
}
...
/* The alt_alarm must persist for the duration of the alarm. */
static alt_alarm alarm;
...
if (alt_alarm_start (&alarm,
alt_ticks_per_second(),
my_alarm_callback,
NULL) < 0)
{
printf ("No system clock available\n");
}
Related Information
Exception Handling on page 142
For more information about these functions.
You can obtain the rate at which the timestamp counter increments by calling the
function alt_timestamp_freq(). This rate is typically the hardware frequency of
the Nios V processor system—usually millions of cycles per second. The timestamp
drivers are defined in the alt_timestamp.h header file.
#include "sys/alt_timestamp.h"
#include "alt_types.h"
int main(void) {
alt_u32 time1;
alt_u32 time2;
alt_u32 time3;
90
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
if (alt_timestamp_start() < 0) {
printf("No timestamp device available\n");
} else {
time1 = alt_timestamp();
func1(); /* first function to monitor */
time2 = alt_timestamp();
func2(); /* second function to monitor */
time3 = alt_timestamp();
printf("time in func1 = %u ticks\n",
(unsigned int)(time2 - time1));
printf("time in func2 = %u ticks\n",
(unsigned int)(time3 - time2));
printf("Number of ticks per second = %u\n",
(unsigned int) alt_timestamp_freq());
}
return 0;
}
Related Information
HAL API Reference on page 186
The HAL API also provides functions to read flash, although it is generally not
necessary. For most flash devices, programs can treat the flash memory space as
simple memory when reading, and do not need to call special HAL API functions. If the
flash device has a special protocol for reading data, you must use the HAL API to both
read and write data.
This section describes the HAL API for the flash device model. The following two APIs
provide two different levels of access to the flash:
• Simple flash access—Functions that write buffers to flash and read them back at
the block level. In writing, if the buffer is less than a full block, these functions
erase preexisting flash data above and below the newly written data.
• Fine-grained flash access—Functions that write buffers to flash and read them
back at the buffer level. In writing, if the buffer is less than a full block, these
functions preserve preexisting flash data above and below the newly written data.
This functionality is generally required for managing a file subsystem.
The API functions for accessing flash devices are defined in sys/alt_flash.h.
The supportable flash IP for Nios V processor is the Generic Serial Flash Interface Intel
FPGA IP.
Related Information
• Embedded Peripherals IP User Guide
• HAL API Reference on page 186
For more information about the UNIX-style functions.
• JEDEC Website
• Generic Serial Flash Interface Intel® FPGA IP User Guide
91
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
After you obtain a handle, you can use the alt_write_flash() function to write
data to the flash device. The prototype is:
A call to this function writes to the flash device identified by the handle fd. The driver
writes the data starting at offset bytes from the base of the flash device. The data
written comes from the address pointed to by src_addr, and the amount of data
written is length.
There is also an alt_read_flash() function to read data from the flash device. The
prototype is:
int alt_read_flash(
alt_flash_fd* fd,
int offset,
void* dest_addr,
int length
)
A call to alt_read_flash() reads from the flash device with the handle fd, offset
bytes from the beginning of the flash device. The function writes the data to location
pointed to by dest_addr, and the amount of data read is length. For most flash
devices, you can access the contents as standard memory, making it unnecessary to
use alt_read_flash().
The function alt_flash_close_dev() takes a file handle and closes the device. The
prototype for this function is:
void alt_flash_close_dev(alt_flash_fd* fd )
Related Information
Fine-Grained Flash Access on page 93
For more information about the use of all of the functions in one code example.
92
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
unexpected data corruption (erasure), if you are performing writes that do not fall on
block boundaries. If you wish to preserve existing flash memory contents, use the
fine-grained flash functions. These are discussed in the following section.
The Example of Writing Flash and Causing Unexpected Data Corruption table shows
the example of an 8-kilobyte (KB) flash memory comprising two 4-KB blocks.
1. First write 5 KB of all 0xAA to flash memory at address 0x0000, and then write 2
KB of all 0xBB to address 0x1400.
2. After the first write succeeds (at time t(2)), the flash memory contains 5 KB of
0xAA, and the rest is empty (that is, 0xFF).
3. Then the second write begins, but before writing to the second block, the block is
erased. At this point, t(3), the flash contains 4 KB of 0xAA and 4 KB of 0xFF.
4. After the second write finishes, at time t(4), the 2 KB of 0xFF at address 0x1000
is corrupted.
• alt_get_flash_info()
• alt_erase_flash_block()
• alt_write_flash_block()
By the nature of flash memory, you cannot erase a single address in a block. You must
erase (that is, set to all ones) an entire block at a time. Writing to flash memory can
only change bits from 1 to 0; to change any bit from 0 to 1, you must erase the entire
block along with it.
Therefore, to alter a specific location in a block while leaving the surrounding contents
unchanged, you must read out the entire contents of the block to a buffer, alter the
value(s) in the buffer, erase the flash block, and finally write the whole block-sized
buffer back to flash memory. The fine-grained flash access functions automate this
process at the flash block level.
#include <stdio.h>
#include <string.h>
#include "sys/alt_flash.h"
#define BUF_SIZE 1024
int main ()
{
alt_flash_fd* fd;
int ret_code;
char source[BUF_SIZE];
char dest[BUF_SIZE];
/* Initialize the source buffer to all 0xAA */
memset(source, 0xAA, BUF_SIZE);
fd = alt_flash_open_dev("/dev/ext_flash");
if (fd!=NULL)
{
ret_code = alt_write_flash(fd, 0, source, BUF_SIZE);
if (ret_code==0)
{
ret_code = alt_read_flash(fd, 0, dest, BUF_SIZE);
if (ret_code==0)
93
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
{
/*
* Success.
* At this point, the flash is all 0xAA and we
* have read that all back to dest
*/
}
}
alt_flash_close_dev(fd);
}
else
{
printf("Cannot open flash device\n");
}
return 0;
}
Related Information
Simple Flash Access on page 92
6.8.3.1. alt_get_flash_info()
alt_get_flash_info() gets the number of erase regions, the number of erase
blocks in each region, and the size of each erase block. The function prototype is as
follows:
int alt_get_flash_info (
alt_flash_fd* fd,
flash_region** info,
int* number_of_regions )
Table 28. Example of Writing Flash and Causing Unexpected Data Corruption
Address Block Time t(0) Time t(1) Time t(2) Time t(3) Time t(4)
0x0000 1 Unknown FF AA AA AA
0x0400 1 Unknown FF AA AA AA
0x0800 1 Unknown FF AA AA AA
0x0C00 1 Unknown FF AA AA AA
0x1400 2 Unknown FF FF FF BB
0x1800 2 Unknown FF FF FF BB
0x1C00 2 Unknown FF FF FF FF
94
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
6.8.3.2. alt_erase_flash()
alt_erase_flash() erases a single block in the flash memory. The function
prototype is as follows:
The flash memory is identified by the handle fd. The block is identified as being
offset bytes from the beginning of the flash memory, and the block size is passed in
length.
6.8.3.3. alt_write_flash_block()
alt_write_flash_block() writes to a single block in the flash memory. The
prototype is:
int alt_write_flash_block(
alt_flash_fd* fd,
int block_offset,
int data_offset,
const void *data,
int length
)
This function writes to the flash memory identified by the handle fd. It writes to the
block located block_offset bytes from the start of the flash device. The function
writes length bytes of data from the location pointed to by data to the location
data_offset bytes from the start of the flash device.
Note: These program and erase functions do not perform address checking, and do not
verify whether a write operation spans into the next block. You must pass in valid
information about the blocks to program or erase.
95
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
int ret_code;
char write_data[BUF_SIZE];
/* Set write_data to all 0xa */
memset(write_data, 0xA, BUF_SIZE);
fd = alt_flash_open_dev(EXT_FLASH_NAME);
if (fd)
{
ret_code = alt_get_flash_info(fd, ®ions, &number_of_regions);
if (number_of_regions && (regions->offset == 0))
{
/* Erase the first block */
ret_code = alt_erase_flash_block(fd,
regions->offset,
regions->block_size);
if (ret_code == 0) {
/*
* Write BUF_SIZE bytes from write_data 100 bytes to
* the first block of the flash
*/
ret_code = alt_write_flash_block (
fd,
regions->offset,
regions->offset+0x100,
write_data,
BUF_SIZE );
}
}
}
return 0;
}
In the HAL DMA device model, there are two categories of DMA transactions: transmit
and receive. The HAL provides two device drivers to implement transmit channels and
receive channels. A transmit channel takes data in a source buffer and transmits it to
a destination device. A receive channel receives data from a device and deposits it in a
destination buffer. Depending on the implementation of the underlying hardware,
software might have access to only one of these two endpoints.
Copying data from memory to memory involves both receive and transmit DMA
channels simultaneously.
96
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
DMA
2. Transmitting Data Memory Transmit Peripheral
to a Peripheral Channel
Example 16. Obtaining a File Handle for a DMA Transmit Device dma_0
#include <stddef.h>
#include "sys/alt_dma.h"
int main(void) {
alt_dma_txchan tx;
tx = alt_dma_txchan_open("/dev/dma_0");
if (tx == NULL) {
/* Error */
} else {
/* Success */
}
return 0;
}
You can use this handle to post a transmit request using alt_dma_txchan_send().
The prototype is:
97
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Two additional functions are provided for manipulating DMA transmit channels:
alt_dma_txchan_space(), and alt_dma_txchan_ioctl(). The
alt_dma_txchan_space() function returns the number of additional transmit
requests that can be queued to the device. The alt_dma_txchan_ioctl()function
performs device-specific manipulation of the transmit device.
Note: If you are using the Avalon Memory-Mapped® (Avalon-MM®) DMA device to transmit
to hardware (not memory-to-memory transfer), call the
alt_dma_txchan_ioctl()function with the request argument set to
ALT_DMA_TX_ONLY_ON.
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
A call to this function posts a receive request to channel dma, for up to length bytes
of data to be placed at address data. This function returns before the DMA
transaction completes. The return value indicates whether the request is successfully
queued. A negative return value indicates that the request failed. When the
transaction completes, the user-supplied function done() is called with argument
handle to provide notification and a pointer to the receive data.
Certain errors can prevent the DMA transfer from completing. Typically this is caused
by a catastrophic hardware failure; for example, if a component involved in the
transfer fails to respond to a read or write request. If the DMA transfer does not
complete (that is, less than length bytes are transferred), function done() is never
called.
Two additional functions are provided for manipulating DMA receive channels:
alt_dma_rxchan_depth() and alt_dma_rxchan_ioctl().
98
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Note: If you are using the Avalon-MM DMA device to receive from hardware (not memory-
to-memory transfer), call the alt_dma_rxchan_ioctl() function with the request
argument set to ALT_DMA_RX_ONLY_ON.
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "alt_types.h"
/* flag used to indicate the transaction is complete */
volatile int dma_complete = 0;
/* function that is called when the transaction completes */
void dma_done (void* handle, void* data)
{
dma_complete = 1;
}
int main (void)
{
alt_u8 buffer[1024];
alt_dma_rxchan rx;
/* Obtain a handle for the device */
if ((rx = alt_dma_rxchan_open ("/dev/dma_0")) == NULL)
{
printf ("Error: failed to open device\n");
exit (1);
}
else
{
/* Post the receive request */
if (alt_dma_rxchan_prepare (rx, buffer, 1024, dma_done, NULL) <
0)
{
printf ("Error: failed to post receive request\n");
exit (1);
}
/* Wait for the transaction to complete */
while (!dma_complete);
printf ("Transaction complete\n");
alt_dma_rxchan_close (rx);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include "sys/alt_dma.h"
#include "system.h"
99
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
The HAL environment is designed to include only those features that you request,
minimizing the total code footprint. If your Nios V hardware system contains exactly
the peripherals used by your program, the HAL contains only the drivers necessary to
control the hardware.
100
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
The following sections describe options to consider when you need to further reduce
code size. Implementing the options in the following sections entails making changes
to BSP settings.
For more information about manipulating BSP settings, refer to the HAL BSP Settings.
Related Information
Lightweight Character-Mode I/O on page 83
Related Information
GNU Options That Control Optimization
By default the HAL always uses the fast variant. You can select the reduced device
driver for all hardware components, or for an individual component, through HAL BSP
settings.
The small footprint option might also affect other peripherals. Refer to each
peripheral’s data sheet for complete details of its driver’s small footprint behavior.
101
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
newlib implements a maze of 22 printf() variants, all based on the same core
engine, and all with slightly different interfaces. Some are specified by the C standard,
some by Posix, some are GNU extensions, and some are newlib extensions. The
newlib libc web page documents the functions that conform to their respective
standards.
For more information about libc, refer to the The Red Hat newlib C Libray web
page.
The canonical printf() functions take a variable number of arguments including one
for each percent-specifier in the format string. This is convenient for you, but
inconvenient for wrapper functions taking a variable number of arguments and then
doing some sort of value-added before invoking the regular printf() library,
because C provides no convenient, portable way for a function to read a variable
number of arguments and then pass them to another function taking a variable
number of arguments. Consequently, for each plain printf() function, the C library
provides a v*printf variant which accepts the extra arguments in varargs vector
format.
102
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
• fprintf()
• printf()
• asprintf()
• asnprintf()
• snprintf()
• sprintf()
• fiprintf()
• iprintf()
• asiprintf()
• asniprintf()
• sniprintf()
• siprintf()
Note: Despite the mnemonic, these functions are not really integer-only: They also support
(for example) unsigned, char and string values.
Lumping all the above variants together, the full list of printf() functions supported
by newlib is:
• fprintf()
• vprintf()
• printf()
• asprintf()
• asnprintf()
• snprintf()
• sprintf()
• vasprintf()
• vasnprintf()
103
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
• vsprintf()
• vsnprintf()
• fiprintf()
• iprintf()
• viprintf()
• asiprintf()
• asniprintf()
• sniprintf()
• siprintf()
• vasiprintf()
• vasniprintf()
• vsiprintf()
• vsniprintf()
• dprintf, vdprintf: Print to a file descriptor (vs FILE*).
• dprintf, vdprintf: No-floating-point-formatting versions of above.
• fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Versions
with wide-char support.
For more information about these printf() variants, refer to the The Red Hat
newlib C Libray web page.
Related Information
Redhat Website
Online documentation for newlib by Red Hat
The Nios V processor tools provide ANSI C file I/O, in the newlib C library, because
there is a per-access performance overhead associated with accessing devices and
files using the UNIX-style file I/O functions. The ANSI C file I/O provides buffered
access, thereby reducing the total number of hardware I/O accesses performed. Also
the ANSI C API is more flexible and therefore easier to use. However, these benefits
are gained at the expense of code footprint.
104
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
These functions are appropriate if your program only needs to accept command
strings and send simple text messages.
To use the minimal character-mode API, include the header file sys/alt_stdio.h.
The following sections outline the effects of the functions on code footprint.
For more information about the minimal character-mode functions, refer to the HAL
API Reference chapter.
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
If the hardware includes a device that your program never uses, consider removing
the device from the hardware. This reduces both code footprint and FPGA resource
usage.
However, there are cases when a device must be present, but runtime software does
not require a driver. The most common example is flash memory. The user program
might boot from flash, but not use it at runtime; thus, it does not need a flash driver.
105
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
You can selectively omit any individual driver, select a specific driver version, or
substitute your own driver.
For more information about controlling driver configurations, refer to the Nios V
Processor Board Support Package Editor chapter.
Another way to control the device driver initialization process is to use the free-
standing environment.
For more information, refer to the Boot Sequence and Entry Point chapter.
Note: If you enable this option, ensure that your main() function (or alt_main() function)
does not return.
106
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
The ANSI C standard also provides for an alternate entry point that avoids automatic
initialization, and assumes that the Nios V programmer initializes any needed
hardware explicitly. The alt_main() function provides a free-standing environment,
giving you complete control over the initialization of the system. The free-standing
environment places on the programmer the responsibility to initialize any system
features used in the program. For example, calls to printf() do not function
correctly in the free-standing environment, unless alt_main() first instantiates a
character-mode device driver, and redirects stdout to the device.
Note: Using the free-standing environment increases the complexity of writing Nios V
programs, because you assume responsibility for initializing the system.
For more information about reducing code footprint, refer to and use the suggestions
described in the Reducing Code Footprint in Embedded Systems chapter.
Note: It is easier to reduce the HAL BSP footprint by using BSP settings, than to use the
free-standing mode.
Related Information
Global Pointer Register on page 112
107
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
• Enables interrupts.
• Calls the alt_sys_init() function, also located in alt_sys_init.c.
alt_sys_init() initializes all device drivers and software packages in the
system.
• Redirects the C standard I/O channels (stdin, stdout, and stderr) to use the
appropriate devices.
• Calls the C++ global constructors, using the _do_ctors() function.
• Registers the C++ global destructors to be called at system shutdown.
• Calls main().
• Calls exit(), passing the return code of main() as the input argument for
exit().
alt_main.c provides this default implementation. The Nios V processor tools copies
alt_main.c to your BSP directory.
Function alt_main() calls function main(). After main() returns, the default
alt_main() enters an infinite loop. Alternatively, your custom alt_main() might
terminate by calling exit(). Do not use a return statement.
The HAL build environment includes mechanisms to override default HAL BSP code.
This lets you override boot loaders, as well as default device drivers and other system
code, with your own implementation.
alt_sys_init.c is a generated file, which you must not modify. However, the Nios V
processor tools enables you to control the generated contents of alt_sys_init.c.
To specify the initialization sequence in alt_sys_init.c, you manipulate the
auto_initialize and alt_sys_init_priority properties of each driver, using
the set_sw_property Tcl command.
Related Information
• Nios V Processor Board Support Package Editor on page 48
For more information about generated files and how to control the contents of
alt_sys_init.c and set_sw_property.
• Developing Device Drivers for the Hardware Abstraction Layer on page 116
For more information about alt_sys_init.c.
108
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
The memory devices that contain the Nios V processor’s reset and exception
addresses are a special case. The Nios V processor tools construct the 32-byte .entry
section starting at the reset address. This section is reserved exclusively for the use of
the reset handler. Similarly, the tools construct a .exceptions section, starting at the
exception address.
In a memory device containing the reset or exception address, the linker creates a
normal (nonreserved) memory section above the .entry or .exceptions section. If
there is a region of memory below the .entry or .exceptions section, it is
unavailable to the Nios V processor software.
109
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Figure 11. HAL Link Map - Unavailable Memory Region Below the .exceptions Section
(unused)
sdram
.exceptions
.text
.rodata
.rwdata
.bss
.sdram
ext_ram .ext_ram
.gsfi_controller_avl_mem .gsfi_controller_avl_mem
110
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
You can control the placement of .text, .rodata, .rwdata, and all other memory
partitions by manipulating BSP settings.
You can launch the BSP Editor in Platform Designer, or at the command line of the
Nios V processor tools. The BSP Editor allows you to perform the following tasks:
• Manipulates the linker’s memory map.
• Displays memory section and region assignments graphically.
• See overlapping or unused sections of memory.
Related Information
• Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
• Getting Started from the Command Line on page 11
Note: A variable foo is placed in the memory named ext_ram, and the function bar() is
placed in the memory named sdram.
In assembly you do this using the .section directive. For example, all code after the
following line is placed in the memory device named ext_ram:
.section .ext_ram.text
The section names ext_ram and sdram are examples. You need to use section names
corresponding to your hardware.
Note: A powerful way to manipulate the linker memory map is by using the BSP Editor. With
the BSP Editor, you can assign linker sections to specific physical regions, and then
review a graphical representation of memory showing unused or overlapping regions.
111
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
By default, the HAL performs no stack or heap checking. This makes function calls and
memory allocation faster, but it means that malloc() (in C) and new (in C++) are
unable to detect heap exhaustion. You can enable run-time stack checking by
manipulating BSP settings. With stack checking on, malloc() and new() can detect
heap exhaustion.
To specify the heap size limit, set the preprocessor symbol ALT_MAX_HEAP_BYTES to
the maximum heap size in decimal. For example, the preprocessor argument -
DALT_MAX_HEAP_BYTES=1048576 sets the heap size limit to 0x100000. You can
specify this command line option through a BSP setting.
Stack checking has performance costs. If you choose to leave stack checking turned
off, you must code your program so as to ensure that it operates within the limits of
available heap and stack memory.
Related Information
• Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
• HAL BSP Settings on page 78
• Nios V Processor Software Development and Implementation on page 15
The global pointer register can access a single contiguous region of 64 KB. To avoid
overflowing this region, the compiler only uses the global pointer with small global
data structures. A data structure is considered “small” if its size is less than or equal
to a specified threshold. By default, this threshold is 8 bytes.
The small data structures are allocated to the small global data
sections, .sdata, .sdata2, .sbss, and .sbss2. The small global data sections are
subsections of the .rwdata and .bss sections.
112
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
RAM
.sdata .rwdata
.sdata2
.sbss
.sbss2 .bss
If the total size of the small global data structures is more than 8 KB, these data
structures overflow the global pointer region. The linker produces an error message
saying "Unable to reach <variable name> ... from the global
pointer ... because the offset ... is out of the allowed range,
-4096 to 4095."
The best solution is to use fewer global variables of size 8 bytes or less. Another
solution is to place only the frequently used global variables inside the .sdata
+ .sbss.
When the size of the global variable is greater than 8 bytes, by default, it gets placed
outside of the .sdata + .sbss, and takes longer to access it. You can improve space-
time performance by placing only the frequently used global variables inside
the .sdata + .sbss leaving space available to add global variables greater than 8
bytes; and by annotating the code to place these global variables inside the .sdata
+ .sbss.
113
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
For information about manipulating project settings, refer to HAL BSP Settings.
Related Information
System Initialization Code Boot Sequence on page 107
The HAL provides a small boot loader program that copies these sections to their run
time locations at boot time. You can specify run time locations for program and data
memory by manipulating BSP settings.
If the runtime location of the .text section is outside of the boot memory, the Nios V
processor tools places a boot loader at the reset address. This bootloader is
responsible for loading all program and data sections before the call to _start. When
booting from a GSFI flash device, this loader function is provided by the hardware.
However, if the runtime location of the .text section is in the boot memory, the
system does not need a separate loader. Instead the _reset entry point in the HAL
executable program is called directly. The function _reset initializes the instruction
cache and then calls _start. This initialization sequence lets you develop applications
that boot and execute directly from flash memory.
When running in this mode, the HAL executable program must take responsibility for
loading any sections that require loading to RAM. The .rwdata, .rodata,
and .exceptions sections are loaded before the call to alt_main(), as required.
This loading is performed by the function alt_load(). To load these functions and
data into memory manually; and to load any additional sections, use the
alt_load_section() function.
For more information about alt_load_section(), refer to the HAL API Reference
chapter.
Related Information
• HAL API Reference on page 186
• Nios V Processor Configuration and Booting Solutions
For more details about Nios® V processor booting method.
114
6. Developing Programs Using the Hardware Abstraction Layer
743810 | 2022.10.31
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
For more information about what happens when you regenerate a BSP, refer to
Revising your BSP.
Note: Avoid modifying HAL source files. If you modify a HAL source file, you cannot
regenerate the BSP without losing your changes. This makes it difficult to keep the
BSP coordinated with changes to the underlying hardware system.
115
743810 | 2022.10.31
Send Feedback
The process of integrating a software package with the HAL is nearly identical with the
process for integrating a device driver.
Confine direct interaction with the hardware to device driver code. In general, the best
practice is to keep most of your program code free of low-level access to the
hardware. Wherever possible, use the high-level HAL application program interface
(API) functions to access hardware. This makes your code more consistent and more
portable to other Nios V systems that might have different hardware configurations.
When you create a new driver, you can integrate the driver with the HAL framework at
one of the following two levels:
• Integration in the HAL API
• Peripheral-specific API
Note: As an alternative to creating a driver, you can compile the device-specific code as a
user library, and link it with the application. This approach is workable if the device-
specific code is independent of the BSP, and does not require any of the extra services
offered by the BSP, such as the ability to add definitions to the system.h file.
Related Information
Applications versus Drivers on page 75
For integration in the HAL API, you write device access functions as specified in this
chapter, and the device becomes accessible to software through the standard HAL API.
For example, if you have a new LCD screen device that displays ASCII characters, you
write a character-mode device driver. With this driver in place, programs can call the
familiar printf() function to stream characters to the LCD screen.
Related Information
• Overview of the Hardware Abstraction Layer on page 73
• HAL Peripheral Services on page 40
For information about configuring and using HAL services.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
The up-front effort to implement integration in the HAL API is higher, but you gain the
benefit of the HAL and C standard library API to manipulate devices.
All other sections in this chapter apply to integrating drivers in the HAL API and
creating drivers with a peripheral-specific API.
Note: Although C++ is supported for programs based on the HAL, HAL drivers can not be
written in C++. Restrict your driver code to either C or assembly language. C is
preferred for portability.
Related Information
Integrating a Device Driver in the HAL on page 126
For details about integration in the HAL API.
Note: This chapter uses the variable <Intel Quartus Prime installation> to
represent the location where the Intel Quartus Prime software is installed. On a
Windows system, by default, that location is c:/<intelFPGA or
intelFPGA_pro>/<version number>.
For more information, refer to the Developing Programs Using the Hardware
Abstraction Layer section.
117
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
For more information about the system.h header file, refer to the Developing
Programs Using the Hardware Abstraction Layer section.
All components provide a directory that defines the device hardware and software. For
example, each component provided in the Intel Quartus Prime software has its own
directory in the <Intel Quartus Prime installation>/ip/altera/ directory.
Many components provide a header file that defines their hardware interface. The
header file is named <component name>_regs.h, included in the inc subdirectory
for the specific component. For example, the Intel-provided JTAG UART component
defines its hardware interface in the file <Intel Quartus
Primeinstallation>/ip/altera/sopc_builder_ip/
altera_avalon_jtag_uart/inc/altera_avalon_jtag_uart_regs.h.
118
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
The _regs.h header file defines the following access macros for the component:
• Register access macros that provide either or both a read or write macro for each
register in the component that supports the operation. The macros are:
— IORD_<component name>_<register name> (<component base
address>)
— IOWR_<component name>_<register name> (<component base
address>, <data>)
For example, altera_avalon_jtag_uart_regs.h defines the following
macros:
— IORD_ALTERA_AVALON_JTAG_UART_DATA()
— IOWR_ALTERA_AVALON_JTAG_UART_DATA()
— IORD_ALTERA_AVALON_JTAG_UART_CONTROL()
— IOWR_ALTERA_AVALON_JTAG_UART_CONTROL()
• Register address macros that return the physical address for each register in a
component. The address register returned is the component’s base address + the
specified register offset value. These macros are named IOADDR_<component
name>_<register name> (<component base address>).
For example, altera_avalon_jtag_uart_regs.h defines the following
macros:
— IOADDR_ALTERA_AVALON_JTAG_UART_DATA()
— IOADDR_ALTERA_AVALON_JTAG_UART_CONTROL()
Use these macros only as parameters to a function that requires the specific
address of a data source or destination. For example, a routine that reads a
stream of data from a particular source register in a component might require
the physical address of the register as a parameter.
• Bit-field masks and offsets that provide access to individual bit-fields in a register.
These macros have the following names:
— <component name>_<register name>_<name of field>_MSK—A bit-mask of
the field
— <component name>_<register name>_<name of field>_OFST—The bit offset
of the start of the field
For example, ALTERA_AVALON_UART_STATUS_PE_MSK and
ALTERA_AVALON_UART_STATUS_PE_OFST access the pe field of the status
register.
Access a device’s registers only with the macros defined in the _regs.h file. You must
use the register access functions to ensure that the processor bypasses the data
cache(if present) when reading and or writing the device. Do not use hard-coded
constants, because they make your software susceptible to changes in the underlying
hardware.
If you are writing the driver for a completely new hardware device, you must prepare
the _regs.h header file.
119
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
For more information about a complete example of the _regs.h file, refer to the
component directory for any of the Intel-supplied components, such as <Intel
Quartus Prime installation>/ip/sopc_builder_ip/
altera_avalon_jtag_uart/inc.
The following sections define the API for the following classes of devices:
• Character-mode devices
• File subsystems
• DMA devices
• Timer devices used as system clock
• Timer devices used as timestamp clock
• Flash memory devices
The following sections describe how to implement device drivers for each class of
device, and how to register them for use in HAL-based systems.
Related Information
Overview of the Hardware Abstraction Layer on page 73
120
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
None of these functions directly modifies the global error status, errno. Instead, the
return value is the negation of the appropriate error code provided in errno.h.
For example, the ioctl() function returns -ENOTTY if it cannot handle a request
rather than set errno to ENOTTY directly. The HAL system routines that call these
functions ensure that errno is set accordingly.
The function prototypes for these functions differ from their application level
counterparts in that they each take an input file descriptor argument of type alt_fd*
rather than int.
A new alt_fd structure is created on a call to open(). This structure instance is then
passed as an input argument to all function calls made for the associated file
descriptor.
typedef struct
{
alt_dev* dev;
void* priv;
int fd_flags;
} alt_fd;
where:
• dev is a pointer to the device structure for the device being used.
• fd_flags is the value of flags passed to open().
• priv is a reserved, implementation-dependent argument, defined by the driver. If
the driver requires any special, non-HAL-defined values to be maintained for each
file or stream, you can store them in a data structure, and use priv maintains a
pointer to the structure. The HAL ignores priv.
Allocate storage for the data structure in your open() function (pointed to by the
alt_dev structure). Free the storage in your close() function.
Note: To avoid memory leaks, ensure that the close() function is called when the file or
stream is no longer needed.
A driver is not required to provide all of the functions in the alt_dev structure. If a
given function pointer is set to NULL, a default action is used instead.
121
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
open Calls to open() for this device succeed, unless the device was previously locked by a call
to ioctl() with req = TIOCEXCL.
close Calls to close() for a valid file descriptor for this device always succeed.
ioctl ioctl() requests that cannot be handled without reference to the device fail.
In addition to the function pointers, the alt_dev structure contains two other fields:
llist and name. llist is for internal use, and must always be set to the value
ALT_LLIST_ENTRY. name is the location of the device in the HAL file system and is
the name of the device as defined in system.h.
This function takes a single input argument, which is the device structure to register.
The return value is zero upon success. A negative return value indicates that the
device cannot be registered.
After a device is registered with the HAL file system, you can access it through the
HAL API and the ANSI C standard library. The node name for the device is the name
specified in the alt_dev structure.
For more information, refer to the Developing Programs Using the Hardware
Abstraction Layer section.
122
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
The only distinction is that the name field of the device represents the mount point for
the file subsystem. Of course, you must also provide any necessary functions to
access the file subsystem, such as read() and write(), similar to the case of the
character-mode device.
Note: If you do not provide an implementation of fstat(), the default behavior returns the
value for a character-mode device, which is incorrect behavior for a file subsystem.
This function takes a single input argument, which is the device structure to register. A
negative return value indicates that the file system cannot be registered.
After a file subsystem is registered with the HAL file system, you can access it through
the HAL API and the ANSI C standard library. The mount point for the file subsystem is
the name specified in the alt_dev structure.
For more information, refer to the Developing Programs Using the Hardware
Abstraction Layer section.
To register the presence of a system clock driver, call the following function:
The input argument nticks is the number of system clock ticks per second, which is
determined by your system clock driver. The return value of this function is zero on
success, and nonzero otherwise.
For more information about writing interrupt service routines, refer to the Exception
Handling section.
For more information about using these functions, refer to the Developing Programs
Using the Hardware Abstraction Layer section.
123
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
struct alt_flash_dev{
alt_llist llist; // internal use only
const char* name;
alt_flash_open open;
alt_flash_close close;
alt_flash_write write;
alt_flash_read read;
alt_flash_get_flash_info get_info;
alt_flash_erase_block erase_block;
alt_flash_write_block write_block;
void* base_addr;
int length;
int number_of_regions;
flash_region region_info[ALT_MAX_NUMBER_OF_FLASH_REGIONS];
alt_flash_lock lock
};
The first parameter llist is for internal use, and must always be set to the value
ALT_LLIST_ENTRY. name is the location of the device in the HAL file system and is the
name of the device as defined in system.h.
The seven fields open to write_block are function pointers that implement the
functionality behind the application API calls to the following functions:
• alt_flash_open_dev()
• alt_flash_close_dev()
• alt_write_flash()
• alt_read_flash()
• alt_get_flash_info()
• alt_erase_flash_block()
• alt_write_flash_block()
• alt_flash_lock()
where:
• the base_addr parameter is the base address of the flash memory
• length is the size of the flash in bytes
• number_of_regions is the number of erase regions in the flash
• region_info contains information about the location and size of the blocks in
the flash device
124
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
For more information about the format of the flash_region structure, refer to Using
Flash Devices in Developing Programs Using the Hardware Abstraction Layer.
Some flash devices allow you to read out the number of regions and their
configuration at run time. For all other flash devices, these two fields must be defined
at compile time.
This function takes a single input argument, which is the device structure to register.
The return value is zero upon success. A negative return value indicates that the
device cannot be registered.
For more information about a complete description of the HAL DMA device model,
refer to Using DMA Devices in the Developing Programs Using the Hardware
Abstraction Layer section.
125
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
alt_txchan_done * done,
void * handle);
int( * ioctl)(alt_dma_txchan dma, int req, void * arg);
};
The prepare() function must be defined. If the ioctl field is set to null, calls to
alt_dma_rxchan_ioctl() return -ENOTTY for this device.
After creating an instance of the alt_dma_rxchan structure, you must register the
device driver with the HAL system to make it available by calling the following
function:
The input argument dev is the device to register. The return value is zero on success,
or negative if the device cannot be registered.
llist This function is for internal use and must always be set to the value ALT_LLIST_ENTRY.
name The name that refers to this channel in calls to alt_dma_rxchan_open(). name is the
name of the device as defined in system.h.
depth The total number of receive requests that can be outstanding at any given time.
prepare A pointer to a function that is called as a result of a call to the application API function
alt_dma_rxchan_prepare(). This function posts a receive request to the DMA device.
The parameters passed to alt_dma_rxchan_prepare() are passed directly to
prepare(). For a description of parameters and return values, refer to the HAL API
Reference" section.
ioctl This is a function that provides device specific I/O control. Refer to sys/alt_dma_dev.h
for a list of the generic options that a device might wish to support.
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
You can take advantage of this service, whether you created a device driver for one of
the HAL generic device models, or you created a peripheral-specific device driver.
Note: The process required to integrate a device driver is nearly identical to that required to
develop a software package. The following sections describe the process for both.
Related Information
• The HAL Peripheral-Specific API on page 117
• Overriding the HAL Default Device Drivers on page 141
126
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
7.8.1. Overview
To publish a device driver or a software package, you provide the following items:
The header file and Tcl script are described in the following sections.
For a device driver or software package to work with the Nios V processor tools, it
must meet the following criteria:
• It must have a defining Tcl script. The Tcl script for each driver or software
package provides the Nios V processor tools with a complete description of the
driver or software. This description includes the following information:
— Name—A unique name identifying the driver or software package
— Source files—The location, name, and type of each C/C++ or assembly
language source or header file
— Associated hardware class (device drivers only)—The name of the hardware
peripheral class the driver supports
— Version and compatibility information—The driver or package version, and (for
drivers) information about what device core versions it supports.
— BSP type(s)—The supported operating system(s)
— Settings—The visible parameters controlling software build and runtime
configuration
• The Tcl script resides in the driver or software package root directory.
• The Tcl script’s file name ends with _sw.tcl. Example: custom_ip_block_sw.tcl.
• The root directory of the driver or software package is located in a directory
named ip, one level beneath the Intel Quartus Prime project directory containing
the design your BSP targets. This approach is recommended if your driver or
software package is used only once, in a specific hardware project.
If your driver or software package uses the HAL auto initialization mechanism
(alt_sys_init()), certain macros must be defined in a header file.
Related Information
• File Names and Locations on page 129
For more information about how file names and directory structures conform to
certain conventions
• Header Files and alt_sys_init.c on page 138
For more information about header file.
127
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
The BSP generator locates software packages and drivers by inspecting a list of known
locations determined by the Nios V processor tools, Intel Quartus Prime software, and
®
IP core IP Library installers, as well as searching locations specified in certain system
environment variables.
The BSP Editor identifies drivers and software packages by locating and sourcing Tcl
scripts with file names ending in _sw.tcl in these locations.
Note: For run-time efficiency, the BSP Editor only looks at driver files that conform to the
criteria listed in this section.
After locating each driver and software package, the Nios V processor tools searches
for a suitable driver for each hardware module in the hardware system (mastered by
the Nios V processor that the BSP is generated for), as well as software packages that
the BSP creator requested.
128
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Creating a Tcl script allows you to add extra definitions in the system.h file, enable
automatic driver initialization through the alt_sys_init.c structure, and enable the
Nios V Processor Tools to control any extra parameters that might exist.
With the Tcl software definition files in place, the Software Build Tools read in the Tcl
file and populate the CMakeLists.txt and other support files accordingly.
When the BSP Editor adds each driver or software package to the system, it uses the
data in the Tcl script defining the driver or software package to control each file copied
in to the BSP. This rule also affects generated BSP files such as the CMakeLists.txt,
toolchain.cmake, system.h, and the BSP settings and summary HTML files.
The file hierarchy that is suitable for the Nios V processor tools is located in the
<Intel Quartus Prime installation>/ip/altera/sopc_builder_ip
directory. This example assumes a device driver supporting a hardware component
named custom_component.
Related Information
• Assumptions and Requirements on page 127
• AN 459: Guidelines for Developing a Nios II HAL Device Driver
For more information about integrating a HAL device driver.
For more information, refer to the Nios V Processor BSP Generation Flow.
The Tcl command and argument descriptions in this section are not exhaustive. For a
detailed explanation of each command and all arguments, refer to the Board Support
Package Tcl Commands section.
129
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
custom_component
custom_component_sw.tcl
inc
custom_component_regs.h
HAL
inc
custom_component.h
src
driver_source_file.c
Note: inc - Contains header file(s) that define the device hardware interfaces. Contents in
this directory are not HAL-specific and apply to a driver, regardless of whether it is
based on the HAL, MicroC/OS-II, or any other RTOS environment.
Note: HAL - Contains software files required to integrate the device with the Nios V
processor hardware abstraction layer. Files in this directory pertain specifically to the
HAL.
130
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
The example in this section creates a device driver for a hardware peripheral whose
component class name is my_custom_component. The driver supports both HAL and
MicroC/OS-II BSP types. It has a single C source file (.c) and two C header files (.h).
create_driver my_custom_component_driver
Note: The set_sw_property command accepts several argument types. Each call to
set_sw_property sets or overwrites a property to the value specified in the second
argument.
If you are creating your own driver to use in place of an existing one (for example, a
custom UART driver for the altera_avalon_uart component), specify a driver
name different from the standard driver. The Nios V processor tools uses your driver
only if you specify it explicitly.
For more information, refer to the Board Support Package Tcl Commands chapter.
Choose a name for your driver or software package that does not conflict with other
Intel-supplied software or IP, or any third-party software or IP installed on your host
system. The BSP generator uses the name you specify to look up the software
package or driver during BSP creation. If the Nios V processor finds multiple
compatible drivers or software packages with the same name, the behavior is
undefined.
131
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Note: The add_sw_property command accepts several argument types. Each call to
add_sw_property adds the final argument to the property specified in the second
argument.
If your driver or software has different source files, paths, or settings that depend on
the operating system used, write a Tcl script for each variant of the driver or software
package. Each script must specify the same software package or driver name in the
create_driver or create_sw_package command, and same hw_class_name in
the case of device drivers. Each script must specify only the files, paths, and other
settings that pertain to that operating system. During BSP generation, only drivers or
software packages that specify compatibility with the selected operating system (OS)
type are eligible to add to the BSP.
132
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Note: If the path begins with the BSP type (e.g HAL or UCOSII), the BSP type is removed
and replaced with the value of the bsp_subdirectory property.
To support this functionality in Nios V processor BSPs, you must set the
set_sw_property command’s auto_initialize argument to true using the
following Tcl command:
If you do not turn on this attribute, alt_sys_init.c does not invoke the INIT and
INSTANCE macros.
By default, the generated BSP CMakeLists.txt include paths to find header files
in /inc or <BSP type>/inc folders.
You might need to set up a header file directory hierarchy to logically organize your
code. You can add additional include paths to your driver or software package using
the add_sw_property command’s include_directory argument as follows:
Note: If the path begins with the BSP type (e.g HAL or UCOSII), the BSP type is removed
and replaced with the value of the bsp_subdirectory property.
Additional include paths are added to the preprocessor flags in the BSP
CMakeLists.txt file. These preprocessor flags allow BSP source files, as well as
application and user library source files that reference the BSP, to find the include path
while each source file is compiled.
Note: Adding additional include paths is not required if your source code includes header
files with explicit path names. You can also specify the location of the header files with
a #include directive similar to the following:
#include "protocol/h/<filename>"
133
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
• You can request a specific version of your driver or software package with BSP
settings.
• You can make updates to your device driver and specify that the driver is still
compatible with a minimum hardware class version, or specific hardware class
versions. This facility is especially useful in situations in which a hardware design
is stable and you foresee making software updates over time.
You can add multiple specific compatible versions. This functionality allows you to roll
out a new version of a device driver that tracks changes supporting a hardware
peripheral change.
For device drivers, if no compatible version information is specified, the version of the
device driver must be equal to the associated hardware class. Thus, if you do not wish
to use this feature, Intel recommends setting the min_compatible_hw_version of
your driver to the lowest version of the associated hardware class your driver is
compatible with.
The Tcl command that publishes settings is especially useful if your driver or software
package has build or runtime options that are normally specified with #define
statements or toolchain.cmake definitions at software build time. Settings can also
add custom variable declarations to the BSP toolchain.cmake.
134
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Use the add_sw_setting Tcl command to add a setting. To specify the details,
add_sw_setting requires each of the following arguments, in the order shown:
• type - The data type, which controls formatting of the setting’s value assignment
in the appropriate generated file.
• destination - The destination file in the BSP.
• displayName - The name that is used to identify the setting when changing BSP
settings or viewing the BSP summary.html document.
• identifier - Conceptually, this argument is the macro defined in a C language
definition (the text immediately following #define), or the name of a variable in a
toolchain.cmake.
• value - A default value assigned to the setting if the BSP user does not manually
change it.
• description - Descriptive text, shown in the BSP summary.html document
Several setting data types are available, controlled by the type argument to
add_sw_setting. They correspond to the data types you can express as #define
statements or values concatenated to toolchain.cmake variables. The specific
setting type depends on your software’s structure or BSP build needs.
Boolean definition boolean_define_only A definition that is generated when true, and absent when false. Use a
boolean definition in your C source files with the #ifdef <setting> ...
#endif construct.
Boolean assignment boolean A definition assigned to 1 when true, 0 when false. Use a boolean
assignment in your C source files with the #if <setting> ...
#else ... construct.
Character character A definition with one character surrounded by single quotation marks (')
Decimal number decimal_number A definition with an unquoted, unformatted decimal number, such as
123. Useful for defining values in software that, for example, might have
a configurable buffer size, such as int buffer[SIZE];
continued...
135
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Double precision double A definition with a double-precision floating point number such as 123.4
number
Floating point number float A definition with a single-precision floating point number such as 234.5
Hexadecimal number hex_number A definition with a number prefixed with 0x, such as 0x1000. Useful for
specifying memory addresses or bit masks
Unquoted string unquoted_string A definition with a string not in quotes, such as BUFFER
system.h system_h_define This destination file is recommended in most cases. Your source code
must use a #include <system.h> statement to make the setting
definitions available. Settings appear as #define statements in
system.h.
Note: Certain setting types are not compatible with the toolchain.cmake destination file
types.
For more information, refer to the Tcl Commands for Drivers and Packages chapter.
A setting's displayName defines how you refers to the setting in the BSP tools. The
BSP Tools append the displayName text after a . (dot) separator to your driver or
software package’s name (as defined in the create_driver or
create_sw_package command). For example, if your driver is named
my_peripheral_driver and your setting’s displayName is small_driver, BSPs
with your driver have a setting my_peripheral_driver.small_driver. Thus each
driver and software package has its own settings namespace.
The identifier argument of add_sw_setting controls the physical name of the setting
in the generated BSP files. The physical name corresponds to the definition being
created in toolchain.cmake and system.h . The identifier is commonly the text
that your software uses in conditionally-compiled code. For example, suppose your
software creates a buffer as follows:
136
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
You can enter the exact text, MY_DRIVER_BUFFER_SIZE, in the identifier argument.
The value argument of add_sw_setting holds the default value of your setting.
This value propagates to the generated BSP unless the end user of the driver or
package (the BSP developer) changes the setting’s assignment before BSP generation.
Note: The value assigned to any setting, whether it is the default value in the driver or
software package Tcl script, or entered by the user configuring the BSP, must be
compatible with the selected setting.
For more information, refer to the Tcl Commands for Drivers and Packages chapter.
#include "system.h"
#ifdef MY_CUSTOM_DRIVER_SMALL
int send_data( <args> )
{
// Small implementation
}
#else
int send_data( <args> )
{
// fast implementation
}
#endif
Note: This example implements a setting for a driver that has two variants of a function, one
implementing a small driver (minimal code footprint) and the other a fast driver
(efficient execution).
A simple Boolean definition setting is added to your driver Tcl file. This feature allows
BSP users to control your driver through the BSP settings interface.
• When you set the setting to true or 1, the BSP defines
MY_CUSTOM_DRIVER_SMALL in either system.h or the BSP toolchain.cmake
file.
• When you compile the BSP, your driver is compiled with the appropriate routine
incorporated in the object file.
• When you disable the setting, MY_CUSTOM_DRIVER_SMALL is not defined.
137
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
Note: Each Tcl command must reside on a single line of the Tcl file. This example is wrapped
due to space constraints.
For more information about detailed usage and restrictions, refer to the Board Support
Package Tcl Commands chapter.
When you create the driver or software package, you specify in a Tcl script whether
you want the alt_sys_init() function to invoke your INSTANCE and INIT macros.
Note: The remainder of this section assumes that you are using the alt_sys_init() HAL
initialization mechanism.
Related Information
• Assumptions and Requirements on page 127
• AN 459: Guidelines for Developing a Nios II HAL Device Driver
For more information about integrating a HAL device driver.
The Nios V processor tools create alt_sys_init.c based on the header files
associated with each device driver and software package. For a device driver, the
header file must define the macros <component name>_INSTANCE and <component
name>_INIT.
138
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
create_sw_package my_sw_package
For more information about a complete example, refer to any of the Intel supplied
device drivers, such as the JTAG UART driver in <Intel Quartus Prime
installation>/ip/sopc_builder_ip/altera_avalon_jtag_uart.
139
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
For more information, refer to the Settings Managed by Nios V Boards Support
Package Editor.
As source files are located using search paths, these namespace restrictions also apply
to file names for device driver source and header files.
140
7. Developing Device Drivers for the Hardware Abstraction Layer
743810 | 2022.10.31
However, if the driver supplied with a component is inappropriate for your application,
you can override the default driver by supplying a different driver.
You can use the BSP Editor to specify a custom driver in the BSP Editor GUI or on the
command line.
On the command line, you specify a custom driver with the following BSP Tcl
command:
For example, if you are using the niosv-bsp command, you replace the default driver
for uart0 with a driver called custom_driver as follows:
Related Information
Integrating a Device Driver in the HAL on page 126
141
743810 | 2022.10.31
Send Feedback
8. Exception Handling
The Nios V processor offers the Internal Interrupt Controller (IIC) to handling
hardware interrupts. The interrupt controllers are discussed in detail in the Hardware
Interrupt Controllers chapter.
• Application context—The status of the Nios V processor and the HAL during normal
program execution, outside of exception funnels and handlers.
• Context switch—The process of saving the Nios V processor’s registers on an
exception or interrupt, and restoring them on return from the exception handling
routine or ISR.
• Exception—A transfer of control away from a program’s normal flow of execution,
caused by an event, either internal or external to the processor, which requires
immediate attention. Exceptions include software exceptions and hardware
interrupts.
• Exception context—The status of the Nios V processor and the HAL after a
software exception or hardware interrupt, when funnel code, a software exception
handler, or an ISR is executing.
• Exception handling system—The complete system of software routines that service
all exceptions, including hardware interrupts, and pass control to software
exception handlers and ISRs as necessary.
• Exception (or interrupt) latency—The time elapsed between the event that causes
the exception (such as an unimplemented instruction or interrupt request) and the
execution of the first instruction at the exception (or interrupt vector) address.
• Exception (or interrupt) response time—The time elapsed between the event that
causes the exception and the execution of the handler.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
8. Exception Handling
743810 | 2022.10.31
143
8. Exception Handling
743810 | 2022.10.31
With the IIC, the HAL interrupt funnel identifies the hardware interrupt cause in
software, and dispatches the registered ISR.
All Nios V processor exception types are precise. This means that after an exception is
handled, the Nios V processor can re-execute the instruction that caused the
exception.
Note: With the IIC, Nios V exceptions are not vectored. Therefore, the same exception
address receives control for all types of exceptions. The general exception funnel at
that address must determine the type of software exception or hardware interrupt.
144
8. Exception Handling
743810 | 2022.10.31
If you are concerned with system performance, response time is the more important
than latency, because it reflects the time elapsed between the physical event and the
system’s specific response to that event.
The IIC is non-vectored, requiring the Nios V processor to dispatch ISRs with a
software routine
When you create a board support package (BSP) project, the build tools include all
needed device drivers. You do not need to write HAL ISRs unless you are interfacing to
a custom peripheral. For reference purposes, this section describes the framework
provided by HAL BSPs for handling hardware interrupts.
For examples of HAL ISRs, refer to existing handlers for Intel components.Developing
Programs Using the Hardware Abstraction Layer section.
Related Information
alt_irq_enabled() on page 214
145
8. Exception Handling
743810 | 2022.10.31
Note: The legacy hardware interrupt API is deprecated and not supported in Nios V
processor-based system.
The BSP implements the Enhanced HAL Hardware Interrupt API, and each driver that
supports the hardware interrupt API publishes this capability to the BSP Editor through
its <driver name>_sw.tcl file.
A driver can publish its interrupt API support by way of a software property. The
driver’s <driver name>_sw.tcl file uses the set_sw_property command to set
supported_interrupt_apis to enhanced_interrupt_api.
You need to perform the following steps to implement hardware ISR with HAL
hardware interrupt API:
1. Create your ISR functions prototype that handles hardware interrupts.
2. Ensure your program registers the ISR with the HAL driver by calling
alt_ic_isr_register().
3. alt_ic_isr_register() enables hardware interrupts for you.
alt_irq_disable_all() Disable all interrupts and return context value correspond to the previous state.
alt_irq_enable_all() Enable all interrupts to the previous state based on the returned context value
from prior alt_irq_disable_all().
Note: In the IIC, the functions are implemented by the HAL. For more information about
each function, refer to the HAL API Reference section.
146
8. Exception Handling
743810 | 2022.10.31
From the point of view of the HAL exception handling system, the most important
function of an ISR is to clear the associated peripheral’s interrupt condition. The
procedure for clearing an hardware interrupt condition is specific to the peripheral.
When the ISR has finished servicing the hardware interrupt, it returns to the HAL
interrupt funnel that called it.
Note: If you write your ISR in assembly language, use ret to return. The HAL general
exception funnel issues an MRET after restoring the application context.
Related Information
Embedded Peripherals IP User Guide
The funnel code receives control from the general exception vector. The funnel
performs tasks such as saving the stack pointer, saving registers and calling RTOS
context-switch routines, and transfers control to the handler. When the handler
returns, the funnel code performs tasks such as calling RTOS process-dispatch
routines and restoring registers, and transfers control to the appropriate foreground
task.
For more information about identifying these API functions that are not available to
ISRs, refer to the HAL API Reference chapter.
Be careful when calling ANSI C standard library functions inside of an ISR. Avoid using
the C standard library I/O API, because calling these functions can result in deadlock
within the system, that is, the system can become permanently blocked in the ISR.
In particular, do not call printf() from within an ISR unless you are certain that
stdout is mapped to a non-interrupt-based device driver. Otherwise, printf() can
deadlock the system, waiting for a hardware interrupt that never occurs because
interrupts are disabled.
147
8. Exception Handling
743810 | 2022.10.31
The HAL registers the ISR by storing the function pointer (isr), in a lookup table.
Note: Registering the ISR can require hardware-specific initialization. The HAL code ensures
that the registered ISR is correctly dispatched when a specific interrupt occurs. For
more information and details about hardware interrupt initialization specific to your
peripheral, refer to the relevant chapter of the Embedded Peripherals IP User Guide.
Related Information
Embedded Peripherals IP User Guide
148
8. Exception Handling
743810 | 2022.10.31
Note: Disable interrupts for as short a time as possible. Maximum interrupt latency increases
with the longest amount of time interrupts are disabled. For more information about
disabled interrupts, refer to the Keep Interrupts Enabled chapter.
Related Information
HAL API Reference on page 186
For more information about the UNIX-style functions.
8.2.5. C Example
This example is based on a Nios V processor system with a 4-bit PIO peripheral
connected to push buttons. An IRQ is generated any time a button is pushed. The ISR
code reads the PIO peripheral’s edge capture register and stores the value to a global
variable. The address of the global variable is passed to the ISR in the context pointer.
#include "altera_avalon_pio_regs.h"
#include "alt_types.h"
/* Read the edge capture register on the button PIO. Store value.*/
* edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE);
149
8. Exception Handling
743810 | 2022.10.31
Example 24. Registering the Button PIO ISR with the HAL
#include "sys/alt_irq.h"
#include "system.h"
...
/* Declare a global variable to hold the edge capture value. */
volatile int edge_capture;
...
/* Initialize the button_pio. */
static void init_button_pio()
{
/* Recast the edge_capture pointer to match the
alt_irq_register() function prototype. */
void * edge_capture_ptr = (void * ) & edge_capture;
/* Enable all 4 button interrupts. */
IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf);
/* Reset the edge capture register. */
IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0);
/* Register the ISR. */
alt_ic_isr_register(BUTTON_PIO_IRQ_INTERRUPT_CONTROLLER_ID,
BUTTON_PIO_IRQ,
handle_button_interrupts,
edge_capture_ptr, 0x0);
}
150
8. Exception Handling
743810 | 2022.10.31
You need to perform the following steps to implement software ISR with HAL software
interrupt API:
1. Create your ISR functions prototype that handles software interrupt.
2. Ensure your program registers the ISR with the HAL driver by calling
alt_niosv_register_msw_interrupt_handler().
3. Enable software interrupt with alt_niosv_enable_msw_interrupt().
After the software interrupt is handled, you are required to clear the software interrupt
by using the alt_niosv_clear_msw_interrupt() function.
Note: If you write your ISR in assembly language, use ret to return. The HAL general
exception funnel issues an MRET after restoring the application context.
Related Information
Embedded Peripherals IP User Guide
151
8. Exception Handling
743810 | 2022.10.31
Note: Disable interrupts for as short a time as possible. Maximum interrupt latency increases
with the longest amount of time interrupts are disabled. For more information about
disabled interrupts, refer to the “Keep Interrupts Enabled” chapter.
For more information about these functions, refer to the "HAL API Reference" chapter.
8.3.5. C Example
#include "sys/msw_interrupt.h"
#include "alt_types.h"
Based on the code in the example, the following execution flow is possible:
152
8. Exception Handling
743810 | 2022.10.31
#include "sys/msw_interrupt.h"
#include "alt_types.h"
...
/* Declare a global variable to hold the incrementing value. */
volatile alt_u32 sw_isr_cnt = 0;
...
int main() {
/* Register the ISR. */
alt_niosv_register_msw_interrupt_handler(sw_isr);
/* Enable software interrupt. */
alt_niosv_enable_msw_interrupt();
/* Generate the software interrupt. */
alt_niosv_trigger_msw_interrupt();
}
If your ISR requires lengthy processing, design your software to perform this
processing outside of the exception context. The ISR can use a message-passing
mechanism to notify the application code to perform the lengthy processing tasks.
153
8. Exception Handling
743810 | 2022.10.31
You can emulate this approach in a single-threaded HAL-based system. The main
program polls a global variable managed by the ISR to determine whether it needs to
perform the processor-intensive operation.
For more information about programming with DMA hardware, refer to Using DMA
Devices.
Double buffering allows the Nios V processor to process one data buffer while the
hardware is transferring data to or from another.
Disable interrupts as infrequently as possible, and for the briefest time possible.
Disable all interrupts only during critical system operations. In the code where
interrupts are disabled, perform only the bare minimum of critical operations, and
reenable interrupts immediately.
For best performance, place the ISRs and the stack in the fastest available memory:
preferably tightly-coupled memory (if available), or on-chip memory.
If it is not possible to place the main stack in fast memory, consider using a separate
exception stack, mapped to a fast memory section, as described in the next section.
154
8. Exception Handling
743810 | 2022.10.31
For more information about mapping memory, refer to Memory Usage chapter.
The HAL implements two types of separate exception stack. Using a separate
exception stack entails a slight additional overhead.
The HAL general exception funnel code takes care of correctly changing the stack
pointer on entry to and exit from an exception handler.
Note: If your ISR is located in a vector table, the HAL does not provide funnel code. In this
case, your code must manage the stack pointer, as well as all other funnel code
functions.
By default, the HAL disables interrupts when it dispatches an ISR. This means that
only one ISR can execute at any time, and ISRs are executed on a first-come first-
served basis. This reduces the system overhead associated with interrupt processing,
and simplifies ISR development. The ISR does not need to be reentrant. ISRs can use
and modify any global or static data structures or hardware registers that are not
shared with application code.
However, first-come first-served execution means that the HAL hardware interrupt
priorities only have an effect if two IRQs are active at the same time. A low-priority
interrupt occurring before a higher-priority interrupt can prevent the higher-priority
ISR from executing. This is a form of priority inversion, and it can have a significant
impact on ISR performance in systems that generate frequent interrupts.
A software system can achieve full hardware interrupt prioritization by using nested
ISRs. With nested ISRs, higher-priority interrupts are allowed to interrupt lower-
priority ISRs.
155
8. Exception Handling
743810 | 2022.10.31
This technique can improve the response time for higher-priority interrupts.
Note: Nested ISRs increase the processing time for lower-priority hardware interrupts.
If your ISR is very short, it might not be worth the overhead to enable nested
hardware interrupts. Enabling nested interrupts for a short ISR can actually increase
the response time for higher-priority interrupts.
Note: If you use a separate exception stack with the IIC, you cannot nest hardware
interrupts.
In some cases, these hardware changes also require changes in the software
architecture or implementation.
The following sections describe changes you can make in the hardware design to
improve ISR performance.
Related Information
Embedded Peripherals IP User Guide
156
8. Exception Handling
743810 | 2022.10.31
You can take advantage of the HAL exception handling system without a complete
understanding of the HAL implementation.
For more information about how to install ISRs using the HAL API, refer to the Nios V
Processor Hardware Interrupt Service Routines and Nios V Processor Software
Interrupt Service Routines.
With the IIC, there is a single hardware interrupt funnel. This funnel manages
processor context switch and RTOS overhead (if any). It determines the source of the
IRQ, and dispatches the correct ISR.
With the IIC, when the Nios V processor generates an exception, the general
exception funnel receives control. Based on the exception type, the general exception
funnel passes control to the software exception funnel, hardware interrupt funnel or
the respective interrupt handlers. The hardware interrupt funnel passes control to one
or more ISRs.
157
8. Exception Handling
743810 | 2022.10.31
Each time an exception occurs, the exception handling system services either a
software exception or interrupts, with hardware interrupts having a higher priority
than the other interrupts. The HAL IIC support does not include nested exceptions but
can handle multiple hardware interrupts per context switch.
Related Information
• General Exception Funnels on page 158
• Hardware Interrupt Funnel on page 161
• Software Exception Funnel on page 161
• Software Interrupt Handler on page 163
• Timer Interrupt Handler on page 163
The general exception funnel looks at the Machine Cause (mcause) register to
determine the exception type. If the Interrupt bit is set and Exception Code field is
referring to hardware interrupts, the general exception funnel transfer control to the
hardware interrupt funnel. Otherwise, the general exception funnel calls the
appropriate timer or software interrupt handler.
The hardware interrupt funnel looks at the hardware IRQ bits in mip register. If any
hardware IRQs are asserted, the interrupt funnel calls the appropriate hardware
interrupt handler.
All hardware interrupts have higher priority than timer and software interrupts.
If the Interrupt bit is not set, there are no interrupts, and the exception is a software
exception. In this case, the general exception funnel calls the software exception
funnel.
For more information about the Nios V processor mcause and mip registers, refer to
the The RISC-V Instruction Set Manual Volume II in RISC-V International website.
158
8. Exception Handling
743810 | 2022.10.31
Related Information
The RISC-V Instruction Set Manual
159
8. Exception Handling
743810 | 2022.10.31
Figure 14. HAL Exception Handling System with the Internal Interrupt Controller
Enter
Save context
No Is it an
interrupt?
Yes
ISR 16
ISR 0
ISR 1
No
Handle
timer interrupts
Restore context
Exit
160
8. Exception Handling
743810 | 2022.10.31
The hardware interrupt funnel calls the user-registered ISRs. It goes through the
hardware IRQs in Machine Interrupt-Pending mip register starting at hardware IRQ0,
and finds the first (highest priority) active hardware IRQ. Then it calls the
corresponding registered ISR. After this ISR executes, the funnel begins scanning the
hardware IRQs again, starting at hardware IRQ0. In this way, higher-priority interrupts
are always processed before lower-priority interrupts. When all hardware IRQs are
clear, the hardware interrupt funnel returns to the top level.
For more information on applying the hardware interrupts, refer to the Nios V
Processor Hardware Interrupt Service Routines chapter.
Figure 15. HAL Hardware Interrupt Funnel for the Internal Interrupt Controller
Enter
i=0
Yes No
Call ISR i IRQ i active? i=i+1
Yes No
i = = 16?
Exit
161
8. Exception Handling
743810 | 2022.10.31
Instruction-
No Related Yes
Exception Handler
Registered?
Optional
Trap Logic
No Debugger
Present? Instruction-
related
Exception
Infinite
Handler
Loop
Yes
EBREAK
Exit
If a handler is registered, the HAL software exception funnel calls it, then restores
context and returns.
For more information about the flowchart of the HAL software exception funnel,
including the optional trap logic, refer to the Figure Software Exception Funnel.
For more information about the RISCV-based processor EBREAK instruction, refer to
the The RISC-V Instruction Set Manual in RISC-V International website.
162
8. Exception Handling
743810 | 2022.10.31
For more information about how to handle advanced exceptions, refer to the Nios V
Instruction-Related Exception Handler chapter.
Related Information
The RISC-V Instruction Set Manual
For more information about the RISCV-based processor instruction, refer to the The
RISC-V Instruction Set Manual in RISC-V International website.
Related Information
The RISC-V Instruction Set Manual
For more information on applying the software interrupt, please refer to Nios V
Processor Software Interrupt Service Routine.
For more information, please refer to Timer Devices and Using Timer Devices chapter.
163
8. Exception Handling
743810 | 2022.10.31
The instruction-related exception handler’s return value is a flag requesting that the
HAL either re-execute the instruction or skip it.
The HAL exception funnel calls the instruction-related exception handler with the
following arguments:
• cause — A value representing the exception type, as shown in the Nios V
Processor Exception Cause Codes table
• exception_pc — Instruction address at which exception occurred
• bad_addr — Bad address associated with exception (if applicable)
Include the following header file in your instruction-related exception handler code:
#include “sys/alt_exceptions.h”
For more information about RISCV-based processor exception causes, refer to the The
RISC-V Instruction Set Manual Volume II in RISC-V International website.
Related Information
The RISC-V Instruction Set Manual
Breakpoint 3 NIOSV_BREAKPOINT
Reserved 10 NIOSV_RESERVED_BIT_10
(2)
Cause symbols are defined in sys/alt_exceptions.h.
164
8. Exception Handling
743810 | 2022.10.31
Reserved 14 NIOSV_RESERVED_BIT_14
For more information, refer to Settings Managed by the Nios V Processor Board
Support Package Editor section.
For more information about alt_main(), refer to Boot Sequence and Entry Point
section.
(2)
Cause symbols are defined in sys/alt_exceptions.h.
(3) This value is passed to the instruction-related exception handler if the cause argument if the
cause is not known.
165
8. Exception Handling
743810 | 2022.10.31
alt_instruction_exception_register(null, null);
When the HAL removes the instruction-related exception handler, it restores back the
default EBREAK.
To disable the interrupt mode, enable the polling mode to avoid the interrupt mode’s
exception. By enabling the polling operation, you can enable the instruction exception
handler function as shown in Example of Instruction-Related Exception Handler. You
can enable the polling driver can via niosv-bsp by executing the following command
below.
niosv - bsp - u - e = "set_setting
altera_avalon_jtag_uart_driver.enable_small_driver {1}"
bsp / settings.bsp
Note: Polling mode has reduced performance compared to the interrupt mode. Therefore,
polling mode is only suitable for debugging or applications where size efficiency is
more important than performance.
Once the polling mode is enabled in the JTAG UART following the instruction from the
previous section, the following steps can help identify the cause of non-interrupt
related exceptions like load, store misaligned, or others.
166
8. Exception Handling
743810 | 2022.10.31
1. In the main.c file, add the following lines to include the library and the following
instr_exception_handler() function.
#include <inttypes.h>
#include <sys/alt_exceptions.h>
// Provides a way to register a custom instruction exception handler
2. Add the following section to register this new exception handling function in the
main() function, right above the code which causes the exception.
nt main(void)
{
alt_instruction_exception_register (instr_exception_handler);
// Register custom instruction exception handler.
printf("Hello world!\n");
function_which_causes_the_exception();
return 0;
}
Once the polling mode is enabled in the JTAG UART following the instruction from the
previous section, the following steps can help with seeing the cause of non-interrupt
related exceptions like load or store misaligned, etc. In the main.c file, add the
following lines to include the library and following instr_exception_handler()
function.
#include <inttypes.h>
Add the following section to register this new exception handling function in the
main() function, right above the code which causes the exception.
int main(void) {
alt_instruction_exception_register (instr_exception_handler); // Register
custom instruction exception handler.
printf("Hello world!\n");
167
8. Exception Handling
743810 | 2022.10.31
function_which_causes_the_exception();
return 0;
}
168
743810 | 2022.10.31
Send Feedback
The MicroC/OS-II RTOS kernel is ported to the Nios V processor. It is built on top of
the Hardware Abstraction Layer (HAL) and board support package (BSP). It provides
RTOS facilities that makes it easier to write programs to run on Nios V processor.
Programs written on top of uCOS-II has the following advantages:
• Programs are portable to other Nios V processor hardware systems of the same
variant.
• Programs are more resistant to changes in the underlying hardware.
• Programs can access all HAL services by calling the UNIX-like HAL application
program interface (API).
• Interrupt Service Routines (ISR) are easy to implement.
For more information about MicroC/OS-II features and usage, refer to MicroC/OS-II -
The Real-Time Kernel by Jean J. Labrosse (CMP Books).
Related Information
Micrium Software and Documentation
Related Information
Micrium Licensing
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
9. MicroC/OS-II Real-Time Operating System
743810 | 2022.10.31
You need not modify source files directly to enable or disable kernel features.
Nonetheless, Intel provides the Nios V processor-specific source code in case you want
to examine it. The MicroC/OS-II source code is located in the following directories:
• Processor-specific code: <Intel Quartus installation directory>/ip/
altera/soft_processor/intel_niosv_m/UCOSII
• Processor-independent code: <Intel Quartus installation directory>/
nios2eds>/components/micrium_uc_osii
The MicroC/OS-II software package behaves like the drivers for hardware
components: When MicroC/OS-II is included in a Nios V project, the header and
source files from components/micrium_uc_osii are included in the project path,
causing the MicroC/OS-II kernel to compile and link as part of the project.
Related Information
Nios® V Embedded Processor Design Handbook
170
9. MicroC/OS-II Real-Time Operating System
743810 | 2022.10.31
Figure 17. Architecture of MicroC/OS-II Programs in Relation to the HAL API Lorem ipsum
User Program
C Standard MicroC/OS-II
Library API
HAL API
You can use the UCOSII directory to provide code that is used only in a multi-
threaded environment. Other than these additional search directories, the mechanism
for providing MicroC/OS-II device drivers is identical to the process for any other
device driver.
The HAL system initialization process calls the MicroC/OS-II function OSInit() before
alt_sys_init(), which instantiates and initializes each device in the system.
Therefore, the complete MicroC/OS-II API is available to device drivers, although the
system is still running in single-threaded mode until the program calls OSStart()
from within main().
Related Information
Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
171
9. MicroC/OS-II Real-Time Operating System
743810 | 2022.10.31
project, the macros expand to MicroC/OS-II API calls. When compiled for a single-
threaded HAL project, the macros expand to benign empty implementations. These
macros are used in Intel-provided device driver code, and you can use them if you
need to write a device driver with similar portability.
The path listed for the header file is relative to the <Intel Quartus installation
directory>/nios2eds/components/micrium_uc_osii/UCOSII/inc directory.
ALT_FLAG_GRP(group) os/ Create a pointer to a flag group with the Empty statement
alt_flag.h name group.
ALT_STATIC_FLAG_GRP(group) os/ Create a static pointer to a flag group with Empty statement
alt_flag.h the name group.
ALT_FLAG_CREATE(group, flags) os/ Call OSFlagCreate() to initialize the flag Return 0 (success)
alt_flag.h group pointer, group, with the flags value
flags. The error code is the return value
of the macro.
ALT_FLAG_PEND(group, flags, os/ Call OSFlagPend() with the first four Return 0 (success)
wait_type, timeout) alt_flag.h input arguments set to group, flags,
wait_type, and timeout respectively.
The error code is the return value of the
macro.
ALT_FLAG_POST(group, flags, opt) os/ Call OSFlagPost() with the first three Return 0 (success)
alt_flag.h input arguments set to group, flags, and
opt respectively. The error code is the
return value of the macro.
ALT_STATIC_SEM(sem) os/ Create a static OS_EVENT pointer with the Empty statement
alt_sem.h name sem.
ALT_SEM_CREATE(sem, value) os/ Call OSSemCreate() with the argument Return 0 (success)
alt_sem.h value to initialize the OS_EVENT pointer
sem. The return value is zero on success,
or negative otherwise.
ALT_SEM_PEND(sem, timeout) os/ Call OSSemPend() with the first two Return 0 (success)
alt_sem.h argument set to sem and timeout
respectively. The error code is the return
value of the macro.
172
9. MicroC/OS-II Real-Time Operating System
743810 | 2022.10.31
This thread-local data is allocated at the top of the task’s stack. You must make
allowance for thread-local data storage when allocating memory for stacks. In general,
the _reent structure consumes approximately 900 bytes of data.
The HAL also allows you to write your ISR in C, rather than assembly language.
Related Information
Exception Handling on page 142
For information about the exception handler software routines, HAL-provided
services, and API.
Related Information
• Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
• Nios V Processor Appendix on page 186
173
9. MicroC/OS-II Real-Time Operating System
743810 | 2022.10.31
174
743810 | 2022.10.31
Send Feedback
In the Intel Quartus Prime Design Suite, the µC/TCP-IP protocol is a software package
that you can add to your board support package (BSP), available through the Nios V
processor software build tools. The µC/TCP-IP protocol includes these features:
• Internet Protocol (IP) including packet forwarding over multiple network interfaces
• Internet control message protocol (ICMP) for network maintenance and debugging
• User datagram protocol (UDP)
• Transmission Control Protocol (TCP) with congestion control, round trip time (RTT)
estimation, and fast recovery and retransmit
• Dynamic host configuration protocol (DHCP)
• Address resolution protocol (ARP) for Ethernet
• Standard sockets API
Related Information
µC/TCP-IP
Related Information
Micrium Licensing
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
10. MicroC/TCP-IP Protocol Stack
743810 | 2022.10.31
Related Information
• Network sockets
• Nios V Embedded Processor Design Handbook
• Overview of the MicroC/OS-II RTOS on page 169
Intel FPGA's implementation of the µC/TCP-IP protocol stack includes an API wrapper
for the socket API.
The µC/TCP-IP protocol stack uses the MicroC/OS-II RTOS multithreaded environment.
Therefore, to use the µC/TCP-IP protocol stack with the Nios V processor software
build tools, you must choose the MicroC/OS-II BSP type. The Nios V processor system
must also contain an Ethernet interface, or media access control (MAC). The Intel-
provided µC/TCP-IP protocol stack includes MAC driver support for Triple Speed
Ethernet Intel FPGA IP core.
There are two µC/TCP-IP Example Designs, using Triple Speed Ethernet Intel FPGA IP
core, which act as reference to demonstrate µC/TCP-IP protocol stack:
• µC/TCP-IP IPerf Example Design
• µC/TCP-IP Simple Socket Server Example Design
Related Information
• Triple-Speed Ethernet Intel® FPGA IP
• Nios® V Processor - Using the MicroC/TCP-IP Stack
• Developing Programs Using the Hardware Abstraction Layer on page 78
176
10. MicroC/TCP-IP Protocol Stack
743810 | 2022.10.31
There are multiple libraries in the directory. The main library is µC-TCP-IP. The main
library depends upon µC-Common, µC-CPU, µC-LIB, µC-DHCPc, and µC-Conf.
µC-Common Includes a Kernel Abstraction Layer (KAL) to easily switch between different OS’s.
Nios V processor uses microC/OS-II KAL to implement µC/TCP-IP protocol stack
µC-LIB Includes library functions such as math functions and string manipulation
µC-DHCPc Addition features to µC/TCP-IP to acquire the IP address via DHCP server instead of
setting a static address
Related Information
MicroC/TCP-IP Github Release
Alternately, you can also enable it through Intel Quartus Prime using the following
steps:
1. Open the Platform Designer.
2. Click the BSP Editor tab.
3. Click the BSP Software Packages tab.
4. Tick the Enable checkbox.
177
10. MicroC/TCP-IP Protocol Stack
743810 | 2022.10.31
// Update TSE sys info struct and MAC address from configuration.
NetDev_Cfg_Ether_TSE.BaseAddr = (CPU_ADDR) conf->tse_sys_info;
Mem_Copy(NetDev_Cfg_Ether_TSE.HW_AddrStr, conf->mac_addr,
sizeof(CPU_CHAR) * NET_IF_802x_ADDR_SIZE_STR);
// Add TSE.
*p_if_nbr = NetIF_Add(
(void *)&NetIF_API_Ether, // const for all eth interfaces
(void *)&NetDev_API_TSE_mSGDMA_Intel_HAL,
NULL, // (void *)&Net_DrvBSP_Nios_II,
(void *)&NetDev_Cfg_Ether_TSE,
NULL, // (void *)&NetPhy_API_Generic,
NULL, // (void *)&NetPhy_Cfg_Ether_TSE,
178
10. MicroC/TCP-IP Protocol Stack
743810 | 2022.10.31
&err_net);
if (err_net != NET_IF_ERR_NONE) {
logf("Failed to NetIF_Add(): (%d).\n", err_net);
return DEF_FALSE;
}
// Start TSE.
NetIF_Start(*p_if_nbr, &err_net);
if (err_net != NET_IF_ERR_NONE){
logf("Failed to NetIF_Start(): (%d).\n", err_net);
return DEF_FALSE;
}
CPU_BOOLEAN ret;
if (conf->use_dhcp) {
ret = conf_dhcp(*p_if_nbr);
} else {
ret = conf_static(*p_if_nbr, conf);
}
return ret;
}
You can use the following µC/OS-II tasks to create a thread, and performs actions
specific task for simple socket server:
• SSSCreateOSDataStructs() — Creates an instance of all the µC/OS-II
resources.
• SSSCreateTasks() — Initializes tasks that do not use the networking services.
• SSSSimpleSocketServerTask()— Manages the socket server connection, and
calls relevant subroutines to manage the socket connection
You can use App_IPerf_TaskTerminal()— Initialize and run iPerf Terminal function
prototype for iPerf application:
Related Information
Nios® V Embedded Processor Design Handbook: MicroC/TCP-IP Simple Socket Server
Concepts
179
10. MicroC/TCP-IP Protocol Stack
743810 | 2022.10.31
Related Information
Nios® V Embedded Processor Design Handbook: Optional Configuration
10.7.3.1. simple_socket_server.c
10.7.3.2. app_iperf.c
Example application code to run Iperf tools with µC/TCP-IP protocol stack.
Related Information
Nios® V Embedded Processor Design Handbook: MicroC/TCP-IP Example Designs
180
743810 | 2022.10.31
Send Feedback
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
11. Publishing Component Information to Embedded Software
743810 | 2022.10.31
Hardware
Component
(*_hw.tcl)
System
Integration Tool
(Platform Designer)
Platform Designer
System File
(.qsys)
Embedded
Software Tools
182
11. Publishing Component Information to Embedded Software
743810 | 2022.10.31
Example 28. Assignment Statement for the BAUD_RATE of uart_0 in a Hardware System
# Tcl assignment statement included in the _hw.tcl file
add_parameter BAUD_RATE_PARAM integer 9600 "This is the default baud rate."
# Dynamically reassign the baud rate based on the parameter value
set_module_assignment embeddedsw.CMacro.BAUD_RATE \
[get_parameter_value BAUD_RATE_PARAM]
Related Information
GCC, the GNU Compiler Collection
Table 40. Examples of How to Format GCC C/C++ 32-bit Processor Constants
C Data Type Examples
183
11. Publishing Component Information to Embedded Software
743810 | 2022.10.31
boolean 1, 0
string ABC
isPrintableDe boolean 0 The slave port provides access to a Intel FPGA UART, Intel FPGA JTAG
vice character-based device. UART
isTimerDevice boolean 0 The slave port provides access to a Intel FPGA Timer
timer device.
isEthernetMac boolean 0 The slave port provides access to an Intel FPGA Triple-Speed Ethernet
Device Ethernet media access control (MAC).
isNonVolatile boolean 0 The memory device is a non-volatile QSPI flash devices, on-chip FPGA
Storage memory device. The contents of a memory configured as a ROM
non-volatile memory device are fixed
and always present. In normal
operation, you can only read from
continued...
184
11. Publishing Component Information to Embedded Software
743810 | 2022.10.31
isFlash boolean 0 The memory device is a flash memory QSPI flash devices
device. If isFlash is true, you must
also set isMemoryDevice and
isNonVolatileStorage to true.
affectsTransa string empty A list of master names delimited by Intel FPGA direct memory access
ctionsOnMaste string spaces, for example m1 m2. Used (DMA), Modular Scatter-Gather DMA
rs when the slave port provides access
to Avalon-MM control registers in the
component. The control registers
control transfers on the specified
master ports.
The slave port can configure the
control registers for master ports on
the listed components. The address
space for this slave port is composed
of the address spaces of the named
master ports.
Nios V embedded software tools use
this information to generate #define
directives describing the address
space of these master ports.
185
743810 | 2022.10.31
Send Feedback
Related Information
• Timestamp Driver on page 90
• Boot Modes on page 114
• Nios V Processor Configuration and Booting Solutions
For more details about Nios® V processor booting method.
• Timestamp Timer on page 42
12.1.1.1. _exit()
Prototype
void _exit (int exit_code)
Commonly Called By
newlib C library
Thread-safe
Yes.
Include
<unistd.h>
Description
The newlib exit() function calls the _exit() function to terminate the current
process. Typically, exit() calls this function when main() completes. Because there
is only a single process in HAL systems, the HAL implementation blocks forever.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
--
12.1.1.2. _rename()
Prototype
int _rename(char *existing, char* new)
Commonly Called By
newlib C library
Thread-safe
Yes.
Include
<stdio.h>
Description
_rename() is unsupported in the HAL environment. This function has no effect and is
implemented purely for newlib compatibility.
Return
It always returns -1, with errno set to ENOSYS.
12.1.1.3. alt_dcache_flush()
Prototype
void alt_dcache_flush (void* start, alt_u32 len)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
The alt_dcache_flush() function flushes the data cache for a memory region of
length len bytes, starting at address start. Flushing the cache consists of writing back
dirty data and then invalidating the cache.
187
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
--
12.1.1.4. alt_dcache_flush_all()
Prototype
void alt_dcache_flush_all (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
The alt_dcache_flush_all() function flushes, that is, writes back dirty data and
then invalidates, the entire contents of the data cache.
Return
--
12.1.1.5. alt_icache_flush_all()
Prototype
void alt_icache_flush_all (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
188
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The alt_icache_flush_all() function invalidates the entire contents of the
instruction cache.
Return
--
12.1.1.6. alt_dcache_flush_no_writeback()
Prototype
void alt_dcache_flush_no_writeback (void* start, alt_u32 len)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
The alt_dcache_flush_no_writeback() is called to flush the data cache for a
memory region of length len bytes, starting at address start. Any dirty lines in the
data cache are NOT written back to memory. The cache becomes invalidated. In
processors without data caches, it has no effect.
Return
--
12.1.1.7. alt_uncached_malloc()
Prototype
volatile void* alt_uncached_malloc (size_t size)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
189
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_cache.h>
Description
Return
If sufficient memory cannot be allocated, this function returns null, otherwise a pointer
to the allocated space is returned.
12.1.1.8. alt_uncached_free()
Prototype
void alt_uncached_free (volatile void* ptr)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
Return
--
12.1.1.9. alt_remap_uncached()
Prototype
volatile void* alt_remap_uncached (void* ptr,
alt_u32 len);
190
12. Nios V Processor Appendix
743810 | 2022.10.31
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
The alt_remap_uncached() routine is not available with Nios V cores with data
caches because mixing cacheable and uncacheable data on the same line is not
supported. This function results in a link error when used with Nios V cores.
Return
The return value for this function is the remapped memory region.
12.1.1.10. alt_remap_cached()
Prototype
alt_u32 len);
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
The alt_remap_cached() function remaps a region of memory for cached access.
The memory to map is len bytes, starting at address ptr.
191
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
The return value for this function is is the start address of the remapped memory
region.
12.1.1.11. alt_icache_flush_all()
Prototype
void alt_icache_flush_all (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
Description
The alt_icache_flush_all() function invalidates the entire contents of the
instruction cache.
Return
--
12.1.1.12. alt_icache_flush()
Prototype
void alt_icache_flush (void* start, alt_u32 len)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_cache.h>
192
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The alt_icache_flush() function invalidates the instruction cache for a memory
region of length len bytes, starting at address start.
Return
--
12.1.1.13. alt_alarm_start()
Prototype
int alt_alarm_start
( alt_alarm* alarm,
alt_u32 nticks,
void* context )
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_alarm.h>
Description
The alt_alarm_start() function schedules an alarm callback.
The HAL waits nticks system clock ticks before calling the callback() function.
When the HAL calls callback(), it passes it the input argument context. The HAL
does not use the context parameter. It only passes it as a parameter to the
callback() function.
The alarm argument is a pointer to a structure that represents this alarm. You must
create it, and it must have a lifetime that is at least as long as that of the alarm.
However, you are not responsible for initializing the contents of the structure pointed
to by alarm. This action is done by the call to alt_alarm_start().
One alarm is created for each call to alt_alarm_start(). Multiple alarms can run
simultaneously.
193
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
The return value for alt_alarm_start() is zero on success, and negative
otherwise. This function fails if there is no system clock available.
12.1.1.14. alt_alarm_stop()
Prototype
void alt_alarm_stop (alt_alarm* alarm)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_alarm.h>
Description
You can call the alt_alarm_stop() function to cancel an alarm previously registered
by a call to alt_alarm_start(). The input argument is a pointer to the alarm
structure in the previous call to alt_alarm_start().
Return
--
12.1.1.15. alt_dma_rxchan_depth()
Prototype
alt_u32 alt_dma_rxchan_depth(alt_dma_rxchan dma)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_dma.h>
194
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The alt_dma_rxchan_depth() function returns the maximum number of receive
requests that can be posted to the specified DMA transmit channel, dma.
Whether this function is thread-safe, or can be called from an ISR, depends on the
underlying device driver. In general it safest to assume that it is not thread-safe.
Return
Returns the maximum number of receive requests that can be posted.
12.1.1.16. alt_dma_rxchan_close()
Prototype
int alt_dma_rxchan_close (alt_dma_rxchan rxchan)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_dma.h>
Description
The alt_dma_rxchan_close() function notifies the system that the application has
finished using the direct memory access (DMA) receive channel, rxchan. The current
implementation always succeeds.
Return
The return value is always zero.
12.1.1.17. alt_dev_reg()
Prototype
int alt_dev_reg(alt_dev* dev)
Commonly Called By
Device drivers
Thread-safe
No.
195
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_dev.h>
Description
The alt_dev_reg() function registers a device with the system. After it is
registered, you can access a device using the standard I/O functions.
For more information, refer to the "Developing Programs Using the Hardware
Abstraction Layer" section.
The system behavior is undefined in the event that a device is registered with a name
that conflicts with an existing device or file system.
The alt_dev_reg() function is not thread-safe in the sense that no other thread can
use the device list at the time that alt_dev_reg() is called. Call alt_dev_reg()
only in the following circumstances:
• When running in single-threaded mode.
• From a device initialization function called by alt_sys_init().
alt_sys_init() may only be called by the single-threaded C startup code.
Return
The return value is zero upon success. A negative return value indicates failure.
12.1.1.18. alt_dma_rxchan_open()
Prototype
alt_dma_rxchan alt_dma_rxchan_open (const char* name)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_dma.h>
Description
The alt_dma_rxchan_open() function obtains an alt_dma_rxchan descriptor for
a DMA receive channel. The input argument, name, is the name of the associated
physical device, for example, /dev/dma_0.
Return
The return value is the requested alt_dma_rxchan descriptor on success and null
otherwise. If an error occurs, errno is set to ENODEV.
196
12. Nios V Processor Appendix
743810 | 2022.10.31
12.1.1.19. alt_dma_rxchan_prepare()
Prototype
int alt_dma_rxchan_prepare (alt_dma_rxchan dma,
void* data,
alt_u32 length,
alt_rxchan_done* done,
void* handle)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_dma.h>
Description
The alt_dma_rxchan_prepare() posts a receive request to a DMA receive channel.
The input arguments are: dma, the channel to use; data, a pointer to the location
that data is to be received to; length, the maximum length of the data to receive in
bytes; done, callback function that is called after the data is received; handle, an
opaque value passed to done.
Whether this function is thread-safe, or can be called from an ISR, depends on the
underlying device driver. In general it safest to assume that it is not thread-safe.
Return
The return value is zero upon success. A negative return value indicates that the
request cannot be posted.
12.1.1.20. alt_dma_rxchan_reg()
Prototype
int alt_dma_rxchan_reg (alt_dma_rxchan_dev* dev)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
197
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_dma_dev.h>
Description
The alt_dma_rxchan_reg() function registers a DMA receive channel with the
system.
After it is registered, a device can be accessed using the functions described in “Using
DMA Devices” in the "Developing Programs Using the Hardware Abstraction Layer"
section.
System behavior is undefined in the event that a channel is registered with a name
that conflicts with an existing channel.
Return
The return value is zero upon success. A negative return value indicates failure.
12.1.1.21. alt_dma_txchan_close()
Prototype
int alt_dma_txchan_close (alt_dma_txchan txchan)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_dma.h>
Description
The alt_dma_txchan_close function notifies the system that the application has
finished using the DMA transmit channel, txchan. The current implementation always
succeeds.
198
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
The return value is zero.
12.1.1.22. alt_dma_txchan_ioctl()
Prototype
int alt_dma_txchan_ioctl (alt_dma_txchan dma,
int req,
void* arg)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_dma.h>
Description
The alt_dma_txchan_ioctl() function performs device specific I/O operations on
the DMA transmit channel, dma. For example, some drivers support options to control
the width of the transfer operations. The input argument, req, is an enumeration of
the requested operation; arg is an additional argument for the request. The
interpretation of arg is request dependent.
For more information, refer to the Generic Requests DMA Might Support table for the
generic requests a device might support.
Do not call the alt_dma_txchan_ioctl() function while DMA transfers are pending
or can result in unpredictable behavior.
Return
A negative return value indicates failure; otherwise the interpretation of the return
value is request specific.
12.1.1.23. alt_dma_txchan_open()
Prototype
alt_dma_txchan alt_dma_txchan_open (const char* name)
Commonly Called By
C/C++ programs
199
12. Nios V Processor Appendix
743810 | 2022.10.31
Device drivers
Thread-safe
Yes.
Include
<sys/alt_dma.h>
Description
The alt_dma_txchan_open() function obtains an alt_dma_txchan() descriptor
for a DMA transmit channel. The input argument, name, is the name of the associated
physical device, for example, /dev/dma_0.
Return
The return value is null on failure and the request alt_dma_txchan otherwise. If an
error occurs, errno is set to ENODEV.
12.1.1.24. alt_dma_txchan_reg()
Prototype
int alt_dma_txchan_reg (alt_dma_txchan_dev* dev)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_dma_dev.h>
Description
The alt_dma_txchan_reg() function registers a DMA transmit channel with the
system.
After it is registered, a device can be accessed using the functions described in “Using
DMA Devices” in the "Developing Programs Using the Hardware Abstraction Layer"
section.
System behavior is undefined in the event that a channel is registered with a name
that conflicts with an existing channel.
200
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
The return value is zero upon success. A negative return value indicates failure.
12.1.1.25. alt_flash_close_dev()
Prototype
void alt_flash_close_dev(alt_flash_fd* fd)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_flash.h>
Description
The alt_flash_close_dev() function closes a flash device. All subsequent calls to
alt_write_flash(), alt_read_flash(), alt_get_flash_info(),
alt_erase_flash_block(), or alt_write_flash_block() for this flash device
fail.
The only valid values for the fd parameter are those returned from the
alt_flash_open_dev function. If any other value is passed, the behavior of this
function is undefined.
Return
--
12.1.1.26. alt_exception_cause_generated_bad_addr()
Prototype
int alt_exception_cause_generated_bad_addr ( alt_exception_cause
cause)
201
12. Nios V Processor Appendix
743810 | 2022.10.31
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
--
Include
<sys/alt_exceptions.h>
Description
This function validates the bad_addr argument to an instruction-related exception
handler. The function parses the handler’s cause argument to determine whether the
bad_addr register contains the exception-causing address.
If the exception is of a type that generates a valid address in bad_addr, this function
returns a nonzero value. Otherwise, it returns zero.
If the cause register is unimplemented in the Nios V processor core, this function
always returns zero.
Return
A nonzero value means bad_addr contains the exception-causing address.
12.1.1.27. alt_erase_flash_block()
Prototype
int offset,
int length)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
202
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_flash.h>
Description
The alt_erase_flash_block() function erases an individual flash erase block. The
parameter fd specifies the flash device; offset is the offset within the flash of the
block to erase; length is the size of the block to erase. No error checking is
performed to check that this is a valid block, or that the length is correct.
For more information, refer to “Using Flash Devices” in the "Developing Programs
Using the Hardware Abstraction Layer" chapter.
The only valid values for the fd parameter are those returned from the
alt_flash_open_dev function. If any other value is passed, the behavior of this
function is undefined.
Return
The return value is zero upon success. A negative return value indicates failure.
12.1.1.28. alt_dma_rxchan_ioctl()
Prototype
int req,
void* arg)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_dma.h>
203
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The alt_dma_rxchan_ioctl() function performs DMA I/O operations on the DMA
receive channel, dma. The I/O operations are device specific. For example, some DMA
drivers support options to control the width of the transfer operations. The input
argument, req, is an enumeration of the requested operation; arg is an additional
argument for the request. The interpretation of arg is request dependent.
Do not call the alt_dma_rxchan_ioctl() function while DMA transfers are pending
or can result in unpredictable behavior.
For device-specific information about the Intel FPGA® DMA controller core, refer to the
"DMA Controller Core" chapter in the Embedded Peripherals IP User Guide.
Return
A negative return value indicates failure. The interpretation of nonnegative return
values is request specific.
ALT_DMA_SET_MODE_128 Transfer data in units of 128 bits. The value of arg is ignored.
ALT_DMA_TX_ONLY_ON The ALT_DMA_TX_ONLY_ON request causes a DMA channel to operate in a mode in which
only the transmitter is under software control. The other side writes continuously from a
single location. The address to which to write is the argument to this request.
ALT_DMA_TX_ONLY_OFF Return to the default mode, in which both the receive and transmit sides of the DMA can be
under software control.
ALT_DMA_RX_ONLY_ON The ALT_DMA_RX_ONLY_ON request causes a DMA channel to operate in a mode in which
only the receiver is under software control. The other side reads continuously from a single
location. The address to read is the argument to this request.
ALT_DMA_RX_ONLY_OFF Return to the default mode, in which both the receive and transmit sides of the DMA can be
under software control.
12.1.1.29. alt_dma_txchan_space()
Prototype
int alt_dma_txchan_space (alt_dma_txchan dma)
Commonly Called By
C/C++ programs
Device drivers
204
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
See description.
Include
<sys/alt_dma.h>
Description
The alt_dma_txchan_space() function returns the number of transmit requests
that can be posted to the specified DMA transmit channel, dma. A negative value
indicates that the value cannot be determined.
Whether this function is thread-safe, or can be called from an ISR, depends on the
underlying device driver. In general it safest to assume that it is not thread-safe.
Return
Returns the number of transmit requests that can be posted.
12.1.1.30. alt_dma_txchan_send()
Prototype
alt_u32 length,
alt_txchan_done* done,
void* handle)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_dma.h>
205
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The alt_dma_txchan_send() function posts a transmit request to a DMA transmit
channel. The input arguments are: dma, the channel to use; from, a pointer to the
start of the data to send; length, the length of the data to send in bytes; done, a
callback function that is called after the data is sent; and handle, an opaque value
passed to done.
Whether this function is thread-safe, or can be called from an ISR, depends on the
underlying device driver. In general it safest to assume that it is not thread-safe.
Return
The return value is negative if the request cannot be posted, and zero otherwise.
12.1.1.31. alt_flash_open_dev()
Prototype
alt_flash_fd* alt_flash_open_dev(const char* name)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_flash.h>
Description
The alt_flash_open_dev() function opens a flash device. After it is opened, you
can perform the following operations:
• Write to a flash device using alt_write_flash()
• Read from a flash device using alt_read_flash()
• Control individual flash blocks using alt_get_flash_info(),
alt_erase_flash_block(), or alt_write_flash_block().
Call the alt_flash_open_dev function only when operating in single-threaded
mode.
Return
The return value is zero upon failure. Any other value indicates success.
12.1.1.32. alt_fs_reg()
Prototype
int alt_fs_reg (alt_dev* dev)
206
12. Nios V Processor Appendix
743810 | 2022.10.31
Commonly Called By
Device drivers
Thread-safe
No.
Include
<sys/alt_dev.h>
Description
The alt_fs_reg() function registers a file system with the HAL. After it is
registered, a file system can be accessed using the standard I/O functions.
For more information, refer to the "Developing Programs Using the Hardware
Abstraction Layer" section.
System behavior is undefined in the event that a file system is registered with a name
that conflicts with an existing device or file system.
alt_fs_reg() is not thread-safe if other threads are using the device list at the time
that alt_fs_reg() is called. Call alt_fs_reg() only in the following
circumstances:
• When running in single-threaded mode.
• From a device initialization function called by alt_sys_init().
alt_sys_init() may only be called by the single-threaded C startup code.
Return
The return value is zero upon success. A negative return value indicates failure.
12.1.1.33. alt_get_flash_info()
Prototype
flash_region** info,
int* number_of_regions)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
207
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_flash.h>
Description
The alt_get_flash_info() function gets the details of the erase region of a flash
part. The flash part is specified by the descriptor fd, a pointer to the start of the
flash_region structures is returned in the info parameter, and the number of flash
regions are returned in number of regions.
The only valid values for the fd parameter are those returned from the
alt_flash_open_dev function. If any other value is passed, the behavior of this
function is undefined.
Return
The return value is zero upon success. A negative return value indicates failure.
12.1.1.34. alt_ic_irq_disable()
Prototype
int alt_ic_irq_disable (alt_u32 ic_id, alt_u32 irq)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_ic_irq_disable() function disables a single interrupt.
208
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
This function returns zero if successful, or nonzero otherwise. The function fails if the
irq parameter is greater than the maximum interrupt port number supported by the
interrupt controller.
12.1.1.35. alt_ic_irq_enabled()
Prototype
int alt_ic_irq_enabled (alt_u32 ic_id, alt_u32 irq)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
This function determines whether a specified interrupt is enabled.
Return
Returns zero if the specified interrupt is disabled, and nonzero otherwise.
12.1.1.36. alt_ic_isr_register()
Prototype
alt_u32 irq,
alt_isr_func isr,
void* isr_context,
void* flags)
209
12. Nios V Processor Appendix
743810 | 2022.10.31
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_ic_isr_register() function registers an ISR. If the function is successful,
the requested interrupt is enabled on return, and isr and isr_context are inserted
in the vector table.
Return
This function returns zero if successful, or nonzero otherwise. The function fails if the
irq parameter is greater than the maximum interrupt port number supported by the
interrupt controller.
12.1.1.37. alt_ic_irq_enable()
Prototype
int alt_ic_irq_enable (alt_u32 ic_id, alt_u32 irq)
Commonly Called By
C/C++ programs
210
12. Nios V Processor Appendix
743810 | 2022.10.31
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_ic_irq_enable() function enables a single interrupt.
Return
This function returns zero if successful, or nonzero otherwise. The function fails if the
irq parameter is greater than the maximum interrupt port number supported by the
interrupt controller.
12.1.1.38. alt_instruction_exception_register()
Prototype
void alt_instruction_exception_register (
alt_exception_result (*handler)
( alt_exception_cause cause,
alt_u32 exception_pc,
alt_u32 bad_addr ))
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
211
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_exceptions.h>
Description
The HAL API function alt_instruction_exception_register() registers an
instruction-related exception handler. The handler argument is a pointer to the
instruction-related exception handler.
You can only use this API function if you have enabled the
hal.enable_instruction_related_exceptions_api setting in the board
support package (BSP).
Return
--
Related Information
Settings Managed by Nios V Processor Board Support Package Editor on page 258
For more comprehensive list of BSP settings for HAL.
12.1.1.39. alt_irq_cpu_enable_interrupts ()
Prototype
void alt_irq_cpu_enable_interrupts ()
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_irq_cpu_enable_interrupts () function enables the CPU to start
taking interrupts.
212
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
--
Related Information
Exception Handling on page 142
12.1.1.40. alt_irq_disable_all()
Prototype
alt_irq_context alt_irq_disable_all (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_irq_disable_all() function disables the processor's interrupt feature by
clearing the Machine-mode Interrupt-Enable bit (mstatus.mie).
Return
Pass the return value as the input argument to a subsequent call to
alt_irq_enable_all().
12.1.1.41. alt_irq_enable_all()
Prototype
void alt_irq_enable_all (alt_irq_context context)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
213
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<sys/alt_irq.h>
Description
The alt_irq_enable_all() function enables the processor's interrupt feature that
were previously disabled by alt_irq_disable_all(). The input argument,
context, is the value returned by a previous call to alt_irq_disable_all().
Using context allows nested calls to alt_irq_disable_all() and
alt_irq_enable_all(). As a result, alt_irq_enable_all() does not
necessarily enable all interrupts, such as interrupts explicitly disabled by
alt_ic_irq_disable().
Return
--
12.1.1.42. alt_irq_enabled()
Prototype
int alt_irq_enabled (void)
Commonly Called By
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
Determines whether interrupts are globally enabled by checking if mstatus.mie bit is
set.
Return
Returns zero if interrupt-enable bit is disabled, and non-zero otherwise.
Related Information
Nios V Processor Hardware Interrupt Service Routines on page 145
12.1.1.43. alt_irq_init()
Prototype
void alt_irq_init (void* base)
Commonly Called By
C/C++ programs
214
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_irq_init() function calls the initilization macros for all interrupt controllers
in the system at config time, before any other non-interrupt controller driver is
initialized. The base parameter is ignored and only present for backwards-
compatibility. Intel recommended that NULL is passed in for the base parameter.
Return
--
12.1.1.44. alt_irq_pending ()
Prototype
void alt_irq_pending (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_irq.h>
Description
The alt_irq_pending () function returns a bit list of the current pending
interrupts. This is used by alt_irq_handler() to determine which registered
interrupt handlers should be called. This routine is only available for the Nios V
internal interrupt controller.
Return
--
12.1.1.45. alt_llist_insert()
Prototype
215
12. Nios V Processor Appendix
743810 | 2022.10.31
alt_llist* entry)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_llist.h>
Description
The alt_llist_insert() function inserts the doubly linked list entry entry in the
list list. This operation is not reentrant. For example, if a list can be manipulated
from different threads, or from within both application code and an ISR, some
mechanism is required to protect access to the list. Interrupts can be disabled, or in
MicroC/OS-II, a mutex can be used.
Return
--
12.1.1.46. alt_llist_remove()
Prototype
void alt_llist_remove(alt_llist* entry)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_llist.h>
Description
The alt_llist_remove() function removes the doubly linked list entry entry from
the list it is currently a member of. This operation is not reentrant. For example if a list
can be manipulated from different threads, or from within both application code and
an ISR, some mechanism is required to protect access to the list. Interrupts can be
locked, or in MicroC/OS-II, a mutex can be used.
216
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
--
12.1.1.47. alt_load_section()
Prototype
alt_u32* to,
alt_u32* end)
Commonly Called By
C/C++ programs
Thread-safe
No.
Include
<sys/alt_load.h>
Description
When operating in run-from-flash mode, the sections .exceptions, .rodata,
and .rwdata are automatically loaded from the boot device to RAM at boot time.
However, if there are any additional sections that require loading, the
alt_load_section() function loads them manually before these sections are used.
The input argument from is the start address in the boot device of the section; to is
the start address in RAM of the section, and end is the end address in RAM of the
section.
To load one of the additional memory sections provided by the default linker script,
use the macro ALT_LOAD_SECTION_BY_NAME rather than calling
alt_load_section() directly. For example, to load the section .onchip_ram, use
the following code:
ALT_LOAD_SECTION_BY_NAME(onchip_ram);
The leading ‘.’ is omitted in the section name. This macro is defined in the header
sys/alt_load.h.
Return
--
217
12. Nios V Processor Appendix
743810 | 2022.10.31
12.1.1.48. alt_nticks()
Prototype
alt_u32 alt_nticks (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<sys/alt_alarm.h>
Description
The alt_nticks() function.
Return
Returns the number of elapsed system clock tick since reset. It returns zero if there is
no system clock available.
12.1.1.49. alt_read_flash()
Prototype
int offset,
void* dest_addr,
int length)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_flash.h>
218
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The alt_read_flash() function reads data from flash. length bytes are read from
the flash fd, starting offset bytes from the beginning of the flash and are written to
the location dest_addr.
The only valid values for the fd parameter are those returned from the
alt_flash_open_dev function. If any other value is passed, the behavior of this
function is undefined.
Return
The return value is zero on success and nonzero otherwise.
12.1.1.50. alt_tick()
Prototype
void alt_tick (void)
Commonly Called By
Device drivers
Thread-safe
No.
Include
<sys/alt_alarm.h>
Description
Only the system clock driver may call the alt_tick() function. The driver is
responsible for making periodic calls to this function at the rate specified in the call to
alt_sysclk_init(). This function provides notification to the system that a system
clock tick has occurred. This function runs as a part of the ISR for the system clock
driver.
Return
--
12.1.1.51. alt_ticks_per_second()
Prototype
alt_u32 alt_ticks_per_second (void)
Commonly Called By
C/C++ programs
Device drivers
219
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
Yes.
Include
<sys/alt_alarm.h>
Description
The alt_ticks_per_second() function returns the number of system clock ticks
that elapse per second. If there is no system clock available, the return value is zero.
Return
Returns the number of system clock ticks that elapse per second.
12.1.1.52. alt_timestamp()
Prototype
alt_u32 alt_timestamp (void)
Commonly Called By
C/C++ programs
Thread-safe
See description.
Include
<sys/alt_timestamp.h>
Description
The alt_timestamp() function returns the current value of the timestamp counter.
For more information, refer to “Using Timer Devices” in the "Developing Programs
Using the Hardware Abstraction Layer" chapter.
Return
Returns the current value of the timestamp counter.
220
12. Nios V Processor Appendix
743810 | 2022.10.31
12.1.1.53. alt_timestamp_freq()
Prototype
alt_u32 alt_timestamp_freq (void)
Commonly Called By
C/C++ programs
Thread-safe
See description.
Include
<sys/alt_timestamp.h>
Description
The alt_timestamp_freq() function returns the rate at which the timestamp
counter increments.
For more information, refer to “Using Timer Devices” in the "Developing Programs
Using the Hardware Abstraction Layer" chapter.
Return
The returned value is the number of counter ticks per second.
12.1.1.54. alt_timestamp_start()
Prototype
int alt_timestamp_start (void)
Commonly Called By
C/C++ programs
Thread-safe
See description.
Include
<sys/alt_timestamp.h>
Description
The alt_timestamp_start() function starts the system timestamp counter.
221
12. Nios V Processor Appendix
743810 | 2022.10.31
For more information, refer to “Using Timer Devices” in the "Developing Programs
Using the Hardware Abstraction Layer" chapter.
This function resets the counter to zero, and starts the counter running.
Return
The return value is zero on success and nonzero otherwise.
12.1.1.55. alt_write_flash()
Prototype
int offset,
int length)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_flash.h>
Description
The alt_write_flash() function writes data to flash. The data to be written is at
address src_addr. length bytes are written to the flash fd, offset bytes from the
beginning of the flash device address space.
Call this function only when operating in single-threaded mode. This function does not
preserve any unwritten areas of any flash sectors affected by this write.
The only valid values for the fd parameter are those returned from the
alt_flash_open_dev function. If any other value is passed, the behavior of this
function is undefined.
Return
The return value is zero on success and nonzero otherwise.
222
12. Nios V Processor Appendix
743810 | 2022.10.31
12.1.1.56. alt_write_flash_block()
Prototype
int block_offset,
int data_offset,
int length)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_flash.h>
Description
The alt_write_flash_block() function writes one block of data to flash. The data
to be written is at address data. length bytes are written to the flash fd, into the
block starting at offset block_offset from the beginning of the flash address space.
The data starts at offset data_offset from the beginning of the flash address space.
The only valid values for the fd parameter are those returned from the
alt_flash_open_dev function. If any other value is passed, the behavior of this
function is undefined.
Return
The return value is zero on success and nonzero otherwise.
12.1.1.57. close()
Prototype
int close (int fd)
Commonly Called By
C/C++ programs
223
12. Nios V Processor Appendix
743810 | 2022.10.31
Device drivers
Thread-safe
See description.
Include
<unistd.h>
Description
The close() function is the standard UNIX-style close() function, which closes the
file descriptor fd.
Valid values for the fd parameter are: stdout, stdin, and stderr, or any value
returned from a call to open().
Return
The return value is zero on success, and –1 otherwise. If an error occurs, errno is set
to indicate the cause.
12.1.1.58. fstat()
Prototype
int fstat (int fd, struct stat *st)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/stat.h>
Description
The fstat() function obtains information about the capabilities of an open file
descriptor. The underlying device driver fills in the input st structure with a
description of its functionality. Refer to the header file sys/stat.h provided with the
compiler for the available options.
224
12. Nios V Processor Appendix
743810 | 2022.10.31
By default, file descriptors are marked as character devices, unless the underlying
driver provides its own implementation of the fstat() function.
Valid values for the fd parameter are: stdout, stdin, and stderr, or any value
returned from a call to open().
Return
The return value is zero on success, or –1 otherwise. If the call fails, errno is set to
indicate the cause of the error.
12.1.1.59. fork()
Prototype
pid_t fork (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<unistd.h>
Description
The fork() function is only provided for compatibility with newlib.
Return
Calls to fork() always fails with the return code –1 and errno set to ENOSYS.
12.1.1.60. fcntl()
Prototype
int fcntl(int fd, int cmd)
Commonly Called By
C/C++ programs
Thread-safe
No.
225
12. Nios V Processor Appendix
743810 | 2022.10.31
Include
<unistd.h>
<fcntl.h>
Description
The fcntl() function is a limited implementation of the standard fcntl() system
call, which can change the state of the flags associated with an open file descriptor.
Normally these flags are set during the call to open(). The main use of this function
is to change the state of a device from blocking to nonblocking (for device drivers that
support this feature).
The input argument fd is the file descriptor to be manipulated. cmd is the command
to execute, which can be either F_GETFL (return the current value of the flags) or
F_SETFL (set the value of the flags).
Return
If cmd is F_SETFL, the argument arg is the new value of flags, otherwise arg is
ignored. Only the flags O_APPEND and O_NONBLOCK can be updated by a call to
fcntl(). All other flags remain unchanged. The return value is zero on success, or –1
otherwise.
If cmd is F_GETFL, the return value is the current value of the flags. If an error
occurs, –1 is returned.
12.1.1.61. execve()
Prototype
Commonly Called By
C/C++ programs
Thread-safe
Yes.
Include
<unistd.h>
Description
The execve() function is only provided for compatibility with newlib.
226
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
Calls to execve() always fail with the return code –1 and errno set to ENOSYS.
12.1.1.62. getpid()
Prototype
pid_t getpid (void)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<unistd.h>
Description
The getpid() function is provided for newlib compatibility and obtains the current
process ID.
Return
Because HAL systems cannot contain multiple processes, getpid() always returns
the same ID number.
12.1.1.63. kill()
Prototype
int kill(int pid, int sig)
Commonly Called By
newlib C library
Thread-safe
Yes.
Include
<signal.h>
227
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The kill() function is used by newlib to send signals to processes. The input
argument pid is the ID of the process to signal, and sig is the signal to send. As
there is only a single process in the HAL, the only valid values for pid are either the
current process ID, as returned by getpid(), or the broadcast values, that is, pid
must be less than or equal to zero.
The following signals result in an immediate shutdown of the system, without call to
exit(): SIGABRT, SIGALRM, SIGFPE, SIGILL, SIGKILL, SIGPIPE, SIGQUIT,
SIGSEGV, SIGTERM, SIGUSR1, SIGUSR2, SIGBUS, SIGPOLL, SIGPROF, SIGSYS,
SIGTRAP, SIGVTALRM, SIGXCPU, and SIGXFSZ.
Return
The return value is zero on success, or –1 otherwise. If the call fails, errno is set to
indicate the cause of the error.
12.1.1.64. stat()
Prototype
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/stat.h>
Description
The stat() function is similar to the fstat() function—It obtains status information
about a file. Instead of using an open file descriptor, like fstat(), stat() takes the
name of a file as an input argument.
Calls to stat() are thread-safe only if the implementation of stat() provided by the
driver that is manipulated is thread-safe.
228
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
--
12.1.1.65. settimeofday()
Prototype
Commonly Called By
C/C++ programs
Thread-safe
No.
Include
<sys/time.h>
Description
Sets the current time and timezone. If the settimeofday() function is called
concurrently with a call to gettimeofday(), the value returned by
gettimeofday() is unreliable.
Return
The return value is zero on success. If no system clock is available, the return value is
-1, and errno is set to ENOSYS.
12.1.1.66. wait()
Prototype
int wait(int *status)
Commonly Called By
newlib C library
Thread-safe
Yes.
Include
<sys/wait.h>
229
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
newlib uses the wait() function to wait for all child processes to exit. Because the
HAL does not support spawning child processes, this function returns immediately.
Return
On return, the content of status is set to zero, which indicates there is no child
processes.
The return value is always –1 and errno is set to ECHILD, which indicates that there
are no child processes to wait for.
12.1.1.67. unlink()
Prototype
int unlink(char *name)
Commonly Called By
newlib C library
Thread-safe
Yes.
Include
<unistd.h>
Description
The unlink() function is only provided for compatibility with newlib.
Return
Calls to unlink() always fails with the return code –1 and errno set to ENOSYS.
12.1.1.68. sbrk()
Prototype
caddr_t sbrk(int incr)
Commonly Called By
newlib C library
Thread-safe
No.
Include
<unistd.h>
230
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The sbrk() function dynamically extends the data segment for the application. The
input argument incr is the size of the block to allocate. Do not call sbrk() directly.
If you want to dynamically allocate memory, use the newlib malloc() function.
Return
--
12.1.1.69. link()
Prototype
int link(const char *_path1,
const char *_path2)
Commonly Called By
newlib C library
Thread-safe
Yes.
Include
<unistd.h>
Description
The link() function is only provided for compatibility with newlib.
Return
Calls to link() always fails with the return code –1 and errno set to ENOSYS.
12.1.1.70. lseek()
Prototype
off_t lseek(int fd, off_t ptr, int whence)
Commonly Called By
C/C++ programs
newlib C library
Thread-safe
See description.
Include
<unistd.h>
231
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The lseek() function moves the read/write pointer associated with the file descriptor
fd. lseek() is wrapper function that passes control directly to the lseek() function
registered for the driver associated with the file descriptor. If the driver does not
provide an implementation of lseek(), an error is reported.
You can use the following values for the input parameter, whence:
• SEEK_SET—The offset is set to ptr bytes.
• SEEK_CUR—The offset is incremented by ptr bytes.
• SEEK_END—The offset is set to the end of the file plus ptr bytes.
Calls to lseek() are thread-safe only if the implementation of lseek() provided
by the driver that is manipulated is thread-safe.
Valid values for the fd parameter are: stdout, stdin, and stderr, or any value
returned from a call to open().
Return
On success, the return value is a nonnegative file pointer. The return value is –1 in the
event of an error. If the call fails, errno is set to indicate the cause of the error.
12.1.1.71. open()
Prototype
int open (const char* pathname, int flags, mode_t mode)
Commonly Called By
C/C++ programs
Thread-safe
See description.
Include
<unistd.h>
<fcntl.h>
Description
The open() function opens a file or device and returns a file descriptor (a small,
nonnegative integer for use in read, write, etc.)
flags is one of: O_RDONLY, O_WRONLY, or O_RDWR, which request opening the file in
read-only, write-only, or read/write mode, respectively.
You can also bitwise-OR flags with O_NONBLOCK, which causes the file to be opened
in nonblocking mode. Neither open() nor any subsequent operation on the returned
file descriptor causes the calling function to wait.
232
12. Nios V Processor Appendix
743810 | 2022.10.31
mode specifies the permissions to use, if a new file is created. It is unused by current
file systems, but is maintained for compatibility.
Calls to open() are thread-safe only if the implementation of open() provided by the
driver that is manipulated is thread-safe.
Return
The return value is the new file descriptor, and –1 otherwise. If an error occurs, errno
is set to indicate the cause.
12.1.1.72. alt_sysclk_init()
Prototype
int alt_sysclk_init (alt_u32 nticks)
Commonly Called By
Device drivers
Thread-safe
No.
Include
<sys/alt_alarm.h>
Description
The alt_sysclk_init() function registers the presence of a system clock driver.
The input argument is the number of ticks per second at which the system clock is
run.
The expectation is that this function is only called from within alt_sys_init(), that
is, while the system is running in single-threaded mode. Concurrent calls to this
function might lead to unpredictable results.
Return
This function returns zero on success; otherwise it returns a negative value. The call
can fail if a system clock driver is already registered, or if no system clock device is
available.
12.1.1.73. times()
Prototype
clock_t times (struct tms *buf)
Commonly Called By
C/C++ programs
233
12. Nios V Processor Appendix
743810 | 2022.10.31
Device drivers
Thread-safe
Yes.
Include
<sys/times.h>
Description
This times() function is provided for compatibility with newlib. It returns the number
of clock ticks since reset. It also fills in the structure pointed to by the input parameter
buf with time accounting information. The definition of the tms structure is:
typedef struct
{
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};
Return
If there is no system clock available, the return value is zero, and errno is set to
ENOSYS.
12.1.1.74. read()
Prototype
int read(int fd, void *ptr, size_t len)
Commonly Called By
C/C++ programs
Device drivers
234
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
See description.
Include
<unistd.h>
Description
The read() function reads a block of data from a file or device. read() is wrapper
function that passes control directly to the read() function registered for the device
driver associated with the open file descriptor fd. The input argument, ptr, is the
location to place the data read and len is the length of the data to read in bytes.
Calls to read() are thread-safe only if the implementation of read() provided by the
driver that is manipulated is thread-safe.
Valid values for the fd parameter are: stdout, stdin, and stderr, or any value
returned from a call to open().
Return
The return argument is the number of bytes read, which might be less than the
requested length
The return value is –1 upon an error. In the event of an error, errno is set to indicate
the cause.
12.1.1.75. write()
Prototype
int write(int fd, const void *ptr, size_t len)
Commonly Called By
C/C++ programs
newlib C library
Thread-safe
See description.
Include
<unistd.h>
235
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The write() function writes a block of data to a file or device. write() is wrapper
function that passes control directly to the write() function registered for the device
driver associated with the file descriptor fd. The input argument ptr is the data to
write and len is the length of the data in bytes.
Valid values for the fd parameter are: stdout, stdin, and stderr, or any value
returned from a call to open().
Return
The return argument is the number of bytes written, which might be less than the
requested length.
The return value is –1 upon an error. In the event of an error, errno is set to indicate
the cause.
12.1.1.76. usleep()
Prototype
int usleep (unsigned int us)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
Yes.
Include
<unistd.h>
Description
The usleep() function blocks until at least us microseconds have elapsed.
Return
The usleep() function returns zero on success, or –1 otherwise. If an error occurs,
errno is set to indicate the cause. The current implementation always succeeds.
12.1.1.77. alt_lock_flash()
Prototype
alt_u32 sectors_to_lock)
236
12. Nios V Processor Appendix
743810 | 2022.10.31
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_flash.h>
Description
Locking to range of the flash memory sectors, which protected from writing and
erasing by passing the uninteger 32 bits value to the sectors_to_lock argument, where
this argument depends on the specific flash device being used,and this argument
value can be found in the flash device datasheet. The flash devices can be supported
are shown as below:
More Micron flash devices are supported in future, and being updated into this
document.
Arguments
• *flash_info: Pointer to general flash device structure.
• sectors_to_lock: Block protection bits, including the top/bottom (TB) bit in the
EPCQ or QSPI, according to the device. For example, in the EPCQ128 device, the
bits are Bit4=TB Bit3=BP3 Bit2=BP2 Bit1=BP1 Bit0=BP0.
Return
• *0 ➤ Success
• -EINVL ➤ Invalid arguments
• -ETIME ➤ Time out and skipping the looping after 0.7 sec
• -ENOLCK ➤ Sectors lock failed
12.1.1.78. gettimeofday()
Prototype
Commonly Called By
C/C++ programs
Device drivers
237
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
See description.
Include
<sys/time.h>
Description
The gettimeofday() function obtains a time structure that indicates the current
time. This time is calculated using the elapsed number of system clock ticks, and the
current time value set by the most recent call to settimeofday().
Return
The return value is zero on success. If no system clock is available, the return value is
-ENOTSUP.
12.1.1.79. ioctl()
Prototype
int ioctl (int fd, int req, void* arg)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/ioctl.h>
Description
The ioctl() function allows application code to manipulate the I/O capabilities of a
device driver in driver-specific ways. This function is equivalent to the standard UNIX
ioctl() function. The input argument fd is an open file descriptor for the device to
manipulate, req is an enumeration defining the operation request, and the
interpretation of arg is request specific.
For file subsystems, ioctl() is wrapper function that passes control directly to the
appropriate device driver’s ioctl() function (as registered in the driver’s alt_dev
structure).
238
12. Nios V Processor Appendix
743810 | 2022.10.31
For devices, ioctl() handles TIOCEXCL and TIOCNXCL requests internally, without
calling the device driver. These requests lock and release a device for exclusive
access. For requests other than TIOCEXCL and TIOCNXCL, ioctl() passes control to
the device driver’s ioctl() function.
Valid values for the fd parameter are: stdout, stdin, and stderr, or any value
returned from a call to open().
Return
The interpretation of the return value is request specific. If the call fails, errno is set
to indicate the cause of the error.
12.1.1.80. isatty()
Prototype
int isatty(int fd)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<unistd.h>
Description
The isatty() function determines whether the device associated with the open file
descriptor fd is a terminal device. This implementation uses the driver’s fstat()
function to determine its reply.
Return
The return value is 1 if the device is a character device, and zero otherwise. If an error
occurs, errno is set to indicate the cause.
12.1.1.81. alt_niosv_enable_msw_interrupt()
Prototype
void alt_niosv_enable_msw_interrupt()
239
12. Nios V Processor Appendix
743810 | 2022.10.31
Commonly Called By
C/C++ programs
Thread-safe
Yes.
Include
<sys/msw_interrupt.h>
Description
The alt_niosv_enable_msw_interrupt() function enables the machine software
interrupt.
Return
--
12.1.1.82. alt_niosv_disable_msw_interrupt()
Prototype
void alt_niosv_disable_msw_interrupt()
Commonly Called By
C/C++ programs
Thread-safe
Yes.
Include
<sys/msw_interrupt.h>
Description
The alt_niosv_disable_msw_interrupt() function disables the machine
software interrupt.
Return
--
12.1.1.83. alt_niosv_is_msw_interrupt_enabled()
Prototype
int alt_niosv_is_msw_interrupt_enabled()
Commonly Called By
C/C++ programs
240
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
Yes.
Include
<sys/msw_interrupt.h>
Description
The int alt_niosv_is_msw_interrupt_enabled() function determines whether
the machine software interrupt is enabled.
Return
Returns zero if the machine software interrupt is disabled, and nonzero otherwise.
12.1.1.84. alt_niosv_trigger_msw_interrupt()
Prototype
void alt_niosv_trigger_msw_interrupt()
Commonly Called By
C/C++ programs
Thread-safe
Yes.
Include
<sys/msw_interrupt.h>
Description
Return
--
12.1.1.85. alt_niosv_clear_msw_interrupt()
Prototype
alt_niosv_clear_msw_interrupt()
Commonly Called By
C/C++ programs
241
12. Nios V Processor Appendix
743810 | 2022.10.31
Thread-safe
Yes.
Include
<sys/msw_interrupt.h>
Description
Return
--
12.1.1.86. alt_niosv_register_msw_interrupt_handler()
Prototype
void alt_niosv_register_msw_interrupt_handler(alt_niosv_sw_isr_t
handle)
Commonly Called By
C/C++ programs
Thread-safe
Yes.
Include
<sys/msw_interrupt.h>
Description
The alt_niosv_register_msw_interrupt_handler() function registers a
software ISR.
Return
--.
242
12. Nios V Processor Appendix
743810 | 2022.10.31
12.1.2.1. alt_getchar()
Prototype
alt_getchar()
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_driver.h>
<sys/alt_stdio.h>
<priv/alt_file.h>
<unistd.h>
Description
The alt_getchar() function uses the ALT_DRIVER_READ() macro to call directly to
the driver, if available; otherwise, it uses the newlib provided getchar() routine.
Return
--
243
12. Nios V Processor Appendix
743810 | 2022.10.31
12.1.2.2. alt_putstr()
Prototype
alt_putstr(const char* str)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_driver.h>
<sys/alt_stdio.h>
Description
The alt_putstr() function ses the ALT_DRIVER_WRITE() macro to call directly to
the driver, if available; otherwise, it uses the newlib provided fputs() routine.
Return
The return value is zero on success and nonzero otherwise.
12.1.2.3. alt_putchar()
Prototype
alt_putchar(int c)
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
See description.
Include
<sys/alt_driver.h>
<sys/alt_stdio.h>
Description
The alt_putchar() function uses the ALT_DRIVER_WRITE() macro to call directly to
the driver, if available; otherwise, it uses the newlib provided putchar() routine.
244
12. Nios V Processor Appendix
743810 | 2022.10.31
Return
The return value is zero on success and nonzero otherwise.
12.1.2.4. alt_printf()
Prototype
alt_printf(const char* fmt, ... )
Commonly Called By
C/C++ programs
Device drivers
Thread-safe
No.
Include
<sys/alt_stdio.h>
Description
The alt_printf() function provides a very minimal printf implementation for use
with very small applications. Only the following format strings are supported: %x, %s,
%c, and %%.
Return
--
The Nios V processor tools are command line utilities that are available when you use
the Nios V Command Shell. It enables you to create applications, board support
package (BSP), and library software for a particular Nios V processor hardware
system. Nios V processor tools create a portable, cross-platform CMake-based project
that can be easily modified later to suit your build flow. Proficient use of these tools for
customization requires some expertise with CMake. The following sections summarize
the details of the build tools utilities command and settings and TCL scripting available
for generating a BSP and application software for your hardware design. There are
many additional options that you can customize using Nios V processor tools.
245
12. Nios V Processor Appendix
743810 | 2022.10.31
All Nios V processor command line utilities tools share the following behavior:
• Send error messages and warning messages to stderr.
• Send messages (other than errors and warnings) to stdout.
• Display one error message for each error.
• Return an exit value of 1 if the tool detects any errors.
• Return an exit value of 0 if the tool does not detect any errors. (Warnings are not
errors).
• If the help or version command line option is specified,
— Return an exit value of 0, and take no other action.
— Send the output (help or version number) to stdout.
• When an error is detected, suppresses all subsequent operations (such as writing
files).
The Nios V processor command line tools described in this section are in the <Intel
Quartus Prime software installation directory>/niosv/bin directory.
Related Information
• niosv-bsp on page 12
• niosv-app on page 13
• niosv-download on page 13
12.2.1.1. niosv-shell
Description
Launch the Nios V Command Shell to run Nios V processor command line utilities
tools.
Usage
niosv-shell
Related Information
Nios V Command Shell on page 17
12.2.1.2. niosv-bsp
Synopsis
246
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
Create, update, generate, or query a BSP. You must specifiy one of the following
commands.
• create (-c)
• update (-u)
• generate (-g)
• query (-q)
A .bsp settings file is always required. When creating a BSP, specify a .qsys file (-s)
and type (-t) . Intel recommends specifying a .qpf file (-p) so that settings used are
from the Intel Quartus Prime project.
Usage
# create settings
niosv-bsp -c -p=<.qpf> -s=<.qsys> -t=<bsp-type> [OPTIONS] settings_file
# update settings
niosv-bsp -u [OPTIONS] <BSP FILE>
# generate settings
niosv-bsp -g [OPTIONS] <BSP FILE>
# query settings
niosv-bsp -q [OPTIONS] <BSP FILE>
Functions
247
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
Options Description
248
12. Nios V Processor Appendix
743810 | 2022.10.31
Options Description
--jvm-max-heap-size=<value> • Optional.
• The maximum memory size to be used for allocations when running this tool.
• This value is specified as <size><unit> where unit can be m (or M) for
multiples of megabytes or g (or G) for multiples of gigabytes.
• The default value is 512m.
--help • Optional.
• Display help for this tool.
12.2.1.3. niosv-app
Synopsis
Description
Usage
Options
Options Description
249
12. Nios V Processor Appendix
743810 | 2022.10.31
Options Description
--jvm-max-heap-size=<value> • Optional.
• The maximum memory size to be used for allocations when running this tool.
• This value is specified as <size><unit> where unit can be m (or M) for multiples
of megabytes or g (or G) for multiples of gigabytes.
• The default value is 512m.
12.2.1.4. niosv-download
Synopsis
Description
Download an ELF file to a Nios V processor CPU. Optionally reset or resume a Nios V
processor CPU.
Usage
#Download app.elf to the only Nios V instance and run from the entry point.
niosv-download -g app.elf
#Download app.elf to the only Nios V instance, issue a debug reset, then run
from the entry point.
niosv-download -g -r app.elf
Options
Options Description
250
12. Nios V Processor Appendix
743810 | 2022.10.31
Options Description
--cable CABLE,-c CABLE Specify the cable of the targeted Nios V processor.
--device DEVICE, -d DEVICE Specify the device of the targeted Nios V processor.
--device DEVICE, -d DEVICE Specify the instance of the targeted Nios V processor.
12.2.1.5. niosv-stack-report
Synopsis
niosv-stack-report [OPTION] <ELF FILE>
Description
Reports memory available for stack and heap from an .elf file.
Usage
Options
Options Description
Related Information
File Format Conversion Tools on page 18
12.2.2.1. elf2hex
Synopsis
251
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The elf2hex utility converts the software and data within an .elf file in the address
range [base, end] into a .hex file that can be used as the initialization data for a
memory component. The width option is to ensure that the resulting .hex file is
formatted properly for its corresponding memory component.
This utility can also create lane files which are used to initialize multi-laned memory
components.
Usage
Options
Options Description
12.2.2.2. elf2flash
Synopsis
252
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
The elf2flash utility converts the software and data within an ELF file in the address
range [base, end] into a SREC file that can be programmed into the flash memory
connected to an Intel FPGA.
This utility can also optionally insert a boot copier into the FLASH file to copy the
software from flash memory to RAM before running it.
Usage
#Generate flash file in srec format
elf2flash --input software/user_application/app/debug/<user application>.elf --
output flash.srec –epcs –-offset 0x0
Options
Options Description
--after <file> Start output at address immediately following data in specified .flash file
Related Information
Other Utilities Tools on page 19
253
12. Nios V Processor Appendix
743810 | 2022.10.31
12.2.3.1. juart-terminal
Synopsis
Description
Usage
#connect to JTAG UART at cable 1
juart-terminal -c 1
Terminal Options
Terminal Options Description
Connection Options
Target Option
254
12. Nios V Processor Appendix
743810 | 2022.10.31
12.2.3.2. cmake
CMake is the open-source utility tool that manages the build process using
CMakeLists.txt, generated from from the niosv-app and niosv-bsp utilities.
CMake uses the CMakeLists.txt file to generate the build file, used to build
main.elf and libbsp.a. The setting can be changed via setting the CMake
argument -G, --generator. Nios V software build tools are based on Unix Makefile
generator.
Related Information
• CMake
• CMake commands
For more various actions the tool can perform.
12.2.3.3. make
The make utility automatically determines which pieces of a large program need to be
recompiled, and issues commands to recompile them. Make gets its knowledge of how
to build your program from a file called the Makefile, which lists each of the non-
source files and how to compute it from other files.
12.2.3.4. openocd
Nios V processor supports the Open On-Chip Debugger for debugging. Open On-Chip
Debugger(OpenOCD), is an open source GNU Project Debugger(GDB) server
implementation that allows a GDB Client to debug embedded target device. In a
standard setup, OpenOCD translates debugging Remote Serial Protocol instructions
from the GDB client into signals that is understood by the target device, then requests
the device to perform the required action and communicate the result back to the GDB
client.
Synopsis
Description
Usage
255
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
Options Description
-d or -d<n>, --debug or --debug<n> Set debug level to <level>, default value = 3 without <n> argument
Related Information
OpenOCD Developer's Guide
12.2.3.5. openocd-cfg-gen
Synopsis
openocd-cfg-gen [OPTIONS] <CONFIGURATION FILE>
Description
Generate the OpenOCD configuration file, that contain information of the active Test
Access Ports (TAPs) on the device for Nios V processor debugging. You can refer to the
JTAG chain device index when selecting the cable, device and instance.
Usage
#Display the JTAG chain device index
openocd-cfg-gen --print
Options
Option Description
256
12. Nios V Processor Appendix
743810 | 2022.10.31
Refer to Ashling RiscFree IDE for Intel FPGAs User Guide for the installation guide. For
more information about GNU command options, please refer to GCC Command
Options.
257
12. Nios V Processor Appendix
743810 | 2022.10.31
Related Information
• Other Utilities Tools on page 19
• Ashling* RiscFree* Integrated Development Environment (IDE) for Intel® FPGAs
User Guide
This section contains a complete list of available settings for BSPs and for Intel FPGA-
supported device drivers and software packages. It does not include settings for
device drivers or software packages furnished by Intel partners or other third parties.
If you are using a third-party driver or component, refer to the supplier's
documentation.
Settings used in the Nios V processor Board Support Package Editor are organized
hierarchically, for logical grouping and to avoid name conflicts. Each setting's position
in the hierarchy is indicated by one or more prefixes. A prefix is an identifier followed
by a dot (.). For example, hal.enable_c_plus_plus is a hardware abstraction
layer (HAL) setting, while ucosii.event_flag.os_flag_accept_en is a member
of the event flag subgroup of MicroC/OS-II settings.
Related Information
HAL BSP Settings on page 78
For more information about how to control BSP settings.
The format in which you specify the setting value depends on the setting type. Several
settings types are supported.
258
12. Nios V Processor Appendix
743810 | 2022.10.31
Intel HAL Settings available with the Intel HAL BSP or any BSP based
on it (for example, Micrium MicroC/OS-II).
Do not confuse BSP settings with BSP Tcl commands. This section covers BSP settings,
including their types, meanings, and legal values.
hal.enable_instruction_related_exceptions_api
• Identifier:ALT_INCLUDE_INSTRUCTION_RELATED_EXCEPTION_API
• Type: Boolean definition
• Default Value: false
• Destination File: system.h
• Description: Enables application program interface (API) for registering handlers
to service instruction-related exceptions. These exception types can be generated
if various processor options are enabled, such as the memory management unit
(MMU), memory protection unit (MPU), or other advanced exception types.
Enabling this setting increases the size of the exception entry code.
• Restrictions: none
259
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.max_file_descriptors
• Identifier: ALT_MAX_FD
• Type: Decimal number
• Default Value: 32
• Destination File: system.h
• Description: Determines the number of file descriptors statically allocated.
• Restriction: If hal.enable_lightweight_device_driver_api is true, there are no file
descriptors so this setting is ignored. If hal.enable_lightweight_device_driver_api
is false, this setting must be at least 4 because HAL needs a file descriptor
for /dev/null, /dev/stdin, /dev/stdout, and /dev/stderr. This setting defines the
value of ALT_MAX_FD in system.h.
hal.sys_clk_timer
• Identifier: ALT_SYS_CLK
• Type: Unquoted string
• Default Value: none
• Destination File: system.h
• Description: Slave descriptor of the system clock timer device. This device
provides a periodic interrupt ("tick") and is typically required for RTOS use. This
setting defines the value of ALT_SYS_CLK in system.h.
• Restriction: none
hal.timestamp_timer
• Identifier: ALT_TIMESTAMP_CLK
• Type: Unquoted string
• Default Value: none
• Destination File: system.h
• Description: Slave descriptor of timestamp timer device. This device is used by
Intel HAL timestamp drivers for high-resolution time measurement. This setting
defines the value of ALT_TIMESTAMP_CLK in system.h.
• Restriction: none
ucosii.os_max_tasks
• Identifier : OS_MAX_TASKS
• Type: Decimal number
• Default Value: 10
• Destination File: system.h
• Description: Maximum number of tasks
• Restriction: none
260
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.os_lowest_prio
• Identifier: OS_LOWEST_PRIO
• Type: Decimal number
• Default Value: 20
• Destination File: system.h
• Description: Lowest assignable priority
• Restriction: none
ucosii.os_thread_safe_newlib
• Identifier: OS_THREAD_SAFE_NEWLIB
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Thread safe C library
• Restriction: none
ucosii.miscellaneous.os_arg_chk_en
• Identifier: OS_ARG_CHK_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable argument checking
• Restriction: none
ucosii.miscellaneous.os_cpu_hooks_en
• Identifier: OS_CPU_HOOKS_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable MicroC/OS-II hooks
• Restriction: none
ucosii.miscellaneous.os_debug_en
• Identifier: OS_DEBUG_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable debug variables
• Restriction: none
261
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.miscellaneous.os_sched_lock_en
• Identifier: OS_SCHED_LOCK_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSSchedLock() and OSSchedUnlock()
• Restriction: none
ucosii.miscellaneous.os_task_stat_en
• Identifier: OS_TASK_STAT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable statistics task
• Restriction: none
ucosii.miscellaneous.os_task_stat_stk_chk_en
• Identifier: OS_TASK_STAT_STK_CHK_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Check task stacks from statistics task
• Restriction: none
ucosii.miscellaneous.os_tick_step_en
• Identifier: OS_TICK_STEP_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable tick stepping feature for uCOS-View
• Restriction: none
ucosii.miscellaneous.os_event_name_size
• Identifier: OS_EVENT_NAME_SIZE
• Type: Decimal number
• Default Value: 32
• Destination File: system.h
• Description: Size of name of Event Control Block groups
• Restriction: none
262
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.miscellaneous.os_max_events
• Identifier: OS_MAX_EVENTS
• Type: Decimal number
• Default Value: 60
• Destination File: system.h
• Description: Maximum number of event control blocks
• Restriction: none
ucosii.miscellaneous.os_task_idle_stk_size
• Identifier: OS_TASK_IDLE_STK_SIZE
• Type: Decimal number
• Default Value: 512
• Destination File: system.h
• Description: Idle task stack size
• Restriction: none
ucosii.miscellaneous.os_task_stat_stk_size
• Identifier: OS_TASK_STAT_STK_SIZE
• Type: Decimal number
• Default Value: 512
• Destination File: system.h
• Description: Statistics task stack size
• Restriction: none
ucosii.task.os_task_change_prio_en
• Identifier: OS_TASK_CHANGE_PRIO_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskChangePrio()
• Restriction: none
ucosii.task.os_task_create_en
• Identifier: OS_TASK_CREATE_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskCreate()
• Restriction: none
263
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.task.os_task_create_ext_en
• Identifier: OS_TASK_CREATE_EXT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskCreateExt()
• Restriction: none
ucosii.task.os_task_del_en
• Identifier: OS_TASK_DEL_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskDel()
• Restriction: none
ucosii.task.os_task_name_size
• Identifier: OS_TASK_NAME_SIZE
• Type: Decimal number
• Default Value: 32
• Destination File: system.h
• Description: Size of task name
• Restriction: none
ucosii.task.os_task_profile_en
• Identifier: OS_TASK_PROFILE_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include data structure for run-time task profiling
• Restriction: none
ucosii.task.os_task_query_en
• Identifier: OS_TASK_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskQuery
• Restriction: none
264
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.task.os_task_suspend_en
• Identifier: OS_TASK_SUSPEND_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskSuspend() and OSTaskResume()
• Restriction: none
ucosii.task.os_task_sw_hook_en
• Identifier: OS_TASK_SW_HOOK_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTaskSwHook()
• Restriction: none
ucosii.time.os_time_tick_hook_en
• Identifier: OS_TIME_TICK_HOOK_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTimeTickHook()
• Restriction: none
ucosii.time.os_time_dly_resume_en
• Identifier: OS_TIME_DLY_RESUME_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTimeDlyResume()
• Restriction: none
ucosii.time.os_time_dly_hmsm_en
• Identifier: OS_TIME_DLY_HMSM_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTimeDlyHMSM()
• Restriction: none
265
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.time.os_time_get_set_en
• Identifier: OS_TIME_GET_SET_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSTimeGet and OSTimeSet()
• Restriction: none
ucosii.os_flag_en
• Identifier: OS_FLAG_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable code for Event Flags. This setting is enabled by default in
MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
ucosii.event_flag.os_flag_wait_clr_en
• Identifier: OS_FLAG_WAIT_CLR_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for Wait on Clear Event Flags. This setting is enabled
by default in MicroC-OS/II BSPs, because it is required for correct functioning of
Intel FPGA device drivers and the HAL in a multithreaded environment. Avoid
disabling it.
• Restriction: none
ucosii.event_flag.os_flag_accept_en
• Identifier: OS_FLAG_ACCEPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSFlagAccept(). This setting is enabled by default
in MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
ucosii.event_flag.os_flag_del_en
• Identifier: OS_FLAG_DEL_EN
• Type: Boolean assignment
• Default Value: 1
266
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.event_flag.os_flag_query_en
• Identifier: OS_FLAG_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSFlagQuery(). This setting is enabled by default in
MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
ucosii.event_flag.os_flag_name_size
• Identifier: OS_FLAG_NAME_SIZE
• Type: Decimal number
• Default Value: 32
• Destination File: system.h
• Description: Size of name of Event Flags group. CAUTION: This is required by the
HAL and many Intel FPGA device drivers; use caution in reducing this value.
• Restriction: none
ucosii.event_flag.os_flags_nbits
• Identifier: OS_FLAGS_NBITS
• Type: Decimal number
• Default Value: 16
• Destination File: system.h
• Description: Event Flag bits (8,16,32). CAUTION: This is required by the HAL and
many Intel FPGA device drivers; use caution in changing this value.
• Restriction: none
ucosii.event_flag.os_max_flags
• Identifier: OS_MAX_FLAGS
• Type: Decimal number
• Default Value: 20
• Destination File: system.h
• Description: Maximum number of Event Flags groups. CAUTION: This is required
by the HAL and many Intel FPGA device drivers; use caution in reducing this
value.
• Restriction: none
267
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.os_mutex_en
• Identifier: OS_MUTEX_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable code for Mutex Semaphores
• Restriction: none
ucosii.mutex.os_mutex_accept_en
• Identifier: OS_MUTEX_ACCEPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMutexAccept()
• Restriction: none
ucosii.mutex.os_mutex_del_en
• Identifier: OS_MUTEX_DEL_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMutexDel()
• Restriction: none
ucosii.mutex.os_mutex_query_en
• Identifier: OS_MUTEX_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMutexQuery
• Restriction: none
ucosii.os_sem_en
• Identifier: OS_SEM_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable code for semaphores. This setting is enabled by default in
MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
268
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.semaphore.os_sem_accept_en
• Identifier: OS_SEM_ACCEPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSSemAccept(). This setting is enabled by default
in MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
ucosii.semaphore.os_sem_set_en
• Identifier: OS_SEM_SET_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSSemSet(). This setting is enabled by default in
MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
ucosii.semaphore.os_sem_del_en
• Identifier: OS_SEM_DEL_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSSemDel(). This setting is enabled by default in
MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
ucosii.semaphore.os_sem_query_en
• Identifier: OS_SEM_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSSemQuery(). This setting is enabled by default
in MicroC-OS/II BSPs, because it is required for correct functioning of Intel FPGA
device drivers and the HAL in a multithreaded environment. Avoid disabling it.
• Restriction: none
269
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.os_mbox_en
• Identifier: OS_MBOX_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable code for mailboxes
• Restriction: none
ucosii.mailbox.os_mbox_accept_en
• Identifier: OS_MBOX_ACCEPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMboxAccept()
• Restriction: none
ucosii.mailbox.os_mbox_del_en
• Identifier: OS_MBOX_DEL_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMboxDel()
• Restriction: none
ucosii.mailbox.os_mbox_post_en
• Identifier: OS_MBOX_POST_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMboxPost()
• Restriction: none
ucosii.mailbox.os_mbox_post_opt_en
• Identifier: OS_MBOX_POST_OPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMboxPostOpt()
• Restriction: none
270
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.mailbox.os_mbox_query_en
• Identifier: OS_MBOX_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMboxQuery()
• Restriction: none
ucosii.os_q_en
• Identifier: OS_Q_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable code for Queues
• Restriction: none
ucosii.queue.os_q_accept_en
• Identifier: OS_Q_ACCEPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSQAccept()
• Restriction: none
ucosii.queue.os_q_del_en
• Identifier: OS_Q_DEL_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSQDel()
• Restriction: none
ucosii.queue.os_q_flush_en
• Identifier: OS_Q_FLUSH_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSQFlush()
• Restriction: none
271
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.queue.os_q_post_en
• Identifier: OS_Q_POST_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code of OSQFlush()
• Restriction: none
ucosii.queue.os_q_post_front_en
• Identifier: OS_Q_POST_FRONT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSQPostFront()
• Restriction: none
ucosii.queue.os_q_post_opt_en
• Identifier: OS_Q_POST_OPT_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSQPostOpt()
• Restriction: none
ucosii.queue.os_q_query_en
• Identifier: OS_Q_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSQQuery()
• Restriction: none
ucosii.queue.os_max_qs
• Identifier: OS_MAX_QS
• Type: Decimal number
• Default Value: 20
• Destination File: system.h
• Description: Maximum number of Queue Control Blocks
• Restriction: none
272
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.os_mem_en
• Identifier: OS_MEM_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Enable code for memory management
• Restriction: none
ucosii.memory.os_mem_query_en
• Identifier: OS_MEM_QUERY_EN
• Type: Boolean assignment
• Default Value: 1
• Destination File: system.h
• Description: Include code for OSMemQuery()
• Restriction: none
ucosii.memory.os_mem_name_size
• Identifier: OS_MEM_NAME_SIZE
• Type: Decimal number
• Default Value: 32
• Destination File: system.h
• Description: Size of memory partition name
• Restriction: none
ucosii.memory.os_max_mem_part
• Identifier: OS_MAX_MEM_PART
• Type: Decimal number
• Default Value: 60
• Destination File: system.h
• Description: Maximum number of memory partitions
• Restriction: none
ucosii.os_tmr_en
• Identifier: OS_TMR_EN
• Type: Boolean assignment
• Default Value: 0
• Destination File: system.h
• Description: Enable code for timers
• Restriction: none
273
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.timer.os_task_tmr_stk_size
• Identifier: OS_TASK_TMR_STK_SIZE
• Type: Decimal number
• Default Value: 512
• Destination File: system.h
• Description: Stack size for timer task
• Restriction: none
ucosii.timer.os_task_tmr_prio
• Identifier: OS_TASK_TMR_PRIO
• Type: Decimal number
• Default Value: 2
• Destination File: system.h
• Description: Priority of timer task (0=highest)
• Restriction: none
ucosii.timer.os_tmr_cfg_max
• Identifier: OS_TMR_CFG_MAX
• Type: Decimal number
• Default Value: 16
• Destination File: system.h
• Description: Maximum number of timers
• Restriction: none
ucosii.timer.os_tmr_cfg_name_size
• Identifier: OS_TMR_CFG_NAME_SIZE
• Type: Decimal number
• Default Value: 16
• Destination File: system.h
• Description: Size of timer name
• Restriction: none
ucosii.timer.os_tmr_cfg_ticks_per_sec
• Identifier: OS_TMR_CFG_TICKS_PER_SEC
• Type: Decimal number
• Default Value: 10
• Destination File: system.h
• Description: Rate at which timer management task runs (Hz)
• Restriction: none
274
12. Nios V Processor Appendix
743810 | 2022.10.31
ucosii.timer.os_tmr_cfg_wheel_size
• Identifier: OS_TMR_CFG_WHEEL_SIZE
• Type: Decimal number
• Default Value: 2
• Destination File: system.h
• Description: Size of timer wheel (number of spokes)
• Restriction: none
altera_avalon_uart_driver.enable_small_driver
• Identifier: ALTERA_AVALON_UART_SMALL
• Type: Boolean definition
• Default Value: false
• Destination File: toolchain.cmake
• Description: Small-footprint (polled mode) driver
• Restriction: none
altera_avalon_uart_driver.enable_ioctl
• Identifier: ALTERA_AVALON_UART_USE_IOCTL
• Type: Boolean definition
• Default Value: false
• Destination File: toolchain.cmake
• Description: Enable driver ioctl() support. This feature is not compatible with the
small driver; ioctl() support is not compiled if either the UART
enable_small_driver or the HAL enable_reduced_device_drivers setting
is enabled.
• Restriction: none
altera_avalon_jtag_uart_driver.enable_small_driver
• Identifier: ALTERA_AVALON_JTAG_UART_SMALL
• Type: Boolean definition
• Default Value: false
• Destination File: toolchain.cmake
• Description: Small-footprint (polled mode) driver
• Restriction: none
altera_avalon_uart_driver.enable_jtag_uart_ignore_fifo_full_error
• Identifier: ALTERA_AVALON_JTAG_UART_IGNORE_FIFO_FULL_ERROR
• Type: Boolean definition
• Default Value: false
275
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.linker.allow_code_at_reset
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: none
• Description: Indicates if initialization code is allowed at the reset address. If true,
defines the macro ALT_ALLOW_CODE_AT_RESET in linker.h.
• Restriction: This setting is typically false if an external bootloader (e.g. flash
bootloader) is present.
hal.linker.enable_alt_load
• Identifier: none
• Type: Boolean assignment
• Default Value: 1
• Destination File: none
• Description: Enables the alt_load() facility. The alt_load() facility copies sections
from the .text memory into RAM. If true, this setting sets up the VMA/LMA
(virtual memory address/low memory address) of sections in linker.x to allow
them to be loaded into the .text memory.
• Restriction: This setting is typically false if an external bootloader (e.g. flash
bootloader) is present.
hal.linker.enable_alt_load_copy_exceptions
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: none
• Description: Causes the alt_load() facility to copy the .exceptions section. If
true, this setting defines the macro ALT_LOAD_COPY_EXCEPTIONS in linker.h.
• Restriction: none
hal.linker.enable_alt_load_copy_rodata
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: none
• Description: Causes the alt_load() facility to copy the .rodata section. If true,
this setting defines the macro ALT_LOAD_COPY_RODATA in linker.h.
• Restriction: none
276
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.linker.enable_alt_load_copy_rwdata
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: none
• Description: Causes the initialization code to copy the .rwdata section. If true,
this setting defines the macro ALT_LOAD_COPY_RWDATA in linker.h.
• Restriction: none
hal.linker.enable_exception_stack
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: none
• Description: Enables use of a separate exception stack. If true, defines the
macro ALT_EXCEPTION_STACK in linker.h, adds a memory region called
exception_stack to linker.x, and provides the symbols
__alt_exception_stack_pointer and __alt_exception_stack_limit in linker.x.
• Restriction: The hal.linker.exception_stack_size and
hal.linker.exception_stack_memory_region_name settings must also be valid. This
setting must be false for MicroC/OS-II BSPs. The exception stack can be used to
improve interrupt and other exception performance if an EIC is not implemented.
hal.linker.exception_stack_memory_region_name
• Identifier: none
• Type: Unquoted string
• Default Value: none
• Destination File: none
• Description: Name of the existing memory region to be divided up to create the
exception_stack memory region. The selected region name is adjusted
automatically when the BSP is generated to create the exception_stack
memory region.
• Restriction: Only used if hal.linker.enable_exception_stack is true.
hal.linker.exception_stack_size
• Identifier: none
• Type: Decimal number
• Default Value: 1024
• Destination File: none
• Description: Size of the exception stack in bytes.
• Restriction: Only used if hal.linker.enable_exception_stack is true. none
277
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.toolchain.ar
• Identifier: AR
• Type: Unquoted string
• Default Value: riscv32-unknown-elf-ar
• Destination File: toolchain.cmake
• Description: Archiver command. Creates library files.
• Restriction: none
hal.toolchain.as
• Identifier: none
• Type: Unquoted string
• Default Value: riscv32-unknown-elf-as
• Destination File: toolchain.cmake
• Description: Assembler command. Note that CC is used for Nios V processor
assembly language source files (.S).
• Restriction: none
hal.make.arflags
• Identifier: ARFLAGS
• Type: Unquoted string
• Default Value: -src
• Destination File: toolchain.cmake
• Description: Custom flags only passed to the archiver. The content of this
variable is directly passed to the archiver rather than the more standard ARFLAGS.
The reason for this is that GNU Make assumes some default content in
ARFLAGS.This setting defines the value of ARFLAGS in Makefile.
• Restriction: none
hal.make.asflags
• Identifier: ASFLAGS
• Type: Unquoted string
• Default Value: -Wa,-gdwarf2
• Destination File: toolchain.cmake
• Description: Custom flags only passed to the assembler. This setting defines the
value of ASFLAGS in toolchain.cmake.
• Restriction: none
hal.make.cflags_debug
• Identifier: CFLAGS_DEBUG
• Type: Unquoted string
• Default Value: -g
278
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.make.cflags_defined_symbols
• Identifier: CFLAGS_DEFINED_SYMBOLS
• Type: Unquoted string
• Default Value: none
• Destination File: toolchain.cmake
• Description: Preprocessor macros to define. A macro definition in this setting has
the same effect as a #define in source code. Adding -DALT_DEBUG to this
setting has the same effect as #define ALT_DEBUG in a source file. Adding -
DFOO=1 to this setting is equivalent to the macro #define FOO 1 in a source
file. Macros defined with this setting are applied to all .S, C source (.c), and C++
files in the BSP. This setting defines the value of CFLAGS_DEFINED_SYMBOLS in
the toolchain.cmake.
• Restriction: none
hal.make.cflags_optimization
• Identifier: CFLAGS_OPTIMIZATION
• Type: Unquoted string
• Default Value: -O0
• Destination File: toolchain.cmake
• Description: C/C++ compiler optimization level. -O0 = no optimization, -O2 =
normal optimization, etc. -O0 is recommended for code that you want to debug
since compiler optimization can remove variables and produce non-sequential
execution of code while debugging. This setting defines the value of
CFLAGS_OPTIMIZATION in toolchain.cmake.
• Restriction: none
hal.make.cflags_undefined_symbols
• Identifier: CFLAGS_UNDEFINED_SYMBOLS
• Type: Unquoted string
• Default Value: none
279
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.make.cflags_user_flags
• Identifier: CFLAGS_USER_FLAGS
• Type: Unquoted string
• Default Value: none
• Destination File: toolchain.cmake
• Description: Custom flags passed to the compiler when compiling C, C++, and .S
files. This setting defines the value of CFLAGS_USER_FLAGS in
toolchain.cmake.
• Restriction: none
hal.make.cflags_warnings
• Identifier: CFLAGS_WARNINGS
• Type: Unquoted string
• Default Value: -Wall
• Destination File: toolchain.cmake
• Description: C/C++ compiler warning level. -Wall is commonly used. This
setting defines the value of CFLAGS_WARNINGS in toolchain.cmake.
• Restriction: none
hal.make.cxx_flags
• Identifier: CXXFLAGS
• Type: Unquoted string
• Default Value: none
• Destination File: toolchain.cmake
• Description: Custom flags only passed to the C++ compiler. This setting defines
the value of CXXFLAGS in toolchain.cmake.
• Restriction: none
hal.toolchain.cc
• Identifier: CC
• Type: Unquoted string
• Default Value: riscv32-unknown-elf-gcc
280
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.toolchain.cxx
• Identifier: CXX
• Type: Unquoted string
• Default Value: riscv32-unknown-elf-g++
• Destination File: toolchain.cmake
• Description: C++ compiler command
• Restriction: none
hal.make.enable_cflag_fstack_protector_strong
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: toolchain.cmake
• Description: Enable the fstack-protector-strong compiler flag in
toolchain.cmake. If true: ALT_CFLAGS += -fstack-protector-strong.
• Restriction: none
hal.make.enable_cflag_wformat_security
• Identifier: none
• Type: Boolean assignment
• Default Value: 0
• Destination File: toolchain.cmake
• Description: Enable the Wformat and Wformat-security compiler flags in
toolchain.cmake to warn against security problems when using format
functions. If true: ALT_CFLAGS += -Wformat -Wformat-security.
• Restriction: none
281
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.toolchain.prefix
• Identifier: none
• Type: Unquoted string
• Default Value: riscv32-unknown-elf-
• Description: Prefix to be used for toolchain executables. The value affects the
individual values of the archiver, assembler, compiler, and linker. Specifically, it
affects the settings.
— hal.toolchain.ar
— hal.toolchain.as
— hal.toolchain.cc
— hal.toolchain.cxx
— hal.toolchain.objdump
Example of the value: ${hal.toolchain.prefix}gcc, $
{hal.toolchain.prefix}objdump, and others.
However, if the override setting hal.toolchain.enable_executable_overrides is
enabled, the individual settings hal.toolchain.ar, hal.toolchain.as,
hal.toolchain.cc, hal.toolchain.cxx, and hal.toolchain.objdump
may be set to custom values and are not derived from this setting's value.
The riscv32-unknown-elf toolchain is available with the Ashling RiscFree IDE for
Intel FPGAs. You must install the Ashling RiscFree IDE for Intel FPGAs to use this
toolchain.
• Restriction: none
hal.toolchain.enable_executable_overrides
• Identifier: none
• Type: Boolean assignment
• Default value: false
• Description: Enable custom values to be set for the toolchain executables. You
can set the settings for hal.toolchain.ar, hal.toolchain.as,
hal.toolchain.cc, hal.toolchain.cxx, and hal.toolchain.objdump to
custom values.
• Restriction: none
hal.enable_c_plus_plus
• Identifier: ALT_NO_C_PLUS_PLUS
• Type: Boolean assignment
• Default Value: 1
282
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.enable_clean_exit
• Identifier: ALT_NO_CLEAN_EXIT
• Type: Boolean assignment
• Default Value: 1
• Destination File: toolchain.cmake
• Description: When your application exits, close file descriptors, call C++
destructors, etc. Code footprint can be reduced by disabling clean exit. If disabled,
adds -DALT_NO_CLEAN_EXIT to ALT_CPPFLAGS and -Wl, --defsym,
exit=_exit to ALT_LDFLAGS in toolchain.cmake.
• Restriction: none
hal.enable_exit
• Identifier: ALT_NO_EXIT
• Type: Boolean assignment
• Default Value: 1
• Destination File: toolchain.cmake
• Description: Add exit() support. This option increases code footprint if your
main() routine returns or calls exit(). If false, adds -DALT_NO_EXIT to
ALT_CPPFLAGS in toolchain.cmake, and reduces footprint.
• Restriction: none
hal.enable_reduced_device_drivers
• Identifier: ALT_USE_SMALL_DRIVERS
• Type: Boolean assignment
• Default Value: 0
• Destination File: toolchain.cmake
• Description: Certain drivers are compiled with reduced functionality to reduce
code footprint. Not all drivers observe this setting. If true, adds -
DALT_USE_SMALL_DRIVERS to ALT_CPPFLAGS in toolchain.cmake. Typically,
drivers support this setting with a polled mode. For example, the
altera_avalon_uart and altera_avalon_jtag_uart reduced drivers operate in polled
mode.
• Restriction: none
283
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.enable_runtime_stack_checking
• Identifier: ALT_STACK_CHECK
• Type: Boolean assignment
• Default Value: 0
• Destination File: toolchain.cmake
• Description: Turns on HAL runtime stack checking feature. Enabling this setting
causes additional code to be placed into each subroutine call to generate an
exception if a stack collision occurs with the heap or statically allocated data. If
true, adds -DALT_STACK_CHECK and -fstack-check to ALT_CPPFLAGS in
toolchain.cmake.
• Restriction: none
hal.enable_sim_optimize
• Identifier: ALT_SIM_OPTIMIZE
• Type: Boolean assignment
• Default Value: 0
• Destination File: toolchain.cmake
• Description: The BSP is compiled with optimizations to speedup HDL simulation
such as initializing the cache, clearing the .bss section, and skipping long delay
loops. If true, adds -DALT_SIM_OPTIMIZE to ALT_CPPFLAGS in
toolchain.cmake.
• Restriction: When this setting is true, the BSP cannot run on hardware.
hal.log_port
• Identifier: ALT_LOG_PORT
• Type: Unquoted string
• Default Value: none
• Destination File: system.h
• Description: Slave descriptor of debug logging character-mode device. If defined,
it enables extra debug messages in the HAL source. This setting is used by the
Intel FPGA logging functions.
hal.log_flags
• Identifier: ALT_LOG_FLAGS
• Type: Decimal Number
• Default Value: 0
• Destination File: toolchain.cmake
• Description: The value is assigned to ALT_LOG_FLAGS in the generated
toolchain.cmake. Refer to hal.log_port for further details. The valid range of
this setting is -1 through 3.
284
12. Nios V Processor Appendix
743810 | 2022.10.31
hal.stderr
• Identifier: ALT_STDERR
• Type: Unquoted string
• Default Value: none
• Destination File: system.h
• Description: Slave descriptor of STDERR character-mode device. This setting is
used by the ALT_STDERR family of defines in system.h.
hal.stdin
• Identifier:ALT_STDIN
• Type: Unquoted string
• Default Value: none
• Destination File: system.h
• Description: Slave descriptor of STDIN character-mode device. This setting is
used by the ALT_STDIN family of defines in system.h.
hal.stdout
• Identifier: ALT_STDOUT
• Type: Unquoted string
• Default Value: none
• Destination File: system.h
• Description: Slave descriptor of STDOUT character-mode device. This setting is
used by the ALT_STDOUT family of defines in system.h.
Related Information
• Assumptions and Requirements on page 127
• AN 459: Guidelines for Developing a Nios II HAL Device Driver
For more information about integrating a HAL device driver.
285
12. Nios V Processor Appendix
743810 | 2022.10.31
The following sections describe each Tcl environment in detail, listing the available
commands.
12.5.2.1. add_memory_device
Usage
add_memory_device <device name> <base address> <span>
Options
• <device name>: String with the name of the memory device.
• <base address>: The base address of the memory device. Hexadecimal or
decimal string.
• <span>: The size (span) of the memory device. Hexadecimal or decimal string.
Description
12.5.2.2. add_memory_region
Usage
add_memory_region <name> <slave_desc> <offset> <span>
286
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <name>: String with the name of the memory region to create.
• <slave_desc>: String with the slave descriptor of the memory device for this
region.
• <offset>: String with the byte offset of the memory region from the memory
device base address.
• <span>: String with the span of the memory region in bytes.
Description
Creates a new memory region for the linker script. This memory region must not
overlap with any other memory region and must be within the memory range of the
associated slave descriptor. The offset and span are decimal numbers unless prefixed
with 0x.
Example
add_memory_region onchip_ram0 onchip_ram0 0 0x100000
12.5.2.3. add_section_mapping
Usage
add_section_mapping <section_name> <memory_region_name>
Options
• <section_name>: String with the name of the linker section.
• <memory_region_name>: String with the name of the memory region to map.
Description
Maps the specified linker section to the specified linker memory region. If the section
does not already exist, add_section_mapping creates it. If it already exists,
add_section_mapping overrides the existing mapping with the new one. The linker
creates the section mappings in the order in which they appear in the linker script.
Example
add_section_mapping .text onchip_ram0
12.5.2.4. are_same_resource
Usage
are_same_resource <slave_desc1> <slave_desc2>
Options
• <slave_desc1>: String with the first slave descriptor to compare.
• <slave_desc2>: String with the second slave descriptor to compare.
287
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
Returns a boolean value that indicates whether the two slave descriptors are
connected to the same resource. To connect to the same resource, the two slave
descriptors must be associated with the same module. The module specifies whether
two slaves access the same resource or different resources within that module. For
example, a dual-port memory has two slaves that access the same resource (the
memory). However, you could create a module that has two slaves that access two
different resources such as a memory and a control port.
12.5.2.5. delete_memory_region
Usage
delete_memory_region <region_name>
Options
• <region_name>: String with the name of the memory region to delete.
Description
Deletes the specified memory region. The region must exist to avoid an error
condition.
12.5.2.6. delete_section_mapping
Usage
delete_section_mapping <section_name>
Options
• <section_name>: String with the name of the section.
Description
Example
delete_section_mapping .text
12.5.2.7. disable_sw_package
Usage
disable_sw_package <software_package_name>
Options
• <software_package_name>: String with the name of the software package.
Description
Disables the specified software package. Settings belonging to the package are no
longer available in the BSP, and associated source files are not included in the
CMakeLists.txt. It is an error to disable a software package that is not enabled.
288
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.8. enable_sw_package
Usage
enable_sw_package <software_package_name>
Options
• <software_package_name>: String with the name of the software package,
with the version number optionally appended with a ':'.
Description
Enables a software package. Adds its associated source files and settings to the BSP.
Specify the desired version in the form <software_package_name>:<version>. If
you do not specify the version, enable_sw_package selects the latest available
version.
Examples
• Example 1:enable_sw_package altera_safeclib:19.1
• Example 2:enable_sw_package my_sw_package
12.5.2.9. get_addr_span
Usage
get_addr_span <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns the address span (length in bytes) of the slave descriptor as an integer
decimal number.
Example
puts [get_addr_span onchip_ram_64_kbytes] Returns: 65536
12.5.2.10. get_assignment
Usage
get_assignment <module_name> <assignment_name>
Options
• <module_name>: Module instance name to query for assignment
• <assignment_name>: Module instance assignment name to query for
Description
Returns the name of the value of the assignment for a specified module instance
name.
289
12. Nios V Processor Appendix
743810 | 2022.10.31
Example
puts [get_assignment "cpu0"
"embeddedsw.configuration.breakSlave"]
Returns: memory_0.s0
12.5.2.11. get_available_drivers
Usage
get_available_drivers <module_name>
Options
• <module_name>: String with the name of the module to query.
Description
Returns a list of available device driver names that are compatible with the specified
module instance. The list is empty if there are no drivers available for the specified
slave descriptor. The format of each entry in the list is the driver name followed by a
colon and the version number (if provided).
Example
puts [get_available_drivers jtag_uart]
Returns: altera_avalon_jtag_uart_driver:7.2
altera_avalon_jtag_uart_driver:6.1
12.5.2.12. get_available_sw_packages
Usage
get_available_sw_packages
Options
None
Description
Returns a list of software package names that are available for the current BSP. The
format of each entry in the list is a string containing the package name followed by a
colon and the version number (if provided).
Example
puts [get_available_sw_packages]
Returns:
altera_quad_seven_seg:19.1
altera_safeclib:19.1
290
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.13. get_base_addr
Usage
get_base_addr <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns the base byte address of the slave descriptor as an integer decimal number.
Example
puts [get_base_addr jtag_uart]
Returns: 67616
12.5.2.14. get_break_offset
Usage
get_break_offset
Options
None
Description
Example
puts [get_break_offset] Returns: 32
12.5.2.15. get_break_slave_desc
Usage
get_break_slave_desc
Options
None
Description
Returns the slave descriptor associated with the processor break address. If null, then
the break device is internal to the processor (debug module).
Example
puts [get_break_slave_desc]
Returns: onchip_ram_64_kbytes
291
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.16. get_cpu_name
Usage
get_cpu_name
Options
None
Description
Example
puts [get_cpu_name] Returns: cpu_0
12.5.2.17. get_current_memory_regions
Usage
get_current_memory_regions
Options
None
Description
Returns a sorted list of records representing the existing linker script memory regions.
Each record in the list represents a memory region. Each record is a list containing the
region name, associated memory device slave descriptor, offset, and span, in that
order.
Example
puts [get_current_memory_regions]
12.5.2.18. get_current_section_mappings
Usage
get_current_section_mappings
Options
None
Description
Returns a list of lists for all the current section mappings. Each list represents a
section mapping with the format {section_name memory_region}. The order of the
section mappings matches their order in the linker script.
292
12. Nios V Processor Appendix
743810 | 2022.10.31
Example
puts [get_current_section_mappings]
12.5.2.19. get_default_memory_regions
Usage
get_default_memory_regions
Options
None
Description
Returns a sorted list of records representing the default linker script memory regions.
The default linker script memory regions are the best guess for memory regions based
on the reset address and exception address of the processor associated with the BSP,
and all other processors in the system that share memories with the processor
associated with the BSP. Each record in the list represents a memory region. Each
record is a list containing the region name, associated memory device slave descriptor,
offset, and span, in that order.
Example
puts [get_default_memory_regions]
Returns:
{reset onchip_ram0 0 32} {onchip_ram0 onchip_ram0 32 1048544}
12.5.2.20. get_driver
Usage
get_driver <module_name>
Options
• <module_name>: String with the name of the module instance to query.
Description
Returns the driver name associated with the specified module instance. The format is
<driver name> followed by a colon and the version (if provided). Returns the string
"none" if there is no driver associated with the specified module instance name.
293
12. Nios V Processor Appendix
743810 | 2022.10.31
Examples
• Example 1:puts [get_driver jtag_uart]
Returns:
altera_avalon_jtag_uart_driver:7.2
• Example 2:puts [get_driver onchip_ram_64_kbytes]
Returns:
none
12.5.2.21. get_enabled_sw_packages
Usage
get_enabled_sw_packages
Options
None
Description
Returns a list of currently enabled software packages. The format of each entry in the
list is the software package name followed by a colon and the version number (if
provided).
Example
puts [get_enabled_sw_packages]
Returns:
altera_safeclib:19.1
12.5.2.22. get_exception_offset
Usage
get_exception_offset
Options
None
Description
Example
puts [get_exception_offset]
Returns:
32
12.5.2.23. get_exception_slave_desc
Usage
get_exception_slave_desc
294
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
None
Description
Returns the slave descriptor associated with the processor exception address.
Example
puts [get_exception_slave_desc]
Returns:
onchip_ram_64_kbytes
12.5.2.24. get_fast_tlb_miss_exception_offset
Usage
get_fast_tlb_miss_exception_offset
Options
None
Description
Returns the byte offset of the processor fast translation lookaside buffer (TLB) miss
exception address. Only a processor with an MMU has such an exception address.
Example
puts [get_fast_tlb_miss_exception_offset]
Returns:
32
12.5.2.25. get_fast_tlb_miss_exception_slave_desc
Usage
get_fast_tlb_miss_exception_slave_desc
Options
None
Description
Returns the slave descriptor associated with the processor fast TLB miss exception
address. Only a processor with an MMU has such an exception address.
Example
puts [get_fast_tlb_miss_exception_slave_desc]
Returns:
onchip_ram_64_kbytes
295
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.26. get_interrupt_controller_id
Usage
get_interrupt_controller_id <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns the interrupt controller ID of the slave descriptor (-1 if not a connected
interrupt controller).
12.5.2.27. get_irq_interrupt_controller_id
Usage
get_irq_interrupt_controller_id <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns the interrupt controller ID connected to the IRQ associated with the slave
descriptor (-1 if none).
12.5.2.28. get_irq_number
Usage
get_irq_number <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
12.5.2.29. get_memory_region
Usage
get_memory_region <name>
Options
• <name>: String with the name of the memory region.
Description
Returns the linker script region information for the specified region. The format of the
region is a list containing the region name, associated memory device slave descriptor,
offset, and span in that order.
296
12. Nios V Processor Appendix
743810 | 2022.10.31
Example
puts [get_memory_region reset]
Returns:
reset onchip_ram0 0 32
12.5.2.30. get_module_class_name
Usage
get_module_class_name <module_name>
Options
• <module_name>: String with the module instance name to query.
Description
Returns the name of the module class associated with the module instance.
Example
puts [get_module_class_name jtag_uart0]
Returns:
altera_avalon_jtag_uart
12.5.2.31. get_module_name
Usage
get_module_name <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns the name of the module instance associated with the slave descriptor. If a
module with one slave, or if it has multiple slaves connected to the same resource, the
slave descriptor is the same as the module name. If a module has multiple slaves that
do not connect to the same resource, the slave descriptor consists of the module
name followed by an underscore and the slave name.
Example
puts [get_module_name multi_jtag_uart0_s1]
Returns:
multi_jtag_uart0
12.5.2.32. get_reset_offset
Usage
get_reset_offset
297
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
None
Description
Example
puts [get_reset_offset]
Returns:
0
12.5.2.33. get_reset_slave_desc
Usage
get_reset_slave_desc
Options
None
Description
Returns the slave descriptor associated with the processor reset address.
Example
puts [get_reset_slave_desc]
Returns:
onchip_ram_64_kbytes
12.5.2.34. get_section_mapping
Usage
get_section_mapping <section_name>
Options
• <section_name>: String with the section name to query.
Description
Returns the name of the memory region for the specified linker section. Returns null if
the linker section does not exist.
Example
puts [get_section_mapping .text]
Returns:
onchip_ram0
298
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.35. get_setting
Usage
get_setting <name>
Options
• <name>: String with the name of the setting to get.
Description
Returns the value of the specified BSP setting. get_setting returns boolean settings
with the value 1 or 0. If the value of the setting is an empty string, get_setting
returns "none".
Example
puts [get_setting hal.enable_c_plus_plus]
Returns:
0
12.5.2.36. get_setting_desc
Usage
get_setting_desc <name>
Options
• <name>: String with the name of the setting to get the description for.
Description
Example
puts [get_setting_desc hal.enable_c_plus_plus]
Returns:
Enable support for a subset of the C++ language.
This option increases code footprint by adding support for C++ constructors.
Certain features, such as multiple inheritance and exceptions are not supported.
If false, adds -DALT_NO_C_PLUS_PLUS to ALT_CPPFLAGS in toolchain.cmake, and
reduces code footprint.
12.5.2.37. get_slave_descs
Usage
get_slave_descs
Options
None
299
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
Returns a sorted list of all the slave descriptors connected to the Nios V processor.
Example
puts [get_slave_descs]
Returns:
jtag_uart0
onchip_ram0
12.5.2.38. is_char_device
Usage
is_char_device <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is a character
device.
Examples
• Example 1:puts [is_char_device jtag_uart]
Returns:
1
• Example 2:puts [is_char_device onchip_ram_64_kbytes]
Returns:
0
12.5.2.39. is_connected_interrupt_controller_device
Usage
is_connected_interrupt_controller_device <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is an interrupt
controller device that is connected to the processor so that the interrupt controller
sends interrupts to the processor.
12.5.2.40. is_connected_to_data_master
Usage
is_connected_to_data_master <slave_desc>
300
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is connected to a
data master.
12.5.2.41. is_connected_to_instruction_master
Usage
is_connected_to_instruction_master <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is connected to an
instruction master.
12.5.2.42. is_ethernet_mac_device
Usage
is_ethernet_mac_device <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is an Ethernet
MAC device.
12.5.2.43. is_flash
Usage
is_flash <slave_desc>
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is a flash memory
device.
12.5.2.44. is_memory_device
Usage
is_memory_device <slave_desc>
301
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is a memory
device.
Examples
• Example 1:puts [is_memory_device jtag_uart]
Returns:0
• Example 2:puts [is_memory_device onchip_ram_64_kbytes]
Returns:1
12.5.2.45. is_non_volatile_storage
Usage
is_non_volatile_storage <slave_desc>
Options
<slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is a non-volatile
storage device.
12.5.2.46. is_timer_device
Usage
is_timer_device <slave_desc>
Options
<slave_desc>: String with the slave descriptor to query.
Description
Returns a boolean value that indicates whether the slave descriptor is a timer device.
12.5.2.47. log_debug
Usage
log_debug <message>
Options
<message>: String with message to log.
Description
Displays a message to the host's stdout when the logging level is debug.
302
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.48. log_default
Usage
log_default <message>
Options
• <message>: String with message to log.
Description
Displays a message to the host’s stdout when the logging level is default or higher.
Example
log_default "This is a default message."
Displays:
INFO: Tcl message: "This is a default message."
12.5.2.49. log_error
Usage
log_error <message>
Options
• <message>: String with message to log.
Description
12.5.2.50. log_verbose
Usage
log_verbose <message>
Options
• <message>: String with message to log.
Description
Displays a message to the host's stdout when the logging level is verbose or higher.
12.5.2.51. set_driver
Usage
set_driver <driver_name> <module_name>
Options
• <driver_name>: String with the name of the device driver to use.
• <module_name>: String with the name of the module instance to set.
303
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
Selects the specified device driver for the specified module instance. The
<driver_name> argument includes a version number, delimited by a colon (:). If you
omit the version number, set_driver uses the latest available version of the driver that
is compatible with the component specified by the <module_name> argument.
If <driver_name> is none, the specified module instance does not use a driver. If
<driver_name> is not none, it must be the name of the associated component class.
Examples
• Example 1:set_driver altera_avalon_jtag_uart_driver:7.2
jtag_uart
• Example 2:set_driver none jtag_uart
12.5.2.52. set_ignore_file
Usage
set_ignore_file <software_component_name> <file_name> <ignore>
Options
• <software_component_name>: Name of the driver, software package, or
operating system to which the file belongs.
• <file_name>: Name of the file.
• <ignore>: Set to true to ignore (not generate or copy) the file, false to generate
or copy the file normally.
Description
You can use this command to have a specific BSP file ignored (not generated or
copied) during BSP generation. This command allows you to take ownership of a
specific file, modify it, and prevent the Nios V processor BSP Tools from overwriting
your modifications.
Note: For a list of generated files associated with a third-party OS, refer to the OS supplier's
documentation.
304
12. Nios V Processor Appendix
743810 | 2022.10.31
Related Information
Nios V Processor Board Support Package Editor on page 48
For more information about the BSP Package Editor.
12.5.2.53. set_setting
Usage
set_setting <name> <value>
Options
• <name>: String with the name of the setting.
• <value>: String with the value of the setting.
Description
Sets the value for the specified BSP setting. Legal values for boolean settings are true,
false, 1, and 0. Use the keyword none instead of an empty string to set a string to an
empty value.
Example
set_setting hal.enable_reduced_device_drivers true
12.5.2.54. update_memory_region
Usage
update_memory_region <name> <slave_desc> <offset> <span>
Options
• <name>: String with the name of the memory region to update.
• <slave_desc>: String with the slave descriptor of the memory device for this
region.
• <offset>: String with the byte offset of the memory region from the memory
device base address.
• <span>: String with the span of the memory region in bytes.
Description
Updates an existing memory region for the linker script. This memory region must not
overlap with any other memory region and must be within the memory range of the
associated slave descriptor. The offset and span are decimal numbers unless prefixed
with 0x.
Example
update_memory_region onchip_ram0 onchip_ram0 0 0x100000
12.5.2.55. update_section_mapping
Usage
update_section_mapping <section_name> <memory_region_name>
305
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <section_name>: String with the name of the linker section.
• <memory_region_name>: String with the name of the memory region to map.
Description
Updates the specified linker section. The linker creates the section mappings in the
order in which they appear in the linker script.
Example
update_section_mapping .text onchip_ram0
12.5.2.56. add_default_memory_regions
Usage
add_default_memory_regions
Description
Defaults the BSP to use default linker script memory regions. The default linker script
memory regions are the best guess for memory regions based on the reset address
and exception address of the processor associated with the BSP, and all other
processors in the system that share memories with the processor associated with the
BSP.
12.5.2.57. create_bsp
Usage
create_bsp <bspType> <bsp version> <processor name> <sopcinfo>
Options
• <bspType>: Type of BSP to create.
• <bsp version>: Version of BSP software element to utilize.
• <processor name>: Name of processor instance for BSP
• <sopcinfo>: .sopcinfo generated file that describes the system the BSP is for.
Description
12.5.2.58. generate_bsp
Usage
generate_bsp <bspDir>
Options
• <bspDir>: BSP directory to generate files to.
306
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
12.5.2.59. get_available_bsp_type_versions
Usage
get_available_bsp_type_versions <bsp_type> <sopcinfo_path>
Options
• <bsp_type>: BSP type identifier (e.g. hal, ucosii).
• <sopcinfo_path>: SOPC Information File path. Its parent folder might include
custom BSP IP software components (*_sw.tcl).
Description
12.5.2.60. get_available_bsp_types
Usage
get_available_bsp_types <sopcinfo_path>
Options
• <sopcinfo_path>: SOPC Information File path. Its parent folder might include
custom BSP IP software components (*_sw.tcl).
Description
12.5.2.61. get_available_cpu_architectures
Usage
get_available_cpu_architectures
Description
12.5.2.62. get_available_cpu_names
Usage
get_available_cpu_names <sopcinfo_path>
Options
• <sopcinfo_path>: SOPC Information File path that contains processor instances
Description
307
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.2.63. get_available_software
Usage
get_available_software <bsp_type> <filter> <sopcinfo_path>
Options
• <bsp_type>: BSP type identifier (e.g. hal, ucosii).
• <sopcinfo_path>: SOPC Information File path. Its parent folder might include
custom BSP IP software components (*_sw.tcl).
• <filter>: A filter can be applied to restrict results. The following filters are
available:
— all
— drivers
— sw_packages
— os_elements
Note: Comma-separated tokens are acceptable.
Description
Gets the available software (drivers, software packages, and bsp components) for a
given BSP type.
12.5.2.64. get_available_software_setting_properties
Usage
get_available_software_setting_properties <setting_name>
<software_name> <software_version> <sopcinfo_path>
Options
• <software_name>: Name of a software component (for example,
"altera_avalon_uart_driver", or "hal").
• <software_version>: Enter "default" for latest version, or a specific version
number.
• <setting_name>: Name of a selected software component setting to get
properties for(e.g. hal.linker.allow_code_at_reset).
• <sopcinfo_path>: SOPC Information File path. Its parent folder might include
custom BSP IP software components (*_sw.tcl).
Description
12.5.2.65. get_available_software_settings
Usage
308
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <software_name>: Name of a software component (e.g.
altera_avalon_uart_driver).
• <software_version>: Enter "default" for latest version, or a specific version
number.
• <sopcinfo_path>: SOPC Information File path. Its parent folder can include
custom BSP IP software components (*_sw.tcl).
Description
12.5.2.66. get_bsp_version
Usage
get_bsp_version
Description
12.5.2.67. get_cpu_architecture
Usage
get_cpu_architecture <processor_name> <sopcinfo_path>
Options
• <processor_name>: processor instance name
• <sopcinfo_path>: SOPC Information File path that contains processor_name
instance
Description
Gets the processor architecture (e.g. niosv) of a specified processor instance given a
SOPC system.
12.5.2.68. get_sopcinfo_file
Usage
get_sopcinfo_file
Description
12.5.2.69. get_supported_bsp_types
Usage
get_supported_bsp_types <processor_name> <sopcinfo_path>
309
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <processor_name>: processor instance name
• <sopcinfo_path>: SOPC Information File path. Its parent folder can include
custom BSP IP software components (*_sw.tcl).
Description
Gets the BSP types supported for a given processor and SOPC system.
12.5.2.70. is_bsp_hal_extension
Usage
is_bsp_hal_extension
Description
Returns a boolean value that indicates whether the BSP instantiated is of a type based
on Intel HAL.
12.5.2.71. open_bsp
Usage
open_bsp <settingsFile>
Options
• <settingsFile>: .bsp settings file to open.
Description
12.5.2.72. save_bsp
Usage
save_bsp <settingsFile>
Options
• <settingsFile>: .bsp settings file to save BSP to.
Description
12.5.2.73. set_bsp_version
Usage
set_bsp_version <version>
Options
• <version>: Version of BSP type software element to use.
310
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
Sets the version of the BSP operating system software element to a specific value. The
value "default' uses the latest version available. If this call is not used, the BSP is
created using the 'default' BSP software element version.
12.5.2.74. set_logging_mode
Usage
set_logging_mode <mode>
Options
• <mode>: Logging Mode: 'silent', 'default', 'verbose', 'debug'
Description
Sets the verbosity level of the logger. Useful to eliminate tool informative messages
Tcl callback scripts are defined and controlled from the *_sw.tcl file associated with
the driver or package. In *_sw.tcl, you can specify where the Tcl functions come
from, when function runs, and the scope of each Tcl function’s operation.
When the BSP is generated with your driver or software package, the settings you
define in the callback scripts are inserted in settings.bsp.
You specify the source of the callback functions with the set_sw_property
command, using the callback_source_file property.
Note: Although you can specify a new setting’s value when you create the setting at BSP
initialization, the setting’s value can change between initialization and generation. For
example, the BSP developer might edit the setting in the BSP Editor.
You specify each callback function’s runtime environment by using the appropriate
property in the set_sw_property command, as shown in the table below.
311
12. Nios V Processor Appendix
743810 | 2022.10.31
Tcl callbacks have access to a specialized set of commands, described in this section.
In addition, Tcl callbacks can use any read-only BSP setting Tcl command.
Note: For more information about BSP setting Tcl commands, refer to the Tcl Commands for
BSP Settings chapter. When a Tcl callback creates a setting, it can specify the value.
However, callbacks cannot change the value of a pre-existing setting.
12.5.3.1. add_class_sw_setting
Usage
add_class_sw_setting <setting-name> <setting-type>
Options
• <setting-name>: Name of the setting to persist in the BSP settings file. This is
prepended with the driver class name associated with this callback script
• <setting-type>: Type of the setting to persist in the BSP settings file.
Description
Creates a BSP setting that is associated with a particular software driver element
class. The set_class_sw_setting_property command is required to set the
values for fields pertaining to a BSP software setting definition. This command is only
valid for a callback script. A callback script is set in the driver's *_sw.tcl file, using
the command set_sw_property callback_source_file <filename>.
Example
add_class_sw_setting MY_FAVORITE_SETTING String
(4) The BSP subdirectory into which the driver or package files are copied
312
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.3.2. add_class_systemh_line
Usage
add_class_systemh_line <macro-name> <macro-value>
Options
• <macro-name>: Macro to be added to the system.h file for the generated BSP
• <macro-value>: Value associated with the macro-name to be added to the
system.h file for the generated BSP
Description
This adds a system.h assignment or macro during a driver callback execution. The BSP
typically uses this during the generate phase depending on the generator. This
command is only valid for a callback script. A callback script is set in the driver's
*_sw.tcl file, using the command set_sw_property callback_source_file
<filename>.
Example
add_class_systemh_line MY_MACRO "Macro_Value";
12.5.3.3. add_module_sw_property
Usage
Options
• <property-name>: Name of the property to add to the BSP for a module
instance
• <property-value>: Value of the property to add to the BSP for a module
instance
Description
This adds a software property to the BSP driver of this module instance. The BSP
typically uses this during the generate phase depending on the generator. This
command is only valid for a callback script. A callback script is set in the driver's
*_sw.tcl file, using the command set_sw_property callback_source_file
<filename>.
Example
12.5.3.4. add_module_sw_setting
Usage
add_module_sw_setting <setting-name> <setting-type>
313
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <setting-name>: Name of the setting to persist in the BSP settings file. This is
prepended with the module name associated with this callback script
• <setting-type>: Type of the setting to persist in the BSP settings file.
Description
Creates a BSP setting that is associated with a particular instance of hardware module
in a SOPC system. The set_module_sw_setting_property command is required
to set the values for fields pertaining to a BSP software setting definition. This
command is only valid for a callback script. A callback script is set in the driver's
*_sw.tcl file, using the command set_sw_property callback_source_file
<filename>.
Example
add_module_sw_setting MY_FAVORITE_SETTING String
12.5.3.5. add_module_systemh_line
Usage
add_module_systemh_line <macro-name> <macro-value>
Options
• <macro-name>: Macro to be added to the system.h file for the generated BSP
• <macro-value>: Value associated with the macro-name to be added to the
system.h file for the generated BSP
Description
This adds a system.h assignment or macro during a driver callback execution. The BSP
typically uses this during the generate phase depending on the generator. This
command is only valid for a callback script. A callback script is set in the driver's
*_sw.tcl file, using the command set_sw_property callback_source_file
<filename>.
Example
add_module_systemh_line MY_MACRO "Macro_Value";
12.5.3.6. add_systemh_line
Usage
add_systemh_line <sw> <name> <value
• <sw>: The software (OS) that the system.h text is associated with
• <name>: Name of macro to write into system.h (left-hand side of #define)
• <value>: Name of value to assign to macro in system.h (right-hand side of
#define)
314
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
Adds a line of text to the system.h file. The <sw> argument is the name of the
software type (typically an operating system name) that the system.h text applies
to. In the context of an operating system Tcl script, the name in the create_os
<name> command must be used. The text is a name-value pair that creates a macro
(#define statement) in the system.h file.
Note: This command can only be used by Tcl scripts that are registered to run at BSP
generation time by an operating system.
Example
add_systemh_line UCOSII OS_TICKS_PER_SEC 100
12.5.3.7. get_class_peripheral
Usage
get_class_peripheral <instance-name> <irq-number>
Options
• <instance-name>: Name of EIC module instance to find connected peripheral
for.
• <irq-number>: IRQ number to locate connected peripheral device
Description
Example
get_class_peripheral eic_1 $irq_2;
12.5.3.8. get_module_assignment
Usage
get_module_assignment <assignment-name>
Options
• <assignment-name>: Name of the module assignment to retrieve the value for,
as defined for the module instance in the .sopcinfo file
Description
Given a module assignment key, return the assignment value of a module associated
with the callback script using this command. The callback script must be set in the
*_sw.tcl file using the following command:
set_sw_property callback_source_file <filename>
315
12. Nios V Processor Appendix
743810 | 2022.10.31
Example
puts [get_module_assignment
embeddedsw.configuration.isMemoryDevice]
Returns:
true
12.5.3.9. get_module_name
Usage
get_module_name
Options
None
Description
Returns the name of the module associated with the callback script using this
command. The callback script must be set in the *_sw.tcl file using the following
command:
set_sw_property callback_source_file <filename>
Example
puts [get_module_name]
Returns:
jtag_uart
12.5.3.10. get_module_peripheral
Usage
get_module_peripheral <irq-number>
Options
• <irq-number>: IRQ number to locate connected peripheral device
Description
Example
get_module_peripheral 2;
12.5.3.11. get_module_sw_setting_value
Usage
get_module_sw_setting_value <setting-name>
316
12. Nios V Processor Appendix
743810 | 2022.10.31
Options
• <setting-name>: Name of the module software setting to retrieve the value for,
as defined by the add_module_sw_setting command.
Description
Given a module software setting name, return the setting value. The callback script
using this command must be set in the *_sw.tcl file using the following command:
set_sw_property callback_source_file <filename>
You can use this command in a generation or validation callback to retrieve the current
value of a setting created in an initialization callback.
Example
puts [get_module_sw_setting_value MY_SETTING]
Returns:
"My setting value"
12.5.3.12. get_peripheral_property
Usage
get_peripheral_property <slave-descriptor> <property-name>
Options
• <slave-descriptor>: Slave descriptor of a connected peripheral device
• <property-name>: Property name to query from the connected peripheral
device
Description
Example
get_peripheral_property jtag_uart supports_preemption;
12.5.3.13. remove_class_systemh_line
Usage
remove_class_systemh_line <macro-name>
Options
• <macro-name>: Macro to be removed to the system.h file for the generated BSP
317
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
This removes a system.h assignment or macro during a driver callback execution. The
BSP typically uses this during the generate phase depending on the generator. This
command is only valid for a callback script. A callback script is set in the driver's
*_sw.tcl file, using the command set_sw_property callback_source_file
<filename>.
Example
remove_class_systemh_line MY_MACRO;
12.5.3.14. remove_module_systemh_line
Usage
remove_module_systemh_line <macro-name>
Options
• <macro-name>: Macro to be removed to the system.h file for the generated BSP
Description
This removes a system.h assignment or macro during a driver callback execution. The
BSP typically uses this during the generate phase depending on the generator. This
command is only valid for a callback script. A callback script is set in the driver's
*_sw.tcl file, using the command set_sw_property callback_source_file
<filename>.
Example
remove_module_systemh_line MY_MACRO;
12.5.3.15. set_class_sw_setting_property
Usage
set_class_sw_setting_property <setting-name> <property> <value>
Options
• <setting-name>: Name of the setting to persist in the BSP settings file
associated with the driver class of this callback script
• <property>: Name of the setting property to update
• <value>: Value of the setting property to update
Description
Update a driver class software setting property. The setting must be added using the
add_class_sw_setting command before calling this method. This command is only
valid for a callback script. A callback script is set in the driver's *_sw.tcl file, using
the command set_sw_property callback_source_file <filename>.
318
12. Nios V Processor Appendix
743810 | 2022.10.31
Example
set_class_sw_setting_property MY_FAVORITE_SETTING default-value
'42'
12.5.3.16. set_module_sw_setting_property
Usage
set_module_sw_setting_property <setting-name> <property> <value>
Options
• <setting-name>: Name of the setting to persist in the BSP settings file
associated with the SOPC module of this callback script
• <property>: Name of the setting property to update
• <value>: Value of the setting property to update
Description
Update a module's software setting property. The setting must be added using the
add_module_sw_setting command before calling this method. This command is
only valid for a callback script. A callback script is set in the driver's *_sw.tcl file,
using the command set_sw_property callback_source_file <filename>.
Example
set_module_sw_setting_property MY_FAVORITE_SETTING default-value
'42'
319
12. Nios V Processor Appendix
743810 | 2022.10.31
A device driver and a software package are both collections of source files added to
the BSP. A device driver is associated with a particular component class (for example,
altera_avalon_jtag_uart). A software package is not associated with any
particular component class, but implements a functionality such as Safe C Library.
To define a device driver or software package, you create a Tcl script defining its
characteristics. This section describes the Tcl commands available to define device
drivers and software packages.
The following commands are available for device driver and software package
creation:
• add_sw_property
• add_sw_setting
• add_sw_setting2
• create_driver
• create_os
• create_sw_package
• set_sw_property
• set_sw_setting_property
Related Information
• Tcl Scripts for BSP Settings on page 62
• Settings Managed by Nios V Processor Board Support Package Editor on page 258
• Tcl Commands for BSP Settings on page 286
12.5.4.1. add_sw_property
Usage
add_sw_property <property> <value>
Options
• <property>: Name of property.
• <value>: Value assigned, or appended to the current value.
Description
This command defines a property for a device driver or software package. A property
is a list of values (for example, a list of file names). The add_sw_property command
defines a property if it is not already defined. The command appends a new value to
the list of values if the property is already defined.
320
12. Nios V Processor Appendix
743810 | 2022.10.31
In the case of a property consisting of a file name or directory name, use a relative
path. Specify the path relative to the directory containing the Tcl script.
321
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.4.2. add_sw_setting
Usage
add_sw_setting <type> <destination> <displayName> <identifier>
<value> <description>
Options
• <type>: Setting type - Boolean, QuotedString, UnquotedString.
• <destination>: The destination BSP file associated with the setting, or the
module generator that processes this setting.
• <displayName>: Setting name.
• <identifier>: Name of the macro created for a generated destination file.
• <value>: Default value of the setting.
• <description>: Setting description.
322
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
This command creates a BSP setting associated with a software package or device
driver. The setting is available whenever the software package or device driver is
present in the BSP. niosv-bsp converts the setting and its value into either a C
preprocessor macro or BSP makefile variable. add_sw_setting passes macro
definitions to the compiler using the -D command line option, or adds them to the
system.h file as #define statements.
The setting only exists once even if there are multiple instances of a software
package. You can use the BSP Tcl commands set_setting and get_setting to set
or get the setting. The value of the setting persists in the BSP settings file.
323
12. Nios V Processor Appendix
743810 | 2022.10.31
• type—This parameter formats the setting value during BSP generation. The
following supported types and usage restrictions apply:
— boolean_define_only—Defines a macro if the setting’s value is 1 or true.
Example: #define LCD_PRESENT. No macro is defined if the setting’s value
is 0 or false. This setting type supports the system_h_define and
public_mk_define destinations, defined below.
— boolean—Defines a macro or makefile variable and sets it to 1 (if the value is
1 or true) or 0 (if the value is 0 or false). Example: #define LCD_PRESENT
1. This type supports all destinations.
— character—Defines a macro as a single character with single quotes around
the character. Example: #define DELIMITER ':'. This type supports the
system_h_define destination, defined below.
— decimal_number—Defines a macro or makefile variable and sets it with an
unquoted decimal (integer) number. Example: #define NUM_COPROCESSORS
3. This type supports all destinations.
— double—Defines a macro name and sets it to a value with a decimal point.
Example: #define PI 3.1416. This type supports the system_h_define
destination, defined below.
— float—Defines a macro name and sets it to a value with a decimal point and
f character. Example: #define PI 3.1416f. This type supports the
system_h_define destination, defined below.
— hex_number—Defines a macro name and sets it to a value with a 0x
prepended to the value. Example: #define LCD_SIZE 0x1000. This type
supports the system_h_define destination, defined below.
— quoted_string—Quoted strings always have the macro name and setting
value added to the destination files. In the destination, the setting value is
enclosed in quotation marks. Example: #define DFLT_ERR "General
error"
If the setting value contains white space, you must place quotation marks
around the value string in the Tcl script. This type supports the
system_h_define destination, defined below.
— unquoted_string—Unquoted strings define a macro or makefile variable
with setting name and value in the destination file. In the destination file, the
setting value is not enclosed in quotation marks. Example: #define
DFLT_ERROR Error This type supports all destinations.
324
12. Nios V Processor Appendix
743810 | 2022.10.31
12.5.4.3. add_sw_setting2
Usage
add_sw_setting2 <setting-name> <setting-type>
Options
• <setting-name>: Name of the setting to persist in the BSP settings file. This is
prepended with BSP Type when persisted.
• <setting-type>: Type of the setting to persist in the BSP settings file.
325
12. Nios V Processor Appendix
743810 | 2022.10.31
Description
This command creates a BSP setting that is associated with a particular software
component. The 'set_sw_setting_property' command is required to set the
values for fields pertaining to a BSP software setting definition.
Example
add_sw_setting2 MY_FAVORITE_SETTING unquoted_string
12.5.4.4. create_driver
Usage
create_driver <name>
Options
• <name>: Name of device driver.
Description
This command creates a new device driver instance available for the Nios V processor
BSP Editor. This command must precede all others that describe the device driver in
its Tcl script. You can only have one create_driver command in each Tcl script. If
the create_driver command appears in the Tcl script, the create_sw_package
and create_os commands cannot appear.
The name argument is usually distinct from all other device drivers and software
packages that the Nios V processor tools might locate. You can specify driver name
identical to another driver if the driver you are describing has a unique version
number assignment.
If your driver differs for different operating systems, you need to provide a unique
name for each BSP type.
12.5.4.5. create_os
Usage
create_os <name>
Options
• <name>: Name of operating system (BSP type).
Description
This command creates a new operating system (OS) instance (also known as a BSP
type) available for the Nios V processor BSP tools. This command must precede all
others that describe the OS in its Tcl script. You can only have one create_os
command in each Tcl script. If the create_os command appears in the Tcl script, the
create_driver or create_sw_package commands cannot appear.
326
12. Nios V Processor Appendix
743810 | 2022.10.31
The name argument is usually distinct from all other operating systems that the Nios
V processor tools might locate. You can specify an OS name identical to OS if the OS
you are describing has a unique version number assignment.
12.5.4.6. create_sw_package
Usage
create_sw_package <name>
Options
• <name>: Name of the software package.
Description
This command creates a new software package instance available for the Nios V
processor BSP Editor. This command must precede all others that describe the
software package in its Tcl script. You can only have one create_sw_package
command in each Tcl script. If the create_sw_package command appears in the Tcl
script, the create_driver or create_os commands cannot appear.
The name argument is usually distinct from all other device drivers and software
packages that the Nios V processor tools might locate. You can specify a name
identical to another software package if the software package you are describing has a
unique version number assignment.
If your software package differs for different operating systems, you need to provide a
unique name for each BSP type.
12.5.4.7. set_sw_property
Usage
set_sw_property <property> <value>
Options
• <property>: Type of software property being set.
• <value>: Value assigned to the property.
Description
Sets the specified value to the specified property. The properties this command
supports can only hold a single value. This command overwrites the existing (or
default) contents of a particular property with the specified value. This command
applies to device drivers and software packages.
327
12. Nios V Processor Appendix
743810 | 2022.10.31
328
12. Nios V Processor Appendix
743810 | 2022.10.31
329
12. Nios V Processor Appendix
743810 | 2022.10.31
Note: This property is valid for operating systems and device drivers.
12.5.4.8. set_sw_setting_property
Usage
set_sw_setting_property <setting-name> <property-name> <property-
value>
Options
• <setting-name>: Name of the setting to persist in the BSP settings file.
• <property-name>: Name of the setting property to update.
• <property-value>: Value of the setting property to update.
Description
Update a software components setting property. The setting must already be added
using add_sw_setting2 command before calling this method.
Example
set_sw_setting_property MY_FAVORITE_SETTING default-value '42'
330
12. Nios V Processor Appendix
743810 | 2022.10.31
The design examples provide scripts that allow you to automate the design example
generation, and build both a BSP project and a simple application project. The design
examples are preset to an Intel FPGA device. If you targeting a different Intel FPGA
device, please perform device migration to the design example project.
Figure 20. IP Parameter Editor for Nios V/m Processor Intel FPGA IP
Note: The script may vary from other design example. Please utilize the design example
readme.txt for detail flow to generate and run the design example
readme.txt Describe the design example details and provide steps to run the design example automation
scripts
create_design.py The primary python script that calls out others automation Tcl script to build the design example
331
12. Nios V Processor Appendix
743810 | 2022.10.31
Example 30. Build Flow from readme.txt (GSFI Bootloader Example Design)
#Launch niosv-shell
<ACDS>/niosv/niosv-shell
#Run create_design.py to build the example design and program the board
quartus_py create_design.py
Related Information
• Nios V Processor Tools on page 15
• Intel® FPGA Technical Training
Online training demonstrations located on the Embedded Design Curriculum
page of the Intel FPGA Technical Training website.
• Nios V Processor Embedded Design Handbook
• Getting Started with the Hardware Abstraction Layer on page 73
332
743810 | 2022.10.31
Send Feedback
IP versions are the same as the Intel Quartus Prime Design Suite software versions up
to v19.1. From Intel Quartus Prime Design Suite software version 19.2 or later, IP
cores have a new IP versioning scheme.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.
743810 | 2022.10.31
Send Feedback
2022.10.31 22.1std Added topic Intel Quartus Prime Software Support for Intel Quartus Prime
Standard Edition software release.
Intel Corporation. All rights reserved. Intel, the Intel logo, and other Intel marks are trademarks of Intel
Corporation or its subsidiaries. Intel warrants performance of its FPGA and semiconductor products to current
specifications in accordance with Intel's standard warranty, but reserves the right to make changes to any ISO
products and services at any time without notice. Intel assumes no responsibility or liability arising out of the 9001:2015
application or use of any information, product, or service described herein except as expressly agreed to in Registered
writing by Intel. Intel customers are advised to obtain the latest version of device specifications before relying
on any published information and before placing orders for products or services.
*Other names and brands may be claimed as the property of others.