]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/MSVC-MingW/port.c
In process of module testing event_groups.c.
[freertos] / FreeRTOS / Source / portable / MSVC-MingW / port.c
index bfd651373eb3717ec09f8fcc13a584ec5d99a0ef..39fc22664b052a33d1409176e12d79a595a05122 100644 (file)
@@ -148,6 +148,9 @@ static unsigned long (*ulIsrHandler[ portMAX_INTERRUPTS ])( void ) = { 0 };
 /* Pointer to the TCB of the currently executing task. */\r
 extern void *pxCurrentTCB;\r
 \r
+/* Used to ensure nothing is processed during the startup sequence. */\r
+static portBASE_TYPE xPortRunning = pdFALSE;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )\r
@@ -190,6 +193,8 @@ TIMECAPS xTimeCaps;
                        Sleep( portTICK_RATE_MS );\r
                }\r
 \r
+               configASSERT( xPortRunning );\r
+\r
                WaitForSingleObject( pvInterruptEventMutex, INFINITE );\r
 \r
                /* The timer has expired, generate the simulated tick event. */\r
@@ -197,7 +202,10 @@ TIMECAPS xTimeCaps;
 \r
                /* The interrupt is now pending - notify the simulated interrupt \r
                handler thread. */\r
-               SetEvent( pvInterruptEvent );\r
+               if( ulCriticalNesting == 0 )\r
+               {\r
+                       SetEvent( pvInterruptEvent );\r
+               }\r
 \r
                /* Give back the mutex so the simulated interrupt handler unblocks \r
                and can access the interrupt handler variables. */\r
@@ -312,7 +320,7 @@ xThreadState *pxThreadState;
                ulCriticalNesting = portNO_CRITICAL_NESTING;\r
 \r
                /* Bump up the priority of the thread that is going to run, in the\r
-               hope that this will asist in getting the Windows thread scheduler to\r
+               hope that this will assist in getting the Windows thread scheduler to\r
                behave as an embedded engineer might expect. */\r
                ResumeThread( pxThreadState->pvThread );\r
 \r
@@ -338,6 +346,7 @@ static unsigned long prvProcessTickInterrupt( void )
 unsigned long ulSwitchRequired;\r
 \r
        /* Process the tick itself. */\r
+       configASSERT( xPortRunning );\r
        ulSwitchRequired = ( unsigned long ) xTaskIncrementTick();\r
 \r
        return ulSwitchRequired;\r
@@ -356,6 +365,13 @@ void *pvObjectList[ 2 ];
        pvObjectList[ 0 ] = pvInterruptEventMutex;\r
        pvObjectList[ 1 ] = pvInterruptEvent;\r
 \r
+       /* Create a pending tick to ensure the first task is started as soon as\r
+       this thread pends. */\r
+       ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );\r
+       SetEvent( pvInterruptEvent );\r
+\r
+       xPortRunning = pdTRUE;\r
+\r
        for(;;)\r
        {\r
                WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE );\r
@@ -489,6 +505,8 @@ void vPortEndScheduler( void )
 \r
 void vPortGenerateSimulatedInterrupt( unsigned long ulInterruptNumber )\r
 {\r
+       configASSERT( xPortRunning );\r
+\r
        if( ( ulInterruptNumber < portMAX_INTERRUPTS ) && ( pvInterruptEventMutex != NULL ) )\r
        {\r
                /* Yield interrupts are processed even when critical nesting is non-zero. */\r
@@ -528,7 +546,7 @@ void vPortSetInterruptHandler( unsigned long ulInterruptNumber, unsigned long (*
 \r
 void vPortEnterCritical( void )\r
 {\r
-       if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )\r
+       if( xPortRunning == pdTRUE )\r
        {\r
                /* The interrupt event mutex is held for the entire critical section,\r
                effectively disabling (simulated) interrupts. */\r
@@ -561,6 +579,7 @@ long lMutexNeedsReleasing;
                        (simulated) disabled? */\r
                        if( ulPendingInterrupts != 0UL )\r
                        {\r
+                               configASSERT( xPortRunning );\r
                                SetEvent( pvInterruptEvent );\r
 \r
                                /* Mutex will be released now, so does not require releasing\r
@@ -577,9 +596,13 @@ long lMutexNeedsReleasing;
                }\r
        }\r
 \r
-       if( lMutexNeedsReleasing == pdTRUE )\r
+       if( pvInterruptEventMutex != NULL )\r
        {\r
-               ReleaseMutex( pvInterruptEventMutex );\r
+               if( lMutexNeedsReleasing == pdTRUE )\r
+               {\r
+                       configASSERT( xPortRunning );\r
+                       ReleaseMutex( pvInterruptEventMutex );\r
+               }\r
        }\r
 }\r
 /*-----------------------------------------------------------*/\r