facebook / facebook/folly

How to port FreeRTOS-style code to Folly?

Open
#1,886 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
30.5k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Description

Hi I have an existing project written in FreeRTOS style running on 32-bit MCUs, but wishing to port over to a Linux environment, e.g. Zynq Petalinux. How do I refactor the code to utilize Folly APIs?

For example, I have a blinking LED flashing at 1 second interval. I also hook up a push button to toggle the blinking LED. Like this FreeRTOS-style pseudo code:

```c++
std::atomic_bool is_led_on = false;
static ThreadPool{.n_worker = 3};

void loopLED() noexcept {
setupLED();
bool led_blink_state = true;
for(;;) {
if(is_led_on) {
digitalWrite(led_blink_state);
led_blink_state = ! led_blink_state;

using std::chrono_literal;
} else {
digitalWrite(false);
}
ThreadPool.schedule_after(1000ms);
}
teardownLED();
}

void loopButton() noexcept {
setupButtion();
for (;;) {
if (button1.is_pressed()) {
is_led_on = ! is_led_on;
}
using std::chrono_literal;
ThreadPool.schedule_after(200ms);
}
teardownButton();
}
```

In particular, how do I retain the `setup -> event loop -> teardown` coding pattern per task in Folly? Or, should I move the `for(;;){}` to somewhere else, in order to utilize Folly well?

I understand running such an example with Folly is an overkill. In a more realistic example the "LEDs" would have been CAN-bus handshakes over 10+ remote hardware components; the "button" would have been a command parser of the incoming `/dev/stdin` stream.

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files, tests, or entry points to inspect. Start by determining whether the repository has existing Folly executor or timer documentation relevant to the requested FreeRTOS-to-Linux port; done would require a clear, repository-backed answer about retaining the setup, event-loop, and teardown pattern.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
developer-experience
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
15/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.