OpenCores
URL https://opencores.org/ocsvn/csa/csa/trunk

Subversion Repositories csa

[/] [csa/] [trunk/] [bench/] [csa_pli.c] - Diff between revs 36 and 37

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 36 Rev 37
Line 175... Line 175...
                unsigned int dword;
                unsigned int dword;
                int i;
                int i;
                int read;
                int read;
                value_s.format = vpiVectorVal;
                value_s.format = vpiVectorVal;
                vpi_get_value(arg_handle_reg, &value_s);
                vpi_get_value(arg_handle_reg, &value_s);
                i=0;
                for(i=0;i+32<=read_size;i+=32)
                if(read_size >= 32)
 
                {
 
                        for(i=0;i<read_size;i+=32)
 
                        {
                        {
                                read=fread(&dword,4,1,fp);
                                read=fread(&dword,4,1,fp);
                                if(1!=read)
                                if(1!=read)
                                {
                                {
                                        vpi_printf("warning read fail [%d] \n",read);
                                        vpi_printf("warning read fail [%d] \n",read);
                                        break;
                                        break;
                                }
                                }
                                value_s.value.vector[i/32].bval=0x00;
                                value_s.value.vector[i/32].bval=0x00;
                                value_s.value.vector[i/32].aval=dword;
                                value_s.value.vector[i/32].aval=dword;
                        }
                        }
                }
 
                if(i<read_size)
                if(i<read_size)
                {
                {
                        PLI_INT32 reduant=read_size-i;
                        PLI_INT32 reduant=read_size-i;
                        PLI_INT32 reduant_mask;
                        PLI_INT32 reduant_mask;
                        int n;
                        int n;
Line 231... Line 227...
        tf_data.compiletf = read_data_compile;
        tf_data.compiletf = read_data_compile;
        tf_data.sizetf    = 0;
        tf_data.sizetf    = 0;
        vpi_register_systf(&tf_data);
        vpi_register_systf(&tf_data);
}
}
 
 
 
// write system call
 
// usage $write_data( file name , [ flags ,] reg)
 
 
 
static int write_data_compile(char* used_data)
 
