]> git.sur5r.net Git - freertos/commitdiff
Increase the priority of the Windows threads used by the FreeRTOS Windows port, and...
authorrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 4 Jan 2017 04:48:22 +0000 (04:48 +0000)
committerrtel <rtel@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Wed, 4 Jan 2017 04:48:22 +0000 (04:48 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2475 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/portable/MSVC-MingW/port.c
FreeRTOS/Source/portable/MSVC-MingW/portmacro.h

index 8189fb0dd1c226d39679ad21c6296af1c1c9380d..2c3e69dd45cfa272a7acb1add7f0bf20270e52e9 100644 (file)
 #define portMAX_INTERRUPTS                             ( ( uint32_t ) sizeof( uint32_t ) * 8UL ) /* The number of bits in an uint32_t. */\r
 #define portNO_CRITICAL_NESTING                ( ( uint32_t ) 0 )\r
 \r
-/* The priorities at which the various components of the simulation execute.\r
-Priorities are higher when a soak test is performed to lessen the effect of\r
-Windows interfering with the timing. */\r
-#define portSOAK_TEST\r
-#ifndef portSOAK_TEST\r
-       #define portDELETE_SELF_THREAD_PRIORITY                  THREAD_PRIORITY_HIGHEST /* Must be highest. */\r
-       #define portSIMULATED_INTERRUPTS_THREAD_PRIORITY THREAD_PRIORITY_NORMAL\r
-       #define portSIMULATED_TIMER_THREAD_PRIORITY              THREAD_PRIORITY_BELOW_NORMAL\r
-       #define portTASK_THREAD_PRIORITY                                 THREAD_PRIORITY_IDLE\r
-#else\r
-       #define portDELETE_SELF_THREAD_PRIORITY                  THREAD_PRIORITY_TIME_CRITICAL /* Must be highest. */\r
-       #define portSIMULATED_INTERRUPTS_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST\r
-       #define portSIMULATED_TIMER_THREAD_PRIORITY              THREAD_PRIORITY_ABOVE_NORMAL\r
-       #define portTASK_THREAD_PRIORITY                                 THREAD_PRIORITY_NORMAL\r
-#endif\r
+/* The priorities at which the various components of the simulation execute. */\r
+#define portDELETE_SELF_THREAD_PRIORITY                         THREAD_PRIORITY_TIME_CRITICAL /* Must be highest. */\r
+#define portSIMULATED_INTERRUPTS_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL\r
+#define portSIMULATED_TIMER_THREAD_PRIORITY             THREAD_PRIORITY_HIGHEST\r
+#define portTASK_THREAD_PRIORITY                                THREAD_PRIORITY_ABOVE_NORMAL\r
+\r
 /*\r
  * Created as a high priority thread, this function uses a timer to simulate\r
  * a tick interrupt being generated on an embedded target.  In this Windows\r
@@ -264,16 +255,6 @@ xThreadState *pxThreadState = NULL;
 int8_t *pcTopOfStack = ( int8_t * ) pxTopOfStack;\r
 const SIZE_T xStackSize = 1024; /* Set the size to a small number which will get rounded up to the minimum possible. */\r
 \r
-       #ifdef portSOAK_TEST\r
-       {\r
-               /* Ensure highest priority class is inherited. */\r
-               if( !SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ) )\r
-               {\r
-                       printf( "SetPriorityClass() failed\r\n" );\r
-               }\r
-       }\r
-       #endif\r
-\r
        /* In this simulated case a stack is not initialised, but instead a thread\r
        is created that will execute the task being created.  The thread handles\r
        the context switching itself.  The xThreadState object is placed onto\r
@@ -295,31 +276,53 @@ const SIZE_T xStackSize = 1024; /* Set the size to a small number which will get
 \r
 BaseType_t xPortStartScheduler( void )\r
 {\r
-void *pvHandle;\r
-int32_t lSuccess = pdPASS;\r
-xThreadState *pxThreadState;\r
-\r
-       /* Install the interrupt handlers used by the scheduler itself. */\r
-       vPortSetInterruptHandler( portINTERRUPT_YIELD, prvProcessYieldInterrupt );\r
-       vPortSetInterruptHandler( portINTERRUPT_TICK, prvProcessTickInterrupt );\r
-\r
-       /* Create the events and mutexes that are used to synchronise all the\r
-       threads. */\r
-       pvInterruptEventMutex = CreateMutex( NULL, FALSE, NULL );\r
-       pvInterruptEvent = CreateEvent( NULL, FALSE, FALSE, NULL );\r
+void *pvHandle = NULL;\r
+int32_t lSuccess;\r
+xThreadState *pxThreadState = NULL;\r
+SYSTEM_INFO xSystemInfo;\r
 \r
-       if( ( pvInterruptEventMutex == NULL ) || ( pvInterruptEvent == NULL ) )\r
+       /* This port runs windows threads with extremely high priority.  All the\r
+       threads execute on the same core - to prevent locking up the host only start\r
+       if the host has multiple cores. */\r
+       GetSystemInfo( &xSystemInfo );\r
+       if( xSystemInfo.dwNumberOfProcessors <= 1 )\r
        {\r
+               printf( "This version of the FreeRTOS Windows port can only be used on multi-core hosts.\r\n" );\r
                lSuccess = pdFAIL;\r
        }\r
-\r
-       /* Set the priority of this thread such that it is above the priority of\r
-       the threads that run tasks.  This higher priority is required to ensure\r
-       simulated interrupts take priority over tasks. */\r
-       pvHandle = GetCurrentThread();\r
-       if( pvHandle == NULL )\r
+       else\r
        {\r
-               lSuccess = pdFAIL;\r
+               lSuccess = pdPASS;\r
+\r
+               /* The highest priority class is used to [try to] prevent other Windows\r
+               activity interfering with FreeRTOS timing too much. */\r
+               if( SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ) == 0 )\r
+               {\r
+                       printf( "SetPriorityClass() failed\r\n" );\r
+               }\r
+\r
+               /* Install the interrupt handlers used by the scheduler itself. */\r
+               vPortSetInterruptHandler( portINTERRUPT_YIELD, prvProcessYieldInterrupt );\r
+               vPortSetInterruptHandler( portINTERRUPT_TICK, prvProcessTickInterrupt );\r
+\r
+               /* Create the events and mutexes that are used to synchronise all the\r
+               threads. */\r
+               pvInterruptEventMutex = CreateMutex( NULL, FALSE, NULL );\r
+               pvInterruptEvent = CreateEvent( NULL, FALSE, FALSE, NULL );\r
+\r
+               if( ( pvInterruptEventMutex == NULL ) || ( pvInterruptEvent == NULL ) )\r
+               {\r
+                       lSuccess = pdFAIL;\r
+               }\r
+\r
+               /* Set the priority of this thread such that it is above the priority of\r
+               the threads that run tasks.  This higher priority is required to ensure\r
+               simulated interrupts take priority over tasks. */\r
+               pvHandle = GetCurrentThread();\r
+               if( pvHandle == NULL )\r
+               {\r
+                       lSuccess = pdFAIL;\r
+               }\r
        }\r
 \r
        if( lSuccess == pdPASS )\r
index 34634fd2e995d18c7bd1b973c9d5763fcb5a9ffd..087cd1493a903b371eca1b58d4ce811e94db0a90 100644 (file)
@@ -71,6 +71,7 @@
 #define PORTMACRO_H\r
 \r
 #include <Windows.h>\r
+#include <WinBase.h>\r
 \r
 /******************************************************************************\r
        Defines\r