Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
7 years ago

How can I write to Custom IP register from C code?

Hello all. I'm designing a custom IP that outputs simple number data in each cycle.

The IP has both Avalon Slave Interface and Avalon Master Slave :

The Master Interface is connected to On-Chip Memory's Avalon Slave Interface where I will store the output data in.

The Slave Interface is connected to Nios2's Avalon Master Interface.

Here, I want to write data into the custom IP, controlled on C code. I plan to use pointers like this :

| volatile int * adr = (int *) (base address of custom IP);

| adr = 0x00000001;

I believe Nios2 Processor IP handles the Interface connections so that I can manage this on C code, right?

I want to send the 32-bit data into the Custom IP, where it will store the data into it's register (reg).

The data will be used to initiate the module - work as a 'start shotting numbers' register.

What I just tried is doing it like :

| // Avalon Slave //

| output reg [31:0] s_rdata;

|

| input s_read;

| input s_write;

| input [3:0] s_addr; //slave address

| input [31:0] s_wdata; //slave writedata

|

| reg [31:0] start;

|

|

| always @(posedge clk) begin

| start <= s_wdata;

| end

|

| (later check 'if(start<=32'b1)' to initiate the module's function)

However, for some reason the data wasn't written into 'start' register.

So the question here is : How can I write to the IP's register, from C code?

I need to make the work of the IP software-controlled.

Thank you.