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




Loading

FreeRTOS Passing Varibles (Arduino Uno)

Posted by jaxxs1 on May 2, 2017

Hello Being new to FreeRTOS i'm struggling to work out how to pass char arrays from one task to another? Before using FreeRTOS I would simply create functions and pass data received from the serial port. Once a start and stop bit was received I would then pass the data to a function to do some work. I now have a task purely looking at the serial port in-coming data and once a command has been received I then need to pass it to another task to process the char array and perform a task. I'm not able to work out how to pass the receive data array to the process data array task?

struct config_t{
        char *atf;   //incoming data command stored here
}config;

void TaskReadSerial( void *pvParameters ); void TaskProcessData( void *pvParameters );

How do I pass char *atf data received in TaskReadSerial to TaskProcessData?

So I'm using atmel studio and the arduino framework for a 328P AVR

Any help will be greatly appreciated

Many thanks, Mark


FreeRTOS Passing Varibles (Arduino Uno)

Posted by rtel on May 2, 2017
     char *atf;   //incoming data command stored here

I presume you know this already, but in case not, this is not allocating space to store data, merely allocating a pointer that can point to data.

There are many ways you could pass received data to another task. The best method will depend on how many bytes are being passed.

If there are relatively few bytes, say less than 5, and if data is arriving slowly, then you could copy the bytes into a queue http://www.freertos.org/Inter-Task-Communication.html. Each demo project in the FreeRTOS download demonstrates how to do this, and the FreeRTOS book will also walk you through it http://www.freertos.org/Documentation/RTOS_book.html. Each space in the queue will need to be large enough to hold the maximum number of bytes the message can contain though, hence this is only suitable for small amounts of data. The benefit of doing it that way is each task has its only copy of the data, so you don't need to worry about one task corrupting data that is being used by another task.

Another way is to have more than one buffer and just pass a pointer to the buffer between tasks on a queue. For example, when buffer A contains a message pass the address of A on a queue to the other task, then start using buffer B. Once buffer B contains a full message pass the address of B to the other task. If the other task has finished with buffer A it can be used to hold the next message again, etc. This scheme has the advantage that the queue only needs to hold pointers, not the actual data, so the queue storage area is smaller. It is harder to implement though as you need to make sure that only one task is using any given buffer at any given time.

There are many other ways too. For example, just write the data into a circular buffer, and use a task notification, event group, counting semaphore, etc. to unblock the task that reads from the buffer each time a complete message has been received.


FreeRTOS Passing Varibles (Arduino Uno)

Posted by jaxxs1 on May 3, 2017

Thank you for your response. I'm very new to micro development having to rely on arduino forums to get examples on how to do things (something I need to work on and get better at). I will see if I can work through some examples and get what I need working.

Thanks, Mark


FreeRTOS Passing Varibles (Arduino Uno)

Posted by richard_damon on May 5, 2017

One quick comment is the "Arduiino" way of doing things is very different from the RTOS way of doing thngs. The first very big question is why do you think you need a seperate task to read the data from the serial port and to process it? Presumably, the serial port is interrrupt driven (if not, that is your first thing to do). If the serial port is really just a serial port at a reasonable speed, the simplest way to get the data from the serial port to a task is a character base queue (thiis would be inefficent if it was very high speed and/or very large messages, but for typical serial protocals it isn't that bad).

If you have multiple serial ports (or other similar streams) coming in that can possible send command to the "ProcessData" operation, then it would make sense to have a FUNCTION (not a task) that you call with the character array, and it processes it. ProcessData may need some mutual excusion within it depending on what it does.

Generally, I have one task (and only one task) for each thing I need to be waiting for that kicks off a specific set of operations.


[ 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