Nios® II Software Developer Handbook

ID 683525
Date 8/28/2023
Public
Document Table of Contents

8.9.1.1. Creating alt_sys_init.c Based on Associated Header Files

The Software Build Tools (SBT) creates 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.

Like a device driver, a software package provides an INSTANCE macro, which alt_sys_init() invokes once. A software package header file can optionally provide an INIT macro.

Example 7–4. Excerpt from an alt_sys_init.c File Performing Driver Initialization

#include "system.h"
#include "sys/alt_sys_init.h"
/*
* device headers
*/
#include "altera_avalon_timer.h"
#include "altera_avalon_uart.h"
/*
* Allocate the device storage
*/
ALTERA_AVALON_UART_INSTANCE( UART1, uart1 );
ALTERA_AVALON_TIMER_INSTANCE( SYSCLK, sysclk );
/*
* Initialize the devices
*/
void alt_sys_init( void )
{
ALTERA_AVALON_UART_INIT( UART1, uart1 );
ALTERA_AVALON_TIMER_INIT( SYSCLK, sysclk );
}