Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Epic] - LekaOS Coordination #19

Closed
ladislas opened this issue Feb 29, 2020 · 2 comments
Closed

[Epic] - LekaOS Coordination #19

ladislas opened this issue Feb 29, 2020 · 2 comments
Assignees
Labels
01 - type: epic General discussion about a futur or current topic

Comments

@ladislas
Copy link
Member

This epic will discuss how we should organize the inner working of LekaOS.

@ladislas ladislas self-assigned this Feb 29, 2020
@ladislas ladislas added the 01 - type: epic General discussion about a futur or current topic label Feb 29, 2020
@ladislas
Copy link
Member Author

State Machines

@ladislas ladislas removed this from Backlog in LekaOS - Tasks, Bugs & PRs Mar 28, 2020
@ladislas ladislas moved this from Backlog to To do in LekaOS - Epics & Stories Mar 30, 2020
@ladislas ladislas moved this from To do to Backlog in LekaOS - Epics & Stories Mar 30, 2020
@ladislas ladislas changed the title LekaOS Coordination [Epic] - LekaOS Coordination Aug 28, 2020
@ladislas
Copy link
Member Author

ladislas commented Oct 25, 2020

Watchdog

Compare between ticker & thread

Different things are to be compared:

  • build size
  • simplicity of code
  • handling of abort()
  • handling of infinite loops
  • interference with deep sleep

Build size

  • with thread: 34980 bytes
  • with ticker: 33300 bytes
  • difference: thread - ticker = 1680 bytes

The use of a ticker instead of a thread saves 1680 bytes of memory.

🏅 for ticker.

$ cmake --build build -t spike_mbed_watchdog_ticker_vs_thread

[2/2] Linking CXX executable spikes/mbed_watchdog_ticker_vs_thread/spike_mbed_watchdog_ticker_vs_thread
| Module                 |         .text |       .data |        .bss |
|------------------------|---------------|-------------|-------------|
| [fill]                 |       60(+60) |       4(+4) |     32(+32) |
| [lib]/c.a              |   4852(+4852) | 2108(+2108) |     89(+89) |
| [lib]/gcc.a            |     760(+760) |       0(+0) |       0(+0) |
| [lib]/mbed-os-static.a | 24520(+24520) |   444(+444) | 8050(+8050) |
| [lib]/misc             |     188(+188) |       4(+4) |     28(+28) |
| main.cpp.obj           |     360(+360) |       0(+0) |   129(+129) |
| Subtotals              | 30740(+30740) | 2560(+2560) | 8328(+8328) |
Total Static RAM memory (data + bss): 10888(+10888) bytes
Total Flash memory (text + data): 33300(+33300) bytes
$ cmake --build build -t spike_mbed_watchdog_ticker_vs_thread

[2/2] Linking CXX executable spikes/mbed_watchdog_ticker_vs_thread/spike_mbed_watchdog_ticker_vs_thread
| Module                 |         .text |       .data |        .bss |
|------------------------|---------------|-------------|-------------|
| [fill]                 |       64(+64) |       4(+4) |     28(+28) |
| [lib]/c.a              |   4852(+4852) | 2108(+2108) |     89(+89) |
| [lib]/gcc.a            |     760(+760) |       0(+0) |       0(+0) |
| [lib]/mbed-os-static.a | 26176(+26176) |   444(+444) | 8050(+8050) |
| [lib]/misc             |     188(+188) |       4(+4) |     28(+28) |
| main.cpp.obj           |     380(+380) |       0(+0) |   253(+253) |
| Subtotals              | 32420(+32420) | 2560(+2560) | 8448(+8448) |
Total Static RAM memory (data + bss): 11008(+11008) bytes
Total Flash memory (text + data): 34980(+34980) bytes

Simplicity of code

See spikes/mbed_watchdog_ticker_vs_thread/main.cpp.

The ticker simpler as you only need a void kick() function to attach, whereas the thread also need a thread function to be started.

🏅 for ticker

Handling of abort()

Both ticker and thread can handle an abort() and thus a fatal error to restart the robot.

Handling of infinite loop

As a surprise, an infinite loop doesn't stop the rtos from running and the watchdog is kicked periodically for both ticker and thread.

After investigation, the reason comes from their respective priority:

  • the ticker is triggered by interrupt, thus is will always have the highest priority and preempt any already running tasks, even in a while(true){} loop
  • a thread is created with osPriorityNormal. If both the infinite loop thread and the watchdog thread have the same priority or if the watchdog thread has a higher priority, it will preempt the infinite loop and kick the watchdog. In this case, it's not possible to catch an infinite loop and reset the system if it happens.

The watchdog thread priority can be modified with set_priority (osPriority priority) once the thread is running and set to osPriorityLow. That way, all tasks have a higher priority than the watchdog. If one task gets stuck, the watchdog won't be kicked and the system will reset.

⚠️ It's important to note that this is true for blocking infinite loops, without wait() functions or with busy wait functions (HAL_Delay or wait_ns). If the infinite loop uses ThisThread::sleep_for(), the watchdog will be kicked and the system will stay stucked.

In this case, a reset command should be sent to the system through BLE.

🏅 for thread

LekaOS - Epics & Stories automation moved this from Backlog to Done Jan 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
01 - type: epic General discussion about a futur or current topic
Projects
No open projects
Development

No branches or pull requests

1 participant