User guide
18-52
DirectC Interface
Here the Verilog code declares a 32-bit bit vector, r1, and a 33-bit
bit vector, r2. The values of both are passed to the C/C++ function
big_2state.
When we pass the short bit vector r1 to vc_2stVectorRef it returns
a null value because it has fewer than 33 bits. This is not the case
when we pass bit vector r2 because it has more than 32 bits. Notice
that from right to left, the first 32 bits of r2 have a value of 2 and the
MSB 33rd bit has a value of 1. This is significant in how the C/C++
stores this data.
#include <stdio.h>
#include "DirectC.h"
big_2state(vc_handle h1, vc_handle h2)
{
U u1,*up1,u2,*up2;
int i;
int size;
up1=vc_2stVectorRef(h1);
up2=vc_2stVectorRef(h2);
if (up1){ /* chech for the null value returned to up1 */
u1=*up1;} else{
u1=0;
printf("\nShort 2 state vector passed to up1\n");
}
if (up2){ /* check for the null value returned to up2 */
size = vc_width (h2); /* to find out the number of bits */
/* in h2 */
printf("\n width of h2 is %d\n",size);
size = (size + 31) >> 5; /* to get number of 32-bit chunks */
printf("\n the number of chunks needed for h2 is %d\n\n",
size);
printf("loading into u2");
for(i = size - 1; i >= 0; i--){
u2=up2[i]; /* load a chunk of the vector */
printf(" %x",up2[i]);}
printf("\n");}