⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drvsleep.c

📁 WinCE 3.0 BSP, 包含Inter SA1110, Intel_815E, Advantech_PCM9574 等
💻 C
字号:
/*

  Copyright(c) 1998,1999 SIC/Hitachi,Ltd.

	Module Name:

		drvsleep.c

	Revision History:

		26th April 1999		Released

*/
#include <windows.h>
#include "shx.h"
#include "platform.h"

/*  DriverSleep
 *
 *  Use SH4 TM0 timer to implement a busy-wait delay, for use by drivers
 *  during power handler functions.
 * 
 *  The following assumptions are made when calling from a power
 *  handler routine:
 *     -- Processor is in kernel mode (so we can access mem directly)
 *     -- We're non preemptible.  Otherwise, we'll get swapped out and
 *        delay could be longer than specified.
 */
void
DriverSleep(DWORD dwMS, BOOL bInPowerHandler)
{
    DWORD TicksRemaining, Constant, CurCount, PrevCount, Delta;
    
    /*
     * If we're not in a power handler, use Sleep to block our
     * thread and let others run.  Note that Sleep() currently
     * is not very accurate for low values - the minimum sleep
     * interval is at least one system tick (25 ms).
     */
    if (!bInPowerHandler) {
        Sleep(dwMS);
        return;
     }

    TicksRemaining = dwMS / 1000 + 1; // fairly close
    Constant = READ_REGISTER_ULONG(TMU_TCOR0);
    PrevCount = READ_REGISTER_ULONG(TMU_TCNT0);

    while (1) {
        CurCount = READ_REGISTER_ULONG(TMU_TCNT0);

        // Check for wrap
        Delta = (PrevCount >= CurCount)? PrevCount - CurCount : PrevCount + Constant - CurCount + 1;
        if (Delta >= TicksRemaining)
            break;
        TicksRemaining -= Delta;
        PrevCount = CurCount;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -