Caveat: This may be incomplete as I'm not sure about your final result, but we can get the compilation errors out. I had to take a slight liberty to add a main
function so I could get something compilable.
Here is a reindented version of your latest program [which has errors]:
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0 *ADC3_read
#define x1 *ADC2_read
#define x2 *ADC1_read
#define x3 *ADC0_read
#define x4 *ADC4_read
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3[i];
ya1_aux = ya1_aux + x3[i] * sin(alfa);
yb1_aux = yb1_aux + x3[i] * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
This is the gcc
error output:
fix1.c: In function ‘main’:
fix1.c:9:17: error: invalid type argument of unary ‘*’ (have ‘uint32_t {aka unsigned int}’)
#define x3 *ADC0_read
^
fix1.c:46:21: note: in expansion of macro ‘x3’
y0_aux = y0_aux + x3[i];
^~
fix1.c:9:17: error: invalid type argument of unary ‘*’ (have ‘uint32_t {aka unsigned int}’)
#define x3 *ADC0_read
^
fix1.c:47:23: note: in expansion of macro ‘x3’
ya1_aux = ya1_aux + x3[i] * sin(alfa);
^~
fix1.c:9:17: error: invalid type argument of unary ‘*’ (have ‘uint32_t {aka unsigned int}’)
#define x3 *ADC0_read
^
fix1.c:48:23: note: in expansion of macro ‘x3’
yb1_aux = yb1_aux + x3[i] * cos(alfa);
^~
Here is one way to change things [this compiles cleanly]:
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0 ADC3_read
#define x1 ADC2_read
#define x2 ADC1_read
#define x3 ADC0_read
#define x4 ADC4_read
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3[i];
ya1_aux = ya1_aux + x3[i] * sin(alfa);
yb1_aux = yb1_aux + x3[i] * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
Here is an alternate way to code it [this also compiles cleanly]:
#include <stdint.h>
#include <math.h>
// declaration of pointers to PIN read
#define F_SAMPLE 2000
#define x0(o) ADC3_read[o]
#define x1(o) ADC2_read[o]
#define x2(o) ADC1_read[o]
#define x3(o) ADC0_read[o]
#define x4(o) ADC4_read[o]
int
main(void)
{
// declaration of variables
int PI = 3.14159;
int teste = 0;
float y_0,
ya1,
yb1,
y_1;
float y0_aux,
ya1_aux,
yb1_aux;
int alfa,
i,
j;
// declaration of PIN read
uint32_t ADC_read[5];
uint32_t *ADC0_read = &ADC_read[0];
uint32_t *ADC1_read = &ADC_read[1];
uint32_t *ADC2_read = &ADC_read[2];
uint32_t *ADC3_read = &ADC_read[3];
uint32_t *ADC4_read = &ADC_read[4];
// control code
for (i = 0; i <= 12000; i++) {
alfa = alfa + (2 * PI / 200);
if (alfa >= 2 * PI)
alfa = alfa - 2 * PI;
j++;
// error = identifier "x3" is undefined
y0_aux = y0_aux + x3(i);
ya1_aux = ya1_aux + x3(i) * sin(alfa);
yb1_aux = yb1_aux + x3(i) * cos(alfa);
if (j == 200) {
y_0 = y0_aux / 200;
ya1 = ya1_aux / 200;
yb1 = yb1_aux / 200;
y_1 = sqrt((ya1 * ya1) + (yb1 * yb1));
y0_aux = 0;
ya1_aux = 0;
yb1_aux = 0;
j = 0;
}
}
}
But, indexing off from ADC0_read
doesn't make sense to me. Your for
loop goes to 12000, but ADC_read
has only 5 elements, so either variant above will probably segfault because you're going way past the end of the array.
More likely, you may want something like:
uint32_t ADC_read[12000];
#define x3(o) ADC_read[(o) + 0]
#define x2(o) ADC_read[(o) + 1]
...
Honestly, I don't see how the individual pointers (ADC3_read
, etc.) fit in [well]