Forum: Mikrocontroller und Digitale Elektronik static declarations follows non-static declaration


von Icke_Wa (Gast)


Lesenswert?

Hallo alle miteinander,

ich wollte grade meinen C-Code compilieren und stieß auf einige 
merkwürdige Fehler.

Ich musste einen Haufen Funktionen schreiben, welche nach Bedarf 
aufgerufen werden müssen (der Bedarf ist noch nicht, demnach sind das 
quasi erstmal alles dummies die nicht aufgerufen werden)
Die Funktionen ähneln sich weitesgehend stark, doch irgendwo in der 
Mitte vom File bekomme ich plötzlich den Fehler:

static declaration of 'SensorSetDigitalTest' follows non-static 
declaration

Hier der Code der Funktion:
1
void SensorSetDigitalTest(bool bypassPLL, bool contextAB, uint8_t colGainA, uint8_t colGainB, bool monoChrome){
2
  uint8_t digitalTestValue_high = 0;
3
  uint8_t digitalTestValue_low  = 0;
4
5
  if(bypassPLL == true)
6
    digitalTestValue_high = 64;
7
8
  if(contextAB == true)
9
    digitalTestValue_high += 32;
10
11
  if(monoChrome == true)
12
    digitalTestValue_low = 128;
13
14
15
  if((colGainA || colGainB) > 3)
16
    CyU3PDebugPrint(4, "Max Value for colGain = 3! \n");
17
  else{
18
    digitalTestValue_high += colGainB;
19
    digitalTestValue_low  += (colGainA << 4);
20
  }
21
22
  SensorWrite2B(SENSOR_ADDR_WR, 0x30, 0xB0, digitalTestValue_high, digitalTestValue_low);
23
}

und der Aufruf im Header:
1
extern void
2
SensorSetDigitalTest(
3
    bool bypassPLL, bool contextAB, uint8_t colGainA, uint8_t colGainB, bool monoChrome);

Weiß irgendwer was hier schief geht? WIe gesagt, sind darüber noch 
einige Funktionen, die sich nur geringfügig unterscheiden und bei denen 
er nicht meckert. Nach dieser Funktion habe ich den Fehler plötzlich an 
jedem Funktionskopf.
Ganz unten im File habe ich dann auch noch den Fehler:
expected declaration or statement at end of input

Ich hab alle { } gecheckt und die sind da. Wenn ich den Platz der 
letzten Funktion mit einer anderen tausche, kommt der Fehler bei der, 
die aktuell die letzte Funktion im File ist.

Würde mich freuen, wenn ihr mir helfen könntet!

Vielen Dank!

Beste Grüße,

lennart

: Verschoben durch Moderator
von Klaus W. (mfgkw)


Lesenswert?

Evtl. hast du dich irgendwo mit Klammern überschlagen?

> Würde mich freuen, wenn ihr mir helfen könntet!
Nicht ohne mehr Quelltext.

: Bearbeitet durch User
von Ralf D. (rad)


Lesenswert?

Das liest sich sehr nach einem fehlenden ; ... irgendwo viel weiter 
"oben", ggf. auch in einem #include - File.
Ohne den Sourcefile und die #includierten Files wird der Fehler nicht zu 
finden sein.


[OffTopic]
Icke_Wa schrieb:
>   if((colGainA || colGainB) > 3)

Was ist die Intention dieser Zeile?
Ich vermute das es eine andere ist als das was da steht ... ;)
[/OffTopic]

von Icke_Wa (Gast)


Lesenswert?

Juten morgen erstmal alle zusammen. Ich wollte den Sourcecode der 
Übersicht halber ungern komplett poasten. Da ich aber ja gerne eure 
Hilfe in Anspruch nehme, habe ich es probiert, wurde dann allerdings 
darauf aufmerksam gemacht, dass der Poast dadurch zu lang wird.

Was ich mal noch probiert habe ist, dass ich die Reihenfolge der 
Funktionen von

- Fehlerfrei
- Fehlerfrei
- Fehlerhaft
- Fehlerhaft

