/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib.h

  • Committer: Suren A. Chilingaryan
  • Date: 2011-04-12 00:57:02 UTC
  • Revision ID: csa@dside.dyndns.org-20110412005702-ir1cch0f1feop7ay
Infrastructure for event API

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
#define PCILIB_MAX_BANKS 6
5
5
 
 
6
#include <time.h>
6
7
#include <stdint.h>
7
8
 
 
9
#ifndef __timespec_defined
 
10
struct timespec {
 
11
    time_t tv_sec;
 
12
    long tv_nsec;
 
13
};
 
14
#endif /* __timespec_defined */
 
15
 
8
16
#define pcilib_memcpy pcilib_memcpy32
9
17
#define pcilib_datacpy pcilib_datacpy32
10
18
 
17
25
typedef uint8_t pcilib_register_bank_addr_t;    /**< Type holding the register bank number */
18
26
typedef uint8_t pcilib_register_size_t;         /**< Type holding the size in bits of the register */
19
27
typedef uint32_t pcilib_register_value_t;       /**< Type holding the register value */
 
28
typedef uint64_t pcilib_event_id_t;
 
29
 
 
30
typedef uint32_t pcilib_event_t;
20
31
 
21
32
typedef enum {
22
33
    PCILIB_LITTLE_ENDIAN = 0,
35
46
    PCILIB_REGISTER_RW = 3
36
47
} pcilib_register_mode_t;
37
48
 
38
 
 
39
49
typedef enum {
40
50
    PCILIB_DEFAULT_PROTOCOL,
41
51
    IPECAMERA_REGISTER_PROTOCOL
42
52
} pcilib_register_protocol_t;
43
53
 
 
54
typedef enum {
 
55
    PCILIB_EVENT_DATA
 
56
} pcilib_event_data_type_t;
 
57
 
44
58
#define PCILIB_BAR_DETECT               ((pcilib_bar_t)-1)
45
59
#define PCILIB_REGISTER_INVALID         ((pcilib_register_t)-1)
46
60
#define PCILIB_ADDRESS_INVALID          ((uintptr_t)-1)
49
63
#define PCILIB_REGISTER_BANK1           1
50
64
#define PCILIB_REGISTER_BANK2           2
51
65
#define PCILIB_REGISTER_BANK3           3
 
66
#define PCILIB_ALL_EVENTS               ((pcilib_event_t)-1)
52
67
 
53
68
typedef struct {
54
69
    pcilib_register_bank_addr_t addr;
69
84
 
70
85
typedef struct {
71
86
    pcilib_register_addr_t addr;
 
87
    pcilib_register_size_t offset;
72
88
    pcilib_register_size_t bits;
73
89
    pcilib_register_value_t defvalue;
74
90
    pcilib_register_mode_t mode;
93
109
    int (*write)(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t value);
94
110
} pcilib_protocol_description_t;
95
111
 
 
112
 
 
113
typedef int (*pcilib_callback_t)(pcilib_event_t event, pcilib_event_id_t event_id, void *user);
 
114
 
 
115
typedef struct {
 
116
    void *(*init)(pcilib_t *ctx);
 
117
    void (*free)(void *ctx);
 
118
 
 
119
    int (*reset)(void *ctx);
 
120
 
 
121
    int (*start)(void *ctx, pcilib_event_t event_mask, pcilib_callback_t callback, void *user);
 
122
    int (*stop)(void *ctx);
 
123
    int (*trigger)(void *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
 
124
    void* (*get_data)(void *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size);
 
125
    int (*return_data)(void *ctx, pcilib_event_id_t event_id);
 
126
} pcilib_event_api_description_t;
 
127
 
96
128
typedef struct {
97
129
    pcilib_register_description_t *registers;
98
130
    pcilib_register_bank_description_t *banks;
99
131
    pcilib_register_range_t *ranges;
 
132
    
 
133
    pcilib_event_api_description_t *event_api;
100
134
} pcilib_model_description_t;
101
135
 
102
136
#ifndef _PCILIB_PCI_C
112
146
 
113
147
void *pcilib_map_bar(pcilib_t *ctx, pcilib_bar_t bar);
114
148
void pcilib_unmap_bar(pcilib_t *ctx, pcilib_bar_t bar, void *data);
115
 
char  *pcilib_resolve_register_address(pcilib_t *ctx, uintptr_t addr);
 
149
char *pcilib_resolve_register_address(pcilib_t *ctx, uintptr_t addr);
 
150
char *pcilib_resolve_data_space(pcilib_t *ctx, uintptr_t addr, size_t *size);
116
151
 
117
152
pcilib_register_bank_t pcilib_find_bank(pcilib_t *ctx, const char *bank);
118
153
pcilib_register_t pcilib_find_register(pcilib_t *ctx, const char *bank, const char *reg);
127
162
int pcilib_read_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t *value);
128
163
int pcilib_write_register(pcilib_t *ctx, const char *bank, const char *regname, pcilib_register_value_t value);
129
164
 
 
165
int pcilib_reset(pcilib_t *ctx);
 
166
int pcilib_start(pcilib_t *ctx, pcilib_event_t event_mask, void *callback, void *user);
 
167
int pcilib_stop(pcilib_t *ctx);
 
168
 
 
169
int pcilib_trigger(pcilib_t *ctx, pcilib_event_t event, size_t trigger_size, void *trigger_data);
 
170
 
 
171
void *pcilib_get_data(pcilib_t *ctx, pcilib_event_id_t event_id, pcilib_event_data_type_t data_type, size_t *size);
 
172
/*
 
173
 * This function is provided to find potentially corrupted data. If the data is overwritten by 
 
174
 * the time return_data is called it will return error.
 
175
 */
 
176
int pcilib_return_data(pcilib_t *ctx, pcilib_event_id_t event_id);
 
177
 
 
178
/*
 
179
 * @param data - will be allocated and shuld be freed if NULL, otherwise used and size should contain correct size.
 
180
 *   In case of failure the content of data is undefined.
 
181
 * @param timeout - will be autotriggered if NULL
 
182
 */
 
183
int pcilib_grab(pcilib_t *ctx, pcilib_event_t event_mask, size_t *size, void **data, const struct timespec *timeout);
 
184
 
130
185
#endif /* _PCITOOL_PCILIB_H */