Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Implementation of large arrays inter tasks

Posted by Damien Etienne on September 11, 2013

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 ?


RE: Implementation of large arrays inter tasks

Posted by Richard on September 11, 2013
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. */

and likewise for the Write function.


RE: Implementation of large arrays inter tasks

Posted by Damien Etienne on September 11, 2013
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...

RE: Implementation of large arrays inter tasks

Posted by Richard Damon on September 12, 2013
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.

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers


STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner