summaryrefslogtreecommitdiff
path: root/os/js/clock.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
commit74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (patch)
treec6e220ba61db3a6ea4052e6841296d829654e664 /os/js/clock.c
parent46439007cf417cbd9ac8049bb4122c890097a0fa (diff)
20060303
Diffstat (limited to 'os/js/clock.c')
-rw-r--r--os/js/clock.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/os/js/clock.c b/os/js/clock.c
new file mode 100644
index 00000000..581ee441
--- /dev/null
+++ b/os/js/clock.c
@@ -0,0 +1,104 @@
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "fns.h"
+#include "io.h"
+
+#include "ureg.h"
+
+typedef struct Clock0link Clock0link;
+typedef struct Clock0link {
+ void (*clock)(void);
+ Clock0link* link;
+} Clock0link;
+
+static Clock0link *clock0link;
+static Lock clock0lock;
+
+void
+microdelay(int ms)
+{
+ int i;
+
+ ms *= 13334; /* experimentally indetermined */
+ for(i=0; i<ms; i++)
+ ;
+}
+
+typedef struct Ctr Ctr;
+struct Ctr
+{
+ ulong lim;
+ ulong ctr;
+ ulong limnr; /* non-resetting */
+ ulong ctl;
+};
+Ctr *ctr;
+
+void
+clockinit(void)
+{
+ KMap *k;
+
+ putphys(TIMECONFIG, 0); /* it's a processor counter */
+ k = kmappa(CLOCK, PTENOCACHE|PTEIO);
+ ctr = (Ctr*)VA(k);
+ ctr->lim = (CLOCKFREQ/HZ)<<10;
+}
+
+void
+clock(Ureg *ur)
+{
+ Clock0link *lp;
+ ulong i;
+
+ USED(ur);
+
+ i = ctr->lim; /* clear interrupt */
+ USED(i);
+ /* is this needed? page 6-43 801-3137-10 suggests so */
+ ctr->lim = (CLOCKFREQ/HZ)<<10;
+
+ m->ticks++;
+
+ if(up)
+ up->pc = ur->pc;
+
+ checkalarms();
+
+ lock(&clock0lock);
+ for(lp = clock0link; lp; lp = lp->link)
+ lp->clock();
+ unlock(&clock0lock);
+
+ if(up && up->state == Running) {
+ if(anyready())
+ sched();
+ }
+}
+
+Timer*
+addclock0link(void (*clockfunc)(void), int)
+{
+ Clock0link *lp;
+
+ if((lp = malloc(sizeof(Clock0link))) == 0){
+ print("addclock0link: too many links\n");
+ return nil;
+ }
+ ilock(&clock0lock);
+ lp->clock = clockfunc;
+ lp->link = clock0link;
+ clock0link = lp;
+ iunlock(&clock0lock);
+ return nil;
+}
+
+uvlong
+fastticks(uvlong *hz)
+{
+ if(hz)
+ *hz = HZ;
+ return m->ticks;
+}