//------------------------------------------------------------------------------------------------------------------------------------------ // Modification by: Alfredo Rainho Neves // This is an updated version that will actually responde a few thousand times // a second. // The CPU load will show very high, but the routine actualy yield // giving other tasks a chance. In a multicore CPU only one core will have // a 100% CPU usage static DWORD WINAPI prvSimulatedPeripheralTimer( LPVOID lpParameter ) { LARGE_INTEGER lpFrequency; LARGE_INTEGER startTime; LARGE_INTEGER currentTime; unsigned long countPerTick; unsigned long elapsed; /* Just to prevent compiler warnings. */ ( void ) lpParameter; // Get the performance counter frequency QueryPerformanceFrequency(&lpFrequency); // Calculate the count per ticks countPerTick = lpFrequency.LowPart / configTICK_RATE_HZ; while(1) { // Get the start time QueryPerformanceCounter(&startTime); // Wait for time period to elapse do { // Yield to another task to make the system more responsive Sleep(0); // Get the current time QueryPerformanceCounter(¤tTime); // Calculate the elpased time elapsed = currentTime.LowPart - startTime.LowPart; } while (elapsed < countPerTick); WaitForSingleObject( pvInterruptEventMutex, INFINITE ); /* The timer has expired, generate the simulated tick event. */ ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK ); /* The interrupt is now pending - notify the simulated interrupt handler thread. */ SetEvent( pvInterruptEvent ); /* Give back the mutex so the simulated interrupt handler unblocks and can access the interrupt handler variables. */ ReleaseMutex( pvInterruptEventMutex ); } #ifdef __GNUC__ /* Should never reach here - MingW complains if you leave this line out, MSVC complains if you put it in. */ return 0; #endif }