greiman / ChRt

ChibiOS/RT for Arduino AVR, SAMD, Due, Teensy 3.x, Teensy 4.0.
89 stars 27 forks source link

Works on Arduino Mega 2560 #1

Open ladislas opened 7 years ago

ladislas commented 7 years ago

Hi there!

First I want to thank you for this, it looks amazing and I'm really happy you decided to still work on this port of ChibiOS just for Arduino.

I've used vanilla ChibiOS but for simple things/project, it's a bit of an overkill. With ChRt I can get the best of both Arduino and ChibiOS.

I've been running all the examples on the Mega2560, changing a few things to see if everything breaks and for the moment I haven't found any bug.

On question I have though is about the chUnusedThreadStack(). I've tried putting a stack of zero but in the Blink example but I still get everything to work as intended. Is that normal?

greiman commented 7 years ago

On AVR space is added to your size for interrupt context and other structures.

I have also found that ChibiOS often appears to work OK when the stack overflows into other areas. Eventually you will either have a crash or corrupt other global memory.

I fill the allocated stack space with a 0x55 pattern at startup and check how much of the pattern remains when you call chUnusedThreadStack() You must have some unused stack.

ladislas commented 7 years ago

Would that mean that the space added for interrupt context and other structures is more than needed?

greiman commented 7 years ago

Would that mean that the space added for interrupt context and other structures is more than needed?

The examples allocate generous stack space since they run on various CPUs.

You must decide how much unused stack to allocate. You must never allow stack overflow.

The purpose of chUnusedThreadStack() is to check if the work-space size is appropriate.

Using an RTOS take experience beyond simple C/C++ programming. An RTOS is a complex tool. Here is a quote from the author of ChibiOS.

What an RTOS is

An RTOS is an operating system whose internal processes are guaranteed to be compliant with (hard or soft) realtime requirements. The fundamental qualities of an RTOS are:

  • Predictability. It is the quality of being predictable in the scheduling behavior.

  • Deterministic. It is the quality of being able to consistently produce the same results under the same conditions.

RTOS are often confused with “fast” operating systems. While efficiency is a positive attribute of an RTOS, efficiency alone does not qualifies an OS as RTOS but it could separate a good RTOS from a not so good one.

What an RTOS is not

An RTOS is not a magic wand, your system will not be “realtime” just because you are using an RTOS, what matters is your system design. The RTOS itself is just a toolbox that offers you the required tools for creating a realtime system, you can use the tools correctly or in the wrong way.