/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to protocols/property.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-10-19 13:58:46 UTC
  • Revision ID: csa@suren.me-20151019135846-nz3f6iobifx06xvq
Support computed (property-based) registers

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <sys/time.h>
 
2
#include <arpa/inet.h>
 
3
#include <assert.h>
 
4
 
 
5
#include "pci.h"
 
6
#include "tools.h"
 
7
#include "model.h"
 
8
#include "error.h"
 
9
 
 
10
 
 
11
int pcilib_property_registers_read(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t *regval) {
 
12
    int err;
 
13
 
 
14
    pcilib_view_t view = addr;
 
15
    pcilib_value_t val = {0};
 
16
 
 
17
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views))
 
18
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
19
 
 
20
    err = pcilib_get_property(ctx, ctx->views[view]->name, &val);
 
21
    if (err) return err;
 
22
 
 
23
    *regval = pcilib_get_value_as_register_value(ctx, &val, &err);
 
24
 
 
25
    return err;
 
26
}
 
27
 
 
28
 
 
29
int pcilib_property_registers_write(pcilib_t *ctx, pcilib_register_bank_context_t *bank, pcilib_register_addr_t addr, pcilib_register_value_t regval) {
 
30
    int err;
 
31
 
 
32
    pcilib_view_t view = addr;
 
33
    pcilib_value_t val = {0};
 
34
 
 
35
    if ((view == PCILIB_VIEW_INVALID)||(view >= ctx->num_views))
 
36
        return PCILIB_ERROR_INVALID_ARGUMENT;
 
37
 
 
38
    err = pcilib_set_value_from_register_value(ctx, &val, regval);
 
39
    if (err) return err;
 
40
 
 
41
    return pcilib_set_property(ctx, ctx->views[view]->name, &val);
 
42
}