123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #include <types.h>
- #include <lib.h>
- #include <spl.h>
- #include <clock.h>
- #include <platform/bus.h>
- #include <lamebus/ltimer.h>
- #include "autoconf.h"
- #define LT_REG_SEC 0
- #define LT_REG_NSEC 4
- #define LT_REG_ROE 8
- #define LT_REG_IRQ 12
- #define LT_REG_COUNT 16
- #define LT_REG_SPKR 20
- static bool havetimerclock;
- int
- config_ltimer(struct ltimer_softc *lt, int ltimerno)
- {
-
- (void)ltimerno;
- lt->lt_hardclock = 0;
-
- if (!havetimerclock) {
- havetimerclock = true;
- lt->lt_timerclock = 1;
-
-
- bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_ROE, 1);
- bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_COUNT,
- LT_GRANULARITY);
- }
-
- return 0;
- }
- void
- ltimer_irq(void *vlt)
- {
- struct ltimer_softc *lt = vlt;
- uint32_t val;
- val = bus_read_register(lt->lt_bus, lt->lt_buspos, LT_REG_IRQ);
- if (val) {
-
- if (lt->lt_hardclock) {
- hardclock();
- }
-
- if (lt->lt_timerclock) {
- timerclock();
- }
- }
- }
- void
- ltimer_beep(void *vlt)
- {
- struct ltimer_softc *lt = vlt;
- bus_write_register(lt->lt_bus, lt->lt_buspos, LT_REG_SPKR, 440);
- }
- void
- ltimer_gettime(void *vlt, time_t *secs, uint32_t *nsecs)
- {
- struct ltimer_softc *lt = vlt;
- uint32_t secs1, secs2;
- int spl;
-
- spl = splhigh();
- secs1 = bus_read_register(lt->lt_bus, lt->lt_buspos,
- LT_REG_SEC);
- *nsecs = bus_read_register(lt->lt_bus, lt->lt_buspos,
- LT_REG_NSEC);
- secs2 = bus_read_register(lt->lt_bus, lt->lt_buspos,
- LT_REG_SEC);
- splx(spl);
- if (*nsecs < 5000000) {
- *secs = secs2;
- }
- else {
- *secs = secs1;
- }
- }
|