@@ -141,6 +141,9 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
141141{
142142 TickType_t xMinimumWindowsBlockTime ;
143143 TIMECAPS xTimeCaps ;
144+ TickType_t xWaitTimeBetweenTicks = portTICK_PERIOD_MS ;
145+ HANDLE hTimer = NULL ;
146+ LARGE_INTEGER liDueTime ;
144147
145148 /* Set the timer resolution to the maximum possible. */
146149 if ( timeGetDevCaps ( & xTimeCaps , sizeof ( xTimeCaps ) ) == MMSYSERR_NOERROR )
@@ -160,22 +163,33 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
160163 /* Just to prevent compiler warnings. */
161164 ( void ) lpParameter ;
162165
166+ /* Tick time for the timer is adjusted with the maximum available
167+ resolution. */
168+ if ( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
169+ {
170+ xWaitTimeBetweenTicks = xMinimumWindowsBlockTime ;
171+ }
172+
173+ /* Convert the tick time in milliseconds to nanoseconds resolution
174+ for the Waitable Timer. */
175+ liDueTime .u .LowPart = xWaitTimeBetweenTicks * 1000 * 1000 ;
176+ liDueTime .u .HighPart = 0 ;
177+
178+ /* Create a synchronization Waitable Timer.*/
179+ hTimer = CreateWaitableTimer ( NULL , FALSE, NULL );
180+
181+ configASSERT ( hTimer != NULL );
182+
183+ /* Set the Waitable Timer. The timer is set to run periodically at every
184+ xWaitTimeBetweenTicks milliseconds. */
185+ configASSERT ( SetWaitableTimer ( hTimer , & liDueTime , xWaitTimeBetweenTicks , NULL , NULL , 0 ) );
186+
163187 while ( xPortRunning == pdTRUE )
164188 {
165189 /* Wait until the timer expires and we can access the simulated interrupt
166- * variables. *NOTE* this is not a 'real time' way of generating tick
167- * events as the next wake time should be relative to the previous wake
168- * time, not the time that Sleep() is called. It is done this way to
169- * prevent overruns in this very non real time simulated/emulated
170- * environment. */
171- if ( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
172- {
173- Sleep ( xMinimumWindowsBlockTime );
174- }
175- else
176- {
177- Sleep ( portTICK_PERIOD_MS );
178- }
190+ * variables. */
191+
192+ WaitForSingleObject ( hTimer , INFINITE );
179193
180194 vPortGenerateSimulatedInterruptFromWindowsThread ( portINTERRUPT_TICK );
181195 }
0 commit comments