timer.c

来自「嵌入式系统基础课件」· C语言 代码 · 共 48 行

C
48
字号
/* ============================================================ */
/* File: TIMER.C						*/
/*								*/
/* Copyright (C) 2001, Daniel W. Lewis and Prentice-Hall	*/
/*								*/
/* Purpose: Library routines for access to the 8253 timer.	*/
/* See file LIBEPC.H for function descriptions.			*/
/*								*/
/* Designed for use with the DJGPP port of the GNU C/C++	*/
/* protected mode 386 compiler.					*/
/*								*/
/* Modification History:					*/
/*								*/
/* ============================================================ */

#include "libepc.h"

extern	void	TimerTickISR(void)	__asm__("TimerTickISR")	;
extern	DWORD32	msec			__asm__("msec")		;
extern	ISR	old_tick_isr		__asm__("old_tick_isr")	;

PRIVATE void InstallTimerTickISR(void)
	{
	static BOOL virgin = TRUE ;

	if (virgin)
		{
		old_tick_isr = GetISR(IRQ2INT(IRQ_TICK)) ;
		SetISR(IRQ2INT(IRQ_TICK), TimerTickISR) ;
		outportb(0x21, inportb(0x21) & ~0x01) ;
		STI ;
		virgin = FALSE ;
		}
	}

DWORD32 Milliseconds(void)
	{
	InstallTimerTickISR() ;
	return msec ;
	}

DWORD32 Now_Plus(int seconds)
	{
	InstallTimerTickISR() ;
	return msec + 1000 * seconds ;
	}

⌨️ 快捷键说明

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