macformula / racecar

Monorepo for all firmware running on our custom ECUs.
https://macformula.github.io/racecar/
9 stars 3 forks source link

RTOS on Linux / POSIX #206

Open BlakeFreer opened 1 month ago

BlakeFreer commented 1 month ago

RTOS on Linux / POSIX

Timeline: Mid November

Description

Our firmware architecture is built on platform abstraction, meaning we can compile any project to run on any platform. This has huge benefits for debugging and development (see this article) but is not fully implemented.

We have no way to build a FreeRTOS project for the CLI or SIL (raspi) platform, so we cannot test any project involving FreeRTOS. This is a huge problem since most of our EV5 projects run on FreeRTOS.

There are two ways which this project can be solved.

First Solution: Port FreeRTOS

This is the ideal solution but might not be possible.

Run FreeRTOS directly on Linux / Windows. This is the ideal solution because:

  1. Using the same RTOS as we do on stm32 will allow us to remove the shared::os layer and allow us to use all of the FreeRTOS features.
  2. We can expect other platforms to behave more like stm32 than if we use a different RTOS.

This may be impossible because FreeRTOS is fundamentally a real-time operating system that relies on thread preemption. This may not be available on a regular operating system.

Second Solution: Custom Implementation

If FreeRTOS is not possible, we will emulate its functions using regular threads (tasks become threads, etc). Write an mcal::cli::os directory which implements the shared::os abstract classes using POSIX threads. Make a demo project showing that you can start tasks, synchronize with semaphores, and lock resources with mutexes.

Decision

Research whether the first solution is possible. If you can't find anything, or if it would only work for linux and not windows, then proceed with the second solution.

TylerStAmour commented 1 month ago

I just want to add one note about Linux, it has a new PREEMPT_RT patch that was just merged with the latest kernel version like 2 weeks ago. It adds soft realtime capability, maybe have a look there.