1 |
/* |
/* |
2 |
* Copyright (C) 2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2006-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: dev_rtc.c,v 1.3 2006/10/14 23:46:17 debug Exp $ |
* $Id: dev_rtc.c,v 1.5 2006/12/30 13:30:59 debug Exp $ |
29 |
* |
* |
30 |
* An experimental Real-Time Clock device. It can be used to retrieve the |
* An experimental Real-Time Clock device. It can be used to retrieve the |
31 |
* current system time, and to cause periodic interrupts. |
* current system time, and to cause periodic interrupts. |
50 |
#define DEV_RTC_TICK_SHIFT 14 |
#define DEV_RTC_TICK_SHIFT 14 |
51 |
|
|
52 |
struct rtc_data { |
struct rtc_data { |
53 |
int hz; |
struct interrupt irq; |
54 |
int irq_nr; |
int pending_interrupts; |
|
int pending_interrupts; |
|
|
struct timer *timer; |
|
55 |
|
|
56 |
struct timeval cur_time; |
int hz; |
57 |
|
struct timer *timer; |
58 |
|
|
59 |
|
struct timeval cur_time; |
60 |
}; |
}; |
61 |
|
|
62 |
|
|
77 |
struct rtc_data *d = (struct rtc_data *) extra; |
struct rtc_data *d = (struct rtc_data *) extra; |
78 |
|
|
79 |
if (d->pending_interrupts > 0) |
if (d->pending_interrupts > 0) |
80 |
cpu_interrupt(cpu, d->irq_nr); |
INTERRUPT_ASSERT(d->irq); |
81 |
else |
else |
82 |
cpu_interrupt_ack(cpu, d->irq_nr); |
INTERRUPT_DEASSERT(d->irq); |
83 |
} |
} |
84 |
|
|
85 |
|
|
133 |
if (d->pending_interrupts > 0) |
if (d->pending_interrupts > 0) |
134 |
d->pending_interrupts --; |
d->pending_interrupts --; |
135 |
|
|
136 |
cpu_interrupt_ack(cpu, d->irq_nr); |
INTERRUPT_DEASSERT(d->irq); |
137 |
|
|
138 |
/* TODO: Reassert the interrupt here, if |
/* TODO: Reassert the interrupt here, if |
139 |
d->pending_interrupts is still above zero? */ |
d->pending_interrupts is still above zero? */ |
166 |
exit(1); |
exit(1); |
167 |
} |
} |
168 |
memset(d, 0, sizeof(struct rtc_data)); |
memset(d, 0, sizeof(struct rtc_data)); |
169 |
d->irq_nr = devinit->irq_nr; |
|
170 |
|
INTERRUPT_CONNECT(devinit->interrupt_path, d->irq); |
171 |
|
|
172 |
memory_device_register(devinit->machine->memory, devinit->name, |
memory_device_register(devinit->machine->memory, devinit->name, |
173 |
devinit->addr, DEV_RTC_LENGTH, dev_rtc_access, (void *)d, |
devinit->addr, DEV_RTC_LENGTH, dev_rtc_access, (void *)d, |