Specifications

Creating a Custom Device Driver for the HAL
This section describes how to provide appropriate files to integrate your device driver in the HAL.
For more information about the correct locations for the files, refer to the “Integrating a Device Driver in
the HAL” chapter.
Related Information
Integrating a Device Driver in the HAL on page 7-15
Header Files and alt_sys_init.c
At the heart of the HAL is the autogenerated source file, alt_sys_init.c. This file contains the source code
that the HAL uses to initialize the device drivers for all supported devices in the system. In particular, this
file defines the alt_sys_init() function, which is called before main() to initialize device drivers
software packages, and make them available to the program.
When you create the driver or software package, you specify in a Tcl script whether you want the
alt_sys_init() function to invoke your INSTANCE and INIT macros.
For more information, refer to the “Enabling Software Initialization” chapter.
Note:
The remainder of this section assumes that you are using the alt_sys_init() HAL initialization
mechanism.
Related Information
Enabling Software Initialization on page 7-22
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 );
}
7-28
Creating a Custom Device Driver for the HAL
NII5V2
2015.05.14
Altera Corporation
Developing Device Drivers for the Hardware Abstraction Layer
Send Feedback