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

why is it base address?

Altera_Forum
Honored Contributor II
1,293 Views

I make leds light by using PIO of sopc! 

but i must change some code in niosII IDE!# include "system.h"# include "altera_avalon_pio_regs.h"# include "alt_types.h" 

 

/*  

* This is a freestanding application, so we want to use alt_main 

* as the entry point. However, if the debugger is run on this 

* application, it will try to set a breakpoint at main, which  

* the application does not contain. The below line creates an 

* alias so the debugger is able to set a breakpoint at main,  

* yet the application retains alt_main as it's entry point. 

*/ 

 

int main (void) __attribute__ ((weak, alias ("alt_main"))); 

 

/*  

* Use alt_main as entry point for this free-standing application 

*/ 

 

int alt_main (void) 

alt_u8 led = 0x2; 

alt_u8 dir = 0; 

volatile int i; 

 

/*  

* Infinitly shift a variable with one bit set back and forth, and write 

* it to the LED PIO. Software loop provides delay element. 

*/ 

while (1)  

if (led & 0x81)  

dir = (dir ^ 0x1); 

 

if (dir)  

led = led >> 1; 

}  

else  

led = led << 1; 

IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, led); 

// Write led data to the address of pio_o_base 

/*  

* The delay element in this design has been written as a while loop 

* to avoid confusing the software debugger. A tight, one line software 

* delay loop such as: 

* for(i=0; i<200000; i++); 

* can cause problems when it is stepped through using a software debugger. 

* The while loop below produces the same behavior as the for loop shown  

* above, but without causing potential debugger problems.  

*/ 

 

i = 0; 

while (i<20000) 

i++; 

 

return 0; 

 

 

I donot know why I must change LED_PIO_BASE to PIO_0_BASE?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
265 Views

It all depends on what name you gave to the PIO in SOPC Builder. 

This name will propagate to the system.h file that gets generated by the IDE.
0 Kudos
Altera_Forum
Honored Contributor II
265 Views

If you have your system library compiled, look under the debug or release folder (whichever mode you compiled with) and look for system.h under system description folder. That system.h file has# defines for all the peripherals connected to that particular Nios II processor and that&#39;s where the name "PIO_0_BASE" is defined. So in your system your pio was called pio_0 or PIO_0. That software template assumes that the 8 bit pio in your system was called led_pio or LED_PIO which is why the compiler expected "LED_PIO_BASE" (that software template assumes you used a hardware reference design that was installed with Nios II).

0 Kudos
Reply