Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

7.7.6.4. Provide *INSTANCE and *INIT Macros

To enable the HAL to use your driver, you must provide two HAL macros. The names of these macros are based on the name of your network interface component, according to the following templates:
  • <component name>_INSTANCE
  • <component name>_INIT

For examples, refer to ALTERA_AVALON_LAN91C111_INSTANCE and ALTERA_AVALON_LAN91C111_INIT in <SMSC path> /inc/iniche/altera_avalon_lan91c111_iniche.h, which is included in <iniche path> /inc/altera_avalon_lan91c111.h.

You can copy altera_avalon_lan91c111_iniche.h and modify it for your own driver. The HAL expects to find the *INIT and *INSTANCE macros in <component name>.h.

For more information, refer to the “Header Files and alt_sys_init.c” chapter. You can accomplish this with a #include directive as in altera_avalon_lan91c111.h, or you can define the macros directly in <component name>.h.

Your *INSTANCE macro declares data structures required by an instance of the MAC. These data structures must include an alt_iniche_dev structure. The *INSTANCE macro must initialize the first three fields of the alt_iniche_dev structure, as follows:

  • The first field, llist, is for internal use, and must always be set to the value ALT_LLIST_ENTRY.
  • The second field, name, must be set to the device name as defined in system.h. For example, altera_avalon_lan91c111_iniche.h uses the C preprocessor’s ## (concatenation) operator to reference the LAN91C111_NAME symbol defined in system.h.
  • The third field, init_func, must point to your software initialization function.

    For more information, refer to the “Provide a Software Initialization Function” chapter.

    For example, altera_avalon_lan91c111_iniche.h inserts a pointer to alt_avalon_lan91c111_init().

Your *INIT macro initializes the driver software. Initialization must include a call to the alt_iniche_dev_reg() macro, defined in alt_iniche_dev.h. This macro registers the device with the HAL by adding the driver instance to alt_iniche_dev_list.

When your driver is included in a Nios II BSP project, the HAL automatically initializes your driver by invoking the *INSTANCE and *INIT macros from its alt_sys_init() function. For more information about the *INSTANCE and *INIT macros, refer to the “Header Files and alt_sys_init.c” chapter.