OpenCores
URL https://opencores.org/ocsvn/kiss-board/kiss-board/trunk

Subversion Repositories kiss-board

[/] [kiss-board/] [tags/] [initial/] [kiss-board_soc/] [sim/] [c/] [pan/] [pan.c] - Blame information for rev 11

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 fukuchi
 
2
#include <stdlib.h>
3
#include <stdio.h>
4
#include <string.h>
5
#include <vpi_user.h>
6
#include <veriuser.h>
7
 
8
void    pan_register();
9
int     pan_compiletf();
10
int     pan_calltf();
11
int     pan_cb_destory();
12
int     pan_cb_change();
13
 
14
typedef struct pan {
15
        FILE            *pp;
16
        vpiHandle       tri;
17
        vpiHandle       mon;
18
} PAN;
19
 
20
void pan_register(){
21
        s_vpi_systf_data tf_data;
22
        tf_data.type      = vpiSysTask;
23
        tf_data.tfname    = "$pan";
24
        tf_data.calltf    = pan_calltf;
25
        tf_data.compiletf = pan_compiletf;
26
        tf_data.sizetf    = NULL;
27
        tf_data.user_data = NULL;
28
        vpi_register_systf(&tf_data);
29
        vpi_printf("pan_register() is done\n");
30
}
31
int pan_compiletf(char *user_data){
32
        vpiHandle systf_h,tfarg_itr,tfarg_h;
33
        int ret;
34
// task check
35
        systf_h = vpi_handle(vpiSysTfCall, NULL);
36
        if (systf_h == NULL) { tf_dofinish(); return 0; }
37
// when none argv
38
        tfarg_itr = vpi_iterate(vpiArgument, systf_h);
39
        if (tfarg_itr == NULL) { tf_dofinish(); return 0; }
40
// argv 1(vpiNet)
41
        tfarg_h = vpi_scan(tfarg_itr);
42
        ret = vpi_get(vpiType,tfarg_h);
43
        if (vpiNet!=ret){
44
                vpi_printf("ERROR(%d):argv[0] is not vpiNet\n",ret);
45
                tf_dofinish(); return 0;
46
        }
47
// argv 2(vpiNet)
48
        tfarg_h = vpi_scan(tfarg_itr);
49
        ret = vpi_get(vpiType,tfarg_h);
50
        if (vpiNet!=ret){
51
                vpi_printf("ERROR(%d):argv[1] is not vpiNet\n",ret);
52
                tf_dofinish(); return 0;
53
        }
54
// argv 3(vpiConstant or vpiParameter)
55
        tfarg_h = vpi_scan(tfarg_itr);
56
        ret=vpi_get(vpiType,tfarg_h);
57
        if ( (vpiConstant!=ret) && (vpiParameter!=ret) ){
58
                vpi_printf("ERROR(%d):argv[2] is not (vpiConstant or vpiParameter)\n",ret);
59
                tf_dofinish(); return 0;
60
        }
61
// too many argv
62
        if (vpi_scan(tfarg_itr)!=NULL) {
63
                tf_error("ERROR: too many argv\n");
64
                vpi_free_object(tfarg_itr);
65
                tf_dofinish(); return 0;
66
        }
67
// ok compiled
68
        vpi_printf("pan_compiletf() is done\n");
69
        return 0;
70
}
71
void pan_triger(PAN *pan,vpiHandle *tri){
72
        s_vpi_time      time;
73
        s_vpi_value     value;
74
        s_cb_data       cb;
75
        value.format    = vpiIntVal;
76
        time.type       = vpiScaledRealTime;
77
        cb.reason       = cbValueChange;
78
        cb.cb_rtn       = pan_cb_change;
79
        cb.time         = &time;
80
        cb.value        = &value;
81
        cb.obj          = *tri;
82
        cb.user_data    = (char *)pan;
83
        vpi_register_cb(&cb);
84
        return;
85
}
86
int pan_calltf(char *user_data){
87
        PAN *pan;
88
        // pan setup
89
        {
90
                vpiHandle systf_h,arg_itr,net1_h,net2_h,string_h;
91
                FILE            *pp;
92
                if (NULL==(systf_h  = vpi_handle(vpiSysTfCall,NULL)))     {vpi_printf("analyze1\n"); return 0; }
93
                if (NULL==(arg_itr  = vpi_iterate(vpiArgument,systf_h)))  {vpi_printf("analyze2\n"); return 0; }
94
                if (NULL==(net1_h   = vpi_scan(arg_itr)))                 {vpi_printf("analyze3\n"); return 0; }
95
                if (NULL==(net2_h   = vpi_scan(arg_itr)))                 {vpi_printf("analyze4\n"); return 0; }
96
                if (NULL==(string_h = vpi_scan(arg_itr)))                 {vpi_printf("analyze5\n"); return 0; }
97
                {
98
                        void            *command;
99
                        s_vpi_value     value;
100
                        value.format = vpiStringVal;
101
                        vpi_get_value(string_h,&value);
102
                        command = malloc( strlen(value.value.str)+1 );
103
                        strcpy(command,value.value.str);
104
#ifdef WIN32
105
                        {
106
                                char *p;
107
                                for (p=(char *)command;'\0'!=*p;p++) if ('/'==*p) *p='\\';
108
                        }
109
#endif
110
                        pp=popen((char *)command,"w");
111
                        vpi_printf("pan_calltf().popen(command:%s)\n",command);
112
                        free(command);
113
                        if (NULL==pp) {
114
                                vpi_printf("pan_calltf().popen(error)\n");
115
                                return 0;
116
                        }
117
                }
118
                pan = malloc(sizeof(PAN));
119
                pan->pp  = pp;
120
                pan->tri = net1_h;
121
                pan->mon = net2_h;
122
                vpi_printf("pan_calltf().malloc(pan:%d)\n",pan);
123
                vpi_printf("pan_calltf().popen(pan->pp:%d)\n",pan->pp);
124
                vpi_printf("pan_calltf().popen(pan->tri:%d)\n",pan->tri);
125
                vpi_printf("pan_calltf().popen(pan->mon:%d)\n",pan->mon);
126
        }
127
// delete callback
128
        {
129
                s_vpi_time      time;
130
                s_vpi_value     value;
131
                s_cb_data       cb;
132
                value.format    = vpiIntVal;
133
                time.type       = vpiScaledRealTime;
134
                cb.reason       = cbStartOfReset;
135
                //cb.reason     = cbStartOfRestart;
136
                //cb.reason     = cbEndOfSave;
137
                cb.cb_rtn       = pan_cb_destory;
138
                cb.time         = NULL; // must be null ;//&time;
139
                cb.value        = NULL; // must be null ;//&value;
140
                cb.obj          = NULL;
141
                cb.user_data    = (char *)pan;
142
                vpi_register_cb(&cb);
143
        }
144
// triger callback
145
        {
146
                int     size;
147
                size = vpi_get(vpiSize,pan->tri);
148
                vpi_printf("pan_calltf().net_size:%d(%s)\n",size,vpi_get_str(vpiFullName,pan->tri));
149
                if (size==1){
150
                        pan_triger(pan,&(pan->tri));    // private call
151
                }
152
                else {
153
                        vpiHandle port_bit_itr;
154
                        vpiHandle port_bit_h;
155
                        port_bit_itr = vpi_iterate(vpiBit,pan->tri);
156
                        while (NULL!=(port_bit_h=vpi_scan(port_bit_itr))) {
157
                                pan_triger(pan,&port_bit_h); // private call
158
                        }
159
                }
160
        }
161
        vpi_printf("pan_calltf() is done\n");
162
        return 0;
163
};
164
int pan_cb_destory(p_cb_data cb_data){
165
        PAN             *pan;
166
        pan = (PAN *)(cb_data->user_data);
167
        //
168
        pclose(pan->pp);
169
        vpi_printf("pan_cb_destroy().pclose(pan->pp:%d)\n",pan->pp);
170
        //
171
        /* release call back */
172
        //vpi_printf("pan_cb_destroy().release(pan->tri:%d)\n",pan->tri);
173
        //
174
        free(pan);
175
        vpi_printf("pan_cb_destory().free(pan:%d)\n",pan);
176
        //
177
        vpi_printf("pan_cb_destory() is done\n");
178
        return 0;
179
}
180
int pan_cb_change(p_cb_data cb_data){
181
        s_vpi_value     triger;
182
        triger.format = vpiIntVal;
183
        vpi_get_value(cb_data->obj,&triger);
184
        if (1==triger.value.integer) {
185
                FILE            *fp;
186
                s_vpi_value     data;
187
                data.format = vpiBinStrVal;
188
                vpi_get_value(((PAN *)(cb_data->user_data))->mon,&data);
189
                //vpi_printf("pan_cb_change().(pan->mon:%d)\n",((PAN *)(cb_data->user_data))->mon);
190
                fp = (0==ferror(((PAN *)(cb_data->user_data))->pp)) ? ((PAN *)(cb_data->user_data))->pp: stderr;
191
                fprintf(fp,":%32f:%32s:%s:\n",
192
                        cb_data->time->real,
193
                        vpi_get_str(vpiFullName,cb_data->obj),
194
                        data.value.str
195
                );
196
                fflush(fp);
197
        }
198
        return 0;
199
}

powered by: WebSVN 2.1.0

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