geändert habe zu

- Fehlerhaft
- Fehlerfrei
- Fehlerhaft
- Fehlerfrei

Der Compiler hat das allerdings bemerkt und wieder in den selben 
Funktionen den Fehler gefunden. Der Fehler müsste demnach doch 
eigentlich wirklich in der Funktion stecken oder?

Die Variable bool habe ich im Header mit:
#define bool int
#define true 1
#define false 0
definiert. Allerdings habe ich auch in fehlerfreien Funktionen schon mit 
bool ohne Probleme gearbeitet.

Außerdem ist mir noch aufgefallen, dass im Header-file bei jedem header 
der fehlerhaften Funktionen ein warning mit "previous declaration of 
'SensorSetDigitalTest' was here".

So jetzt Schlussletztlich doch nochmal etwas Sourcecode: Hier mal noch 
der obere Teil vom c-File mit den Funktionen die ich aufrufe (nicht alle 
davon).
1
#include <cyu3system.h>
2
#include <cyu3os.h>
3
#include <cyu3dma.h>
4
#include <cyu3error.h>
5
#include <cyu3uart.h>
6
#include <cyu3i2c.h>
7
#include <cyu3types.h>
8
#include <cyu3gpio.h>
9
#include <cyu3utils.h>
10
#include "sensor.h"
11
12
13
14
/* This function inserts a delay between successful I2C transfers to prevent
15
 false errors due to the slave being busy.
16
 */
