Hi,
i've an issue with an FreeRTOS Scheduling Task. I tried multiple changes, but i don't get what is my fault.
I got the error, that there are multiple definition of setup' and
loop'
All four files (PWM_A6.cpp, PWM_A6.h, Scheduler.cpp and Scheduler.h) are placed in the same path. I've also tried to place the Scheduler files in a separate path, but this also doesn't worked.
#include "PWM_A6.h"
#include <Arduino.h>
#include <Arduino_FreeRTOS.h>
#include "Scheduler.h"
#include <FreeRTOSConfig.h>
int ledPin = 13;
int ledPin1 = 12;
int ledPin2 = 8;
int pwm = 11;
int LED0 = 0;
int LED1 = 0;
int LED2 = 0;
int analogin = A0;
int PWM_REG = 0;
void tBlinkLED(void *pvParameters);
void tLevelControl(void *pvParameters);
void tMotorTask(void *pvParameters);
//The setup function is called once at startup of the sketch
void setup() {
Serial.begin(115200); // Serielle Schnittstelle
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(pwm, OUTPUT);
xTaskCreate(tBlinkLED, " Blink ", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
xTaskCreate(tLevelControl, " Blink ", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
xTaskCreate(tMotorTask, " Blink ", configMINIMAL_STACK_SIZE, NULL, 3, NULL);
PWM_REG = 128; //50% duty cycle
analogWrite(pwm, PWM_REG);
vTaskStartScheduler();
}
void Toggle_Task() {
if (LED0 == 0) {
digitalWrite(ledPin, HIGH);
LED0 = 1;
} else {
digitalWrite(ledPin, LOW);
LED0 = 0;
}
}
// The loop function is called in an endless loop
void loop() {
//Toggle_Task();
//delay(500);
}
int main(void) {
init();
setup(); // Code , der einmal aufgerufen wird
while (true) {
loop();
}
}
And the scheduler.cpp
#include "Scheduler.h"
#include <Arduino.h>
#include <Arduino_FreeRTOS.h>
#include <FreeRTOSConfig.h>
#include "PWM_A6.h"
extern int ledPin;
extern int ledPin1;
//extern int ledPin2;
extern int analogin;
extern int pwm;
//The setup function is called once at startup of the sketch
void setup() {
// Add your initialization code here
}
// The loop function is called in an endless loop
void loop() {
//Add your repeated code here
}
void tMotorTask(void *pvParameters) {
//TickType_t xLastWakeTime;
int DAC_values[7] = { 0, 38, 77, 128, 179, 230, 255 };
int DAC_out;
int n = 0;
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
//xLastWakeTime = xTaskGetTickCount();
for (;;) {
DAC_out = DAC_values[n];
analogWrite(pwm, DAC_out);
n++;
if (n >= 7) {
n = 0;
}
vTaskDelay(xDelay);
}
}
void tBlinkLED(void *pvParameters) {
//Block for 500 ms.
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
//TickType_t xLastWakeTime;
static int LED1 = 0;
//xLastWakeTime = xTaskGetTickCount();
for (;;) {
if (LED1 == 0) {
LED1 = 1;
digitalWrite(ledPin, HIGH);
} else {
LED1 = 0;
digitalWrite(ledPin, LOW);
}
//Block for 500 msec
vTaskDelay(xDelay);
}
}
void tLevelControl(void *pvParameters) {
// Block for 500 ms.
int ADCValue;
int LIM = 100;
static int LED2 = 0;
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
//TickType_t xLastWakeTime;
//xLastWakeTime = xTaskGetTickCount();
for (;;) {
ADCValue = analogRead(analogin);
if (ADCValue >= LIM) {
LED2 = 1;
digitalWrite(ledPin1, HIGH);
} else {
LED2 = 0;
digitalWrite(ledPin1, LOW);
}
/* Block for 500 msec */
vTaskDelay(xDelay);
}
}
Error output:
Starting combiner
"/home/unnamed/eclipse/cpp-2020-06/eclipse//arduinoPlugin/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc" -Wall -Wextra -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "/home/unnamed/eclipse-workspace/PWM_A6/Release/PWM_A6.elf" ./PWM_A6.cpp.o ./Scheduler.cpp.o ./libraries/Scheduler/src/Scheduler.cpp.o ./libraries/FreeRTOS/src/croutine.c.o ./libraries/FreeRTOS/src/event_groups.c.o ./libraries/FreeRTOS/src/heap_3.c.o ./libraries/FreeRTOS/src/list.c.o ./libraries/FreeRTOS/src/port.c.o ./libraries/FreeRTOS/src/queue.c.o ./libraries/FreeRTOS/src/stream_buffer.c.o ./libraries/FreeRTOS/src/tasks.c.o ./libraries/FreeRTOS/src/timers.c.o ./libraries/FreeRTOS/src/variantHooks.cpp.o /home/unnamed/eclipse-workspace/PWM_A6/Release/arduino.ar "-L/home/unnamed/eclipse-workspace/PWM_A6/Release" -lm
./Scheduler.cpp.o (symbol from plugin): In function `setup':
(.text+0x0): multiple definition of `setup'
./PWM_A6.cpp.o (symbol from plugin):(.text+0x0): first defined here
./Scheduler.cpp.o (symbol from plugin): In function `setup':
(.text+0x0): multiple definition of `loop'
./PWM_A6.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [makefile:82: PWM_A6.elf] Fehler 1
"make all" terminated with exit code 2. Build might be incomplete.
19:45:45 Build Failed. 5 errors, 0 warnings. (took 1s.125ms)