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

📄 timer.c

📁 用于汇编领域的,运用于OS的MAIN函数.基于硬件基础的源代码
💻 C
字号:
#include "hos.h"void timer_isr(void);unsigned long systick;void timer_handler(void){	systick++;	// decrease counter of current	current->counter--;	if (!current->counter){// switch		current->counter=INIT_COUNTER; // restore it		/*		current=next_p(); // select next process		// change stack		__asm__("movl %0, %%esp\n\t"			: : "m"(current->esp));			*/		current->need_reschedule=1;	}	outbyte(0x20, 0x20);	/* EOI to Master */	outbyte(0xA0, 0x20);	/* EOI to Slave */}void init_timer(void){	int temp = 1193180 / HZ;	outbyte(MODECTRL, S_CNTR0 | RWLSB_MSB | TIMER_MODE3);	outbyte(TIMER_PORT0, (temp & 0xFF));	outbyte(TIMER_PORT0, ((temp >> 8) & 0xFF));	systick = 0;	set_intr_gate(0x20, &timer_isr);	unmask_irq(0);}void delay(int TenMillisecond){   int before = systick;   int after;   while(1){      after = systick;	  if (before > after){	     before = systick;		 continue;	  }	  if ((before+TenMillisecond)==after)	     break;  }}

⌨️ 快捷键说明

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