Quality RTOS & Embedded Software

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


Loading

Tasks are blocking on xSemaphoreTake

Posted by Roland Rabien on February 25, 2013
Hi,

I'm new to FreeRTOS and I'm trying to get what I think is a fairly simple project going, and I'm having problems with tasks blocking indefinitely on xSemaphoreTake. I'm using a Atmel Sam3u4e with Atmel Studio 6 SP2 and FreeRTOS 7.3.0 that ships with the Atmel Software Framework 3.5.1.

I have reduced my program to the minimal parts to reproduce the problem. I have two tasks, loggertask and systask. loggertask is woken by one of three data ready interrupts, and then uses spi to read from either a accelerometer, gyro or magnetometer. systask does nothing but wait on a semaphore that is never given.

I create loggertask from systask like this:


#define LOGGERTASK_STACK_SIZE((4 * 1024)/sizeof(portSTACK_TYPE))
#define LOGGERTASK_PRIORITY(tskIDLE_PRIORITY + 2)

vSemaphoreCreateBinary(loggertask->sync);
if (xTaskCreate(loggertask_entry_point, name, LOGGERTASK_STACK_SIZE, loggertask, LOGGERTASK_PRIORITY, &loggertask->task) == pdPASS)
return loggertask;


The main loop looks like this:

static void loggertask_entry_point(void* pvParameters)
{
LoggerTask* loggertask = (LoggerTask*)pvParameters;

xSemaphoreTake(loggertask->sync, 0);
while (true)
{
if (xSemaphoreTake(loggertask->sync, 100) == pdTRUE)
{
if (loggertask->magReady)
loggertask_read_mag(loggertask);

if (loggertask->accelReady || ioport_get_pin_level(PIN_MEMS_INT_ACCEL) == IOPORT_PIN_LEVEL_HIGH)
loggertask_read_accel(loggertask);

if (loggertask->gyroReady || ioport_get_pin_level(PIN_MEMS_INT_ACCEL) == IOPORT_PIN_LEVEL_HIGH)
loggertask_read_gyro(loggertask);

if (!loggertask->record)
{
loggertask_uninit(loggertask);
vTaskDelete(NULL);
}
}
}
}


And my interrupts look like:

void loggertask_accel_int(uint32_t a, uint32_t b)
{
g_loggertask->accelReady = true;
loggertask_wake(g_loggertask, true);
}

void loggertask_gyro_int(uint32_t a, uint32_t b)
{
g_loggertask->gyroReady = true;
loggertask_wake(g_loggertask, true);
}

void loggertask_mag_int(uint32_t a, uint32_t b)
{
g_loggertask->magReady = true;
loggertask_wake(g_loggertask, true);
}

void loggertask_wake(LoggerTask* loggertask, bool fromISR)
{
if (fromISR)
{
portBASE_TYPE taskWoken = pdFALSE;
xSemaphoreGiveFromISR(loggertask->sync, &taskWoken);
portEND_SWITCHING_ISR(taskWoken);
}
else
{
xSemaphoreGive(loggertask->sync);
}
}


As for my systask, it is very simple, I create it like this:

#define SYSTASK_STACK_SIZE((4 * 1024)/sizeof(portSTACK_TYPE))
#define SYSTASK_PRIORITY(tskIDLE_PRIORITY + 2)

if (xTaskCreate(systask_entry_point, name, SYSTASK_STACK_SIZE, systask, SYSTASK_PRIORITY, NULL) == pdPASS)
return systask;


And it's loop looks like this:

static void systask_entry_point(void* pvParameters)
{
SysTask* systask = (SysTask*)pvParameters;

vSemaphoreCreateBinary(systask->sync);

systask_init_peripherals(systask);

while (true)
{
xSemaphoreTake(systask->sync, 250);

systask_service_logger(systask);
systask_power_monitor();
}
}


The systask_service_logger function creates the loggertask 1 second after the system starts and does nothing else. Future plans are for the systask will take data from the loggertask and write it to an sdcard.

After approximation 10 minutes of runtime, the loggertask hangs on xSemaphoreTake(). The interrupts are still firing, but the call to xSemaphoreGiveFromISR() fails with a errQUEUE_FULL. systask is still running. No breakpoints I set in loggertask ever get hit. FreeRTOS Viewer lists the logger task as Ready with a top of stack 0x2007eea0 and start of stack 0x2007df38. IDLE is running and sys and Tmr Svc are blocked. Removing the calls to read the accelerometer, gyro, magnetometer does not solve the problem, so I loggertask must be getting stuck in xSemaphoreTake().

Is there any way to force a context switch to loggertask so I can examine it's callstack? Where do I look to see if loggertask->sync is corrupted.

My program is very simple, so I must be doing something fairly basic incorrectly. Can anybody see what it is?

Thanks,
Roland

RE: Tasks are blocking on xSemaphoreTake

Posted by Roland Rabien on February 26, 2013
And it turns out I should read the FAQ more carefully. There is a whole document on interrupt priorities. Anyway, I wasted a lot of time, but at least I'm moving forward again.

RE: Tasks are blocking on xSemaphoreTake

Posted by Richard on February 26, 2013
Self solving support requests are the best kind ;o)

Regards.


[ 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