bzr branch
http://suren.me/webbzr/alps/pcitool
119
by Suren A. Chilingaryan
Initial support of event streaming in cli |
1 |
#define _POSIX_C_SOURCE 200112L
|
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
2 |
#define _GNU_SOURCE
|
119
by Suren A. Chilingaryan
Initial support of event streaming in cli |
3 |
|
1
by Suren A. Chilingaryan
Initial import |
4 |
#include <stdio.h> |
5 |
#include <string.h> |
|
6 |
#include <unistd.h> |
|
7 |
#include <stdint.h> |
|
7.1.1
by Suren A. Chilingaryan
Initial support of IPECamera protocol |
8 |
#include <assert.h> |
7.1.5
by Suren A. Chilingaryan
Support for FPGA registers |
9 |
#include <ctype.h> |
119
by Suren A. Chilingaryan
Initial support of event streaming in cli |
10 |
#include <time.h> |
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
11 |
#include <sched.h> |
7.1.1
by Suren A. Chilingaryan
Initial support of IPECamera protocol |
12 |
#include <arpa/inet.h> |
117
by Suren A. Chilingaryan
new event architecture, first trial |
13 |
#include <sys/time.h> |
7.1.1
by Suren A. Chilingaryan
Initial support of IPECamera protocol |
14 |
|
236
by Suren A. Chilingaryan
Big redign of model structures |
15 |
#include "pci.h" |
7.1.1
by Suren A. Chilingaryan
Initial support of IPECamera protocol |
16 |
#include "tools.h" |
126
by Suren A. Chilingaryan
multithread preprocessing of ipecamera frames and code reorganization |
17 |
#include "error.h" |
7.1.1
by Suren A. Chilingaryan
Initial support of IPECamera protocol |
18 |
|
7.1.5
by Suren A. Chilingaryan
Support for FPGA registers |
19 |
int pcilib_isnumber(const char *str) { |
20 |
int i = 0; |
|
21 |
for (i = 0; str[i]; i++) |
|
22 |
if (!isdigit(str[i])) return 0; |
|
23 |
return 1; |
|
24 |
}
|
|
25 |
||
26 |
int pcilib_isxnumber(const char *str) { |
|
27 |
int i = 0; |
|
12
by Suren A. Chilingaryan
Correctly detect hex numbers starting from 0x |
28 |
|
29 |
if ((str[0] == '0')&&((str[1] == 'x')||(str[1] == 'X'))) i += 2; |
|
30 |
||
31 |
for (; str[i]; i++) |
|
7.1.5
by Suren A. Chilingaryan
Support for FPGA registers |
32 |
if (!isxdigit(str[i])) return 0; |
12
by Suren A. Chilingaryan
Correctly detect hex numbers starting from 0x |
33 |
|
7.1.5
by Suren A. Chilingaryan
Support for FPGA registers |
34 |
return 1; |
35 |
}
|
|
36 |
||
62
by Suren A. Chilingaryan
Suppport DMA modes in console application (not functional yet) |
37 |
int pcilib_isnumber_n(const char *str, size_t len) { |
38 |
int i = 0; |
|
39 |
for (i = 0; (str[i])&&(i < len); i++) |
|
40 |
if (!isdigit(str[i])) return 0; |
|
41 |
return 1; |
|
42 |
}
|
|
43 |
||
44 |
int pcilib_isxnumber_n(const char *str, size_t len) { |
|
45 |
int i = 0; |
|
46 |
||
47 |
if ((len > 1)&&(str[0] == '0')&&((str[1] == 'x')||(str[1] == 'X'))) i += 2; |
|
48 |
||
49 |
for (; (str[i])&&(i < len); i++) |
|
50 |
if (!isxdigit(str[i])) return 0; |
|
51 |
||
52 |
return 1; |
|
53 |
}
|
|
54 |
||
7.1.5
by Suren A. Chilingaryan
Support for FPGA registers |
55 |
|
7.1.1
by Suren A. Chilingaryan
Initial support of IPECamera protocol |
56 |
uint16_t pcilib_swap16(uint16_t x) { |
57 |
return (((x<<8)&0xFFFF) | ((x>>8)&0xFFFF)); |
|
58 |
}
|
|
59 |
||
60 |
uint32_t pcilib_swap32(uint32_t x) { |
|
61 |
return ((x & 0xFF) << 24) | \ |
|
62 |
((x & 0xFF00) << 8) | \ |
|
63 |
((x & 0xFF0000) >> 8) | \ |
|
64 |
((x & 0xFF000000) >> 24); |
|
65 |
}
|
|
66 |
||
67 |
uint64_t pcilib_swap64(uint64_t x) { |
|
68 |
return (((uint64_t)(x) << 56) | \ |
|
69 |
(((uint64_t)(x) << 40) & 0xff000000000000ULL) | \ |
|
70 |
(((uint64_t)(x) << 24) & 0xff0000000000ULL) | \ |
|
71 |
(((uint64_t)(x) << 8) & 0xff00000000ULL) | \ |
|
72 |
(((uint64_t)(x) >> 8) & 0xff000000ULL) | \ |
|
73 |
(((uint64_t)(x) >> 24) & 0xff0000ULL) | \ |
|
74 |
(((uint64_t)(x) >> 40) & 0xff00ULL) | \ |
|
75 |
((uint64_t)(x) >> 56)); |
|
76 |
}
|
|
77 |
||
78 |
void pcilib_swap(void *dst, void *src, size_t size, size_t n) { |
|
79 |
int i; |
|
80 |
switch (size) { |
|
81 |
case 1: |
|
82 |
if (src != dst) memcpy(dst, src, n); |
|
83 |
break; |
|
84 |
case 2: |
|
85 |
for (i = 0; i < n; i++) { |
|
86 |
((uint16_t*)dst)[i] = pcilib_swap16(((uint16_t*)src)[i]); |
|
87 |
}
|
|
88 |
break; |
|
89 |
case 4: |
|
90 |
for (i = 0; i < n; i++) { |
|
91 |
((uint32_t*)dst)[i] = pcilib_swap32(((uint32_t*)src)[i]); |
|
92 |
}
|
|
93 |
break; |
|
94 |
case 8: |
|
95 |
for (i = 0; i < n; i++) { |
|
96 |
((uint64_t*)dst)[i] = pcilib_swap64(((uint64_t*)src)[i]); |
|
97 |
}
|
|
98 |
break; |
|
99 |
default: |
|
100 |
pcilib_error("Invalid word size: %i", size); |
|
101 |
}
|
|
102 |
}
|
|
103 |
||
330
by Suren A. Chilingaryan
Support for 64-bit registes |
104 |
|
105 |
||
106 |