Giter Site home page Giter Site logo

thetmirror / freertos-emulator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from khchentw/freertos-emulator

0.0 0.0 0.0 4.4 MB

POSIX based FreeRTOS emulator with SDL2 graphics interface and multiple async communications interfaces, aiming to make it possible to teach FreeRTOS without embedded hardware using similar processes

Home Page: https://alxhoff.github.io/FreeRTOS-Emulator/

License: GNU General Public License v3.0

C 80.68% C++ 15.38% CMake 3.05% GDB 0.01% Shell 0.10% Makefile 0.78%

freertos-emulator's Introduction

FreeRTOS Emulator

Coverity Scan Build Status

An implementation of POSIX based FreeRTOS with the combination of SDL2 graphics. Aimed at providing an x86 emulation solution for teaching FreeRTOS to students without the need of embedded hardware. Used at the Technical University of Munich in the teaching of the "Embedded Systems Programming Lab". Please excuse any references to "students" or "course" if you're not one of my students.

Based on the FreeRTOS (V5.X) simulator developed by William Davy. Updated to use FreeRTOS V9.0.0.

Checkout the Wiki page for a detailed Documentation!

Doxygen documentation can also be found on the GitHub Pages page.

Dependencies

The simulator uses the SDL2 graphics libraries.

Debian/Ubuntu

Assuming that you have some basic utilities like make, cmake and git already installed, execute:

sudo apt-get install build-essential libsdl2-ttf-dev libsdl2-mixer-dev libsdl2-image-dev libsdl2-gfx-dev libsdl2-dev

Additional requirements for development:

# Depending on your OS version you might have to add the llvm-toolchain-4.0 APT source before
sudo apt-get install clang-4.0 clang-tidy-4.0

Arch

sudo pacman -S sdl2 sdl2_gfx sdl2_image sdl2_mixer sdl2_ttf

Additional requirements for development:

sudo pacman -S clang

Windows/Mac

¯\(°_o)/¯

....install linux?

(Have a look at the Remote Toolchain wiki section)

Building

cd build
cmake ..
make

For those requiring an IDE run

cmake -G "Eclipse CDT4 - Unix Makefiles" ./

to generate the appropriate project files to allow for the emulator to be imported into Eclipse.

Additional targets

Documentation

Doxygen documentation, found in the docs folder, can be generated from cmake/make by passing the variable DOCS=on and making the target docs.

cmake -DDOCS=on ..
make docs

Tests

In test.cmake a number of extra targets are provided to help with linting.

Git --check

make commit

Checks for whitespaces and empty lines.

Astyle Formatting

cmake -DENABLE_ASTYLE=ON ..
make format

Invokes the Astyle formatter.

Warning: The default version of CMake which is installed f.e. on Ubuntu 16.04 will throw an arror when running make to setup the bin/astyle binary. Please upgrade to a newrer version manually if required:

VERSION=3.16
BUILD=5
wget -q https://cmake.org/files/v$VERSION/cmake-$VERSION.$BUILD-Linux-x86_64.sh
mkdir /opt/cmake
sh cmake-$VERSION.$BUILD-Linux-x86_64.sh --prefix=/opt/cmake --skip-license --exclude-subdir
ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
rm cmake-$VERSION.$BUILD-Linux-x86_64.sh

Clang Tidy

cmake -DENABLE_CLANG_TIDY=ON ..
make tidy

Uses clang tidy to find style violations, interface misuse of bugs found via static analysis.

To generate a list of warnings/errors use the build target tidy_list and then view the file tidy.fixes.

CppCheck

cmake -DENABLE_CPPCHECK=ON ..
make check

Code analysis with CppCheck, focusing on undefined behaviour bugs.

Valgrind (memcheck)

cmake -DENABLE_MEMCHECK=ON ..
make memcheck

Memory checker.

Google Tests/Coverage

Coverage

cmake -DENABLE_COVERAGE=ON ..
make

Each sanitizer must be run stand alone, thus you cannot run them together.

Address sanitizer

cmake -DENABLE_ASAN=ON ..
make

Undefined behaviour sanitizer

cmake -DENABLE_USAN=ON ..
make

Thread sanitizer

cmake -DENABLE_TSAN=ON ..
make

All checks

The target make all_checks

cmake -DALL_CHECKS=ON ..
make

will perform all checks

Running

The binary will be created inside a bin folder. The emulator should be run from this folder becuase at the moment the Gfx libraries rely on hardcoded resource paths for things such as fonts. As such to run perform the following.

cd bin
./FreeRTOS_Emulator

Debugging

The emulator uses the signals SIGUSR1 and SIG34 and as such GDB needs to be told to ignore the signal. An appropriate .gdbinit is in the bin directory. Copy the .gdbinit into your home directory or make sure to debug from the bin directory. Such that GDB does not get interrupted by the POSIX signals used by the emulator for IPC.

If using an IDE, make sure to configure your debug to load the gdbinit file.

Tracing

Note: this is experiemental and proves to be unstable with the AIO libraries, it was used during development of the emulator and provides a novel function for small experiements, it should not be used for serious debugging of the entire emulator as this will cause errors.

Tracing, found in lib/tracer is instrumented using GCC's function instrumentation.

Running

cmake -DTRACE_FUNCTIONS=ON ..

will include the constructor, destructor and the needed __cyg_profile_func_xxx functions that are called upon entry and exit of any functions called during the execution of the program. These callback functions are implemented to log the function, caller and timestamp of each function calls, written to a file named trace.out. As the values written out are memory offsets and, as such, are not human readable the trace dump must be processed by the script readtracelog.sh which uses addr2line to convert the memory offsets into human readable function calls, done using the memory map of the compiled executable.

Example

Adding something like

+void printhello(void)
+{
+    printf("hello");
+}
+
 int main(int argc, char *argv[])
 {
+    printhello();

To your code and then compiling and running the executable, after passing -DTRACE_FUNCTIONS=ON to cmake of course, you will be presented with an output similar to

x 0x55e138f918a9 0x55e138f9fe4d 1587039262
e 0x55e138f92f72 0x7f2117466023 1587039262
e 0x55e138f92f34 0x55e138f92f99 1587039262
x 0x55e138f92f34 0x55e138f92f99 1587039262
e 0x55e138f918f0 0x7f2117bb242b 1587039262

After processing using the provided script sorcery, running something such as

./readtracelog.sh ../../bin/FreeRTOS_Emulator ../../build/trace.out

You will see a human readable output that logs the function entries and exit made in the program

Exit  trace_begin at 2020-04-16T14:14:22+02:00
Enter main at 2020-04-16T14:14:22+02:00, called from ?? (??:0)
Enter printhello at 2020-04-16T14:14:22+02:00, called from main (main.c:624)
Exit  printhello at 2020-04-16T14:14:22+02:00
Enter trace_end at 2020-04-16T14:14:22+02:00, called from ?? (??:0)

Note that the ?? visible in the output above are the result of the function instrumentation only being able to map to functions compiled using the -finstrument-functions compile flag. Extenal libraries etc are only linked against and not compiled using this flag, therefore they cannot be instrumented.


Buy Me A Coffee

freertos-emulator's People

Contributors

alxhoff avatar philippvk avatar stickler-ci avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.