FreeRTOS / FreeRTOS-Kernel

FreeRTOS kernel files only, submoduled into https://github.com/FreeRTOS/FreeRTOS and various other repos.
https://www.FreeRTOS.org
MIT License
2.51k stars 1.05k forks source link

[Feature Request] Queue Sets with ability to add the same object to several Sets #1053

Open Vitaly1983 opened 1 month ago

Vitaly1983 commented 1 month ago

It would be useful for future versions of FreeRTOS to support Queue Sets in a way that would allow adding the same object (Queue or Semaphore) to more than one QueueSet. Currently this is impossible. I recently worked on a project where this feature would allow me to reduce number of necessary threads by one, because with this possibility, I would have been able to implement communication stuff for serial interface, receive and send functions, in only one thread, but without it, I ended up with two – separate threads for RX and TX.

Pseudo code for what I would like to have in the source code:

Thread COMM_THREAD
.......
do
{
  EVENT1 = WAIT_FOR_EVENT_FROM_SET(RX_MSG_READY, TX_MSG_READY);
  IF (EVENT1 was from TX_MSG_READY)
  {
    INITIATE_TRANSFER_VIA_DMA();
    do
    {
      EVENT2 = WAIT_FOR_EVENT_FROM_SET(RX_MSG_READY, TX_DMA_COMPLETE_SEMAPHORE);
      IF (EVENT2 was from RX_MSG_READY)
      {
        PROCESS_RX_MSG();
      };
    } while (EVENT2 was not from TX_DMA_COMPLETE_SEMAPHORE);
  } else IF (EVENT1 was from RX_MSG_READY)
  {
    PROCESS_RX_MSG();
  }
} while (1);

The first and second polling should poll for two different objects, see WAIT_FOR_EVENT_FROM_SET, but one object should be common in both function calls -- that is RX_MSG_READY (Queue or Semaphore). I was unable to reformulate this algorithm in terms of single thread, without possibility to add the same synchronization object (RX_MSG_READY in the pseudocode above), to two QueueSets, and was forced to write a separate thread function for processing of messages from TX_MSG_READY object (be it Queue or Semaphore).