Quality RTOS & Embedded Software

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


Loading

Handle common memory access using FreeRTOS

Posted by savindra on May 3, 2016

Hi,

I am having two task vATask and vBTask. vATask - it is handling Modbus TCP communication at every 5 ms vBTask- it is handling CAN communication with a device at every 10 ms

I want to access a common memory resources for both the task . I mean i want to receive data from CAN interface(CAN Rx interrupt for receiving data) and put in some CAN Rx buffers when the request come from Modbus TCP then i want to send the requested data from CAN Rx buffers.

When some request comes from Modbus TCP to write some data i want to write in CAN Tx buffers and send it to CAN interface.

I am worried about the data corruption because both task accesssing the same memory locations.I After reading FreeRTOS documentation i got to know about semaphore and mutex.

I am new to RTOS concepts . Can you please guide me what to use(semaphore or mutex) and how can i use in my application.

Regards, Savindra Kumar


Handle common memory access using FreeRTOS

Posted by rtel on May 3, 2016

The answer really depends on the type of the data.

If you are writing data from an interrupt, then reading it from a task, then you have one writer and one reader, which is the simplest case.

If you have one writer and one reader and the size of the data is the natural size of the architecture, then you don't need to use any protection at all. For example, if you are on a 32-bit MCU and the data is 32-bits, then the read will always be atomic (all 32-bits will be read at once) - so you have nothing to worry about.

If the data cannot be read atomically, then you do need to concern yourself with avoiding data corruption - for example if the data is a 64-bit type on a 32-bit architecture (so requiring two memory accesses), or if the data is a structure that has more than one member and all the members must be read atomically - then probably the easiest thing to do is perform the read from a critical section (so wrap the read with taskENTERCRITICAL() / taskEXITCRITICAL()).


[ 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.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

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.


Careers

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

Renesas

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