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

📄 ataiotmr.c

📁 ATADRVR是DOS下的磁盘驱动程序,采用PIO传输 ,PCI DMA传输,ATA包,等非常全面代码示例... 内部有C与Asm描述. 编译环境:Borland C/C++ 4.52 与 Bo
💻 C
字号:
//********************************************************************
// ATA LOW LEVEL I/O DRIVER -- ATAIOTMR.C
//
// by Hale Landis (hlandis@ata-atapi.com)
//
// There is no copyright and there are no restrictions on the use
// of this ATA Low Level I/O Driver code.  It is distributed to
// help other programmers understand how the ATA device interface
// works and it is distributed without any warranty.  Use this
// code at your own risk.
//
// This code is based on the ATA-2, ATA-3 and ATA-4 standards and
// on interviews with various ATA controller and drive designers.
//
// This code has been run on many ATA (IDE) drives and
// MFM/RLL controllers.  This code may be a little
// more picky about the status it sees at various times.  A real
// BIOS probably would not check the status as carefully.
//
// Compile with one of the Borland C or C++ compilers.
//
// This C source file contains functions to access the BIOS
// Time of Day information and to set and check the command
// time out period.
//********************************************************************

#include <dos.h>

#include "ataio.h"

//**************************************************************

long tmr_time_out = 20L;      // max command execution time in seconds

long tmr_cmd_start_time;      // command start time - see the
                              // tmr_set_timeout() and
                              // tmr_chk_timeout() functions.

//*************************************************************
//
// tmr_read_bios_timer() - function to read the BIOS timer
//
//**************************************************************

long tmr_read_bios_timer( void )

{
   long curTime;

   // Pointer to the low order word
   // of the BIOS time of day counter at
   // location 40:6C in the BIOS data area.
   static volatile long far * todPtr = MK_FP( 0x40, 0x6c );

   // loop so we get a valid value without
   // turning interrupts off and on again
   do
   {
      curTime = * todPtr;
   } while ( curTime != * todPtr );
   return curTime;
}

//*************************************************************
//
// tmr_set_timeout() - get the command start time
//
//**************************************************************

void tmr_set_timeout( void )

{

   // get the command start time
   tmr_cmd_start_time = tmr_read_bios_timer();
}

//*************************************************************
//
// tmr_chk_timeout() - check for command timeout.
//
// Gives non-zero return if command has timed out.
//
//**************************************************************

int tmr_chk_timeout( void )

{
   long curTime;

   // get current time
   curTime = tmr_read_bios_timer();

   // if we have passed midnight, restart
   if ( curTime < tmr_cmd_start_time )
   {
      tmr_cmd_start_time = curTime;
      return 0;
   }

   // timed out yet ?
   if ( curTime >= ( tmr_cmd_start_time + ( tmr_time_out * 18L ) ) )
      return 1;      // yes

   // no timeout yet
   return 0;
}

// end ataiotmr.c

⌨️ 快捷键说明

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