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

Subversion Repositories csa

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

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 20 simon111
#include <stdio.h>
21 13 simon111
#include <vpi_user.h>
22
 
23
 
24 20 simon111
char  data[120*8*8];
25 13 simon111
 
26
static int read_data(char *fn)
27
{
28
        vpiHandle    systf_handle;
29
        vpiHandle    arg_itr;
30
        vpiHandle    arg_handle;
31
        s_vpi_value  value_s;
32
 
33
        FILE        *fp;
34
        FILE        *fp1;
35
        char         str[120];
36
        int          i;
37
        int          n;
38
 
39
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
40
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
41
        if (arg_itr == NULL)
42
        {
43
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
44
                return(0);
45
        }
46
 
47
        /* read file name */
48
        arg_handle = vpi_scan(arg_itr);
49
        value_s.format = vpiStringVal;
50
        vpi_get_value(arg_handle, &value_s);
51
        strcpy(str,value_s.value.str);
52
 
53
        fp=fopen(str,"r");
54
        if(fp)
55
        {
56
                fscanf(fp,"%s",&data);
57
                value_s.format = vpiBinStrVal;
58
                value_s.value.str=data;
59
                arg_handle = vpi_scan(arg_itr);
60
                vpi_put_value(arg_handle, &value_s,NULL, vpiNoDelay);
61
                fclose(fp);
62
        }
63
        else
64
        {
65
                vpi_printf("can't open the input file in %s \n", __FUNCTION__);
66
        }
67
 
68
        return 0;
69
}
70
 
71
static void read_data_register()
72
{
73
        s_vpi_systf_data tf_data;
74
        tf_data.type      = vpiSysTask;
75
        tf_data.tfname    = "$read_data";
76
        tf_data.calltf    = read_data;
77
        tf_data.compiletf = 0;
78
        tf_data.sizetf    = 0;
79
        vpi_register_systf(&tf_data);
80
}
81
 
82
static int write_data(char *xx)
83
{
84
        vpiHandle    systf_handle;
85
        vpiHandle    arg_itr;
86
        vpiHandle    arg_handle;
87
        s_vpi_value  value_s;
88
 
89
        FILE        *fp;
90
        char         str[120];
91
        int          i;
92
        int          n;
93
 
94
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
95
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
96
        if (arg_itr == NULL)
97
        {
98
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
99
                return(0);
100
        }
101
 
102
        /* read file name */
103
        arg_handle = vpi_scan(arg_itr);
104
        value_s.format = vpiStringVal;
105
        vpi_get_value(arg_handle, &value_s);
106
        strcpy(str,value_s.value.str);
107
 
108 15 simon111
        arg_handle = vpi_scan(arg_itr);
109
        value_s.format = vpiStringVal;
110
        vpi_get_value(arg_handle, &value_s);
111
        if(!strcmp("a",value_s.value.str))
112
                fp=fopen(str,"a");
113
        else
114
                fp=fopen(str,"w");
115 13 simon111
        if(fp)
116
        {
117
                value_s.format = vpiBinStrVal;
118
                arg_handle = vpi_scan(arg_itr);
119
                vpi_get_value(arg_handle, &value_s);
120
                //fprintf(fp,"%s\n",data);
121
                fprintf(fp,"%s\n",value_s.value.str);
122
                fclose(fp);
123
        }
124
        else
125
        {
126
                vpi_printf("can't open the output file in %s \n", __FUNCTION__);
127
        }
128
 
129
        return 0;
130
}
131
 
132
static void write_data_register()
133
{
134
        s_vpi_systf_data tf_data;
135
        tf_data.type      = vpiSysTask;
136
        tf_data.tfname    = "$write_data";
137
        tf_data.calltf    = write_data;
138
        tf_data.compiletf = 0;
139
        tf_data.sizetf    = 0;
140
        vpi_register_systf(&tf_data);
141
}
142
 
143
void (*vlog_startup_routines[])() = {
144
        read_data_register,
145
        write_data_register,
146
 
147
};
148
 

powered by: WebSVN 2.1.0

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