Skip to content

Commit 067d04e

Browse files
authored
Add vPortGenerateSimulatedInterruptFromWindowsThread in MSVC port (FreeRTOS#1044)
Add vPortGenerateSimulatedInterruptFromWindowsThread in MSVC port to enable native windows threads to notify FreeRTOS tasks.
1 parent 78c8bbd commit 067d04e

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

portable/MSVC-MingW/port.c

+27-22
Original file line numberDiff line numberDiff line change
@@ -177,28 +177,7 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
177177
Sleep( portTICK_PERIOD_MS );
178178
}
179179

180-
if( xPortRunning == pdTRUE )
181-
{
182-
configASSERT( xPortRunning );
183-
184-
/* Can't proceed if in a critical section as pvInterruptEventMutex won't
185-
* be available. */
186-
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
187-
188-
/* The timer has expired, generate the simulated tick event. */
189-
ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );
190-
191-
/* The interrupt is now pending - notify the simulated interrupt
192-
* handler thread. Must be outside of a critical section to get here so
193-
* the handler thread can execute immediately pvInterruptEventMutex is
194-
* released. */
195-
configASSERT( ulCriticalNesting == 0UL );
196-
SetEvent( pvInterruptEvent );
197-
198-
/* Give back the mutex so the simulated interrupt handler unblocks
199-
* and can access the interrupt handler variables. */
200-
ReleaseMutex( pvInterruptEventMutex );
201-
}
180+
vPortGenerateSimulatedInterruptFromWindowsThread( portINTERRUPT_TICK );
202181
}
203182

204183
return 0;
@@ -636,6 +615,32 @@ void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
636615
}
637616
/*-----------------------------------------------------------*/
638617

618+
void vPortGenerateSimulatedInterruptFromWindowsThread( uint32_t ulInterruptNumber )
619+
{
620+
if( xPortRunning == pdTRUE )
621+
{
622+
/* Can't proceed if in a critical section as pvInterruptEventMutex won't
623+
* be available. */
624+
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
625+
626+
/* Pending a user defined interrupt to be handled in simulated interrupt
627+
* handler thread. */
628+
ulPendingInterrupts |= ( 1 << ulInterruptNumber );
629+
630+
/* The interrupt is now pending - notify the simulated interrupt
631+
* handler thread. Must be outside of a critical section to get here so
632+
* the handler thread can execute immediately pvInterruptEventMutex is
633+
* released. */
634+
configASSERT( ulCriticalNesting == 0UL );
635+
SetEvent( pvInterruptEvent );
636+
637+
/* Give back the mutex so the simulated interrupt handler unblocks
638+
* and can access the interrupt handler variables. */
639+
ReleaseMutex( pvInterruptEventMutex );
640+
}
641+
}
642+
/*-----------------------------------------------------------*/
643+
639644
void vPortSetInterruptHandler( uint32_t ulInterruptNumber,
640645
uint32_t ( * pvHandler )( void ) )
641646
{

portable/MSVC-MingW/portmacro.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ void vPortExitCritical( void );
184184
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
185185
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
186186

187-
#define portINTERRUPT_YIELD ( 0UL )
188-
#define portINTERRUPT_TICK ( 1UL )
187+
#define portINTERRUPT_YIELD ( 0UL )
188+
#define portINTERRUPT_TICK ( 1UL )
189+
#define portINTERRUPT_APPLICATION_DEFINED_START ( 2UL )
189190

190191
/*
191192
* Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
@@ -194,6 +195,14 @@ void vPortExitCritical( void );
194195
*/
195196
void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber );
196197

198+
/*
199+
* Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
200+
* Each bit can be used to represent an individual interrupt - with the first
201+
* two bits being used for the Yield and Tick interrupts respectively. This function
202+
* can be called in a windows thread.
203+
*/
204+
void vPortGenerateSimulatedInterruptFromWindowsThread( uint32_t ulInterruptNumber );
205+
197206
/*
198207
* Install an interrupt handler to be called by the simulated interrupt handler
199208
* thread. The interrupt number must be above any used by the kernel itself

0 commit comments

Comments
 (0)