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

Problem with Semaphores

Posted by Prince Chauhan on November 20, 2012
I am Using the STM32VL_DISCOVERY board with ATOLLIC TRUE STUDIO. I was trying to using the SEMAPHORE feature of FREERTOS. But i am facing a problem that the task with highest priority gets exicuted bt other task does not.
i tried many ways bt problem is same, even i tried the tasks with same priorities, in tht the TASK1 is exicuted. Whem i saw the debugger thn i got tht it went to a infinite loop somewhere. I am a beginner with RTOS, can any one help me.


...........
static xSemaphoreHandle XSemaphore;
................
int main(void)
{
vSemaphoreCreateBinary( XSemaphore);

if(XSemaphore != NULL)
{
prvSetupHardware();

xTaskCreate( prvTask1, ( signed char * ) "Task1", 100, NULL, 2, NULL );
xTaskCreate( prvTask2, ( signed char * ) "Task2", 100, NULL, 1, NULL );


vTaskStartScheduler();
}


for( ;; );
}

static void prvTask1( void *pvParameters )
{
int i;

for(;;)
{
xSemaphoreTake( XSemaphore, portMAX_DELAY );

STM32vldiscovery_LEDOn( LED3 );

for(i=0;i<100000;i++)
{

}

xSemaphoreGive( XSemaphore);

}
}


static void prvTask2( void *pvParameters )
{
int j;

for(;;)
{
xSemaphoreTake( XSemaphore, portMAX_DELAY );


STM32vldiscovery_LEDOff( LED3);

for(j=0;j<100000;j++)
{

}
xSemaphoreGive(XSemaphore);
}



}

static void prvSetupHardware( void )
{

/* Set up the LED outputs and the button inputs. */
STM32vldiscovery_LEDInit( LED3 );
STM32vldiscovery_LEDInit( LED4 );
/* Start with the LEDs off. */
STM32vldiscovery_LEDOff( LED3 );
STM32vldiscovery_LEDOff( LED4 );
}

void vApplicationMallocFailedHook( void )
{
for( ;; );
}

void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
{
( void ) pcTaskName;
( void ) pxTask;


for( ;; );
}

RE: Problem with Semaphores

Posted by Prince Chauhan on November 20, 2012
i just included the #define INCLUDE_vTaskSuspend 1
bt thr problem is same... still the task of higher priority is exicuted. bt the problem of infinite loop is not now.

RE: Problem with Semaphores

Posted by Dave on November 20, 2012
The code you have posted will execute like this:

1) The higher priority task will take the semaphore.
2) The higher priority task will run its null loop.
3) The higher priority task will give the semaphore back.
4) The higher priority task will go back to step 1 and repeat indefinitely.

The lower priority task does not even run as far as blocking on the semaphore because the higher priority task never blocks.


RE: Problem with Semaphores

Posted by Prince Chauhan on November 21, 2012
Thaks for ur response,
now i tried it with xSemaphoreTake( XSemaphore, portMAX_DELAY ); out of the loop,, bt it is behaviing in the same way,, now what to do,,

RE: Problem with Semaphores

Posted by Prince Chauhan on November 21, 2012
well, i soved the problem, nd now its working properly,,
Thanks for ur help...


[ 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