Call C++ function from Arduino C library

I have a particular case where a C library calls delay functions. I am working withe the Portenta, and would like to replace those delay() functions with mbed dleep_for commands (ro be more thread friendly).

Does anyone know of a way that this can be done.

I have not been able to do this.

Thanks

The delay() if often adapted to the available best option for that board.
The Portenta has Mbed running under Arduino, therefor the Mbed sleep is used.
See the source code at https://github.com/arduino/ArduinoCore-mbed/blob/master/cores/arduino/wiring.cpp#L51

void delay(unsigned long ms)
{
#ifndef NO_RTOS
  rtos::ThisThread::sleep_for(ms * 1ms);
#else
  wait_us(ms * 1000);
#endif
}

I don't know if the delay() is weak and can be overruled.

I couldn't call the sleep_for function from within C (as :: is a C++ construct)

but what I did was create a function in C++ with the sleep_for function, and declared it as

extern "C" in the .h (c++) file.

This allowed me to call it from within C.

1 Like

Your topic seems to be more specific to programming than to the IDE. Hence it has been moved to de Programming questions section of the forum.

If your question has been solved, you can mark it as such with the "solution" button under the most useful reply. This will let others know that a solution was foudn / provided.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.