Altera_Forum
Honored Contributor
13 years agoUsing an address to access registers
I have what seems to be a fairly common IO problem in FPGA hardware design. I'm designing an FPGA that will do a number of hardware functions for my CPU. Things like handling input bits, output bits, and several UARTs. I'm using a multiplexed 8 bit address/data bus to communicate with the FPGA.
To handle the communication with all the different hardware functions I am setting up a number of "registers", up to 256 of them, that I can write or read to control all the functions I design in. The problem is how to manage and address that large set of data registers. I want to set up structures of named variables something like this:
struct packed {
reg firmware_version;
reg hardware_options_flags;
reg inputs;
reg outputs;
reg uart1_baud_rate;
reg uart1_data;
} registers;
Of course the final set of registers will be much larger, approaching 256 of them. Then my CPU software will know that firmware_version is at address 0, and uart1_baud_rate is at address 4, and so on. My question is how do I use the address that the CPU is sending to access a variable inside this packed structure? I have tried to calculate the bit address range (something like 8*addr+7: 8*addr) but the compiler complains that its not a constant. Is my only option to use a huge case statement with 256 different entries in it?