Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Best way to access ressource between task

Posted by ogh on June 11, 2015


I'm asking myself which is the best way to access to a shared resource between task, for example: I've a file containing raw data and two task that should access to this resources: -) The first task is getting data from serial port one and should write data to the file. -) The second task should read data from this file and send these to another serial port (based on external request). The first solution is to use a Mutex on this file. The other solution I'm thinking is to create a third task managing access to this file and receiving request (and data) from other other task and sending data to other task through Queue. Which is the best solution?

Thanks for your help

Best way to access ressource between task

Posted by heinbali01 on June 11, 2015

It depends on how complex the actions will be. Are you using real files in a FAT (or other) file-system? In that case a third task could open the file in update mode ("w+") and provide read- and write-services. That task can indeed open a QueueHandle_t and receive commands.

Note that a QueueHandle_t is not ideal for hi-volume data exchange. It is useful for small messages, for instance a token (enum), a pointer to data, or a pointer to a (command) structure.

If the "file" is not really a file but just shared memory, a simpler mutex of binary semaphore will be sufficient and a lot cheaper.


Best way to access ressource between task

Posted by ogh on June 12, 2015

Thanks for your answer. You 're right I'm using a FAT system (FatsFS and STM32Cube lib) on a SD card. Data that tasks should pass through Queue will not exceed 10 bytes.

Best way to access ressource between task

Posted by heinbali01 on June 12, 2015

I'm using a FAT system (FatsFS and STM32Cube lib)

I'm not sure how FatFS (by ChaN) will behave if you open the same file two times: once in read- and once in write-mode.

FreeRTOS' own +FAT library has decided to either allow to open a file by:

  • a single task using "w" or "w+" mode
  • multiples tasks all using "r" mode

In other words: there may be many readers but just one writer.

Writing data to a file is often the realisation of a transaction. It may be a payment, a reservation, a commitment. Now if you think of it as transactions, it becomes more meaningful to introduce a third party (task) who can do the transactions. This task will handle one transaction at a time without getting interrupted, you make that sure by design.

One product I make has four FM tuners. It is very easy to send some SPI data to a tuner and change the frequency. I have several tasks which must interact with the tuners somehow, in read- and/or write-more. Doing that directly gave problems at some point, and so I also introduced a separate

void vTunerTask( void *pvParameters )

which handles request for all four FM tuners, and that works well.


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

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists