Nios® V Processor Software Developer Handbook

ID 743810
Date 4/01/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

4.4.1.1. Tcl Script to Examine Hardware and Choose Settings

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.

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"

# Get all slaves attached to the processor.
set slave_descs [get_slave_descs]
foreach slave_desc $slave_descs {

# Lookup module class name for slave descriptor.
set module_name [get_module_name $slave_desc]
set module_class_name [get_module_class_name $module_name]

# If the module_name contains "stdio", we choose it and return immediately.
if { [regexp .*stdio.* $module_name] } {
return $slave_desc
}

# 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
}}

# Track last character device in case no JTAG UARTs found.
if { [is_char_device $slave_desc] } {
set last_stdio $slave_desc
}}
if {$first_jtag_uart != "none"} {
return $first_jtag_uart
}
return $last_stdio
}

# Call routine to determine stdio
set default_stdio [choose_default_stdio]

# Set stdio settings to use results of above call.
set_setting hal.stdin $default_stdio
set_setting hal.stdout $default_stdio
set_setting hal.stderr $default_stdio