verretj wrote on Wednesday, November 19, 2008:
Hello,
I have ported FreeRTOS on LPC2212 and now I am currently testing the mutex functionnality of FreeRTOS.
So I simply created two tasks and a mutex. Each Task writes either 1 or 2 in a common buffer which is the shared resource guarded by the mutex. When I try to run it I get a data abort error, does anyone have an idea about this ?
I have checked that the creation of both task and of the mutex goes well and that heap and stack is sufficient (I do not return from vTaskStartScheduler and highwatermarks are different from zero)
I have also checked configuration
#define configQUEUE_REGISTRY_SIZE 5
#define configUSE_MUTEXES 1
The problem is related to the mutex since without it I have got no problems.
But I cannot see what I have done wrong.
void Task1 (void * pvParameters)
{
int ret;
unsigned portBASE_TYPE uxHighWaterMark1;
/* Inspect our own high water mark on entering the task. */
uxHighWaterMark1 = uxTaskGetStackHighWaterMark( NULL );
for( ;; )
{
/*attendre mutex et le prendre dès qu’il est disponible*/
ret = xSemaphoreTake( mutex, portMAX_DELAY );
if (ret == pdFALSE)
{
return;
}
/*ecrire 1 dans le buffer*/
/*buffer non plein*/
if ( i < SIZE_BUF-1 )
{
buf[i] = 1;
i++;
buf[i] = 1;
i++;
}
else
{
i = 0;
}
/* Inspect our own high water mark on entering the task. */
uxHighWaterMark1 = uxTaskGetStackHighWaterMark( NULL );
/*liberer mutex*/
ret = xSemaphoreGive( mutex );
if (ret == pdFALSE)
{
/*Erreur lors de la liberation du mutex*/
return;
}
}
}
…
int main(int argc, char *argv[])
{
int ret = -1;
unsigned int Value =0;
xTaskHandle xHandle1;
xTaskHandle xHandle2;
/* Configure la PLL */
PLL_Config();
/*initialisation buffer et mutex */
i = 0;
/*Creation du semaphore*/
mutex = xSemaphoreCreateMutex ();
if( mutex == NULL )
{
/*Erreur lors de la creation du mutex*/
return -1;
}
/*cree les taches */
ret = xTaskCreate( Task1, "TASK1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 1, &xHandle1 );
if(ret!= pdPASS)
{
return -1;
}
ret = -1;
ret = xTaskCreate( Task2, "TASK2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 2, &xHandle2 );
if(ret!= pdPASS)
{
return -1;
}
/*demarre le scheduler*/
vTaskStartScheduler();
return 0;
}