Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Revert "Fix inaccurate ticks in windows port (#142)" #143

Merged
merged 1 commit into from
Aug 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 14 additions & 26 deletions portable/MSVC-MingW/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
* 1 tab == 4 spaces!
*/

/* Standard includes. */
Expand Down Expand Up @@ -139,9 +140,6 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
{
TickType_t xMinimumWindowsBlockTime;
TIMECAPS xTimeCaps;
TickType_t xWaitTimeBetweenTicks = portTICK_PERIOD_MS;
HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;

/* Set the timer resolution to the maximum possible. */
if( timeGetDevCaps( &xTimeCaps, sizeof( xTimeCaps ) ) == MMSYSERR_NOERROR )
Expand All @@ -161,32 +159,22 @@ LARGE_INTEGER liDueTime;
/* Just to prevent compiler warnings. */
( 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 ) );

for( ;; )
{
/* Wait until the timer expires and we can access the simulated interrupt
variables. */
WaitForSingleObject( hTimer, INFINITE );
variables. *NOTE* this is not a 'real time' way of generating tick
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
prevent overruns in this very non real time simulated/emulated
environment. */
if( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
{
Sleep( xMinimumWindowsBlockTime );
}
else
{
Sleep( portTICK_PERIOD_MS );
}

configASSERT( xPortRunning );

Expand Down