2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _LIBMEINOS_CMOS_H_
20 #define _LIBMEINOS_CMOS_H_
22 #include <sys/types.h>
24 #define CMOS_PORT_ADDRESS 0x70
25 #define CMOS_PORT_DATA 0x71
27 #define CMOS_OFFSET_SECOND 0x00
28 #define CMOS_OFFSET_ALARMSECOND 0x01
29 #define CMOS_OFFSET_MINUTE 0x02
30 #define CMOS_OFFSET_ALARMINUTE 0x03
31 #define CMOS_OFFSET_HOUR 0x04
32 #define CMOS_OFFSET_ALARMHOUR 0x05
33 #define CMOS_OFFSET_DAYOFWEEK 0x06
34 #define CMOS_OFFSET_DAYOFMONTH 0x07
35 #define CMOS_OFFSET_MONTH 0x08
36 #define CMOS_OFFSET_YEAR 0x09
37 #define CMOS_OFFSET_SRA 0x0A
38 #define CMOS_OFFSET_SRB 0x0B
39 #define CMOS_OFFSET_SRC 0x0C
40 #define CMOS_OFFSET_SRD 0x0D
41 #define CMOS_OFFSET_POST 0x0E
42 #define CMOS_OFFSET_SHUTDOWN 0x0F
43 #define CMOS_OFFSET_FDTYPES 0x10
44 #define CMOS_OFFSET_HDTYPES 0x12
45 #define CMOS_OFFSET_DEVICEBYTE 0x14
46 #define CMOS_OFFSET_BASEMEMLOW 0x15
47 #define CMOS_OFFSET_BASEMEMHIGH 0x16
48 #define CMOS_OFFSET_EXTMEMLOW 0x17
49 #define CMOS_OFFSET_EXTMEMHIGH 0x18
50 #define CMOS_OFFSET_CHECKSUMHIGH 0x2E
51 #define CMOS_OFFSET_CHECKSUMLOW 0x2F
52 #define CMOS_OFFSET_CENTURY 0x32
54 #define cmos_bcd2bin(bcd) (((bcd>>4)&0x0F)*10+(bcd&0x0F))
55 #define cmos_bin2bcd(bin) (((bin/10)<<8)+(bin%10))
57 #define cmos_getsecond() cmos_bcd2bin(cmos_read(CMOS_OFFSET_SECOND))
58 #define cmos_getminute() cmos_bcd2bin(cmos_read(CMOS_OFFSET_MINUTE))
59 #define cmos_gethour() cmos_bcd2bin(cmos_read(CMOS_OFFSET_HOUR))
60 #define cmos_getdayofweek() cmos_bcd2bin(cmos_read(CMOS_OFFSET_DAYOFWEEK))
61 #define cmos_getday() cmos_bcd2bin(cmos_read(CMOS_OFFSET_DAYOFMONTH))
62 #define cmos_getmonth() cmos_bcd2bin(cmos_read(CMOS_OFFSET_MONTH))
63 #define cmos_getyear() (cmos_bcd2bin(cmos_read(CMOS_OFFSET_CENTURY))*100+cmos_bcd2bin(cmos_read(CMOS_OFFSET_YEAR)))
65 #define cmos_setsecond(v) cmos_write(CMOS_OFFSET_SECOND,cmos_bin2bcd(v))
66 #define cmos_setminute(v) cmos_write(CMOS_OFFSET_MINUTE,cmos_bin2bcd(v))
67 #define cmos_sethour(v) cmos_write(CMOS_OFFSET_HOUR,cmos_bin2bcd(v))
68 #define cmos_setdayofweek(v) cmos_write(CMOS_OFFSET_DAYOFWEEK,cmos_bin2bcd(v))
69 #define cmos_setday(v) cmos_write(CMOS_OFFSET_DAYOFMONTH,cmos_bin2bcd(v))
70 #define cmos_setmonth(v) cmos_write(CMOS_OFFSET_MONTH,cmos_bin2bcd(v))
71 #define cmos_setyear(v) do { cmos_write(CMOS_OFFSET_YEAR,cmos_bin2bcd(v&0xFF)); cmos_write(CMOS_OFFSET_CENTURY,cmos_bin2bcd((v>>8)&0xFF)); } while(0);
73 #define cmos_getbasemem() ((cmos_read(CMOS_OFFSET_BASEMEMHIGH)<<8)|cmos_read(CMOS_OFFSET_BASEMEMLOW))
74 #define cmos_getextmem() ((cmos_read(CMOS_OFFSET_EXTMEMHIGH)<<8)|cmos_read(CMOS_OFFSET_EXTMEMLOW))
75 #define cmos_getchecksum() ((cmos_read(CMOS_OFFSET_CHECKSUMHIGH)<<8)|cmos_read(CMOS_OFFSET_CHECKSUMLOW))
77 int cmos_read(size_t offset
);
78 void cmos_write(size_t offset
,int val
);