First of all thank you for your reply maxgerhardt
The platform.ini is the following:
[env:nucleo_l476rg]
platform = ststm32
board = nucleo_l476rg
framework = mbed
build_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT
And the structure of my project is the following. I am implementing the basic example of blinking led. But I am including several external libraries that I have written. These libraries have ifndef declaration and it looks like platformio is ignoring them, because I also get some warnings on re-declaration and re-definition.
I have one main.cpp file which calls to secondary file (Task file) that executes the blinking code. These file has one function to turn on the led and one to turn it off. It will call these functions depending on the current state of the program.
If our current state is led1 ON there is only one possible output which is go to state led1 OFF after some time. But if the current state is led1 OFF there are two possible outputs (requests): if the variable x > 10, just stop the execution, else go back to led1 ON after some period.
The code implemented creates one list of requests which contains all the possible outputs of the current state, therefore I check the value of the last request performed in order to know to which state I should go.
I hope the explanation is clear and the code of the blinking file as well. I will not include the MainBlock.h, but there, I have all my libraries included, as well as mbed.h, rtos.h and thread.h.
Please do not hesitate to ask for more information if it is not clear. Thanks in advance
#include “MainBlock.h” //mainblock.h contains the includes of the external libraries
// Header code defined in the model
DigitalOut myled1(LED1);
void __userImplemented__MainBlock__LED1on() {
myled1 = 1;
printf(“Led1 on.\n”);
}
void __userImplemented__MainBlock__LED1off(int val){
myled1 = 0;
printf(“Led1 off.\n”);
val = val + 1
printf(“Valor de x=%d\n”,val);
}
#define STATE__START__STATE 0
#define STATE__Led1on 1
#define STATE__Led1off 2
#define STATE__STOP__STATE 3
void MainBlock__LED1on() {
__userImplemented__MainBlock__LED1on();
}
void MainBlock__LED1off(int x) {
__userImplemented__MainBlock__LED1off(x);
}
void mainFunc__MainBlock(){
int period = 2;
int x = 0;
int __currentState = STATE__START__STATE;
attribute((unused)) request __req0;
attribute((unused))int *__params0[0];
attribute((unused)) request __req1;
attribute((unused))int *__params1[0];
attribute((unused))setOfRequests __list;
attribute((unused))size_t __myCond;
attribute((unused))request *__returnRequest;
char * __myname = “mainFunc__MainBlock”;
fillListOfRequests(&__list, __myname, NULL, __myCond, &__mainMutex);
/* Main loop on states */
while(__currentState != STATE__STOP__STATE) {
switch(__currentState) {
case STATE__START__STATE:
__currentState = STATE__Led1on;
break;
case STATE__Led1on:
wait_us((period)*1000000);
MainBlock__LED1off(x);
__currentState = STATE__Led1off;
break;
case STATE__Led1off:
if (!(x > 10)) {
makeNewRequest(&__req0, 241, IMMEDIATE, 1, (period)*1000000, (period)*1000000, 0,
__params0); //case for going back to led1 ON
addRequestToList(&__list, &__req0);
}
if (x > 10) {
makeNewRequest(&__req1, 249, IMMEDIATE, 0, 0, 0, 0, __params1); //case for stopping execution
addRequestToList(&__list, &__req1);
}
if (nbOfRequests(&__list) == 0) {
debug2Msg(__myname, "No possible request");
__currentState = STATE__STOP__STATE;
break;
}
__returnRequest = executeListOfRequests(&__list);
clearListOfRequests(&__list);
traceRequest(__myname, __returnRequest); //we ask for the first request of the list
if (__returnRequest == &__req0) {
MainBlock__LED1on();
__currentState = STATE__Led1on;
}
else if (__returnRequest == &__req1) {
__currentState = STATE__STOP__STATE;
}
break;
}
}
return ;
}