{
 
        vpiHandle systf_h;
 
        vpiHandle trarg_itr; // argument iterator
 
        vpiHandle trarg_h;   // argument handle;
 
        PLI_INT32 trarg_type; // argument type
 
        s_vpi_value  value_s;
 
 
 
 
 
        systf_h=vpi_handle(vpiSysTfCall,NULL);
 
        if(!systf_h)
 
        {
 
                vpi_printf("ERROR: could not obtain the handle to systf call\n");
 
                tf_dofinish();
 
                return 0;
 
        }
 
 
 
        trarg_itr=vpi_iterate(vpiArgument, systf_h);
 
        if(!trarg_itr)
 
        {
 
                vpi_printf("ERROR: could not obtain the iterate to argument\n");
 
                tf_dofinish();
 
                return 0;
 
        }
 
 
 
 
 
        // get the first argument
 
        trarg_h=vpi_scan(trarg_itr);
 
        if(vpi_get(vpiType,trarg_h)!=vpiConstant&&vpi_get(vpiConstType,trarg_h)!=vpiStringConst)
 
        {
 
                vpi_printf("the first argument type is incorrect (not a string constant)\n");
 
                tf_dofinish();
 
                return 0;
 
        }
 
 
 
        // get flag
 
        trarg_h=vpi_scan(trarg_itr);
 
        trarg_type=vpi_get(vpiType,trarg_h);
 
        if(trarg_type==vpiConstant&&vpi_get(vpiConstType,trarg_h)==vpiStringConst)
 
        // flag
 
        {
 
                value_s.format=vpiStringVal;
 
                vpi_get_value(trarg_h,&value_s);
 
 
 
                if(
 
                           strcasecmp(value_s.value.str,"A")
 
                           )
 
                {
 
                        vpi_printf("error, not only support addpend A flag[%s]\n",value_s.value.str);
 
                        tf_dofinish();
 
                        return 0;
 
                }
 
 
 
                trarg_h=vpi_scan(trarg_itr);
 
                trarg_type=vpi_get(vpiType,trarg_h);
 
        }
 
 
 
        if(trarg_type!=vpiConstant&&trarg_type!=vpiReg)
 
        {
 
                vpi_printf("error, the last argument is not a constant val [%d]\n",trarg_type);
 
                tf_dofinish();
 
                return 0;
 
        }
 
        if(trarg_type==vpiConstant)
 
        {
 
                if(0!=vpi_get(vpiConstType,trarg_h))
 
                {
 
                        vpi_printf("error, the last argument is not a sub 0 type constant val \n");
 
                        tf_dofinish();
 
                        return 0;
 
                }
 
        }
 
 
 
        return 0;
 
}
 
 
static int write_data(char *xx)
static int write_data(char *xx)
{
{
        vpiHandle    systf_handle;
        vpiHandle    systf_handle;
        vpiHandle    arg_itr;
        vpiHandle    arg_itr;
 
        vpiHandle    arg_handle_fn;
        vpiHandle    arg_handle;
        vpiHandle    arg_handle;
        s_vpi_value  value_s;
        s_vpi_value  value_s;
 
 
        FILE        *fp;
        FILE        *fp;
        char         str[120];
 
        int          i;
 
        int          n;
 
 
 
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
 
        if(systf_handle== NULL)
 
        {
 
                vpi_printf("ERROR: $pow failed to obtain systf call handles\n");
 
                tf_dofinish();
 
                return(0);
 
        }
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
        if (arg_itr == NULL)
        if (arg_itr == NULL)
        {
        {
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
 
                tf_dofinish();
                return(0);
                return(0);
        }
        }
 
 
        /* read file name */
        /* read file name */
        arg_handle = vpi_scan(arg_itr);
        arg_handle = vpi_scan(arg_itr);
        value_s.format = vpiStringVal;
        value_s.format = vpiStringVal;
        vpi_get_value(arg_handle, &value_s);
        vpi_get_value(arg_handle, &value_s);
        strcpy(str,value_s.value.str);
 
 
 
        arg_handle = vpi_scan(arg_itr);
        arg_handle = vpi_scan(arg_itr);
        value_s.format = vpiStringVal;
        if(vpi_get(vpiType,arg_handle)==vpiConstant&&vpi_get(vpiConstType,arg_handle)==vpiStringConst)
        vpi_get_value(arg_handle, &value_s);
        // flags
        if(!strcmp("a",value_s.value.str))
        {
                fp=fopen(str,"ab");
                fp=fopen(value_s.value.str,"ab");// if have flag, then open the file with append mode
 
                arg_handle = vpi_scan(arg_itr);
 
        }
        else
        else
                fp=fopen(str,"wb");
        {
        if(fp)
                fp=fopen(value_s.value.str,"wb");
 
        }
 
        if(!fp)
 
        {
 
                vpi_printf("can not open file to write\n");
 
                tf_dofinish();
 
                return 0;
 
        }
 
 
 
        // write data
        {
        {
                unsigned int word;
                unsigned int word;
                int b;
                int b;
                int i;
                int i;
                int vector_size;
                int vector_size;
                value_s.format = vpiVectorVal;
                value_s.format = vpiVectorVal;
                arg_handle = vpi_scan(arg_itr);
 
                vector_size = vpi_get(vpiSize, arg_handle);
                vector_size = vpi_get(vpiSize, arg_handle);
                vpi_get_value(arg_handle, &value_s);
                vpi_get_value(arg_handle, &value_s);
                for(i=0;i<vector_size/32;i++)
                for(i=0;i+32<=vector_size;i+=32)
                {
                {
                        fwrite(&value_s.value.vector[i].aval,4,1,fp);
                        if(1!=fwrite(&value_s.value.vector[i/32].aval,4,1,fp))
 
                        {
 
                                vpi_printf("[%d]warning:write fail \n",__LINE__);
                }
                }
                fwrite(&value_s.value.vector[i].aval,(vector_size%32)/8,1,fp);
 
                fclose(fp);
 
        }
        }
        else
                if(i<vector_size)
 
                {
 
                        int n;
 
                        unsigned char b;
 
                        unsigned int  last=value_s.value.vector[i/32].aval;
 
                        unsigned int  mask=0xff;
 
                        PLI_INT32 reduant=vector_size-i;
 
                        for(n=0;n<reduant;n+=8)
 
                        {
 
                                b=(last&(mask<<n))>>n;
 
                                if(1!=fwrite(&b,1,1,fp))
        {
        {
                vpi_printf("can't open the output file in %s \n", __FUNCTION__);
                                        vpi_printf("[%d]warning:write fail \n",__LINE__);
 
                                }
 
                        }
 
                }
 
                //fwrite(&value_s.value.vector[i].aval,(vector_size%32)/8,1,fp);
 
                fclose(fp);
        }
        }
 
 
        return 0;
        return 0;
}
}
 
 
Line 295... Line 399...
{
{
        s_vpi_systf_data tf_data;
        s_vpi_systf_data tf_data;
        tf_data.type      = vpiSysTask;
        tf_data.type      = vpiSysTask;
        tf_data.tfname    = "$write_data";
        tf_data.tfname    = "$write_data";
        tf_data.calltf    = write_data;
        tf_data.calltf    = write_data;
        tf_data.compiletf = 0;
        tf_data.compiletf = write_data_compile;
        tf_data.sizetf    = 0;
        tf_data.sizetf    = 0;
        vpi_register_systf(&tf_data);
        vpi_register_systf(&tf_data);
}
}
 
 
void (*vlog_startup_routines[])() = {
void (*vlog_startup_routines[])() = {

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.