/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 default.c

  • Committer: Suren A. Chilingaryan
  • Date: 2011-03-09 15:55:27 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: csa@dside.dyndns.org-20110309155527-7ui77xsz2f7ms0b8
Support for FPGA 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 "tools.h"
 
6
#include "default.h"
 
7
#include "error.h"
 
8
 
 
9
#define BIT_MASK(bits) ((1l << (bits)) - 1)
 
10
 
 
11
#define default_datacpy(dst, src, access, bank)   pcilib_datacpy(dst, src, access, 1, bank->raw_endianess)
 
12
 
 
13
int pcilib_default_read(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t *value) {
 
14
    int err;
 
15
    
 
16
    char *ptr;
 
17
    pcilib_register_value_t val = 0;
 
18
    int access = bank->access / 8;
 
19
 
 
20
    ptr =  pcilib_resolve_register_address(ctx, bank->read_addr + addr * access);
 
21
    default_datacpy(&val, ptr, access, bank);
 
22
    
 
23
    *value = val&BIT_MASK(bits);
 
24
 
 
25
    return 0;
 
26
}
 
27
 
 
28
 
 
29
int pcilib_default_write(pcilib_t *ctx, pcilib_register_bank_description_t *bank, pcilib_register_addr_t addr, uint8_t bits, pcilib_register_value_t value) {
 
30
    int err;
 
31
    
 
32
    char *ptr;
 
33
    int access = bank->access / 8;
 
34
 
 
35
    ptr =  pcilib_resolve_register_address(ctx, bank->write_addr + addr * access);
 
36
    default_datacpy(ptr, &value, access, bank);
 
37
 
 
38
    return 0;
 
39
}