📄 cmostime.c
字号:
/** Snixos Project version 1.0, 2003.6* (C) Copyright 2003,2004,2005 Jockeyson,KeqiangGao <Snallie@tom.com>* All Rights Reserved.* Distributed under the terms of the GNU General Public License.** This program is a free and open source software and you can redistribute * it and/or modify it under the terms of the GNU General Public License as* published by the Free Software Foundation. As no any liability is assumed * for any incidental or consequential damages in connection with the * information or program fragments contained herein,so any exception arised* is at your own risk. It is ABSOLUTELY WITHOUT ANY WARRANTY.* Bug report please send to Snallie@tom.com .*//* cmostime.c: get system time from cmos Author : snallie@tom.com Time : 2003.6*/#include "cmostime.h"#include "io.h"#define GETCMOS(addr) ({ \outb_delay(0x80|addr,0x70); \inb_delay(0x71); \})/* cmose index address */#define CMOS_SEC 0x0#define CMOS_MIN 0x2#define CMOS_HOUR 0x4#define CMOS_WEEKDAY 0x6#define CMOS_DAY 0x7#define CMOS_MONTH 0x8#define CMOS_YEAR 0x9#define BCD_TO_BINARY(val) ((val)=((val)&15) + ((val)>>4)*10)#define CENTURY 20char *weekName[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };void getTime(struct tm *cmosTime){ cmosTime->sec = GETCMOS(CMOS_SEC); cmosTime->min = GETCMOS(CMOS_MIN); cmosTime->hour = GETCMOS(CMOS_HOUR); cmosTime->dayofweek = GETCMOS(CMOS_WEEKDAY); cmosTime->day = GETCMOS(CMOS_DAY); cmosTime->month = GETCMOS(CMOS_MONTH); cmosTime->year = GETCMOS(CMOS_YEAR); BCD_TO_BINARY(cmosTime->sec); BCD_TO_BINARY(cmosTime->min); BCD_TO_BINARY(cmosTime->hour); BCD_TO_BINARY(cmosTime->day); BCD_TO_BINARY(cmosTime->month); BCD_TO_BINARY(cmosTime->year); cmosTime->weekname = weekName[cmosTime->dayofweek - 1]; //cmosTime->month--; cmosTime->year += CENTURY * 100;}void cmosDelay(const int sec){ struct tm time; int count, old_sec; count = sec; getTime(&time); old_sec = time.sec; while (count) { getTime(&time); if ((old_sec + 1) % 60 == time.sec) { count--; old_sec = time.sec; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -