Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
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 users set the setting to true or 1, the BSP defines MY_CUSTOM_DRIVER_SMALL in either system.h or the BSP public.mk file. When the user compiles the BSP, your driver is compiled with the appropriate routine incorporated in the object file. When a user disables the setting, MY_CUSTOM_DRIVER_SMALL is not defined.

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

Each argument has several variants.

For more information about detailed usage and restrictions, refer to the "Nios II Software Build Tools Reference" chapter.