AnsweredAssumed Answered

What best way to pass large or unknown amounts  of data between tasks

Question asked by DaveTonyCook on Aug 20, 2016
Latest reply on Aug 23, 2016 by Daniel Chen



I have an application that requests data sets from a remote target via serial coms.  The data sets returned can be of any size from a few bytes to a Kbyte.  The receiving task reads in the data set one byte at a time storing the data in a 2k circular buffer. This process continues until the frame delimiter is reached. The circular buffer has wrap around detection. The read uses the MQX serial driver in interrupt mode Non-Blocking and returns 1 byte per call if there is one available.


My current solution.


The circular buffer is a 2K static array that has file scope.  I have provided a global accessor function that will return a pointer to this buffer and can be called from any task.  The buffer also has a semaphore to lock access whilst being written to or read from.


Once a requested data set has been received the receive task informs the control task that a data set frame has been received and is ready for unpacking and processing. The control task calls a function that pends on an event with a time out. When the receive task post this event the control task calls the accessor function to get a pointer to the circular buffer holding the received data.


This approach works well however being new to MQX I feel I might be missing a more elegant solution?

If using an MQX message queue which message queue would be the best to use to solve this problem?

Also, whats the best / most efficient way of dealing with unknown data set size, can you dynamically set the size of the message queue?


Thanks for your help