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
|
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include "pcilib.h"
#include "pcilib/error.h"
const char* prop = "/registers/fpga/reg1";
char* reg;
int stop = 0;
/*
void *get_prop(void *arg)
{
pcilib_t *ctx = (pcilib_t*)arg;
while(!stop)
{
int err;
pcilib_value_t val = {0};
err = pcilib_get_property(ctx, prop, &val);
if(err)
{
pcilib_error("Error in pcilib_read_register");
return NULL;
}
long value = pcilib_get_value_as_int(ctx, &val, &err);
pcilib_clean_value(ctx, &val);
if(err)
{
pcilib_error("Error in pcilib_get_value_as_int");
return NULL;
}
printf("reg = %li\n", value);
}
return NULL;
}
*/
void *read_reg(void *arg)
{
pcilib_t *ctx = (pcilib_t*)arg;
while(!stop)
{
int err;
pcilib_register_value_t reg_val = {0};
pcilib_value_t val = {0};
err = pcilib_read_register(ctx, NULL, reg, ®_val);
if(err)
{
pcilib_error("Error in pcilib_read_register");
return NULL;
}
err = pcilib_set_value_from_register_value(ctx, &val, reg_val);
if(err)
{
pcilib_error("Error in pcilib_set_value_from_register_value");
return NULL;
}
long value = pcilib_get_value_as_int(ctx, &val, &err);
pcilib_clean_value(ctx, &val);
if(err)
{
pcilib_error("Error in pcilib_get_value_as_int");
return NULL;
}
printf("reg = %li\n", value);
}
return NULL;
}
int main(int argc, char *argv[])
{
if (argc < 5) {
printf("Usage:\n\t\t%s <device> <model> <register> <num_threads>\n", argv[0]);
exit(0);
}
reg = argv[3];
int threads = atoi( argv[4] );
pcilib_t *ctx = pcilib_open(argv[1], argv[2]);
for(int i = 0; i < threads; i++)
{
pthread_t pth;
pthread_create(&pth, NULL, read_reg, ctx);
}
getchar();
stop = 1;
return 0;
}
|