2 * FreeRTOS SMP Kernel V202110.00
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * https://www.FreeRTOS.org
23 * https://github.com/FreeRTOS
28 /* Standard includes. */
31 /* Scheduler includes. */
38 #pragma comment(lib, "winmm.lib")
41 #define portMAX_INTERRUPTS ( ( uint32_t ) sizeof( uint32_t ) * 8UL ) /* The number of bits in an uint32_t. */
42 #define portNO_CRITICAL_NESTING ( ( uint32_t ) 0 )
44 /* The priorities at which the various components of the simulation execute. */
45 #define portDELETE_SELF_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL /* Must be highest. */
46 #define portSIMULATED_INTERRUPTS_THREAD_PRIORITY THREAD_PRIORITY_TIME_CRITICAL
47 #define portSIMULATED_TIMER_THREAD_PRIORITY THREAD_PRIORITY_HIGHEST
48 #define portTASK_THREAD_PRIORITY THREAD_PRIORITY_ABOVE_NORMAL
51 * Created as a high priority thread, this function uses a timer to simulate
52 * a tick interrupt being generated on an embedded target. In this Windows
53 * environment the timer does not achieve anything approaching real time
56 static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter );
59 * Process all the simulated interrupts - each represented by a bit in
60 * ulPendingInterrupts variable.
62 static void prvProcessSimulatedInterrupts( void );
65 * Interrupt handlers used by the kernel itself. These are executed from the
66 * simulated interrupt handler thread.
68 static uint32_t prvProcessYieldInterrupt( void );
69 static uint32_t prvProcessTickInterrupt( void );
72 * Exiting a critical section will cause the calling task to block on yield
73 * event to wait for an interrupt to process if an interrupt was pended while
74 * inside the critical section. This variable protects against a recursive
75 * attempt to obtain pvInterruptEventMutex if a critical section is used inside
76 * an interrupt handler itself.
78 volatile BaseType_t xInsideInterrupt = pdFALSE;
81 * Called when the process exits to let Windows know the high timer resolution
82 * is no longer required.
84 static BOOL WINAPI prvEndProcess( DWORD dwCtrlType );
86 /*-----------------------------------------------------------*/
88 /* The WIN32 simulator runs each task in a thread. The context switching is
89 managed by the threads, so the task stack does not have to be managed directly,
90 although the task stack is still used to hold an xThreadState structure this is
91 the only thing it will ever hold. The structure indirectly maps the task handle
92 to a thread handle. */
95 /* Handle of the thread that executes the task. */
98 /* Event used to make sure the thread does not execute past a yield point
99 between the call to SuspendThread() to suspend the thread and the
100 asynchronous SuspendThread() operation actually being performed. */
104 /* Simulated interrupts waiting to be processed. This is a bit mask where each
105 bit represents one interrupt, so a maximum of 32 interrupts can be simulated. */
106 static volatile uint32_t ulPendingInterrupts = 0UL;
108 /* An event used to inform the simulated interrupt processing thread (a high
109 priority thread that simulated interrupt processing) that an interrupt is
111 static void *pvInterruptEvent = NULL;
113 /* Mutex used to protect all the simulated interrupt variables that are accessed
114 by multiple threads. */
115 static void *pvInterruptEventMutex = NULL;
117 /* The critical nesting count for the currently executing task. This is
118 initialised to a non-zero value so interrupts do not become enabled during
119 the initialisation phase. As each task has its own critical nesting value
120 ulCriticalNesting will get set to zero when the first task runs. This
121 initialisation is probably not critical in this simulated environment as the
122 simulated interrupt handlers do not get created until the FreeRTOS scheduler is
124 static volatile uint32_t ulCriticalNesting = 9999UL;
126 /* Handlers for all the simulated software interrupts. The first two positions
127 are used for the Yield and Tick interrupts so are handled slightly differently,
128 all the other interrupts can be user defined. */
129 static uint32_t (*ulIsrHandler[ portMAX_INTERRUPTS ])( void ) = { 0 };
131 /* Pointer to the TCB of the currently executing task. */
132 extern void * volatile pxCurrentTCB;
134 /* Used to ensure nothing is processed during the startup sequence. */
135 static BaseType_t xPortRunning = pdFALSE;
137 /*-----------------------------------------------------------*/
139 static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
141 TickType_t xMinimumWindowsBlockTime;
144 /* Set the timer resolution to the maximum possible. */
145 if( timeGetDevCaps( &xTimeCaps, sizeof( xTimeCaps ) ) == MMSYSERR_NOERROR )
147 xMinimumWindowsBlockTime = ( TickType_t ) xTimeCaps.wPeriodMin;
148 timeBeginPeriod( xTimeCaps.wPeriodMin );
150 /* Register an exit handler so the timeBeginPeriod() function can be
151 matched with a timeEndPeriod() when the application exits. */
152 SetConsoleCtrlHandler( prvEndProcess, TRUE );
156 xMinimumWindowsBlockTime = ( TickType_t ) 20;
159 /* Just to prevent compiler warnings. */
160 ( void ) lpParameter;
164 /* Wait until the timer expires and we can access the simulated interrupt
165 variables. *NOTE* this is not a 'real time' way of generating tick
166 events as the next wake time should be relative to the previous wake
167 time, not the time that Sleep() is called. It is done this way to
168 prevent overruns in this very non real time simulated/emulated
170 if( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
172 Sleep( xMinimumWindowsBlockTime );
176 Sleep( portTICK_PERIOD_MS );
179 configASSERT( xPortRunning );
181 /* Can't proceed if in a critical section as pvInterruptEventMutex won't
183 WaitForSingleObject( pvInterruptEventMutex, INFINITE );
185 /* The timer has expired, generate the simulated tick event. */
186 ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );
188 /* The interrupt is now pending - notify the simulated interrupt
189 handler thread. Must be outside of a critical section to get here so
190 the handler thread can execute immediately pvInterruptEventMutex is
192 configASSERT( ulCriticalNesting == 0UL );
193 SetEvent( pvInterruptEvent );
195 /* Give back the mutex so the simulated interrupt handler unblocks
196 and can access the interrupt handler variables. */
197 ReleaseMutex( pvInterruptEventMutex );
201 /* Should never reach here - MingW complains if you leave this line out,
202 MSVC complains if you put it in. */
206 /*-----------------------------------------------------------*/
208 static BOOL WINAPI prvEndProcess( DWORD dwCtrlType )
214 if( timeGetDevCaps( &xTimeCaps, sizeof( xTimeCaps ) ) == MMSYSERR_NOERROR )
216 /* Match the call to timeBeginPeriod( xTimeCaps.wPeriodMin ) made when
217 the process started with a timeEndPeriod() as the process exits. */
218 timeEndPeriod( xTimeCaps.wPeriodMin );
223 /*-----------------------------------------------------------*/
225 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
227 ThreadState_t *pxThreadState = NULL;
228 int8_t *pcTopOfStack = ( int8_t * ) pxTopOfStack;
229 const SIZE_T xStackSize = 1024; /* Set the size to a small number which will get rounded up to the minimum possible. */
231 /* In this simulated case a stack is not initialised, but instead a thread
232 is created that will execute the task being created. The thread handles
233 the context switching itself. The ThreadState_t object is placed onto
234 the stack that was created for the task - so the stack buffer is still
235 used, just not in the conventional way. It will not be used for anything
236 other than holding this structure. */
237 pxThreadState = ( ThreadState_t * ) ( pcTopOfStack - sizeof( ThreadState_t ) );
239 /* Create the event used to prevent the thread from executing past its yield
240 point if the SuspendThread() call that suspends the thread does not take
241 effect immediately (it is an asynchronous call). */
242 pxThreadState->pvYieldEvent = CreateEvent( NULL, /* Default security attributes. */
243 FALSE, /* Auto reset. */
244 FALSE, /* Start not signalled. */
245 NULL );/* No name. */
247 /* Create the thread itself. */
248 pxThreadState->pvThread = CreateThread( NULL, xStackSize, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION, NULL );
249 configASSERT( pxThreadState->pvThread ); /* See comment where TerminateThread() is called. */
250 SetThreadAffinityMask( pxThreadState->pvThread, 0x01 );
251 SetThreadPriorityBoost( pxThreadState->pvThread, TRUE );
252 SetThreadPriority( pxThreadState->pvThread, portTASK_THREAD_PRIORITY );
254 return ( StackType_t * ) pxThreadState;
256 /*-----------------------------------------------------------*/
258 BaseType_t xPortStartScheduler( void )
260 void *pvHandle = NULL;
262 ThreadState_t *pxThreadState = NULL;
263 SYSTEM_INFO xSystemInfo;
265 /* This port runs windows threads with extremely high priority. All the
266 threads execute on the same core - to prevent locking up the host only start
267 if the host has multiple cores. */
268 GetSystemInfo( &xSystemInfo );
269 if( xSystemInfo.dwNumberOfProcessors <= 1 )
271 printf( "This version of the FreeRTOS Windows port can only be used on multi-core hosts.\r\n" );
278 /* The highest priority class is used to [try to] prevent other Windows
279 activity interfering with FreeRTOS timing too much. */
280 if( SetPriorityClass( GetCurrentProcess(), REALTIME_PRIORITY_CLASS ) == 0 )
282 printf( "SetPriorityClass() failed\r\n" );
285 /* Install the interrupt handlers used by the scheduler itself. */
286 vPortSetInterruptHandler( portINTERRUPT_YIELD, prvProcessYieldInterrupt );
287 vPortSetInterruptHandler( portINTERRUPT_TICK, prvProcessTickInterrupt );
289 /* Create the events and mutexes that are used to synchronise all the
291 pvInterruptEventMutex = CreateMutex( NULL, FALSE, NULL );
292 pvInterruptEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
294 if( ( pvInterruptEventMutex == NULL ) || ( pvInterruptEvent == NULL ) )
299 /* Set the priority of this thread such that it is above the priority of
300 the threads that run tasks. This higher priority is required to ensure
301 simulated interrupts take priority over tasks. */
302 pvHandle = GetCurrentThread();
303 if( pvHandle == NULL )
309 if( lSuccess == pdPASS )
311 if( SetThreadPriority( pvHandle, portSIMULATED_INTERRUPTS_THREAD_PRIORITY ) == 0 )
315 SetThreadPriorityBoost( pvHandle, TRUE );
316 SetThreadAffinityMask( pvHandle, 0x01 );
319 if( lSuccess == pdPASS )
321 /* Start the thread that simulates the timer peripheral to generate
322 tick interrupts. The priority is set below that of the simulated
323 interrupt handler so the interrupt event mutex is used for the
324 handshake / overrun protection. */
325 pvHandle = CreateThread( NULL, 0, prvSimulatedPeripheralTimer, NULL, CREATE_SUSPENDED, NULL );
326 if( pvHandle != NULL )
328 SetThreadPriority( pvHandle, portSIMULATED_TIMER_THREAD_PRIORITY );
329 SetThreadPriorityBoost( pvHandle, TRUE );
330 SetThreadAffinityMask( pvHandle, 0x01 );
331 ResumeThread( pvHandle );
334 /* Start the highest priority task by obtaining its associated thread
335 state structure, in which is stored the thread handle. */
336 pxThreadState = ( ThreadState_t * ) *( ( size_t * ) pxCurrentTCB );
337 ulCriticalNesting = portNO_CRITICAL_NESTING;
339 /* Start the first task. */
340 ResumeThread( pxThreadState->pvThread );
342 /* Handle all simulated interrupts - including yield requests and
344 prvProcessSimulatedInterrupts();
347 /* Would not expect to return from prvProcessSimulatedInterrupts(), so should
351 /*-----------------------------------------------------------*/
353 static uint32_t prvProcessYieldInterrupt( void )
355 /* Always return true as this is a yield. */
358 /*-----------------------------------------------------------*/
360 static uint32_t prvProcessTickInterrupt( void )
362 uint32_t ulSwitchRequired;
364 /* Process the tick itself. */
365 configASSERT( xPortRunning );
366 ulSwitchRequired = ( uint32_t ) xTaskIncrementTick();
368 return ulSwitchRequired;
370 /*-----------------------------------------------------------*/
372 static void prvProcessSimulatedInterrupts( void )
374 uint32_t ulSwitchRequired, i;
375 ThreadState_t *pxThreadState;
376 void *pvObjectList[ 2 ];
379 /* Going to block on the mutex that ensured exclusive access to the simulated
380 interrupt objects, and the event that signals that a simulated interrupt
381 should be processed. */
382 pvObjectList[ 0 ] = pvInterruptEventMutex;
383 pvObjectList[ 1 ] = pvInterruptEvent;
385 /* Create a pending tick to ensure the first task is started as soon as
386 this thread pends. */
387 ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );
388 SetEvent( pvInterruptEvent );
390 xPortRunning = pdTRUE;
394 xInsideInterrupt = pdFALSE;
395 WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE );
397 /* Cannot be in a critical section to get here. Tasks that exit a
398 critical section will block on a yield mutex to wait for an interrupt to
399 process if an interrupt was set pending while the task was inside the
400 critical section. xInsideInterrupt prevents interrupts that contain
401 critical sections from doing the same. */
402 xInsideInterrupt = pdTRUE;
404 /* Used to indicate whether the simulated interrupt processing has
405 necessitated a context switch to another task/thread. */
406 ulSwitchRequired = pdFALSE;
408 /* For each interrupt we are interested in processing, each of which is
409 represented by a bit in the 32bit ulPendingInterrupts variable. */
410 for( i = 0; i < portMAX_INTERRUPTS; i++ )
412 /* Is the simulated interrupt pending? */
413 if( ( ulPendingInterrupts & ( 1UL << i ) ) != 0 )
415 /* Is a handler installed? */
416 if( ulIsrHandler[ i ] != NULL )
418 /* Run the actual handler. Handlers return pdTRUE if they
419 necessitate a context switch. */
420 if( ulIsrHandler[ i ]() != pdFALSE )
422 /* A bit mask is used purely to help debugging. */
423 ulSwitchRequired |= ( 1 << i );
427 /* Clear the interrupt pending bit. */
428 ulPendingInterrupts &= ~( 1UL << i );
432 if( ulSwitchRequired != pdFALSE )
434 void *pvOldCurrentTCB;
436 pvOldCurrentTCB = pxCurrentTCB;
438 /* Select the next task to run. */
439 vTaskSwitchContext();
441 /* If the task selected to enter the running state is not the task
442 that is already in the running state. */
443 if( pvOldCurrentTCB != pxCurrentTCB )
445 /* Suspend the old thread. In the cases where the (simulated)
446 interrupt is asynchronous (tick event swapping a task out rather
447 than a task blocking or yielding) it doesn't matter if the
448 'suspend' operation doesn't take effect immediately - if it
449 doesn't it would just be like the interrupt occurring slightly
450 later. In cases where the yield was caused by a task blocking
451 or yielding then the task will block on a yield event after the
452 yield operation in case the 'suspend' operation doesn't take
453 effect immediately. */
454 pxThreadState = ( ThreadState_t *) *( ( size_t * ) pvOldCurrentTCB );
455 SuspendThread( pxThreadState->pvThread );
457 /* Ensure the thread is actually suspended by performing a
458 synchronous operation that can only complete when the thread is
459 actually suspended. The below code asks for dummy register
460 data. Experimentation shows that these two lines don't appear
461 to do anything now, but according to
462 https://devblogs.microsoft.com/oldnewthing/20150205-00/?p=44743
463 they do - so as they do not harm (slight run-time hit). */
464 xContext.ContextFlags = CONTEXT_INTEGER;
465 ( void ) GetThreadContext( pxThreadState->pvThread, &xContext );
467 /* Obtain the state of the task now selected to enter the
469 pxThreadState = ( ThreadState_t * ) ( *( size_t *) pxCurrentTCB );
471 /* pxThreadState->pvThread can be NULL if the task deleted
472 itself - but a deleted task should never be resumed here. */
473 configASSERT( pxThreadState->pvThread != NULL );
474 ResumeThread( pxThreadState->pvThread );
478 /* If the thread that is about to be resumed stopped running
479 because it yielded then it will wait on an event when it resumed
480 (to ensure it does not continue running after the call to
481 SuspendThread() above as SuspendThread() is asynchronous).
482 Signal the event to ensure the thread can proceed now it is
483 valid for it to do so. Signaling the event is benign in the case that
484 the task was switched out asynchronously by an interrupt as the event
485 is reset before the task blocks on it. */
486 pxThreadState = ( ThreadState_t * ) ( *( size_t *) pxCurrentTCB );
487 SetEvent( pxThreadState->pvYieldEvent );
488 ReleaseMutex( pvInterruptEventMutex );
491 /*-----------------------------------------------------------*/
493 void vPortDeleteThread( void *pvTaskToDelete )
495 ThreadState_t *pxThreadState;
496 uint32_t ulErrorCode;
498 /* Remove compiler warnings if configASSERT() is not defined. */
499 ( void ) ulErrorCode;
501 /* Find the handle of the thread being deleted. */
502 pxThreadState = ( ThreadState_t * ) ( *( size_t *) pvTaskToDelete );
504 /* Check that the thread is still valid, it might have been closed by
505 vPortCloseRunningThread() - which will be the case if the task associated
506 with the thread originally deleted itself rather than being deleted by a
508 if( pxThreadState->pvThread != NULL )
510 WaitForSingleObject( pvInterruptEventMutex, INFINITE );
512 /* !!! This is not a nice way to terminate a thread, and will eventually
513 result in resources being depleted if tasks frequently delete other
514 tasks (rather than deleting themselves) as the task stacks will not be
516 ulErrorCode = TerminateThread( pxThreadState->pvThread, 0 );
517 configASSERT( ulErrorCode );
519 ulErrorCode = CloseHandle( pxThreadState->pvThread );
520 configASSERT( ulErrorCode );
522 ReleaseMutex( pvInterruptEventMutex );
525 /*-----------------------------------------------------------*/
527 void vPortCloseRunningThread( void *pvTaskToDelete, volatile BaseType_t *pxPendYield )
529 ThreadState_t *pxThreadState;
531 uint32_t ulErrorCode;
533 /* Remove compiler warnings if configASSERT() is not defined. */
534 ( void ) ulErrorCode;
536 /* Find the handle of the thread being deleted. */
537 pxThreadState = ( ThreadState_t * ) ( *( size_t *) pvTaskToDelete );
538 pvThread = pxThreadState->pvThread;
540 /* Raise the Windows priority of the thread to ensure the FreeRTOS scheduler
541 does not run and swap it out before it is closed. If that were to happen
542 the thread would never run again and effectively be a thread handle and
544 SetThreadPriority( pvThread, portDELETE_SELF_THREAD_PRIORITY );
546 /* This function will not return, therefore a yield is set as pending to
547 ensure a context switch occurs away from this thread on the next tick. */
548 *pxPendYield = pdTRUE;
550 /* Mark the thread associated with this task as invalid so
551 vPortDeleteThread() does not try to terminate it. */
552 pxThreadState->pvThread = NULL;
554 /* Close the thread. */
555 ulErrorCode = CloseHandle( pvThread );
556 configASSERT( ulErrorCode );
558 /* This is called from a critical section, which must be exited before the
561 CloseHandle( pxThreadState->pvYieldEvent );
564 /*-----------------------------------------------------------*/
566 void vPortEndScheduler( void )
570 /*-----------------------------------------------------------*/
572 void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
574 ThreadState_t *pxThreadState = ( ThreadState_t *) *( ( size_t * ) pxCurrentTCB );
576 configASSERT( xPortRunning );
578 if( ( ulInterruptNumber < portMAX_INTERRUPTS ) && ( pvInterruptEventMutex != NULL ) )
580 WaitForSingleObject( pvInterruptEventMutex, INFINITE );
581 ulPendingInterrupts |= ( 1 << ulInterruptNumber );
583 /* The simulated interrupt is now held pending, but don't actually
584 process it yet if this call is within a critical section. It is
585 possible for this to be in a critical section as calls to wait for
586 mutexes are accumulative. If in a critical section then the event
587 will get set when the critical section nesting count is wound back
589 if( ulCriticalNesting == portNO_CRITICAL_NESTING )
591 SetEvent( pvInterruptEvent );
593 /* Going to wait for an event - make sure the event is not already
595 ResetEvent( pxThreadState->pvYieldEvent );
598 ReleaseMutex( pvInterruptEventMutex );
599 if( ulCriticalNesting == portNO_CRITICAL_NESTING )
601 /* An interrupt was pended so ensure to block to allow it to
602 execute. In most cases the (simulated) interrupt will have
603 executed before the next line is reached - so this is just to make
605 WaitForSingleObject( pxThreadState->pvYieldEvent, INFINITE );
609 /*-----------------------------------------------------------*/
611 void vPortSetInterruptHandler( uint32_t ulInterruptNumber, uint32_t (*pvHandler)( void ) )
613 if( ulInterruptNumber < portMAX_INTERRUPTS )
615 if( pvInterruptEventMutex != NULL )
617 WaitForSingleObject( pvInterruptEventMutex, INFINITE );
618 ulIsrHandler[ ulInterruptNumber ] = pvHandler;
619 ReleaseMutex( pvInterruptEventMutex );
623 ulIsrHandler[ ulInterruptNumber ] = pvHandler;
627 /*-----------------------------------------------------------*/
629 void vPortEnterCritical( void )
631 if( xPortRunning == pdTRUE )
633 /* The interrupt event mutex is held for the entire critical section,
634 effectively disabling (simulated) interrupts. */
635 WaitForSingleObject( pvInterruptEventMutex, INFINITE );
640 /*-----------------------------------------------------------*/
642 void vPortExitCritical( void )
644 int32_t lMutexNeedsReleasing;
646 /* The interrupt event mutex should already be held by this thread as it was
647 obtained on entry to the critical section. */
648 lMutexNeedsReleasing = pdTRUE;
650 if( ulCriticalNesting > portNO_CRITICAL_NESTING )
654 /* Don't need to wait for any pending interrupts to execute if the
655 critical section was exited from inside an interrupt. */
656 if( ( ulCriticalNesting == portNO_CRITICAL_NESTING ) && ( xInsideInterrupt == pdFALSE ) )
658 /* Were any interrupts set to pending while interrupts were
659 (simulated) disabled? */
660 if( ulPendingInterrupts != 0UL )
662 ThreadState_t *pxThreadState = ( ThreadState_t *) *( ( size_t * ) pxCurrentTCB );
664 configASSERT( xPortRunning );
666 /* The interrupt won't actually executed until
667 pvInterruptEventMutex is released as it waits on both
668 pvInterruptEventMutex and pvInterruptEvent.
669 pvInterruptEvent is only set when the simulated
670 interrupt is pended if the interrupt is pended
671 from outside a critical section - hence it is set
673 SetEvent( pvInterruptEvent );
674 /* The calling task is going to wait for an event to ensure the
675 interrupt that is pending executes immediately after the
676 critical section is exited - so make sure the event is not
678 ResetEvent( pxThreadState->pvYieldEvent );
680 /* Mutex will be released now so the (simulated) interrupt can
681 execute, so does not require releasing on function exit. */
682 lMutexNeedsReleasing = pdFALSE;
683 ReleaseMutex( pvInterruptEventMutex );
684 WaitForSingleObject( pxThreadState->pvYieldEvent, INFINITE );
689 if( pvInterruptEventMutex != NULL )
691 if( lMutexNeedsReleasing == pdTRUE )
693 configASSERT( xPortRunning );
694 ReleaseMutex( pvInterruptEventMutex );
698 /*-----------------------------------------------------------*/