Raspberry Pi 2, get system clock with timeval

This Simulink model has an S-function builder block to access the linux system time via gettimeofday
Updated 16 Dec 2015

View License

This model uses Raspberry Pi library block to toggle the LED and a executes custom written S-function to access the targeted system time for comparison
to the running simulation time. This is helpful in quantifying soft-real-time performance.

The POSIX gettimeofday() function has resolution down to microseconds but windows and linux have good resolution to around
10ms and about 1ms, respecctively, depending.

The S-function builder auto-generates a .tlc file and generates a fully-inlined S-function that is helpful in targeting the Raspberry Pi device
(or any other Simulink Coder target).

getSystemClockTimeval.c works on the host PC and also the Raspberry Pi runnning Debian Wheezy linux. The simulink code computes the differnce between
the operating system's local time and the simulation time then logs that to a file. The write-to-file block works on the host or the targeted Raspberry Pi.

This Simulink model was tested and runs on R2015b on Windows 10 with the gcc MinGW 64-bit compiler.

To run this model on a PC with Matlab, double click the light blue initiailzation block to specify h_fixed=0.1 seconds, then open the s-function builder block, hit build, and upon successfully creating the s-function getSystemClockTimeval.c and associated .tlc file it will build getSystemClockTimeval.mexw64. You can then run the simulation on the host PC. It logs a matfile called myTestData.mat in the working directory.

To run this file on the Rasperry Pi 2 model B, double click the initialization block to assign h_fixed=0.1 seconds, then open the S-function builder, build the s-function and associated .tlc file, then close that dialogue box. Press ctrl-B to build and target the model to your properly configured Raspberry Pi 2 device.

Marc Compere, comperem@erau.edu
created : 16 December 2015
modified: 16 December 2015

Cite As

Marc Compere (2024). Raspberry Pi 2, get system clock with timeval (https://www.mathworks.com/matlabcentral/fileexchange/54546-raspberry-pi-2-get-system-clock-with-timeval), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Simulink Supported Hardware in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes