Merge branch 'main' into ulTaskGetRunTimeCounter

This commit is contained in:
Rahul Kar 2025-02-06 18:06:58 +05:30 committed by GitHub
commit 64b3f74948
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 33 deletions

View file

@ -141,6 +141,9 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
{ {
TickType_t xMinimumWindowsBlockTime; TickType_t xMinimumWindowsBlockTime;
TIMECAPS xTimeCaps; TIMECAPS xTimeCaps;
TickType_t xWaitTimeBetweenTicks = portTICK_PERIOD_MS;
HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;
/* Set the timer resolution to the maximum possible. */ /* Set the timer resolution to the maximum possible. */
if( timeGetDevCaps( &xTimeCaps, sizeof( xTimeCaps ) ) == MMSYSERR_NOERROR ) if( timeGetDevCaps( &xTimeCaps, sizeof( xTimeCaps ) ) == MMSYSERR_NOERROR )
@ -160,22 +163,33 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
/* Just to prevent compiler warnings. */ /* Just to prevent compiler warnings. */
( void ) lpParameter; ( void ) lpParameter;
/* Tick time for the timer is adjusted with the maximum available
resolution. */
if( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
{
xWaitTimeBetweenTicks = xMinimumWindowsBlockTime;
}
/* Convert the tick time in milliseconds to nanoseconds resolution
for the Waitable Timer. */
liDueTime.u.LowPart = xWaitTimeBetweenTicks * 1000 * 1000;
liDueTime.u.HighPart = 0;
/* Create a synchronization Waitable Timer.*/
hTimer = CreateWaitableTimer( NULL, FALSE, NULL );
configASSERT( hTimer != NULL );
/* Set the Waitable Timer. The timer is set to run periodically at every
xWaitTimeBetweenTicks milliseconds. */
configASSERT( SetWaitableTimer( hTimer, &liDueTime, xWaitTimeBetweenTicks, NULL, NULL, 0 ) );
while( xPortRunning == pdTRUE ) while( xPortRunning == pdTRUE )
{ {
/* Wait until the timer expires and we can access the simulated interrupt /* Wait until the timer expires and we can access the simulated interrupt
* variables. *NOTE* this is not a 'real time' way of generating tick * variables. */
* events as the next wake time should be relative to the previous wake
* time, not the time that Sleep() is called. It is done this way to WaitForSingleObject( hTimer, INFINITE );
* prevent overruns in this very non real time simulated/emulated
* environment. */
if( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
{
Sleep( xMinimumWindowsBlockTime );
}
else
{
Sleep( portTICK_PERIOD_MS );
}
vPortGenerateSimulatedInterruptFromWindowsThread( portINTERRUPT_TICK ); vPortGenerateSimulatedInterruptFromWindowsThread( portINTERRUPT_TICK );
} }

View file

@ -97,6 +97,7 @@ static inline Thread_t * prvGetThreadFromTask( TaskHandle_t xTask )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static pthread_once_t hSigSetupThread = PTHREAD_ONCE_INIT; static pthread_once_t hSigSetupThread = PTHREAD_ONCE_INIT;
static pthread_once_t hThreadKeyOnce = PTHREAD_ONCE_INIT;
static sigset_t xAllSignals; static sigset_t xAllSignals;
static sigset_t xSchedulerOriginalSignalMask; static sigset_t xSchedulerOriginalSignalMask;
static pthread_t hMainThread = ( pthread_t ) NULL; static pthread_t hMainThread = ( pthread_t ) NULL;
@ -105,7 +106,6 @@ static BaseType_t xSchedulerEnd = pdFALSE;
static pthread_t hTimerTickThread; static pthread_t hTimerTickThread;
static bool xTimerTickThreadShouldRun; static bool xTimerTickThreadShouldRun;
static uint64_t prvStartTimeNs; static uint64_t prvStartTimeNs;
static pthread_mutex_t xThreadMutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t xThreadKey = 0; static pthread_key_t xThreadKey = 0;
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -134,14 +134,7 @@ static void prvThreadKeyDestructor( void * pvData )
static void prvInitThreadKey( void ) static void prvInitThreadKey( void )
{ {
pthread_mutex_lock( &xThreadMutex ); pthread_key_create( &xThreadKey, prvThreadKeyDestructor );
if( xThreadKey == 0 )
{
pthread_key_create( &xThreadKey, prvThreadKeyDestructor );
}
pthread_mutex_unlock( &xThreadMutex );
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -149,7 +142,7 @@ static void prvMarkAsFreeRTOSThread( void )
{ {
uint8_t * pucThreadData = NULL; uint8_t * pucThreadData = NULL;
prvInitThreadKey(); ( void ) pthread_once( &hThreadKeyOnce, prvInitThreadKey );
pucThreadData = malloc( 1 ); pucThreadData = malloc( 1 );
configASSERT( pucThreadData != NULL ); configASSERT( pucThreadData != NULL );
@ -165,7 +158,10 @@ static BaseType_t prvIsFreeRTOSThread( void )
uint8_t * pucThreadData = NULL; uint8_t * pucThreadData = NULL;
BaseType_t xRet = pdFALSE; BaseType_t xRet = pdFALSE;
( void ) pthread_once( &hThreadKeyOnce, prvInitThreadKey );
pucThreadData = ( uint8_t * ) pthread_getspecific( xThreadKey ); pucThreadData = ( uint8_t * ) pthread_getspecific( xThreadKey );
if( ( pucThreadData != NULL ) && ( *pucThreadData == 1 ) ) if( ( pucThreadData != NULL ) && ( *pucThreadData == 1 ) )
{ {
xRet = pdTRUE; xRet = pdTRUE;
@ -192,13 +188,13 @@ void prvFatalError( const char * pcCall,
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvPortSetCurrentThreadName(char * pxThreadName) static void prvPortSetCurrentThreadName( char * pxThreadName )
{ {
#ifdef __APPLE__ #ifdef __APPLE__
pthread_setname_np(pxThreadName); pthread_setname_np( pxThreadName );
#else #else
pthread_setname_np(pthread_self(), pxThreadName); pthread_setname_np( pthread_self(), pxThreadName );
#endif #endif
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -269,7 +265,7 @@ BaseType_t xPortStartScheduler( void )
sigset_t xSignals; sigset_t xSignals;
hMainThread = pthread_self(); hMainThread = pthread_self();
prvPortSetCurrentThreadName("Scheduler"); prvPortSetCurrentThreadName( "Scheduler" );
/* Start the timer that generates the tick ISR(SIGALRM). /* Start the timer that generates the tick ISR(SIGALRM).
* Interrupts are disabled here already. */ * Interrupts are disabled here already. */
@ -303,9 +299,12 @@ BaseType_t xPortStartScheduler( void )
* memset the internal struct members for MacOS/Linux Compatibility */ * memset the internal struct members for MacOS/Linux Compatibility */
#if __APPLE__ #if __APPLE__
hSigSetupThread.__sig = _PTHREAD_ONCE_SIG_init; hSigSetupThread.__sig = _PTHREAD_ONCE_SIG_init;
memset( ( void * ) &hSigSetupThread.__opaque, 0, sizeof(hSigSetupThread.__opaque)); hThreadKeyOnce.__sig = _PTHREAD_ONCE_SIG_init;
memset( ( void * ) &hSigSetupThread.__opaque, 0, sizeof( hSigSetupThread.__opaque ) );
memset( ( void * ) &hThreadKeyOnce.__opaque, 0, sizeof( hThreadKeyOnce.__opaque ) );
#else /* Linux PTHREAD library*/ #else /* Linux PTHREAD library*/
hSigSetupThread = PTHREAD_ONCE_INIT; hSigSetupThread = PTHREAD_ONCE_INIT;
hThreadKeyOnce = PTHREAD_ONCE_INIT;
#endif /* __APPLE__*/ #endif /* __APPLE__*/
/* Restore original signal mask. */ /* Restore original signal mask. */
@ -392,7 +391,7 @@ void vPortDisableInterrupts( void )
{ {
if( prvIsFreeRTOSThread() == pdTRUE ) if( prvIsFreeRTOSThread() == pdTRUE )
{ {
pthread_sigmask(SIG_BLOCK, &xAllSignals, NULL); pthread_sigmask( SIG_BLOCK, &xAllSignals, NULL );
} }
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
@ -540,7 +539,7 @@ static void * prvWaitForStart( void * pvParams )
vPortEnableInterrupts(); vPortEnableInterrupts();
/* Set thread name */ /* Set thread name */
prvPortSetCurrentThreadName(pcTaskGetName(xTaskGetCurrentTaskHandle())); prvPortSetCurrentThreadName( pcTaskGetName( xTaskGetCurrentTaskHandle() ) );
/* Call the task's entry point. */ /* Call the task's entry point. */
pxThread->pxCode( pxThread->pvParams ); pxThread->pxCode( pxThread->pvParams );