timer.c

来自「一个微型操作系统源码」· C语言 代码 · 共 59 行

C
59
字号
/* * timer.c - OSV timer driver * * OSV * Copyright (C) 2002 Ciprian DOSOFTEI <rocksoul@mail.com> * All rights reserved. *  * http://backster.free.fr/osv * * This file is part of the OSV project. OSV is free software, also known as * "open source"; you can redistribute it and/or modify it under the terms  * of the GNU General Public License (GPL), version 2, as published by the Free * Software Foundation (FSF). To explore alternate licensing terms, contact  * the author at rocksoul@mail.com or +40740649907. *  * OSV is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have * received a copy of the GPL along with OSV; see the file COPYING.  If * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. */#include <timer.h>#include <types.h>#include <asm/io.h>dword TIMER_count; static void setPITfreq (const dword);void initTimer () {  TIMER_count = 0;  setPITfreq (1000 / INTERVALSIZE);}static void setPITfreq (const dword hz) {  word tmp;  PIT_CONTROL control;  tmp = 1193180 / hz;  control.fields.counting_style = PIT_CSTYLE_16_BITS;  control.fields.counter_mode = PIT_CM_MODE3;  control.fields.counter_access = PIT_CA_RW_0_7_8_15;  control.fields.counter_select = PIT_CSEL_COUNTER0;  outb(PIT_CONTROL_REG, control.value);   outb(PIT_COUNTER0_REG, LOW_BYTE(tmp));  outb(PIT_COUNTER0_REG, HI_BYTE(tmp));}void delay_msec (const dword msec) {  dword old_count;  old_count = TIMER_count;  while (TIMER_count - old_count < msec)    ;}dword get_count () {  return TIMER_count;}

⌨️ 快捷键说明

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