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

Multi Task and Functions...problem?

Posted by Michael on November 16, 2008
Hello!

I have a little problem with functions which wokrs in more than one task.
Example :

If I use only this task it works perfectly.
void xTaskOne(void* param)
{
for(;;)
{

rprintf("Send text to uart 1 \n ");

}


}
but If is another task...
void xTaskTwo(void* param)
{
for(;;)
{

rprintf("Send text to uart 2 \n ");

}


}
Functions rprintf works strange but I know why ( that because scheduler works... ) and I want to block Task by Semaphores/Mutex
void xTask(void* param)
{
for(;;)
{
if(xSemaphoreTake(xSemaphore,150 )==pdPASS)
rprintf("Send text to uart \n ");
xSemaphoreGive(xSemaphore )
}


}
but this don't work... System freezing. What should I do to make use functions in many Task???

I'm sorry for my english...

RE: Multi Task and Functions...problem?

Posted by Artur on November 17, 2008
Who "give" semaphore before you try to "take" it?

In your case you try manage access to the resource and it can be convenient to create separate "driver" to do that. This can allow you to use (in tasks) simple driver function to e.g. print something without worrying about mechanism used to synchronize access to resource.

Regards,

RE: Multi Task and Functions...problem?

Posted by Nick Reed on November 17, 2008
Mayby try only giving the semaphore back if you could take it first:

if(xSemaphoreTake(xSemaphore,150 )==pdPASS)
{
rprintf("Send text to uart \n ");
xSemaphoreGive(xSemaphore );
}

-----
Nick

RE: Multi Task and Functions...problem?

Posted by Richard on November 17, 2008
If your rprintf() function does all the buffering you need then one simple solution is to use a critical section. Each time you want to printf wrap the call to rprintf() in taskENTER_CRITICAL()/taskEXIT_CRITICAL().


taskENTER_CRITICAL();
rprintf( "Send the message here\n" );
taskEXIT_CRITICAL();

You could wrap this up in a function to prevent you having to write it out in full each time you print.

Critical sections are not a good solution where they would adversely effect the responsiveness of your system though.

Another solution is to write the driver so that you queue messages yourself. If you want to write out a string you queue a pointer to the string. The driver just reads out the strings from the queue in turn. The driver (which could be an interrupt or a task) is then the only thing that is allowed to access the UART directly so serialisation and mutual exclusion are guaranteed.

Regards.


[ 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