ArduinoModbus icon indicating copy to clipboard operation
ArduinoModbus copied to clipboard

Use `rtos::ThisThread::sleep_for` as delay in `_sleep_response_timeout()` for Mbed OS boards

Open salasidis opened this issue 2 years ago • 0 comments

The code currently present is as follows

#elif defined(_MBED) - or ir could reference actual boards PORTENTA_H7 etc
    delay(ctx->response_timeout.tv_sec * 1000);
    delayMicroseconds(ctx->response_timeout.tv_usec);
#else

I would like if possible to add an #ifdef _MBED (as used by Portenta and others)

In there the delay can be changed to:

rtos::ThisThread::sleep_for(mbed::chrono::milliseconds_u32(sec * 1000));
rtos::ThisThread::sleep_for(mbed::chrono::milliseconds_u32(usec / 1000));
delayMicroseconds(usec % 1000);

This way delays are task switch implemented - not wasting CPU time, The sub ms delay will be done in the usal Arduino way, as MBed does not allow sub ms sleep intervals (ticker res 1mS).

salasidis avatar Jan 07 '23 16:01 salasidis