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

Subversion Repositories csa

[/] [csa/] [trunk/] [bench/] [csa_pli.c] - Blame information for rev 13

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

Line No. Rev Author Line
1 13 simon111
/*
2
 * =====================================================================================
3
 *
4
 *       Filename:  read_ikey.c
5
 *
6
 *    Description:  this is a pli module to read the input key
7
 *
8
 *        Version:  1.0
9
 *        Created:  07/10/2008 09:18:10 PM
10
 *       Revision:  none
11
 *       Compiler:  gcc
12
 *
13
 *         Author:  mengxipeng@gmail.com
14
 *        Company:  mengxipeng
15
 *
16
 * =====================================================================================
17
 */
18
 
19
#include <string.h>
20
#include <vpi_user.h>
21
 
22
 
23
char  data[120];
24
 
25
static int read_data(char *fn)
26
{
27
        vpiHandle    systf_handle;
28
        vpiHandle    arg_itr;
29
        vpiHandle    arg_handle;
30
        s_vpi_value  value_s;
31
 
32
        FILE        *fp;
33
        FILE        *fp1;
34
        char         str[120];
35
        int          i;
36
        int          n;
37
 
38
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
39
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
40
        if (arg_itr == NULL)
41
        {
42
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
43
                return(0);
44
        }
45
 
46
        /* read file name */
47
        arg_handle = vpi_scan(arg_itr);
48
        value_s.format = vpiStringVal;
49
        vpi_get_value(arg_handle, &value_s);
50
        strcpy(str,value_s.value.str);
51
 
52
        fp=fopen(str,"r");
53
        if(fp)
54
        {
55
                fscanf(fp,"%s",&data);
56
                value_s.format = vpiBinStrVal;
57
                value_s.value.str=data;
58
                arg_handle = vpi_scan(arg_itr);
59
                vpi_put_value(arg_handle, &value_s,NULL, vpiNoDelay);
60
                fclose(fp);
61
        }
62
        else
63
        {
64
                vpi_printf("can't open the input file in %s \n", __FUNCTION__);
65
        }
66
 
67
        return 0;
68
}
69
 
70
static void read_data_register()
71
{
72
        s_vpi_systf_data tf_data;
73
        tf_data.type      = vpiSysTask;
74
        tf_data.tfname    = "$read_data";
75
        tf_data.calltf    = read_data;
76
        tf_data.compiletf = 0;
77
        tf_data.sizetf    = 0;
78
        vpi_register_systf(&tf_data);
79
}
80
 
81
static int write_data(char *xx)
82
{
83
        vpiHandle    systf_handle;
84
        vpiHandle    arg_itr;
85
        vpiHandle    arg_handle;
86
        s_vpi_value  value_s;
87
 
88
        FILE        *fp;
89
        char         str[120];
90
        int          i;
91
        int          n;
92
 
93
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
94
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
95
        if (arg_itr == NULL)
96
        {
97
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
98
                return(0);
99
        }
100
 
101
        /* read file name */
102
        arg_handle = vpi_scan(arg_itr);
103
        value_s.format = vpiStringVal;
104
        vpi_get_value(arg_handle, &value_s);
105
        strcpy(str,value_s.value.str);
106
 
107
        fp=fopen(str,"w");
108
        if(fp)
109
        {
110
                value_s.format = vpiBinStrVal;
111
                arg_handle = vpi_scan(arg_itr);
112
                vpi_get_value(arg_handle, &value_s);
113
                //fprintf(fp,"%s\n",data);
114
                fprintf(fp,"%s\n",value_s.value.str);
115
                fclose(fp);
116
        }
117
        else
118
        {
119
                vpi_printf("can't open the output file in %s \n", __FUNCTION__);
120
        }
121
 
122
        return 0;
123
}
124
 
125
static void write_data_register()
126
{
127
        s_vpi_systf_data tf_data;
128
        tf_data.type      = vpiSysTask;
129
        tf_data.tfname    = "$write_data";
130
        tf_data.calltf    = write_data;
131
        tf_data.compiletf = 0;
132
        tf_data.sizetf    = 0;
133
        vpi_register_systf(&tf_data);
134
}
135
 
136
void (*vlog_startup_routines[])() = {
137
        read_data_register,
138
        write_data_register,
139
 
140
};
141
 

powered by: WebSVN 2.1.0

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