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

📄 drvsleep.c

📁 WinCE5.0BSP for Renesas SH7770
💻 C
字号:
//
//  Copyright(C) Renesas Technology Corp. 1998-2003. All rights reserved.
//
//  DrvLib for ITS-DS7
//
//  FILE      : drvsleep.c
//  CREATED   : 1999.04.26
//  MODIFIED  : 2003.06.20
//  AUTHOR    : Renesas Technology Corp.
//  HARDWARE  : RENESAS ITS-DS7
//  HISTORY   : 
//              2003.06.20
//              - Created release code.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.
Copyright (c) 1995-2000 Microsoft Corporation.  All rights reserved.

Module Name:  

  drvsleep.c

Abstract:  

  This module contains the implementation of DriverSleep(), which
  is used when delays are needed within power handling routines, where
  no system calls are allowed.  The SH3 implementation polls the free
  running timer to implement a delay.
  
Functions:

  DriverSleep
  
Notes:

Revision History:

  Glenn Davis 4/1/97

--*/

#include <windows.h>
#include "shx.h"
#include "platform.h"
#include "sh7770.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 + -