Help with tasks

dthif1980 wrote on Thursday, March 12, 2009:


I’m quite new to the FreeRTOS world and I’m trying to build a application using it.

Platform: AVR32 (using AVR32 Studio)
Framework: AT32UC3A-1.4.0
Language: GNUC++

At the moment, I’m just trying to make the tasks work. I double checked eveything with the Atmel EVK1100 ControlPanel application that uses FreeRTOS and everything seems fine, but I always end up having the same problem…

My application is quite simple. Here is a code sample:
Note that:
configCPU_CLOCK_HZ == CP_CPU_SPEED == 48000000
configPBA_CLOCK_HZ == CP_PBA_SPEED == 12000000

--------------------------------- Main.cpp File ----------------------------------------

// Main
// Main function. Starts the different tasks and wait forever.
int main(void)
    int                 bRet = FALSE;
    CBDR29010           obj;

    /* Primary Initialization.
    -------------------------- */
    // Switch the main clock to OSC0.
    pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

    // Initialize the delay driver.

    // Init Clocks.

    // Start the tasks.

    // Start the OS. It should never return from there.

    return 0;

--------------------------------- BDR29010.cpp File ----------------------------------------

// Constants
#define TASK_COMM_MANAGER_DELAY         10

// Prototypes
portTASK_FUNCTION_PROTO(CommManagerTask, pParams);

// CBDR29010::Activate
bool CBDR29010::Activate()
    bool        bRet            = false;
    int         taskCreateRet   = pdFAIL;
    xTaskHandle createdTaskHdl  = NULL;

    taskCreateRet = xTaskCreate(CommManagerTask, (const signed portCHAR*) "COMM_MGR",
                                TASK_COMM_MANAGER_STACK_SIZE, (void*)this,
                                TASK_COMM_MANAGER_PRIORITY, &createdTaskHdl);

    if(taskCreateRet == pdPASS)
        bRet = true;
        bRet = false;

    return bRet;

// TASK: ManagerCommTask
portTASK_FUNCTION_PROTO(CommManagerTask, pParams)
        int allo = 1;

    } while (1);

I trace the execution of the task. It enters correctly, calls the vTaskDelay(…) function but never returns from there. If I pause the execution, I get this
"No source available for "_handle_Supervisor_Call() " "

Checking the stack, it looks like it hangs just after the "portEXIT_CRITICAL();" call of the xTaskResumeAll() function in task.c.

Here is a copy of my FreeRTOSConfig.h file:

#define configUSE_MUTEXES         1
#define configUSE_PREEMPTION      1
#define configUSE_IDLE_HOOK       0
#define configUSE_TICK_HOOK       0
#define configCPU_CLOCK_HZ        ( CP_CPU_SPEED ) /* Hz clk gen */
#define configPBA_CLOCK_HZ        ( CP_PBA_SPEED )
#define configTICK_RATE_HZ        ( ( portTickType ) 1000 )
#define configMAX_PRIORITIES      ( ( unsigned portBASE_TYPE ) 8 )
#define configMINIMAL_STACK_SIZE  ( ( unsigned portSHORT ) 256 )
/* configTOTAL_HEAP_SIZE is not used when heap_3.c is used. */
#define configTOTAL_HEAP_SIZE     ( ( size_t ) ( 1024*25 ) )
#define configMAX_TASK_NAME_LEN   ( 20 )
#define configUSE_TRACE_FACILITY  0
#define configUSE_16_BIT_TICKS    0
#define configIDLE_SHOULD_YIELD   1

#define configUSE_CO_ROUTINES     0
#define configMAX_CO_ROUTINE_PRIORITIES ( 0 )

#define INCLUDE_vTaskPrioritySet            1
#define INCLUDE_uxTaskPriorityGet           1
#define INCLUDE_vTaskDelete                 1
#define INCLUDE_vTaskCleanUpResources       0
#define INCLUDE_vTaskSuspend                1
#define INCLUDE_vTaskDelayUntil             1
#define INCLUDE_vTaskDelay                  1
#define INCLUDE_xTaskGetCurrentTaskHandle   1
#define INCLUDE_xTaskGetSchedulerState      0

#define configTICK_USE_TC             0
#define configTICK_TC_CHANNEL         2

#define configHEAP_INIT               1

I have no idea if those settings are ok, but I presume they are since I based myself on a working application of the Atmel framework. But I suspect that I am missing some configuration to make this work…

Please, if you have any insight or suggestions, let me know.
Best regards,

davedoors wrote on Friday, March 13, 2009:

Can you confirm that the tick interrupt is working? If the tick is not incrementing time then your block time will never time out after calling vTaskDelay() and the task will remain blocked.

dthif1980 wrote on Friday, March 13, 2009:

I’m not sure where to look to confirm this… I’ll search, but in the meantime, if you have any indications, please let me know.

Thanks again,

dthif1980 wrote on Friday, March 13, 2009:

I traced in VTaskDelay() and xTickCount is 0… which I presume is the problem… I will try to find why, but again, any advice is welcome in the meantime.

Best regards.

dthif1980 wrote on Friday, March 13, 2009:

ok, sorry, my vTickCount is incrementing… I traced in the "vTaskIncrementTick" function and the ticks are coming.

For some reason, my task that called vTaskDelay() looks to be never awoken…

edwards3 wrote on Friday, March 13, 2009:

Look at prvSetupTimerInterrupt() in port.c.  This is where the tick interrupt is configured.

dthif1980 wrote on Friday, March 13, 2009:

looks like my last post didn’t proceed… I wrote that I was wrong. The xTickCount is indeed incrementing… I traced in the vTaskIncrementTick function.

Looks like my task is never awoken…

dthif1980 wrote on Friday, March 13, 2009:

I found that it is a call to taskYIELD() that provokes the hanging… In the vTaskDelay function :

xAlreadyYielded = xTaskResumeAll();

returns false which provoke this:

/* Force a reschedule if xTaskResumeAll has not already done so, we may
have put ourselves to sleep. */
if( !xAlreadyYielded )

When called, those are the current values of the different variables:
xTicksToDelay = 10
xTickCount = 0
xTimeToWake = 10

I’m continuing my search… please feel free to give me advices, that will be much appreciated!

Best regards,

dthif1980 wrote on Friday, March 13, 2009:

Problem solved!

Actually, it was a stupid problem (as I though).

In the AVR32 framework, there is a driver called INTC that has a "exception.x" file. So, in the project settings, I must exclude this file in order to use the "exception.x" file from FreeRTOS. I have examples in the AVR32 framework that work.

My error was to inconsciously exclude the "exception.x" file of FreeRTOS instead…
Anyway, I hope this thread can help someone in the future!

Thanks to all,