Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Does FreeRTOS have built-in support for queues that can hold variable sized elements?

Does FreeRTOS have built-in support for queues that can hold variable sized elements?

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshardwaredebugginghelpquestion
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arnold_w
    wrote on last edited by
    #1

    I need to debug some code executing on top of FreeRTOS that runs on an embedded ARM processor and I have no knowledge of FreeRTOS and I was hoping someone here could please help me. Image there are two threads in the entire code, one high-priority communication bus driver and one low-priority application thread. Whenever the application wants to write, it queues a struct onto a queue and when the communication driver sees that there is a struct in the queue, it pulls the struct out and starts writing over the communication bus according to the instructions in the struct. Now, let's assume the application first wants to write 1 byte and then shortly thereafter wants to write 2 bytes and the bytes to write are located on the stack and NOT in static variables/arrays. What the recommended way to handle this? Clearly the 2nd struct would be 1 byte larger than the 1st struct, but they both need to go into the same queue.

    L L 2 Replies Last reply
    0
    • A arnold_w

      I need to debug some code executing on top of FreeRTOS that runs on an embedded ARM processor and I have no knowledge of FreeRTOS and I was hoping someone here could please help me. Image there are two threads in the entire code, one high-priority communication bus driver and one low-priority application thread. Whenever the application wants to write, it queues a struct onto a queue and when the communication driver sees that there is a struct in the queue, it pulls the struct out and starts writing over the communication bus according to the instructions in the struct. Now, let's assume the application first wants to write 1 byte and then shortly thereafter wants to write 2 bytes and the bytes to write are located on the stack and NOT in static variables/arrays. What the recommended way to handle this? Clearly the 2nd struct would be 1 byte larger than the 1st struct, but they both need to go into the same queue.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I have had a similar issue in the past, and created a struct like this:

      struct sq
      {
      int nbytes;
      // any other items
      byte queueItems[1];
      }

      When a struct is required it is a simple matter to allocate it dynamically from the struct size plus the number of bytes to be added to the queueItems array. The nbytes item can then be filled in with the number of bytes in the array to be handled elsewhere.

      1 Reply Last reply
      0
      • A arnold_w

        I need to debug some code executing on top of FreeRTOS that runs on an embedded ARM processor and I have no knowledge of FreeRTOS and I was hoping someone here could please help me. Image there are two threads in the entire code, one high-priority communication bus driver and one low-priority application thread. Whenever the application wants to write, it queues a struct onto a queue and when the communication driver sees that there is a struct in the queue, it pulls the struct out and starts writing over the communication bus according to the instructions in the struct. Now, let's assume the application first wants to write 1 byte and then shortly thereafter wants to write 2 bytes and the bytes to write are located on the stack and NOT in static variables/arrays. What the recommended way to handle this? Clearly the 2nd struct would be 1 byte larger than the 1st struct, but they both need to go into the same queue.

        L Offline
        L Offline
        leon de boer
        wrote on last edited by
        #3

        Generally you would have a circular queue of pointers to struct on the transmission queue. You don't want to be copying data around when you don't have to and it means the transmission queue is always just a pointer that the transmission sender can check what the pointer points to. In your struct you could have for example a field which would be "size to send" and then the data. You either free the struct after sending if dynamic, or clear a flag in the struct to mark it free for reuse if using static structs. As you are feeding two threads into one queue you will also need to put a binary semaphore on queue access.

        In vino veritas

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups