/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
1
#include <stdio.h>
2
#include <pthread.h>
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
3
#include <stdlib.h>
4
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
5
#include "pcilib.h"
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
6
#include "pcilib/error.h"
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
7
8
const char* prop = "/registers/fpga/reg1";
9
char* reg;
10
int stop = 0;
11
346.1.38 by Vasilii Chernov
Fix python3 initialization from pcilib_t
12
/*
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
13
void *get_prop(void *arg)
14
{
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
15
    pcilib_t *ctx = (pcilib_t*)arg;
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
16
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
17
    while(!stop)
18
    {
19
        int err;
20
        pcilib_value_t val = {0};
21
        err = pcilib_get_property(ctx, prop, &val);
22
        if(err)
23
        {
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
24
            pcilib_error("Error in pcilib_read_register");
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
25
            return NULL;
26
        }
27
        long value = pcilib_get_value_as_int(ctx, &val, &err);
28
        pcilib_clean_value(ctx, &val);
29
        if(err)
30
        {
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
31
            pcilib_error("Error in pcilib_get_value_as_int");
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
32
            return NULL;
33
        }
34
        printf("reg = %li\n", value);
35
    }
36
    return NULL;
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
37
}
346.1.38 by Vasilii Chernov
Fix python3 initialization from pcilib_t
38
*/
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
39
40
void *read_reg(void *arg)
41
{
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
42
    pcilib_t *ctx = (pcilib_t*)arg;
43
44
    while(!stop)
45
    {
46
        int err;
47
        pcilib_register_value_t reg_val = {0};
48
        pcilib_value_t val = {0};
49
50
        err = pcilib_read_register(ctx, NULL, reg, &reg_val);
51
52
        if(err)
53
        {
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
54
            pcilib_error("Error in pcilib_read_register");
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
55
            return NULL;
56
        }
57
        err = pcilib_set_value_from_register_value(ctx, &val, reg_val);
58
        if(err)
59
        {
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
60
            pcilib_error("Error in pcilib_set_value_from_register_value");
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
61
            return NULL;
62
        }
63
        long value = pcilib_get_value_as_int(ctx, &val, &err);
64
        pcilib_clean_value(ctx, &val);
65
        if(err)
66
        {
367 by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov
67
            pcilib_error("Error in pcilib_get_value_as_int");
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
68
            return NULL;
69
        }
70
        printf("reg = %li\n", value);
71
    }
72
    return NULL;
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
73
}
74
75
int main(int argc, char *argv[])
76
{
353 by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov
77
    if (argc < 5) {
78
        printf("Usage:\n\t\t%s <device> <model> <register> <num_threads>\n", argv[0]);
79
        exit(0);
80
    }
81
82
    reg = argv[3];
83
    int threads = atoi( argv[4] );
84
85
    pcilib_t *ctx = pcilib_open(argv[1], argv[2]);
86
87
    for(int i = 0; i < threads; i++)
88
    {
89
        pthread_t pth;
90
        pthread_create(&pth, NULL, read_reg, ctx);
91
    }
92
93
    getchar();
94
    stop = 1;
95
    return 0;
346.1.18 by Vasilii Chernov
Add test to repository. Add GIL states to pcilib_set_value_from_pyobject
96
}