2 Copyright � 1995-2007, The AROS Development Team. All rights reserved.
8 #include "battclock_intern.h"
11 #include <aros/debug.h>
12 /*****************************************************************************
15 #include <proto/battclock.h>
16 #include <proto/utility.h>
17 #include <proto/exec.h>
18 #include <proto/oop.h>
20 #include <utility/date.h>
21 #include <asm/amcc440.h>
24 AROS_LH1(void, WriteBattClock
,
27 AROS_LHA(ULONG
, time
, D0
),
30 APTR
*, BattClockBase
, 3, Battclock
)
33 Set the systems battery backed up clock to the time specified. The
34 value should be the number of seconds since 00:00:00 on 1.1.1978.
37 time - The number of seconds elapsed since 00:00:00 1.1.1978
40 The clock will be set.
43 This may not do anything on some systems where the battery backed
44 up clock either doesn't exist, or may not be writable.
51 ReadBattClock, ResetBattClock
56 27-11-96 digulla automatically created from
57 battclock_lib.fd and clib/battclock_protos.h
59 *****************************************************************************/
63 struct ClockData date
;
65 OOP_AttrBase __IHidd_I2CDevice
;
67 /* The code here looks more complex than it really is */
69 struct pHidd_I2C_ProbeAddress p
, *msg
=&p
;
70 struct Library
*OOPBase
= OpenLibrary("oop.library", 0);
71 struct Library
*I2CBase
= OpenLibrary("i2c-amcc440.library", 0);
73 Amiga2Date(time
, &date
);
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 */
96 struct TagItem attrs
[] = {
97 { aHidd_I2CDevice_Driver
, (IPTR
)i2c
},
98 { aHidd_I2CDevice_Address
, 0xd0 },
99 { aHidd_I2CDevice_Name
, (IPTR
)"RTC" },
103 OOP_Object
*obj
= OOP_NewObject(NULL
, CLID_Hidd_I2CDevice
, attrs
);
105 D(bug("[BATT] RTC found. Object=%08x\n", obj
));
107 /* i2c device object created. read data now */
110 struct pHidd_I2CDevice_WriteRead msg
;
112 msg
.mID
= OOP_GetMethodID((STRPTR
)IID_Hidd_I2CDevice
, moHidd_I2CDevice_WriteRead
);
113 msg
.readBuffer
= &wb
[1];
115 msg
.writeBuffer
= &wb
[0];
118 OOP_DoMethod(obj
, &msg
.mID
);
122 D(bug("[BATT] Old dump: "));
123 for (i
=1; i
< 8; i
++)
125 D(bug("%02x ", wb
[i
]));
129 /* Data read. Modify the bits and pieces now */
130 wb
[1] = (wb
[1] & 0x80) | (date
.sec
/ 10) << 4 | (date
.sec
% 10);
131 wb
[2] = (date
.min
/ 10) << 4 | (date
.min
% 10);
132 wb
[3] = (wb
[3] & 0xc0) | (date
.hour
/ 10) << 4 | (date
.hour
% 10);
133 wb
[4] = (wb
[4] & 0x80) | (date
.wday
);
134 wb
[5] = (date
.mday
/ 10) << 4 | (date
.mday
% 10);
135 wb
[6] = (date
.month
/ 10) << 4 | (date
.month
% 10);
136 wb
[7] = ((date
.year
- 2000) / 10) << 4 | ((date
.year
- 2000) % 10);
138 D(bug("[BATT] New dump: "));
139 for (i
=1; i
< 8; i
++)
141 D(bug("%02x ", wb
[i
]));
145 /* Write data to RTC */
147 msg
.readBuffer
= NULL
;
149 msg
.writeBuffer
= &wb
[0];
152 OOP_DoMethod(obj
, &msg
.mID
);
154 /* Done with i2c device */
155 OOP_DisposeObject(obj
);
159 /* Done with i2c bus */
160 OOP_DisposeObject(i2c
);
164 OOP_ReleaseAttrBase(IID_Hidd_I2CDevice
);
166 CloseLibrary(OOPBase
);
168 CloseLibrary(I2CBase
);
171 } /* WriteBattClock */