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++

Your hardware and uClinux

Altera_Forum
Honored Contributor II
3,001 Views

Hi again, 

 

Adding an Avalon custom hardware and its software driver (either HAL or not) is easy and straightforward. Having said that I mean the standard Nios II IDE project_syslib/system_description/system.h way. 

 

Building a custom system that runs uClinux is also not an issue but haw can I use my Avalon hardware under uClinux? 

 

Thanks for any suggestions, 

Piotr.
0 Kudos
14 Replies
Altera_Forum
Honored Contributor II
624 Views

I guess it depends if you want to build a proper Linux driver for your avalon hardware. The basic IRQ and base address for your hardware should appear within the  

 

<project>/build/include/nios2_system.h 

 

file in your kernel project directory. 

 

If you&#39;re not interested in building a driver, then the hardware can be accessed from a regular Linux application as it would be in a non-HAL standalone application. 

 

If you&#39;re interested in building a driver, I think there was a thread in this forum to help you get started...
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

 

--- Quote Start ---  

originally posted by ken@Nov 29 2004, 10:06 AM 

if you&#39;re not interested in building a driver, then the hardware can be accessed from a regular linux application as it would be in a non-hal standalone application. 

--- Quote End ---  

 

 

Let’s assume that I am not interested in the Linux driver, at least for now, and want to access my HW from uClinux application (which should be far easier for a hardware guy like me). This is not a problem from within a standalone non-HAL application: there are IOWR and IORD macros to use, but are there any equivalents of these in the uClinux environment?
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Fair enough, here&#39;s a code example that pokes around a hardware timer from a user application: 

 

include Rules.mak ECLIPSE_WORKSPACE := /cygdrive/c/altera/kits/nios2/bin/eclipse/workspace KERNEL_PROJECT := uKit_kernel_default BUILDDIR := $(ECLIPSE_WORKSPACE)/$(KERNEL_PROJECT)/build/include CFLAGS += -O0 -g -I$(BUILDDIR) all: timer.exe timer.gdb 

 

#include <errno.h># include <stdio.h># include "nios2_system.h" int main (int argc, char* argv) {  int i;  np_timer *timer;    timer = na_timer0;  i = (timer->np_timerperiodh << 16) | timer->np_timerperiodl;  printf ("timer period valud is %i \n", i);    timer->np_timersnapl = 0;  i = (timer->np_timersnaph << 16) | timer->np_timersnapl;  printf ("The current timer value is %i\n", i);    return 0; } 

 

The first code segment is a Makefile and the second one is the timer.c file that is referenced within the Makefile. 

 

You&#39;ll notice the inclusion of the "nios2_system.h" header file within timer.c, that file is dynamically generated and can be found within a kernel project build/include directory. 

 

The two code segments can be copied into an application project and built after ensuring that you&#39;re referencing the correct kernel project. 

 

Does this help?
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

This is OK now. Thank you for your help Ken. 

 

Regards, 

Piotr.
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Hi i compiled this file and tried to start it under uClinux but i get allways this error message: 

# cd /bin# timer 

BINFMT_FLAT: bad magic/rev <0x3000000, need 0x4> 

BINFMT_FLAT: bad magic/rev <0x3000000, need 0x4> 

MZ>: not found#  

 

 

Does anybody know something about this message?
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Can I see your Makefile?

0 Kudos
Altera_Forum
Honored Contributor II
624 Views

hi ken, 

 

<div class='quotetop'>QUOTE </div> 

--- Quote Start ---  

np_timer *timer;[/b] 

--- Quote End ---  

in timer.c 

 

Where is np_timer defined?
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

It&#39;s defined in the linux kernel... 

 

.../linux-2.6.x/include/asm/nios2nommu/timer_struct.h
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Hi Ken: 

 

 

where are the other hardware_structs? For example lan91c111, dma,....... 

You have make the API?
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

All of that would be in the kernel includes directory... 

 

[SOPC Builder]$ cd $KERNEL_PLUGIN/linux-2.6.x/include 

 

At least, that&#39;s where I&#39;d expect to find them. I haven&#39;t checked in awhile.
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Hi Ken ! 

 

 

I want to write a driver in uClinux ( from Microtronix plug-in in NIOS II IDE ), so i need a c example of using iow ( iowrite ) / ior ( ioread ) 

 

Please help me. 

 

 

Thank you very much !
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Linux doesn&#39;t make use of the IORD and IOWR commands that Altera defines. So you won&#39;t find any examples of those. 

 

What I would recommend would be to take a look at some of the freebie sites with information on how to write device drivers. That&#39;s usually a good starting point. 

 

For instance, I learned how to write my first modular driver using: 

 

http://lwn.net/articles/driver-porting/ (http://lwn.net/articles/driver-porting/

 

A few mods have to be made to some of the Makefile examples but all in all it worked pretty well. 

 

A few things to note: 

(1) any type of kernel work (device drivers, making mod&#39;s to the kernel, etc). cannot be performed from within Eclipse. It needs to be done from the commandline (Nios II SDK Shell) 

(2) the kernel source code can be found at $KERNEL_PLUGIN/linux-2.6.x 

(3) your kernel build directory can be found at $ECLIPSE_WORKSPACE/<project>/build 

 

Hope this helps...
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

Hi Ken ! 

 

But, there should be a function to access a hardware on the board ( ie: 4 pins of speaker on the Altera Cyclone 1c12 eval board ) 

 

Please show me if there is 

 

Thank you very much, 

 

OneNet
0 Kudos
Altera_Forum
Honored Contributor II
624 Views

All hardware in any Nios II based system can be accessed via simple memory reads/writes. 

 

So, for example, if your hardware has registers at 0x00920830, then you can read from the first 4 bytes of your register by using something as simple as: 

 

int *addr = 0x80920830; 

int reg = *addr; 

 

Notice that I turned on the high bit for the address of the registers. This bypasses the data cache so that I&#39;m guaranteed to receive current data. Writing is done in the same fashion. 

 

Since access is so simple, there are no macro&#39;s to read and write from hardware for Linux as far as I know.
0 Kudos
Reply