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

📄 timer.c

📁 raywill写的操作系统内核
💻 C
字号:
#include <maray/type.h>
#include <i386/vector.h>
#include <i386/irq.h>
#include <i386/timer.h>
#include <maray/tty.h>
#include <asmcmd.h>
#include <libc.h>
/*'tick' time elapse*/
int timefly;

static void timer_irq();

/*
*how do we init timer:
*		1.init the timer frequency
*		2.set the timer irq routine.
*		3.enable timer
*/
void init_timer()
{
		int max;
		vector_t v;

	  timefly=0;
	
		/*00,use IRQ timer,00:read 2 bytes,low &high;
		  011,mode 3(square wave);0,binary mode*/
		max=SHED_RREQ;				/*set to 10ms */
		outportb(0x43,0x36);	/*0000110110b=0x36*/
		outportb(0x40, max & 0xff);//LSB
		outportb( 0x40,max >> 8 );//MSB
		
		//install the timer handler
   	v.eip = (unsigned)timer_irq;
	  v.access_byte = 0x8E; /* present, ring 0, '386 interrupt gate D=32bit gate*/
		setvect(&v, 0x20);
}

void enable_timer()
{
	enable_irq(TIMER_IRQ);
}

void disable_timer()
{
	disable_irq(TIMER_IRQ);
}


/*
*route of the timer irq.
*scheduler will goes from here.
*/	
static void timer_irq()
{
	timefly++;
	if(timefly%10==0)
	{
		char buf[20];
		int oldx,oldy;
		cli();
		getxy(&oldx,&oldy);
		gotoxy(60,23);
		print(itoa((int)timefly,buf));
		gotoxy(50,21);
		print( timetostr(update_sys_time(timefly),buf) );
		gotoxy(oldx,oldy);
		sti();			
	}
	outportb(0x20,0x20);
}

⌨️ 快捷键说明

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