vi.c
2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include "acc_user.h"
#include "vcsuser.h"
FILE *OutFile=NULL;
char OutFileName[256]={'\0'};
void PrintTabHeader(char *header)
{
fprintf(OutFile, "#\n");
fprintf(OutFile, "# created by %s.c\n", header);
fprintf(OutFile, "#\n");
fprintf(OutFile, "vclk @C 1(8) 0(8)\n");
fprintf(OutFile, "vbus_data[6:0] @I @E 2\n");
fprintf(OutFile, "vbus_sync @I @E 2\n");
fprintf(OutFile, "\n"); /* required newline */
}
void open_viout_file(void)
{
char *filename = tmpnam(NULL);
if (OutFile != NULL) {
fclose(OutFile);
OutFile = NULL;
if (OutFileName[0]) remove(OutFileName);
OutFileName[0] ='\0';
}
acc_initialize();
acc_configure(accDevelopmentVersion, "1.6");
strcpy(OutFileName, filename);
if ((OutFile = fopen(filename, "w")) == NULL) {
tf_error("Couldn't open output file %s", filename);
tf_putp(0, -1);
}
PrintTabHeader("top level rdp vi");
tf_putp(0, 0);
}
void output_vi()
{
int vbus_data, vbus_sync;
if (OutFile != NULL)
{
if (tf_nump() != 2)
{
tf_error("Illegal number of arguments to output_vi");
tf_putp(0, -1);
}
else
{
vbus_data = tf_getp(1);
vbus_sync = tf_getp(2);
fprintf(OutFile, "0x%.2x %d \n", vbus_data, vbus_sync);
}
}
tf_putp(0, 0);
}
void ipc_vi_get()
{
int length = 0;
handle h;
struct stat statbuf;
s_setval_value my_value_s = { accIntVal };
s_setval_delay my_delay_s = { { accRealTime, 0, 0, 0 }, accNoDelay };
fclose(OutFile);
OutFile = NULL;
if (tf_nump() != 1) {
tf_error("Illegal number of arguments to ipc_vi_get");
tf_putp(0, -1);
}
if ((lstat(OutFileName, &statbuf)) == 0)
length = statbuf.st_size;
h = acc_handle_tfarg(1);
my_value_s.value.integer = length;
acc_set_value(h, &my_value_s, &my_delay_s);
tf_putp(0, 0);
}
void ipc_vi_read()
{
int start, count, i, d[8], j, ch;
handle h[8];
s_setval_value my_value_s = { accIntVal };
s_setval_delay my_delay_s = { { accRealTime, 0, 0, 0 }, accNoDelay };
FILE *f;
if (tf_nump() != 10) {
tf_error("Illegal number of arguments to ipc_vi_read");
tf_putp(0, -1);
}
start = (int)tf_getp(1);
count = (int)tf_getp(2);
memset(d, 0, sizeof(int)*8);
if ((f = fopen(OutFileName, "r")) != NULL) {
fseek(f, start, SEEK_SET);
for (i=0, j=0; i<count; i++) { /* Store as Big endian */
ch = fgetc(f);
if (feof(f)) ch = 0;
d[j] = (d[j]<<8) + ch;
if ((i & 3) == 3) j++;
}
fclose(f);
}
for (i=0; i<8; i++) {
h[i] = acc_handle_tfarg(3+i);
my_value_s.value.integer = d[i];
acc_set_value(h[i], &my_value_s, &my_delay_s);
}
tf_putp(0, 0);
}