17
static void SensorI2CAccessDelay(CyU3PReturnStatus_t status) {
18
  /* Add a 10us delay if the I2C operation that preceded this call was successful. */
19
  if (status == CY_U3P_SUCCESS)
20
    CyU3PBusyWait(10);
21
}
22
23
/* Write to an I2C slave with two bytes of data. */
24
CyU3PReturnStatus_t SensorWrite2B(uint8_t slaveAddr, uint8_t highAddr,
25
    uint8_t lowAddr, uint8_t highData, uint8_t lowData) {
26
  CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
27
  CyU3PI2cPreamble_t preamble;
28
  uint8_t buf[2];
29
30
  /* Validate the I2C slave address. */
31
  if ((slaveAddr != SENSOR_ADDR_WR) && (slaveAddr != I2C_MEMORY_ADDR_WR)) {
32
    CyU3PDebugPrint(4, "I2C Slave address is not valid!\n");
33
    return 1;
34
  }
35
36
  /* Set the parameters for the I2C API access and then call the write API. */
37
  preamble.buffer[0] = slaveAddr;
38
  preamble.buffer[1] = highAddr;
39
  preamble.buffer[2] = lowAddr;
40
  preamble.length = 3; /*  Three byte preamble. */
41
  preamble.ctrlMask = 0x0000; /*  No additional start and stop bits. */
42
43
  buf[0] = highData;
44
  buf[1] = lowData;
45
46
  apiRetStatus = CyU3PI2cTransmitBytes(&preamble, buf, 2, 0);
47
  SensorI2CAccessDelay(apiRetStatus);
48
49
  return apiRetStatus;
50
}
51
52
CyU3PReturnStatus_t SensorWrite(uint8_t slaveAddr, uint8_t highAddr,
53
    uint8_t lowAddr, uint8_t count, uint8_t *buf) {
54
  CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
55
  CyU3PI2cPreamble_t preamble;
56
57
  /* Validate the I2C slave address. */
58
  if ((slaveAddr != SENSOR_ADDR_WR) && (slaveAddr != I2C_MEMORY_ADDR_WR)) {
59
    CyU3PDebugPrint(4, "I2C Slave address is not valid!\n");
60
    return 1;
61
  }
62
63
  if (count > 64) {
64
    CyU3PDebugPrint(4, "ERROR: SensorWrite count > 64\n");
65
    return 1;
66
  }
67
68
  /* Set up the I2C control parameters and invoke the write API. */
69
  preamble.buffer[0] = slaveAddr;
70
  preamble.buffer[1] = highAddr;
71
  preamble.buffer[2] = lowAddr;
72
  preamble.length = 3;
73
  preamble.ctrlMask = 0x0000;
74
75
  apiRetStatus = CyU3PI2cTransmitBytes(&preamble, buf, count, 0);
76
  SensorI2CAccessDelay(apiRetStatus);
77
78
  return apiRetStatus;
79
}
80
81
CyU3PReturnStatus_t SensorRead2B(uint8_t slaveAddr, uint8_t highAddr,
82
    uint8_t lowAddr, uint8_t *buf) {
83
  CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
84
  CyU3PI2cPreamble_t preamble;
85
86
  if ((slaveAddr != SENSOR_ADDR_RD) && (slaveAddr != I2C_MEMORY_ADDR_RD)) {
87
    CyU3PDebugPrint(4, "I2C Slave address is not valid!\n");
88
    return 1;
89
  }
90
91
  preamble.buffer[0] = slaveAddr & I2C_SLAVEADDR_MASK; /*  Mask out the transfer type bit. */
92
  preamble.buffer[1] = highAddr;
93
  preamble.buffer[2] = lowAddr;
94
  preamble.buffer[3] = slaveAddr;
95
  preamble.length = 4;
96
  preamble.ctrlMask = 0x0004; /*  Send start bit after third byte of preamble. */
97
98
  apiRetStatus = CyU3PI2cReceiveBytes(&preamble, buf, 2, 0);
99
  SensorI2CAccessDelay(apiRetStatus);
100
101
  return apiRetStatus;
102
}
103
104
CyU3PReturnStatus_t SensorRead(uint8_t slaveAddr, uint8_t highAddr,
105
    uint8_t lowAddr, uint8_t count, uint8_t *buf) {
106
  CyU3PReturnStatus_t apiRetStatus = CY_U3P_SUCCESS;
107
  CyU3PI2cPreamble_t preamble;
108
109
  /* Validate the parameters. */
110
  if ((slaveAddr != SENSOR_ADDR_RD) && (slaveAddr != I2C_MEMORY_ADDR_RD)) {
111
    CyU3PDebugPrint(4, "I2C Slave address is not valid!\n");
112
    return 1;
113
  }
114
  if (count > 64) {
115
    CyU3PDebugPrint(4, "ERROR: SensorWrite count > 64\n");
116
    return 1;
117
  }
118
119
  preamble.buffer[0] = slaveAddr & I2C_SLAVEADDR_MASK; /*  Mask out the transfer type bit. */
120
  preamble.buffer[1] = highAddr;
121
  preamble.buffer[2] = lowAddr;
122
  preamble.buffer[3] = slaveAddr;
123
  preamble.length = 4;
124
  preamble.ctrlMask = 0x0004; /*  Send start bit after third byte of preamble. */
125
126
  apiRetStatus = CyU3PI2cReceiveBytes(&preamble, buf, count, 0);
127
  SensorI2CAccessDelay(apiRetStatus);
128
129
  return apiRetStatus;
130
}
131
132
/*
133
 * Reset the image sensor using GPIO.
134
 */
135
void SensorReset(void) {
136
  CyU3PReturnStatus_t apiRetStatus;
137
138
  /* Drive the GPIO low to reset the sensor. */
139
  apiRetStatus = CyU3PGpioSetValue(SENSOR_RESET_GPIO, CyFalse);
140
  if (apiRetStatus != CY_U3P_SUCCESS) {
141
    CyU3PDebugPrint(4, "GPIO Set Value Error, Error Code = %d\n",
142
        apiRetStatus);
143
    return;
144
  }
145
146
  /* Wait for some time to allow proper reset. */
147
  CyU3PThreadSleep(10);
148
149
  /* Drive the GPIO high to bring the sensor out of reset. */
150
  apiRetStatus = CyU3PGpioSetValue(SENSOR_RESET_GPIO, CyTrue);
151
  if (apiRetStatus != CY_U3P_SUCCESS) {
152
    CyU3PDebugPrint(4, "GPIO Set Value Error, Error Code = %d\n",
153
        apiRetStatus);
154
    return;
155
  }
156
157
  /* Delay the allow the sensor to power up. */
158
  CyU3PThreadSleep(10);
159
  return;
160
}
161
162
163
164
/*
165
   Verify that the sensor can be accessed over the I2C bus from FX3.
166
 */
