Implementation of large arrays inter tasks

Hello, I’m quite new with rtos and I have a question because I’m facing a sensitive problem I’ve implemented a task that handle a SD Card. Other task can write read and perform several action on the sd card. My problem is how to safely transfer the data, since I’m limited in ram, I cannot make a queue that has all the required array. I’m based on the freertos UDP/IP example http://www.freertos.org/Pend-on-multiple-rtos-objects.html Passing a pointer to an array is not a problem, although how to safely do it is a big headache. I’ve made a structure with different pointers to the required arrays and also few flags to avoid double access but even in that case, some array may be accessed by two tasks at the same time. The point is that my SDCard task should not have large array but only access by pointers to arrays given by other tasks. What would be the best way to do that ? Thanks

Implementation of large arrays inter tasks

The simplest way would be to simply guard access to the SD card with a semaphore.  For example: void MyReadFunction()
{
    /* Wait to get the seamphore. */
    if( xSemaphoreTake() == pdPASS )
    {
        /* Got the semaphore, can access the card here. */
        ….         /* Must give the semaphore back so other tasks waiting to access the card can do so. */
        xSemaphoreGive();
    }
} and likewise for the Write function. Regards.

Implementation of large arrays inter tasks

I cannot access directly the SD cards from task due to memory limitation, that’s why i have a separated task to avoid having big depth of stack calls. The card is already protected against double access by semaphore. The problem I’m facing is not the sd card access but the handling of large array inter task without having to recopy the arrays (what queue does). So far the solution I consider  might be a queue with a pointer to a structure that contain a pointer to the array also as a mutex flag and checking this struct through critical code execution to check and set the mutex flag of the struct…

Implementation of large arrays inter tasks

The way to avoid copying large buffers is to pass the address of the buffer in the queue rather than the buffer itself. When the receiving task is done with it, it needs to return the buffer to where it came from so the originating task can use it again.