I am importing C function in my testbench. The output in C model is correct, while the same output imported in SV testbench is incorrect only in case of appending zeros.
For example
C output:: 0xc1960000, -18.750
SV ouput = c196
EDA Playground Link:
In reply to yasirdv:
You only allocate 4 characters for your out_cipher, hence only 4 characters being returned. You also have an out of bounds access error when setting out_cipher[4] to ‘\0’, as out_cipher only goes from 0 to 3.
In reply to cgales:
Thanks for your recommendation. But in my opinion, this is not the case. It only happens in case of 00. If there are non-zero bytes, the output is returned correctly. For example, if there is any character other than 00, its ascii value goes to the output. Also, if I try to append “00” as character, its ascii value 0x30 is appended. But I need 00.
In reply to yasirdv:
The basic problem is the output of fp_func is a string, and you are trying to display that result with a %h format which requires an integral type. That is illegal and should be an error. The string data type does not allow the character ‘\0’ and will remove ir.
Also as cgales mentions, you only allocated 4 bytes to out_cipher, yet you are tring to write to the 5th byte. You are just lucky this did corrupt anything else.
It is not clear why you are trying to have your function return a string and not a unsigned int. If you could explain that, maybe we can suggest a better solution.
In reply to dave_59:
Thanks a lot, Due to your valuable suggestions, I’ve been able to do it correctly.
This is the correct output achieved for reference.
In reply to yasirdv:
You did not make your code publicly accessible. It would be better to paste and format your code directly into your posting anyways.
In reply to dave_59:
I forgot that previously. Now its publicly available. Thanks for reminding me!
Hi
I am new to the concept of DPI. I am having a testbench through which i am supplying some random stream of data to the DUT and i am capturing those in the scoreboard. Parallely i have a “.so” file and few header files. I am not able to coordinate the bridge between these two and how to use the “.so” file. Can anyone please help me with how i can use those / any basic documents i should go through ?
In reply to rishabmu:
I suggest staring with a simple DPI example before trying to integrate DPI into an exiting testbench. Check your tool’s user manual and examples directory.
Thank you Dave for the response, I will go through and come back with dedicated question.