167
uint8_t SensorI2cBusTest(void) {
168
  /* The sensor ID register can be read here to verify sensor connectivity. */
169
  uint8_t buf[2];
170
171
  /* Reading sensor ID */
172
  if (SensorRead2B(SENSOR_ADDR_RD, 0x00, 0x00, buf) == CY_U3P_SUCCESS) {
173
    if ((buf[0] == 0x01) && (buf[1] == 0x02)) {
174
      return CY_U3P_SUCCESS;
175
    }
176
  }
177
  return 1;
178
}
179
180
181
182
183
184
/*
185
 Get the current brightness setting from the image sensor.
186
 */
187
uint8_t SensorGetBrightness(void) {
188
  uint8_t buf[2];
189
190
  SensorRead2B(SENSOR_ADDR_RD, 0x00, 0x02, buf);
191
  return (uint8_t) buf[1];
192
}
193
194
/*
195
 Update the brightness setting for the image sensor.
196
 */
197
void SensorSetBrightness(uint8_t brightness) {
198
  SensorWrite2B(SENSOR_ADDR_WR, 0x00, 0x02, 0x00, brightness);
199
}


und noch der obere Teil des Header Files:
1
#ifndef _INCLUDED_SENSOR_H_
2
#define _INCLUDED_SENSOR_H_
3
4
#define bool uint8_t
5
#define true 1
6
#define false 0
7
8
9
#include <cyu3types.h>
10
#include <stdbool.h>
11
12
/* I2C Slave address for the image sensor. */
13
#define SENSOR_ADDR_WR 0x20             /* Slave address used to write sensor registers. Default set to EEPROM. */
14
#define SENSOR_ADDR_RD 0x21             /* Slave address used to read from sensor registers. Default set to EEPROM */
15
16
#define I2C_SLAVEADDR_MASK 0xFE         /* Mask to get actual I2C slave address value without direction bit. */
17
18
#define I2C_MEMORY_ADDR_WR 0xA0         /* I2C slave address used to write to an EEPROM. */
19
#define I2C_MEMORY_ADDR_RD 0xA1         /* I2C slave address used to read from an EEPROM. */
20
21
/* GPIO 22 on FX3 is used to reset the Image sensor. */
22
#define SENSOR_RESET_GPIO 37
23
24
enum RESET_REGISTER_BITS {RR_RESET=0, RR_RESTART, RR_STREAM, RR_LOCK_REG, RR_STDBY_EOF, RR_DRIVE_PINS=6, RR_PARALLEL_EN, RR_GPI_EN, RR_MASK_BAD, RR_RESTART_BAD, RR_FORCED_PLL_ON, RR_NONE=255};
25
enum BINNING { NO_BINNING = 0, HORIZONTAL_BINNING, FULL_BINNING, NONE }; // for Register R0x3032
26
enum LINE_VALID { NORMAL = 0, CONTINUOUSLY, LINE_XOR_FRAME}; // for Register R0x306E
27
/*
28
 Horizontal binning: Horizontal only binning
29
 Full binning: Horizontal AND Vertical Binning
30
*/
31
32
/* Function    : SensorWrite2B
33
   Description : Write two bytes of data to image sensor over I2C interface.
34
   Parameters  :
35
                 slaveAddr - I2C slave address for the sensor.
36
                 highAddr  - High byte of memory address being written to.
37
                 lowAddr   - Low byte of memory address being written to.
38
                 highData  - High byte of data to be written.
39
                 lowData   - Low byte of data to be written.
40
 */
41
42
43
44
extern CyU3PReturnStatus_t
45
SensorWrite2B (
46
        uint8_t slaveAddr,
47
        uint8_t highAddr,
48
        uint8_t lowAddr,
49
        uint8_t highData,
50
        uint8_t lowData);
