Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,083 Views

Embedded Linux and HAL

Hello, 

I'd like to make a question about the peripheral when Linux is installed on a FPGA with NIOS. If I want to access to a peripheral register, I think that I have to make a driver in a Linux manner (device file, major number, etc.). If it is so, how can I call the hal functions? For example, if I want to write in a register, if I make the driver in Linux standard manner, I call fwrite() in the application (that will call the file operations). Can I access to the register without calling IOWR?  

Thank you
0 Kudos
6 Replies
Altera_Forum
Honored Contributor I
54 Views

The best way to make a Linux driver for something that isn't used to boot the kernel is to use a kernel module. You can link the HAL functions in when you create your kernel module. There information on doing this on the net. Just search for "writing Linux device drivers". 

 

You could also consider not using a driver and just using the mmap system call to map the section of memory containing your device registers into the address space of your application. Weather this will work or not depends on the device you are using and how you want applications to interface with it.
Altera_Forum
Honored Contributor I
54 Views

 

--- Quote Start ---  

The best way to make a Linux driver for something that isn't used to boot the kernel is to use a kernel module. You can link the HAL functions in when you create your kernel module. There information on doing this on the net. Just search for "writing Linux device drivers". 

 

--- Quote End ---  

 

 

Thank you for the answer. But, if I make a kernel module, is the linking of the hal's function mandatory to access the register or I can access to the peripheral in the classic Linux manner, i.e. with inb and outb?
Altera_Forum
Honored Contributor I
54 Views

Registers are just memory mapped locations. If you have an address, and it's mapped in kernel address space (see device driver tutorials) you can access your device as you would any other. Just make sure your FPGA logic supports the access types you are using in your driver.

Altera_Forum
Honored Contributor I
54 Views

 

--- Quote Start ---  

Registers are just memory mapped locations. If you have an address, and it's mapped in kernel address space (see device driver tutorials) you can access your device as you would any other. Just make sure your FPGA logic supports the access types you are using in your driver. 

--- Quote End ---  

 

 

The phrase "FPGA logic supports the access types you are using in your driver" means that when in the driver I call outb, the system calls the hal's function?
Altera_Forum
Honored Contributor I
54 Views

outb etc are common interfaces. They will be translated to whatever the device driver translates them to. The default on X86 is I/O instructions. On ARM and other architectures, they are probably just memory accesses. What I meant by supporting the access types is that your FPGA device needs to be able to read or write the size data of the outb etc functions take as arguments. 8, 16, 32 bits depending on what you are using. 8 bit -> outb, 16 bit -> outw, 32 bit -> outl. 

 

When writing your kernel driver, you can use the HAL functions or outb etc, or both as needed. It is easier to read if you use HAL, but more portable to use outb etc.
Altera_Forum
Honored Contributor I
54 Views

Thank you very much!

Reply