From 09ce6e1ab439707922953cde34804d428c89b244 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Wed, 14 Mar 2012 17:37:50 -0500 Subject: [PATCH] Restore the original Revolution FreeRTOSConfig and make the osx simulation scheduler not start high priority tasks when they are created because I can't reliably get the starting task to stop (because currently in a swapping mutex I think). --- .../FreeRTOS/Source/portable/GCC/Posix/port.c | 33 +++++++++++++++---- flight/Revolution/System/inc/FreeRTOSConfig.h | 2 +- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/flight/PiOS.osx/osx/Libraries/FreeRTOS/Source/portable/GCC/Posix/port.c b/flight/PiOS.osx/osx/Libraries/FreeRTOS/Source/portable/GCC/Posix/port.c index b8e4cb91f..06be34407 100644 --- a/flight/PiOS.osx/osx/Libraries/FreeRTOS/Source/portable/GCC/Posix/port.c +++ b/flight/PiOS.osx/osx/Libraries/FreeRTOS/Source/portable/GCC/Posix/port.c @@ -399,6 +399,9 @@ xParams *pxThisThreadParams = pvPortMalloc( sizeof( xParams ) ); /* Wait until the task suspends. */ while ( xSentinel == 0 ); + + //printf( "Task suspended detected for %i\r\n", lIndexOfLastAddedTask); + vPortExitCritical(); return pxTopOfStack; @@ -415,6 +418,7 @@ void vPortStartFirstTask( void ) /* Start the first task. */ xInterruptsEnabled = pdTRUE; xRunning = 1; + unmaskSuspend(); resumeThread( xTaskGetCurrentTaskHandle() ); } @@ -820,13 +824,30 @@ void * pParams = pxParams->pvParams; pxThreads[lIndex].name = (char *) ((tskTCB *) hTask)->pcTaskName; xInterruptsEnabled = pdTRUE; - if(prvGetTaskHandle(pthread_self()) != xTaskGetCurrentTaskHandle()) { + if(1 || prvGetTaskHandle(pthread_self()) != xTaskGetCurrentTaskHandle()) { pauseSelf(); claimRunningSemaphore(7); unmaskSuspend(); } else { - //fprintf(stdout, "New thread wants to run right away %s\r\n", threadToName(pthread_self())); + fprintf(stdout, "New thread wants to run right away %s\r\n", threadToName(pthread_self())); + + assert(pthread_mutex_trylock( &xSwappingThreadMutex )!= EBUSY); + + // Find the previously running thread. xTaskGetCurrentHandle no longer reflects current state + + portLONG lIndex; + for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS && pxThreads[ lIndex ].hTask != hTask; lIndex++ ) + if(pxThreads[ lIndex ].status == RUNNING) + break; + + pthread_mutex_unlock( &xSwappingThreadMutex ); + + assert(pxThreads[ lIndex ].hTask != NULL); // Should find a thread that is running + + if( pxThreads[lIndex].hThread != pthread_self()) + assert(pauseOtherThread(pxThreads[ lIndex ].hTask) == 0); + prvSetThreadStatus(pthread_self(), RUNNING); claimRunningSemaphore(6); } @@ -1232,10 +1253,10 @@ void pauseSelf() xInterruptsEnabled = pdTRUE; prvSetThreadStatus( pthread_self(), RUNNING ); - //if (xResult == 0) - // fprintf(stdout, "Thread resumed from signal %s\r\n", threadToName( pthread_self() )); - //else - // fprintf(stdout, "Thread resumed from timeout %s\r\n", threadToName( pthread_self() )); +// if (xResult == 0) +// fprintf(stdout, "Thread resumed from signal %s\r\n", threadToName( pthread_self() )); +// else +// fprintf(stdout, "Thread resumed from timeout %s\r\n", threadToName( pthread_self() )); } diff --git a/flight/Revolution/System/inc/FreeRTOSConfig.h b/flight/Revolution/System/inc/FreeRTOSConfig.h index 8a9eda866..72d6e288a 100644 --- a/flight/Revolution/System/inc/FreeRTOSConfig.h +++ b/flight/Revolution/System/inc/FreeRTOSConfig.h @@ -43,7 +43,7 @@ #define configCHECK_FOR_STACK_OVERFLOW 2 #define configQUEUE_REGISTRY_SIZE 10 -#define configUSE_TIMERS 0 +#define configUSE_TIMERS 1 #define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1) /* run timers at max priority */ #define configTIMER_QUEUE_LENGTH 10 #define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE