-
Notifications
You must be signed in to change notification settings - Fork 2
/
fftcontrol.c~
165 lines (122 loc) · 2.91 KB
/
fftcontrol.c~
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#include "pciedma.h"
#include "fftcontrol.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#define DEBUG
/* For Debugging */
#ifdef DEBUG
#define PRINT print
#else
#define PRINT(...) ((void)0)
#endif
/* GLOBAL VARIABLES */
/*----------------------*/
extern void * bar;
unsigned int readFFTstatus()
{
if (bar == NULL){
PRINT("Error: BAR0 is not mapped\n");
return -1;
}
return ((unsigned int*)bar)[FFT_INDEX + 1];
}
int configFFT(int size,int scaling, int fwdinv)
{
unsigned int ctl;
if (bar == NULL){
PRINT("Error: BAR0 is not mapped\n");
return -1;
}
if(size > 16 || size < 3){
PRINT("FFT size must be between 8 and 64k points\n");
return -1;
}
if(fwdinv < 0 || fwdinv > 1){
PRINT("Invalid forward/inverse selection\n");
return -1;
}
ctl = 0;
ctl = (scaling<< SCALING_SHIFT) & SCALING_MASK;
ctl = ctl | (fwdinv << FWDINV_SHIFT);
ctl = ctl | size;
printf("Writing configuration: %08x\n",ctl);
((unsigned int*)bar)[FFT_INDEX + 0] = ctl;
return 0;
}
int setFFTsize(int size)
{
unsigned int ctl;
unsigned int points, fwdinv, scaling;
if (bar == NULL){
PRINT("Error: BAR0 is not mapped\n");
return -1;
}
if(size > 16 || size < 3){
PRINT("FFT size must be between 8 and 64k points\n");
return -1;
}
ctl = ((unsigned int*)bar)[FFT_INDEX + 0];
points = ctl & SIZE_MASK;
fwdinv = (ctl & FWDINV_MASK);
scaling = (ctl & SCALING_MASK);
ctl = 0;
ctl = (scaling);
ctl = ctl | fwdinv;
ctl = ctl | size;
((unsigned int*)bar)[FFT_INDEX + 0] = ctl;
return 0;
}
// 0 forward; 1 - inverse
int setFFTfwdinv(int fwdinv)
{
unsigned int ctl;
unsigned int points, fwdinv_ctl, scaling;
if (bar == NULL){
PRINT("Error: BAR0 is not mapped\n");
return -1;
}
if(fwdinv < 0 || fwdinv > 1){
PRINT("Invalid forward/inverse selection\n");
return -1;
}
ctl = ((unsigned int*)bar)[FFT_INDEX + 0];
points = ctl & SIZE_MASK;
fwdinv_ctl = (ctl & FWDINV_MASK);
scaling = (ctl & SCALING_MASK);
ctl = 0;
ctl = (scaling);
ctl = ctl | (fwdinv << FWDINV_SHIFT);
ctl = ctl | points;
((unsigned int*)bar)[FFT_INDEX + 0] = ctl;
return 0;
}
int setFFTscaling(int scale_sched)
{
unsigned int ctl;
unsigned int points, fwdinv, scaling;
if (bar == NULL){
PRINT("Error: BAR0 is not mapped\n");
return -1;
}
ctl = ((unsigned int*)bar)[FFT_INDEX + 0];
points = ctl & SIZE_MASK;
fwdinv = (ctl & FWDINV_MASK);
scaling = (ctl & SCALING_MASK);
ctl = 0;
ctl = ((scale_sched<<SCALING_SHIFT) & SCALING_MASK);
ctl = ctl | fwdinv;
ctl = ctl | points;
((unsigned int*)bar)[FFT_INDEX + 0] = ctl;
return 0;
}
int FFTreset()
{
if (bar == NULL){
PRINT("Error: BAR0 is not mapped\n");
return -1;
}
((unsigned int*)bar)[FFT_RST_INDEX] = FFT_RST_CODE;
return 0;
}