22
22
* https://www.FreeRTOS.org
23
23
* https://github.com/FreeRTOS
24
24
*
25
- * 1 tab == 4 spaces!
26
25
*/
27
26
28
27
/* Standard includes. */
@@ -140,6 +139,9 @@ static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter )
140
139
{
141
140
TickType_t xMinimumWindowsBlockTime ;
142
141
TIMECAPS xTimeCaps ;
142
+ TickType_t xWaitTimeBetweenTicks = portTICK_PERIOD_MS ;
143
+ HANDLE hTimer = NULL ;
144
+ LARGE_INTEGER liDueTime ;
143
145
144
146
/* Set the timer resolution to the maximum possible. */
145
147
if ( timeGetDevCaps ( & xTimeCaps , sizeof ( xTimeCaps ) ) == MMSYSERR_NOERROR )
@@ -159,22 +161,32 @@ TIMECAPS xTimeCaps;
159
161
/* Just to prevent compiler warnings. */
160
162
( void ) lpParameter ;
161
163
164
+ /* Tick time for the timer is adjusted with the maximum available
165
+ resolution. */
166
+ if ( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
167
+ {
168
+ xWaitTimeBetweenTicks = xMinimumWindowsBlockTime ;
169
+ }
170
+
171
+ /* Convert the tick time in milliseconds to nanoseconds resolution
172
+ for the Waitable Timer. */
173
+ liDueTime .u .LowPart = xWaitTimeBetweenTicks * 1000 * 1000 ;
174
+ liDueTime .u .HighPart = 0 ;
175
+
176
+ /* Create a synchronization Waitable Timer.*/
177
+ hTimer = CreateWaitableTimer ( NULL , FALSE, NULL );
178
+
179
+ configASSERT ( hTimer != NULL );
180
+
181
+ /* Set the Waitable Timer. The timer is set to run periodically at every
182
+ xWaitTimeBetweenTicks milliseconds. */
183
+ configASSERT ( SetWaitableTimer ( hTimer , & liDueTime , xWaitTimeBetweenTicks , NULL , NULL , 0 ) );
184
+
162
185
for ( ;; )
163
186
{
164
187
/* 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
169
- environment. */
170
- if ( portTICK_PERIOD_MS < xMinimumWindowsBlockTime )
171
- {
172
- Sleep ( xMinimumWindowsBlockTime );
173
- }
174
- else
175
- {
176
- Sleep ( portTICK_PERIOD_MS );
177
- }
188
+ variables. */
189
+ WaitForSingleObject ( hTimer , INFINITE );
178
190
179
191
configASSERT ( xPortRunning );
180
192
0 commit comments