Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12618 Discussions

Integrating device driver into HAL

Altera_Forum
Honored Contributor II
1,273 Views

I am trying to integrate a peripheral specific device driver (created by me) into the HAL.  

I would like the HAL to automatically instantiate and register my device driver so I have created the  

appropriate directory structure and files shown in figure 5-1 of the SW Dev Manual. 

 

I have created an include file that defines the *_INSTANCE and *_INIT macros and 

placed it in the device’s HAL/inc directory. I have create source code files that 

manipulates the device and placed the files into the HAL/src directory. 

I have included a makefile fragment. 

 

After doing all that I have manually called the *_INSTANCE and *_INIT macros from within 

main() and the driver has successfully registered no problem. I cannot however get 

the HAL to automatically instantiate and register my device driver. That is, my *_INSTANCE and *_INIT  

macros are not added to the auto generated file alt_sys_init.c 

 

The question is, where should I place the driver files so that they will be picked up 

by the IDE ? Or, how do I tell the IDE where I have placed the driver files so they 

will be included ? 

 

thanks.
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
405 Views

Hello snapper, 

 

Normally the source code of your device driver is placed in the directory “%nios-root%/components”. The code includes a ptf-file which is necessary to include your device into the SOPCB. Did you add your new hardware in SOPCB in your project? After adding the device and generating the system in SOPCB and creating a new project in the Nios II IDE the initialization code will be called automatically when the system starts-up. This call (“alt_sys_init”) can be found in “%nios-software-project-root%_syslib/Debug/system_description/alt_sys_init.c”. 

 

 

Bye, 

niosIIuser
0 Kudos
Altera_Forum
Honored Contributor II
405 Views

niosIIuser, 

 

I'm afraid you've missed some steps to get your driver initialised from alt_sys_init, rather than document those here I would rather refer you to the documentation. This can be found in the Nios II Software Developers which can be found in the nios2\documents directory and is the file n2sw_nii5v2.pdf file. Chapter 5 Developing Device Drivers for the Hal has a whole section on how to integrate your driver into the Hal.
0 Kudos
Altera_Forum
Honored Contributor II
405 Views

Thanks for the comments. I finally managed to get the driver integrated and work but not without some experimenting. 

There may be other ways to achieve the same result, but in the end I found that ‘publishing’ the device as user logic through SOPCB was required. This created a bunch of sub directories with the prefix user_logic. If I then prefixed my *_INIT and *_INSTANCE macros and all driver files with USER_LOGIC and put the drivers in the newly created sub folders things seem to work as required. 

I don’t see that mentioned in the Nios II Software Developers any where…..
0 Kudos
Altera_Forum
Honored Contributor II
405 Views

In the errata.txt that comes with the kit it says: 

 

 

"151055 - When you first create a component's inc directory,  

or HAL component header file, you may need to perform  

a clean build, i.e. rebuild, of existing system  

library projects for the new files to be detected." 

 

Could it be that was the problem you were running up against? The important thing here is that it's the system library project, not the application project.
0 Kudos
Reply