Using FreeRTOS Ring Buffers

Hi ,

I am trying to implement an Fault storage and retrieval application

  1. When the new fault occurs , I wanna be able to store the fault (This fault will be reported to fault monitoring task by any other task running in the system)
  2. I should be able to delete the fault when the fault no longer exists
  3. I should be able to add new faults to the list and check if the new fault already exists in the fault table .

I would like to know if I can use the FreeRTOs ring buffer for this sought of application ?


As you said you want to have a table (or list) with random access to each element and the ability to erase elements. Hence a ring buffer is by design not applicable. It’s a FIFO you can push into one end and pop from the other.
Seems you have to create your own data structure (e.g. a doubly linked list) or use e.g. std::deque - in case you’re using C++ maybe protected by a mutex when accessed by multiple tasks.

What exactly do you mean by “a fault?” something that causes a processor exception and thus must by handled in a fault ISR?

Nope . Its just the application level system faults . Its mostly an enum like Over speed or under speed .

I am actually using C . And if I create my own linked list , can I use malloc or should I be using pvPortMalloc?

You should use pvPortMalloc to ensure thread safety. If you want pvPortMalloc to use malloc supplied by the runtime, use heap_3. More details here - FreeRTOS - Memory management options for the FreeRTOS small footprint, professional grade, real time kernel (scheduler)

1 Like