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

Struct interface for IO doesn't work

Altera_Forum
Honored Contributor II
1,307 Views

I was trying to convert a large code base written for the NIOS I processor to NIOS II. My clever idea was to simply include the excalibur.h and compile for NIOS II. However, every time I read from a memory address through the old struct interface of NIOS I, the compiler uses a ldw assembly instruction. If I do the same memory-mapped read using the macros supplied with NIOS II, the compiler uses a ldwio. What gives? Did Altera hack their compiler to explicitly not support a struct-based interface for memory-mapped IO? 

 

--Jordan
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
520 Views

Hi Jordan, 

 

> However, every time I read from a memory address through the old struct interface of NIOS I, 

> the compiler uses a ldw assembly instruction. 

 

This is correct behavior. 

 

> If I do the same memory-mapped read using the macros supplied with NIOS II, the compiler 

> uses a ldwio. 

 

If you're referring to the IORD/WR macros, this is correct. 

 

> What gives? 

 

The compiler doesn't know anything about your data cache. If you don't implement a data 

cache, then ldw/ldwio behave identically. However, if you do implement a data cache you 

need to do one of two things: 

 

1. Use the IO macros, which will explicitly use ldxio, or, 

2. Make your structs (describing registers) volatile, and use -mno-cache-volatile. 

 

The volatile keyword in no sufficient -- it only tells the compiler that it must perform 

memory read/write on each object reference (rather than storing it in a register). But it 

doesn't tell the compiler anything about _how_ to access the object -- that's where the 

compiler flag comes in :-) 

 

Hope this helps. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
520 Views

Ah, I didn't know about the compiler flag. 

 

Thanks, that does help. 

 

--Jordan
0 Kudos
Reply