Can someone explain to me FreeRTOS and how it is used here?

I am trying to learn more about FreeRTOS and, more specifically, how it is implemented here. I see that the firmware and program updates can occur independently of the running application but what kinds of avenues does FreeRTOS open up for the users. Also, what is the difference between what is implemented in the Photon and what FreeRTOS distributes?
#curious

Caveat: Noob me. I don’t know if Particle’s base code uses FreeRTOS now.

FreeRTOS is one of many free and not-free Real Time Operating Systems. If you are unfamiliar with the concepts of multi-tasking, there are zillions of web pages and books to read.

FreeRTOS has two basic operating modes (chosen by you in config settings in the source code):

  1. Preemptive multitasking - here, there are 2+ tasks competing for CPU time that is administered by a scheduler. Some tasks go dormant waiting on things like an I/O complete interrupt event, waiting on a data message queue to become non-empty, waiting on a mutual exclusion semaphore to become free and the task takes ownership, and so on. To use this preemption mode, you must be learned in RTOS principles. One task preempting another has great flexibility but is very prone to deadlocks and programming errors that cause race conditions that can be infrequent.

  2. Cooperative multitasking. Here, the tasks cannot be preempted by another task’s event going true. Much simpler for the beginner. Similar to a no-RTOS program that uses multiple finite state machines (FSM). Sounds complex; is not. Often, FSMs will suffice and are really simple, and you need no 3rd party code.

Particle may have special compatibility issues with a preemptive RTOS due to the base code needing to get CPU time but was not written with an RTOS in mind.

FreeRTOS has some good pubs to read.

2 Likes

@ruben and @stevech, the Photon uses FreeRTOS as a requirement of the Broadcom wifi chip and the support code called WICED. A good example of co-operative multi-tasking code runs on the older Core. The Photon, however, does make use of the preemptive multitasking afforded by FreeRTOS. In the present configuration, one “thread” is used for WICED and another for the Photon system firmware, also shared with the user code. So, to parts of the system firmware and the user code, there appears to be cooperative multitasking, even though another thread is running WICED.

This will soon change to a true multi-thread environment with WICED, the system firmware and the user app each having their own threads. As @stevech pointed out, this changes the game but the Particle team are experts at this. What this will mean is that the user code will never block, unless of course it is written to!

It is important to note that FreeRTOS is not open to the user code at this time. It may be possible in the future to create user threads or make use of other FreeRTOS capabilities but not until everything has stabilized and matured IMO. :smile:

3 Likes

Hi @peekay123,
I don’t want to bug MDMA, since I think he must live on go pills now :grinning:. So do you know how far away the Photon is from running the wiced - wifi system and userapp in different threads?

1 Like

It looks like the v0.4.6 release now has separate system and user threads (docs here).