Quality RTOS & Embedded Software

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


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