25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_rtc.c,v 1.5 2006/12/30 13:30:59 debug Exp $ |
* $Id: dev_rtc.c,v 1.7 2007/06/15 19:57:34 debug Exp $ |
29 |
* |
* |
30 |
* An experimental Real-Time Clock device. It can be used to retrieve the |
* COMMENT: A generic Real-Time Clock device, for the test machines |
31 |
* current system time, and to cause periodic interrupts. |
* |
32 |
|
* It can be used to retrieve the current system time, and to cause periodic |
33 |
|
* interrupts. |
34 |
*/ |
*/ |
35 |
|
|
36 |
#include <stdio.h> |
#include <stdio.h> |
76 |
|
|
77 |
DEVICE_TICK(rtc) |
DEVICE_TICK(rtc) |
78 |
{ |
{ |
79 |
struct rtc_data *d = (struct rtc_data *) extra; |
struct rtc_data *d = extra; |
80 |
|
|
81 |
if (d->pending_interrupts > 0) |
if (d->pending_interrupts > 0) |
82 |
INTERRUPT_ASSERT(d->irq); |
INTERRUPT_ASSERT(d->irq); |
87 |
|
|
88 |
DEVICE_ACCESS(rtc) |
DEVICE_ACCESS(rtc) |
89 |
{ |
{ |
90 |
struct rtc_data *d = (struct rtc_data *) extra; |
struct rtc_data *d = extra; |
91 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
92 |
|
|
93 |
if (writeflag == MEM_WRITE) |
if (writeflag == MEM_WRITE) |
161 |
|
|
162 |
DEVINIT(rtc) |
DEVINIT(rtc) |
163 |
{ |
{ |
164 |
struct rtc_data *d = malloc(sizeof(struct rtc_data)); |
struct rtc_data *d; |
165 |
|
|
166 |
if (d == NULL) { |
CHECK_ALLOCATION(d = malloc(sizeof(struct rtc_data))); |
|
fprintf(stderr, "out of memory\n"); |
|
|
exit(1); |
|
|
} |
|
167 |
memset(d, 0, sizeof(struct rtc_data)); |
memset(d, 0, sizeof(struct rtc_data)); |
168 |
|
|
169 |
INTERRUPT_CONNECT(devinit->interrupt_path, d->irq); |
INTERRUPT_CONNECT(devinit->interrupt_path, d->irq); |
173 |
DM_DEFAULT, NULL); |
DM_DEFAULT, NULL); |
174 |
|
|
175 |
machine_add_tickfunction(devinit->machine, |
machine_add_tickfunction(devinit->machine, |
176 |
dev_rtc_tick, d, DEV_RTC_TICK_SHIFT, 0.0); |
dev_rtc_tick, d, DEV_RTC_TICK_SHIFT); |
177 |
|
|
178 |
return 1; |
return 1; |
179 |
} |
} |