2 Copyright � 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: ReadBattClock() function.
8 #include "battclock_intern.h"
11 #include <aros/debug.h>
13 /*****************************************************************************
16 #include <proto/battclock.h>
17 #include <proto/utility.h>
18 #include <proto/exec.h>
19 #include <proto/oop.h>
21 #include <utility/date.h>
22 #include <asm/amcc440.h>
24 AROS_LH0(ULONG
, ReadBattClock
,
30 struct BattClockBase
*, BattClockBase
, 2, Battclock
)
33 Return the value stored in the battery back up clock. This value
34 is the number of seconds that have elapsed since midnight on the
35 1st of January 1978 (00:00:00 1.1.1978).
37 If the value of the battery clock is invalid, then the clock will
43 The number of seconds since 1.1.1978 00:00:00
52 WriteBattClock, ResetBattClock
57 27-11-96 digulla automatically created from
58 battclock_lib.fd and clib/battclock_protos.h
60 *****************************************************************************/
64 struct ClockData date
;
67 OOP_AttrBase __IHidd_I2CDevice
;
69 /* The code here looks more complex than it really is */
71 struct pHidd_I2C_ProbeAddress p
, *msg
=&p
;
72 struct Library
*OOPBase
= OpenLibrary("oop.library", 0);
73 struct Library
*I2CBase
= OpenLibrary("i2c-amcc440.library", 0);
75 __IHidd_I2CDevice
= OOP_ObtainAttrBase(IID_Hidd_I2CDevice
);
78 i2c
= OOP_NewObject(NULL
, CLID_I2C_AMCC440
, NULL
);
80 p
.mID
= OOP_GetMethodID((STRPTR
)IID_Hidd_I2C
, moHidd_I2C_ProbeAddress
);
82 D(bug("[BATT] i2c=%08x\n", i2c
));
86 /* i2c class successfully created. Probe for RTC on the bus... */
87 D(bug("[BATT] Probing i2c RTC...\n"));
91 if (OOP_DoMethod(i2c
, (OOP_Msg
) msg
))
93 /* Got it. Now read the data (7 bytes) from address 1 in RTC */
97 struct TagItem attrs
[] = {
98 { aHidd_I2CDevice_Driver
, (IPTR
)i2c
},
99 { aHidd_I2CDevice_Address
, 0xd0 },
100 { aHidd_I2CDevice_Name
, (IPTR
)"RTC" },
104 OOP_Object
*obj
= OOP_NewObject(NULL
, CLID_Hidd_I2CDevice
, attrs
);
106 D(bug("[BATT] RTC found. Object=%08x\n", obj
));
108 /* i2c device object created. read data now */
111 struct pHidd_I2CDevice_WriteRead msg
;
113 msg
.mID
= OOP_GetMethodID((STRPTR
)IID_Hidd_I2CDevice
, moHidd_I2CDevice_WriteRead
);
114 msg
.readBuffer
= &data
[0];
116 msg
.writeBuffer
= &wb
[0];
119 OOP_DoMethod(obj
, &msg
.mID
);
123 D(bug("[BATT] Dump: "));
124 for (i
=0; i
< 7; i
++)
126 D(bug("%02x ", data
[i
]));
130 /* Ok, let's hope data was successfuly read from RTC. Convert it to ClockDate structure */
131 date
.year
= 2000 + (data
[6] & 0xf) + 10*(data
[6] >> 4);
132 date
.month
= (data
[5] & 0xf) + (data
[5] >> 4)*10;
133 date
.mday
= (data
[4] & 0xf) + (data
[4] >> 4)*10;
134 date
.hour
= (data
[2] & 0xf) + ((data
[2] & 0x30) >> 4)*10;
135 date
.min
= (data
[1] & 0xf) + ((data
[1] & 0x70) >> 4)*10;
136 date
.sec
= (data
[0] & 0xf) + ((data
[0] & 0x70) >> 4)*10;
138 /* Done with i2c device */
139 OOP_DisposeObject(obj
);
143 /* Done with i2c bus */
144 OOP_DisposeObject(i2c
);
146 secs
=Date2Amiga(&date
);
150 OOP_ReleaseAttrBase(IID_Hidd_I2CDevice
);
152 CloseLibrary(OOPBase
);
154 CloseLibrary(I2CBase
);
159 } /* ReadBattClock */