Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
840 Views

Issue with the application layer from NIOS II IDE while accessing a custom instructio

Hello, 

 

I have implemented a custom instruction for full adder (just a basic one) in verilog for NIOS II. 

However when my application code (C) from NIOS II tries to access the macro for the custom instruction, I 

see one input operand value being tried up to a strange value, 2047 (!). Any guess what might be causing the issue? 

I have checked almost all the sides, however I could not find the issue. 

 

I am attaching the verilog modules with this email, I have tested in Modelsim and there it works good. 

I am pasting the valid instructions from the file custom_add_hw.tcl below: 

 

"add_interface nios_custom_instruction_slave_0 nios_custom_instruction end 

set_interface_property nios_custom_instruction_slave_0 clockCycle 0https://www.alteraforum.com/forum/attachment.php?attachmentid=6957  

set_interface_property nios_custom_instruction_slave_0 operands 2 

set_interface_property nios_custom_instruction_slave_0 ENABLED true 

 

 

add_interface_port nios_custom_instruction_slave_0 clk clk Input 1 

add_interface_port nios_custom_instruction_slave_0 reset reset Input 1 

add_interface_port nios_custom_instruction_slave_0 dataa dataa Input 32 

add_interface_port nios_custom_instruction_slave_0 datab datab Input 32 

add_interface_port nios_custom_instruction_slave_0 n n Input 3 

add_interface_port nios_custom_instruction_slave_0 clk_en clk_en Input 1 

add_interface_port nios_custom_instruction_slave_0 start start Input 1 

add_interface_port nios_custom_instruction_slave_0 done done Output 1 

add_interface_port nios_custom_instruction_slave_0 result result Output 32"https://www.alteraforum.com/forum/attachment.php?attachmentid=6957 https://www.alteraforum.com/forum/attachment.php?attachmentid=6958 https://www.alteraforum.com/forum/attachment.php?attachmentid=6959  

 

Now from the NIOS II IDE, I am trying to call the custom instruction using the macro  

sumOutput = ALT_CI_CUSTOM_ADD_INST(4,1,10); as shown in the attached .c file. 

However the output I am getting is, 

Hello from Nios II! 

 

 

The sum is 2057  

which is 2047 (for dataa, I donno why) + 10 (for datab, which gets proper value). 

 

Please help me in solving this issue. 

 

Thank You, 

Akhil
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
47 Views

Hello, 

 

Can someone be of assistance to this post please? I am struck at this point in the simulation, appreciate any inputs. 

If the post is not clear, I can explain the scenario once again. 

 

Thank You, 

Akhil
Altera_Forum
Honored Contributor I
47 Views

Have you simulated this to make sure it's not the custom instruction itself? i.e. do you know for sure your custom instruction is seeing n = 4, dataa = 2047, datab = 10? 

 

Also did you read page 11 of this document? http://www.altera.com/literature/ug/ug_nios2_custom_instruction.pdf By including the clock enable, start, and done signals it is up to your custom instruction to time everything properly.
Altera_Forum
Honored Contributor I
47 Views

Hello, 

 

Sorry, it had been my fault in the verilog and the fault was with respect to the timing. 

Earlier, I had been trying to do the ADD operation and read the result output port in the same clock cycle which was making the module confused 

and I guess the dataa port had been getting unknown value (like 2047) because of that timing issue. I really appreciate for BadOmen who made me 

to look into the custom instruction timing diagram once again (I am just a beginner). 

 

See what I did now is having separate 'write' and 'read' instructions and added the lines of code in verilog module custom_Component.v 

if(write && chipselect) begin 

cin = 0; 

{cout, output_value} = writedataa + writedatab + cin; 

end 

 

else if((read == 1) && (chipselect == 1)) 

begin 

readdata <= output_value; 

end 

 

so that before reading a result port, there will be a write latency. 

I tried to access from the application code (in NIOS II IDE) like this: 

 

/* Write Sum */ dataa = 0XFFFFFFFF; 

datab = 0XFFFFFFFF; 

sumOutput = ALT_CI_CUSTOM_ADD_INST(1,dataa,datab); 

printf("\nThe result line value is %lu",sumOutput); // Expect some unknown value to print 

/* Read Sum */ 

sumOutput = ALT_CI_CUSTOM_ADD_INST(4,dataa,datab); // Expect the earlier SUM value to print 

printf("\nThe SUM of %lu and %lu is %lu",dataa,datab,sumOutput); 

 

And the sumOutput variable printed an expected value!. 

 

I appreciate the effort taken by forum admins to sort this out. 

 

Thank You, 

Akhil
Reply