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

Linux Application

Altera_Forum
Honored Contributor II
1,216 Views

Greetings, Long story here... 

 

I have taken the Linux Ref Design provided by Microtronix and I have added a PIO -> user_pio. I have re-generated the system and compiled my design in Quartus. When I launch the IDE, I can create a NIOS II C Application and run code to write to my PIO (using IOWR_ALTERA_AVALON_PIO_DATA macro function). 

 

When I create my Linux Application Project, it does not like the IOWR_ALTERA_AVALON_PIO_DATA macro - understandably since this macro is not supported in uC-Linux. 

 

So... I have tried to access my pio using a FILE pointer such that: 

 

FILE *fp_User_PIO = 0; fp_User_PIO = fopen("/dev/user_pio","w"); if(fp_User_PIO==0)   printf("Error opening User PIO\n"); // write AA to my PIO fprintf(fp_User_PIO, "%d", 0xAA); 

 

After adding this prog to my filesystem and running the program; it crashed. No suprise after realizing that my new PIO that I added does not exist in /dev (Note that the button_pio created by the ref design does exist as /dev/button) 

 

So, I tried writing to my user_pio as memory: 

 

char* pUserPIO = (char *)USER_PIO_BASE; // this is the base address for my user_pio defined in my system.h file (yes I have included it) // write AA to my PIO pUserPIO = 0xAA; 

This too crashed. I am assuming this is standard practice with a "real" OS such that you don't want any yahoo writing to "just any" memory location. 

 

I have considered using malloc() but figure this will grab a whole new hunk of memory. 

 

Does anyone know how to write to my user_pio? 

 

Should I add it to my FS as /dev/user_pio? If so, how? 

 

Thanks, 

-Terry
0 Kudos
1 Reply
Altera_Forum
Honored Contributor II
271 Views

Hi Terry, 

 

There are several approaches for you.  

 

The "standard" way is to write a driver in kernel (the way Microtronix did for PIO buttons), implementing your PIO device as some kind of device Linux knows (the button is implemented as a character device). Then you can add the device node under /dev/ directory and read/write it as a file.  

 

You can also take advantage of uClinux (no virtual memory and no memory protection) and read/write your device directly, but remember to bypass the cache. This is a quick (but dirty) approach. (It looks like you have tried this approach, but as long as you turned on the 31 bit of the USER_PIO_BASE, I don't think it caused the system crash). 

 

Good luck, 

wentao
0 Kudos
Reply