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

Subversion Repositories csa

[/] [csa/] [trunk/] [bench/] [csa_pli.c] - Rev 35

Go to most recent revision | Compare with Previous | Blame | View Log

/*
 * =====================================================================================
 *
 *       Filename:  read_ikey.c
 *
 *    Description:  this is a pli module to read the input key 
 *
 *        Version:  1.0
 *        Created:  07/10/2008 09:18:10 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  mengxipeng@gmail.com
 *        Company:  mengxipeng
 *
 * =====================================================================================
 */
 
#include <string.h>
#include <stdio.h>
#include <vpi_user.h>
 
 
char  data[120*8*8];
 
static int read_data(char *fn)
{
        vpiHandle    systf_handle;
        vpiHandle    arg_itr;
        vpiHandle    arg_handle;
        s_vpi_value  value_s;
 
        FILE        *fp;
        FILE        *fp1;
        char         str[120];
        int          i;
        int          n;
 
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
        if (arg_itr == NULL) 
        {
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
                return(0);
        }
 
        /* read file name */
        arg_handle = vpi_scan(arg_itr);
        value_s.format = vpiStringVal;
        vpi_get_value(arg_handle, &value_s);
        strcpy(str,value_s.value.str);
 
        fp=fopen(str,"rb");
        if(fp)
        {
                int i;
                int b;
                unsigned int word;
                int vector_size;
                //fscanf(fp,"%s",&data);
                arg_handle = vpi_scan(arg_itr);
 
                vector_size = vpi_get(vpiSize, arg_handle);
                vpi_printf("vector_size=%d \n", vector_size);
 
                value_s.format = vpiVectorVal;
                vpi_get_value(arg_handle, &value_s);
                for (i=0;i<vector_size/32;i++)
                {
                        fread(&word,4,1,fp);
                        value_s.value.vector[i].bval=0;
                        value_s.value.vector[i].aval=word;
                }
                vpi_put_value(arg_handle, &value_s,NULL, vpiNoDelay);
                fclose(fp);
        }
        else
        {
                vpi_printf("can't open the input file in %s \n", __FUNCTION__);
        }
 
        return 0;
}
 
static void read_data_register()
{
        s_vpi_systf_data tf_data;
        tf_data.type      = vpiSysTask;
        tf_data.tfname    = "$read_data";
        tf_data.calltf    = read_data;
        tf_data.compiletf = 0;
        tf_data.sizetf    = 0;
        vpi_register_systf(&tf_data);
}
 
static int write_data(char *xx)
{
        vpiHandle    systf_handle;
        vpiHandle    arg_itr;
        vpiHandle    arg_handle;
        s_vpi_value  value_s;
 
        FILE        *fp;
        char         str[120];
        int          i;
        int          n;
 
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
        if (arg_itr == NULL) 
        {
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
                return(0);
        }
 
        /* read file name */
        arg_handle = vpi_scan(arg_itr);
        value_s.format = vpiStringVal;
        vpi_get_value(arg_handle, &value_s);
        strcpy(str,value_s.value.str);
 
        arg_handle = vpi_scan(arg_itr);
        value_s.format = vpiStringVal;
        vpi_get_value(arg_handle, &value_s);
        if(!strcmp("a",value_s.value.str))
                fp=fopen(str,"ab");
        else
                fp=fopen(str,"wb");
        if(fp)
        {
                unsigned int word;
                int b;
                int i;
                int vector_size;
                value_s.format = vpiVectorVal;
                arg_handle = vpi_scan(arg_itr);
                vector_size = vpi_get(vpiSize, arg_handle);
                vpi_printf("str:%s vector_size=%d\n",str,vector_size);
                vpi_get_value(arg_handle, &value_s);
                for(i=0;i<vector_size/32;i++)
                {
                        vpi_printf("i=%d\n",i);
                        fwrite(&value_s.value.vector[i].aval,4,1,fp);
                }
                fwrite(&value_s.value.vector[i].aval,(vector_size%32)/8,1,fp);
                fclose(fp);
        }
        else
        {
                vpi_printf("can't open the output file in %s \n", __FUNCTION__);
        }
 
        return 0;
}
 
static void write_data_register()
{
        s_vpi_systf_data tf_data;
        tf_data.type      = vpiSysTask;
        tf_data.tfname    = "$write_data";
        tf_data.calltf    = write_data;
        tf_data.compiletf = 0;
        tf_data.sizetf    = 0;
        vpi_register_systf(&tf_data);
}
 
void (*vlog_startup_routines[])() = {
        read_data_register,
        write_data_register,
        0
};
 
 

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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