modelica-3rdparty / Modelica_DeviceDrivers

Free library for interfacing hardware drivers to Modelica models. There is support for joysticks, keyboards, UDP, TCP/IP, LCM, MQTT, shared memory, AD/DA converters, serial port and other devices.
BSD 3-Clause "New" or "Revised" License
77 stars 31 forks source link

RealtimeSynchronize block "clock_nanosleep" error on Linux #357

Closed bernhard-thiele closed 2 years ago

bernhard-thiele commented 2 years ago

Sporadically there is an error when using Blocks.OperatingSystem.RealtimeSynchronize on Linux. The simulation exits with the message MDDRealtimeSynchronize.h: clock_nanosleep(..) failed.

The reason for this is that https://github.com/modelica-3rdparty/Modelica_DeviceDrivers/blob/b2fa5d7a55de4342a29ca68f7c18c9edb1c100bf/Modelica_DeviceDrivers/Resources/Include/MDDRealtimeSynchronize.h#L960 fails due to an invalid t_abs (negative t_abs.tv_nsec). The cause is further up in https://github.com/modelica-3rdparty/Modelica_DeviceDrivers/blob/b2fa5d7a55de4342a29ca68f7c18c9edb1c100bf/Modelica_DeviceDrivers/Resources/Include/MDDRealtimeSynchronize.h#L928 where it was overlooked that timespec_subtract(...) may modify its third argument for perfomring a carry.