51
52
/* Function    : SensorWrite
53
   Description : Write arbitrary amount of data to image sensor over I2C interface.
54
   Parameters  :
55
                 slaveAddr - I2C slave address for the sensor.
56
                 highAddr  - High byte of memory address being written to.
57
                 lowAddr   - Low byte of memory address being written to.
58
                 count     - Size of write data in bytes. Limited to a maximum of 64 bytes.
59
                 buf       - Pointer to buffer containing data.
60
 */
61
extern CyU3PReturnStatus_t
62
SensorWrite (
63
        uint8_t slaveAddr,
64
        uint8_t highAddr,
65
        uint8_t lowAddr,
66
        uint8_t count,
67
        uint8_t *buf);
68
69
/* Function    : SensorRead2B
70
   Description : Read 2 bytes of data from image sensor over I2C interface.
71
   Parameters  :
72
                 slaveAddr - I2C slave address for the sensor.
73
                 highAddr  - High byte of memory address being read from.
74
                 lowAddr   - Low byte of memory address being read from.
75
                 buf       - Buffer to be filled with data. MSB goes in byte 0.
76
 */
77
extern CyU3PReturnStatus_t
78
SensorRead2B (
79
        uint8_t slaveAddr,
80
        uint8_t highAddr,
81
        uint8_t lowAddr,
82
        uint8_t *buf);
83
84
/* Function    : SensorRead
85
   Description : Read arbitrary amount of data from image sensor over I2C interface.
86
   Parameters  :
87
                 slaveAddr - I2C slave address for the sensor.
88
                 highAddr  - High byte of memory address being read from.
89
                 lowAddr   - Low byte of memory address being read from.
90
                 count     = Size of data to be read in bytes. Limited to a max of 64.
91
                 buf       - Buffer to be filled with data.
92
 */
93
extern CyU3PReturnStatus_t
94
SensorRead (
95
        uint8_t slaveAddr,
96
        uint8_t highAddr,
97
        uint8_t lowAddr,
98
        uint8_t count,
99
        uint8_t *buf);
100
101
/* Function    : SensorInit
102
   Description : Initialize the image sensor.
103
   Parameters  : None
104
 */
105
extern void
106
SensorInit (
107
        void);
108
109
/* Function    : SensorReset
110
   Description : Reset the image sensor using FX3 GPIO.
111
   Parameters  : None
112
 */
113
extern void
114
SensorReset (
115
        void);
116
117
/* Function    : SensorI2cBusTest
118
   Description : Test whether the image sensor is connected on the I2C bus.
119
   Parameters  : None
120
 */
121
extern uint8_t
122
SensorI2cBusTest (
123
        void);
124
125
/* Function    : SensorGetBrightness
126
   Description : Get the current brightness setting from the image sensor.
127
   Parameters  : None
128
 */
129
extern uint8_t
130
SensorGetBrightness (
131
        void);
132
133
/* Function    : SensorSetBrightness
134
   Description : Set the desired brightness setting on the image sensor.
135
   Parameters  :
136
                 brightness - Desired brightness level.
137
 */
138
extern void
139
SensorSetBrightness (
140
        uint8_t brightness);

Alle anderen Files des Projekts habe ich nicht angefasst, sondern wurden 
vom Hersteller zur Verfügung gestellt. Ohne Veränderungen lässt sich das 
Projekt auch problemlos kompilieren.

@ Ralf: Ja ich erinner mich an die Zeile, es war spät und ich habe mich 
gefragt ob das nicht eigentlich auch geht ... habe es beim nochmal 
drüber nachdenken mal schnell korrigiert :P Danke für den Hint. Das 
hätte wahrscheinlich mal wieder ein paar Stunden Zeit gekostet ^^

von Icke_Wa (Gast)


Lesenswert?

Man jetzt fühl ich mich aber mal wieder dämlich. Habe grade im Header 
eine Funktion gefunden, die mit { anstatt ; abgeschlossen wurde. Ihr 
hattet also recht und die miese Sau ist gefunden :)


Vielen Dank für eure Hilfe!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.