Forum Discussion
Altera_Forum
Honored Contributor
21 years agoYour hardware and uClinux
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.14 Replies
- Altera_Forum
Honored Contributor
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'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're interested in building a driver, I think there was a thread in this forum to help you get started... - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by ken@Nov 29 2004, 10:06 AM if you'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? - Altera_Forum
Honored Contributor
Fair enough, here'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
The first code segment is a Makefile and the second one is the timer.c file that is referenced within the Makefile. You'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're referencing the correct kernel project. Does this help?#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; } - Altera_Forum
Honored Contributor
This is OK now. Thank you for your help Ken.
Regards, Piotr. - Altera_Forum
Honored Contributor
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? - Altera_Forum
Honored Contributor
Can I see your Makefile?
- Altera_Forum
Honored Contributor
hi ken,
<div class='quotetop'>QUOTE </div> --- Quote Start --- np_timer *timer;[/b] --- Quote End --- in timer.c Where is np_timer defined? - Altera_Forum
Honored Contributor
It's defined in the linux kernel...
.../linux-2.6.x/include/asm/nios2nommu/timer_struct.h - Altera_Forum
Honored Contributor
Hi Ken:
where are the other hardware_structs? For example lan91c111, dma,....... You have make the API? - Altera_Forum
Honored Contributor
All of that would be in the kernel includes directory...
[SOPC Builder]$ cd $KERNEL_PLUGIN/linux-2.6.x/include At least, that's where I'd expect to find them. I haven't checked in awhile.