Nios® V Processor Software Developer Handbook

ID 743810
Date 2/14/2023
Public

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

Document Table of Contents

7.8.5.3.8. Setting Creation Example

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

Add the MY_CUSTOM_DRIVER_SMALL setting to your driver as follows using the add_sw_setting Tcl command:

add_sw_setting boolean_define_only system_h_define small_driver
 MY_CUSTOM_DRIVER_SMALL false
 "Enable the small implementation of the driver for my_peripheral"
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.