FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
5952 Discussions

is there a way to build a register to a variable in nios?

Honored Contributor II

My intention is to define a variable on a specific address which is connected to io bus. 

So that everytime i place a value in the variable it will automaticly route itself to the io's 

0 Kudos
1 Reply
Honored Contributor II

1) Define the symbol value in the linker script, eg: 

/* Address of systom monitor - interrupts and timers/counters. * Mapped to be accessible as offsets from %gp. * See nios_sysmon.h */ nios_sysmon = 0x20000;2) Define an absolute symbol in a assembly source file: eg (I think): 

.global nios_sysmon .equ nios_sysmon,0x20000 This should also work inside an asm() statement in a C file - even in a .h file. 


Remember to make the C variable 'volatile' and to define an address that will bypass the data cache - my example above is real, but I don' use the data cache. 


Such 'direct access' to variables requires 2 instructions (because the NIOS doesn't have 32bit address offsets). The compiler can't know that multiple variables are in nearby addresses - so has to generate separate addresses for each - which adds a lot of register pressure (as well as a few extra instructions). 


I arranged for my IO and tightly coupled data memory to be accessable from %gp - but had to fix the compiler so that it would add structure offsets into the offset from %gp (ok because if the start of an item is in the 'small data area' then so must be the end).