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

Subversion Repositories csa

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

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 35 simon111
        fp=fopen(str,"rb");
54 13 simon111
        if(fp)
55
        {
56 35 simon111
                int i;
57
                int b;
58
                unsigned int word;
59
                int vector_size;
60
                //fscanf(fp,"%s",&data);
61 13 simon111
                arg_handle = vpi_scan(arg_itr);
62 35 simon111
 
63
                vector_size = vpi_get(vpiSize, arg_handle);
64
                vpi_printf("vector_size=%d \n", vector_size);
65
 
66
                value_s.format = vpiVectorVal;
67
                vpi_get_value(arg_handle, &value_s);
68
                for (i=0;i<vector_size/32;i++)
69
                {
70
                        fread(&word,4,1,fp);
71
                        value_s.value.vector[i].bval=0;
72
                        value_s.value.vector[i].aval=word;
73
                }
74 13 simon111
                vpi_put_value(arg_handle, &value_s,NULL, vpiNoDelay);
75
                fclose(fp);
76
        }
77
        else
78
        {
79
                vpi_printf("can't open the input file in %s \n", __FUNCTION__);
80
        }
81
 
82
        return 0;
83
}
84
 
85
static void read_data_register()
86
{
87
        s_vpi_systf_data tf_data;
88
        tf_data.type      = vpiSysTask;
89
        tf_data.tfname    = "$read_data";
90
        tf_data.calltf    = read_data;
91
        tf_data.compiletf = 0;
92
        tf_data.sizetf    = 0;
93
        vpi_register_systf(&tf_data);
94
}
95
 
96
static int write_data(char *xx)
97
{
98
        vpiHandle    systf_handle;
99
        vpiHandle    arg_itr;
100
        vpiHandle    arg_handle;
101
        s_vpi_value  value_s;
102
 
103
        FILE        *fp;
104
        char         str[120];
105
        int          i;
106
        int          n;
107
 
108
        systf_handle = vpi_handle(vpiSysTfCall, NULL);
109
        arg_itr = vpi_iterate(vpiArgument, systf_handle);
110
        if (arg_itr == NULL)
111
        {
112
                vpi_printf("ERROR: $pow failed to obtain systf arg handles\n");
113
                return(0);
114
        }
115
 
116
        /* read file name */
117
        arg_handle = vpi_scan(arg_itr);
118
        value_s.format = vpiStringVal;
119
        vpi_get_value(arg_handle, &value_s);
120
        strcpy(str,value_s.value.str);
121
 
122 15 simon111
        arg_handle = vpi_scan(arg_itr);
123
        value_s.format = vpiStringVal;
124
        vpi_get_value(arg_handle, &value_s);
125
        if(!strcmp("a",value_s.value.str))
126 35 simon111
                fp=fopen(str,"ab");
127 15 simon111
        else
128 35 simon111
                fp=fopen(str,"wb");
129 13 simon111
        if(fp)
130
        {
131 35 simon111
                unsigned int word;
132
                int b;
133
                int i;
134
                int vector_size;
135
                value_s.format = vpiVectorVal;
136 13 simon111
                arg_handle = vpi_scan(arg_itr);
137 35 simon111
                vector_size = vpi_get(vpiSize, arg_handle);
138
                vpi_printf("str:%s vector_size=%d\n",str,vector_size);
139 13 simon111
                vpi_get_value(arg_handle, &value_s);
140 35 simon111
                for(i=0;i<vector_size/32;i++)
141
                {
142
                        vpi_printf("i=%d\n",i);
143
                        fwrite(&value_s.value.vector[i].aval,4,1,fp);
144
                }
145
                fwrite(&value_s.value.vector[i].aval,(vector_size%32)/8,1,fp);
146 13 simon111
                fclose(fp);
147
        }
148
        else
149
        {
150
                vpi_printf("can't open the output file in %s \n", __FUNCTION__);
151
        }
152
 
153
        return 0;
154
}
155
 
156
static void write_data_register()
157
{
158
        s_vpi_systf_data tf_data;
159
        tf_data.type      = vpiSysTask;
160
        tf_data.tfname    = "$write_data";
161
        tf_data.calltf    = write_data;
162
        tf_data.compiletf = 0;
163
        tf_data.sizetf    = 0;
164
        vpi_register_systf(&tf_data);
165
}
166
 
167
void (*vlog_startup_routines[])() = {
168
        read_data_register,
169
        write_data_register,
170
 
171
};
172
 

powered by: WebSVN 2.1.0

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