- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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...- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- 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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
#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'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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is OK now. Thank you for your help Ken.
Regards, Piotr.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can I see your Makefile?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi ken,
<div class='quotetop'>QUOTE </div> --- Quote Start --- np_timer *timer;[/b] --- Quote End --- in timer.c Where is np_timer defined?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It's defined in the linux kernel...
.../linux-2.6.x/include/asm/nios2nommu/timer_struct.h- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ken:
where are the other hardware_structs? For example lan91c111, dma,....... You have make the API?- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 !- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Linux doesn't make use of the IORD and IOWR commands that Altera defines. So you won'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'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'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...- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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'm guaranteed to receive current data. Writing is done in the same fashion. Since access is so simple, there are no macro's to read and write from hardware for Linux as far as I know.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page