#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