Ok, let's start by simply controlling the LEDs first.
-- Reconfigure the linux kernel. Under "Processor type and features" take off "Enable leds, seven segment display". This will prevent the kernel from automatically incrementing the LEDs when running. Recompile the kernel and upload to the board.
-- Start a new project, "Microtronix Nios II" -> "Linux Application Project". Call it
"LEDControl" or something like that. Press Finish.
-- Create a make file. Right click on LEDControl in Navigator view, choose "New" -> "File" then call it "Makefile"
-- In the Makefile, put
include Rules.mak
all: LEDControl.exe LEDControl.gdb
-- Add new file again, this time call it "LEDControl.c". This will be the main program.
-- Add this code to LEDControl.c, replace the nios2_system.h path with correct path of your linux kernel project. I couldn't get the include path to work properly in Eclipse, so this is a quick hack.
/* program for writing to LEDs on the Nios board */# include <stdio.h># include <unistd.h> // for sleep()# include <
C:\altera\kits\nios2\bin\eclipse\workspace\linux1\build\include\nios2_system.h>
int main ()
{
np_pio *pio = na_led_pio;
pio->np_piodirection = 3;
pio->np_piodata = 0;
unsigned char mydata=0;
while(1)
{
pio->np_piodata = mydata;
mydata++;
sleep(1);
}
return 0;
}
-- Right click on project and choose "Build Project". LEDControl.exe should have been built.
-- Assuming you have a CF card and a mounted file system and ftpd running and all, ftp to the board and upload LEDControl.exe to the board. In my case it goes under /mnt/ide0. If your configuration is different, you must find a different way to get the executable to the board.
-- I use telnet to access the board. So in my case i would telnet, then login as "root" "uClinux". cd /mnt/ide0. Make the app executable by typing "chmod 700 LEDControl.exe". Then execute the application "./LEDControl.exe"
-- When it runs LEDs should start incrementing in a sequence. Press control+c to break the execution.
- Thomas