¡¾Nios II¡¿How Can I Find Out These Functions £¿

I'm a beginner in the Nios II System. When I learn the examples provided by Nios II IDE, I always see this type's function : IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, count); The function appears in the example "count_binary".

But I can't find out the detailed information about this type function , only find these three messages: #define IOWR_ALTERA_AVALON_PIO_DATA(base, data) IOWR(base, 0, data)

#define IOWR(BASE, REGNUM, DATA) \ __builtin_stwio (__IO_CALC_ADDRESS_NATIVE ((BASE), (REGNUM)), (DATA))

#define __IO_CALC_ADDRESS_NATIVE(BASE, REGNUM) \ ((void *)(((alt_u8*)BASE) + ((REGNUM) * (SYSTEM_BUS_WIDTH/8))))

But I still don't understand the meanning of this function. Please tell me how can I find out the detailed information about these types' function?

Reply to
hezhikuan2007
Loading thread data ...

In chapter 13 of the Quartus II Handbook V5: Embedded Peripherals, there is a brief note on page 6 under "Software Programming Model" that mentions the header file and the fact that there's no HAL API for the PIO core.

And that's about the extent of the documentation IIRC.

I've had similar frustrations with several aspects of the NIOS API - and on more than one occasion have had to search header files and 'reverse engineer' the interface to work out how to use the component.

These aren't "functions" as such but are macros which ultimately result in what appears to be a simple direct memory-pointer access provided by __builtin_stwio.

Regards,

--
Mark McDougall, Engineer
Virtual Logic Pty Ltd, 
21-25 King St, Rockdale, 2216
Ph: +612-9599-3255 Fax: +612-9599-3266
Reply to
Mark McDougall

The macro is setting a register in one of the GPIO devices, in this case the first one, at the base address. LED_PIO_BASE is the base address of the device, as it was assigned in the SOPC builder.

This translates it to a generic base+offset register access.

However, IOWR uses register numbers rather than register offsets. The register offset for a given number depends on the bus width.

This works out the final register address.

In your simple example, the call

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, count);

is equivalent to

*(volatile unsigned long *)LED_PIO_BASE = count;

In other words, it is a write to the bus address specified in LED_PIO_BASE. However, if you want to keep your code portable between different NIOS systems, use the macros.

Kind regards,

Iwo

Reply to
Iwo Mergler

Thank you very much!

Reply to
lexluthor

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.