forked from oscimp/lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfir_conf.c
More file actions
144 lines (123 loc) · 3.04 KB
/
fir_conf.c
File metadata and controls
144 lines (123 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (c) 2015-2018 OscillatorIMP Digital
* Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
/* memory management */
#include <sys/mman.h>
#include <fir_core/fir_config.h>
int fir_send_conf(const char *filename, const char *fileCoeff, const int coeffSize)
{
int i;
uint32_t coeffs[coeffSize];
int aa, size = coeffSize * sizeof(uint32_t);
int fir = open(filename, O_RDWR);
if (fir < 0) {
printf("%s: open failed\n", filename);
return fir;
}
printf("configuration\n");
FILE *coeff_fd = fopen(fileCoeff, "r");
if (coeff_fd == NULL) {
printf("%s: open failed\n", fileCoeff);
return EXIT_FAILURE;
}
for (i = coeffSize-1; i >= 0; i--) {
fscanf(coeff_fd, "%d", &aa);
coeffs[i] = aa;
}
do {
i = write(fir, coeffs, size);
size -= i;
} while (size > 0);
fclose(coeff_fd);
close(fir);
return 0;
}
int fir_readCoeffSigned(int32_t *coeffTab, const char *fileCoeff, const int coeffSize)
{
int aa, i;
FILE *coeff_fd = fopen(fileCoeff, "r");
if (coeff_fd == NULL) {
printf("%s: open failed\n", fileCoeff);
return EXIT_FAILURE;
}
for (i = coeffSize-1; i >= 0; i--) {
fscanf(coeff_fd, "%d", &aa);
coeffTab[i] = aa;
}
fclose(coeff_fd);
return EXIT_SUCCESS;
}
int fir_send_confSigned(const char *filename, const char *fileCoeff, const int coeffSize)
{
int32_t coeffs[coeffSize];
int size = coeffSize * sizeof(int32_t), fir = open(filename, O_RDWR);
if (fir < 0) {
printf("%s: open failed\n", filename);
return fir;
}
printf("configuration\n");
if (fir_readCoeffSigned(coeffs, fileCoeff, coeffSize) == EXIT_FAILURE)
return EXIT_FAILURE;
do {
size -= write(fir, coeffs, size);
} while (size > 0);
close(fir);
return EXIT_SUCCESS;
}
int fir_MultiSend_StartStop_confSigned(const char *basename,
const int startFir, const int nbFir,
const char *fileCoeff, const int coeffSize)
{
int32_t coeffs[coeffSize];
int i, size, fir;
char filename[128];
printf("configuration\n");
if (fir_readCoeffSigned(coeffs, fileCoeff, coeffSize) == EXIT_FAILURE)
return EXIT_FAILURE;
for (i=startFir; i < startFir+nbFir; i++) {
size = coeffSize * sizeof(int32_t);
sprintf(filename, basename, i);
fir = open(filename, O_RDWR);
if (fir < 0) {
printf("fail to open %s\n", filename);
return EXIT_FAILURE;
}
do {
size -= write(fir, coeffs, size);
} while (size > 0);
close(fir);
}
return EXIT_SUCCESS;
}
int fir_MultiSend_confSigned(const char *basename, const int nbFir,
const char *fileCoeff, const int coeffSize)
{
return fir_MultiSend_StartStop_confSigned(basename, 0, nbFir, fileCoeff, coeffSize);
}
int fir_read_conf(const char *filename, short *content, const int coeffSize)
{
int i;
int aa=0;
int size = coeffSize;
int fir = open(filename, O_RDWR);
if (fir < 0) {
printf("%s: open failed\n", filename);
return fir;
}
do {
i = read(fir, content+aa, size);
size -= i;
aa+=i;
} while (size > 0);
close(fir);
return 0;
}