M bitsy/clock.c => bitsy/clock.c +15 -19
@@ 20,6 20,7 @@ OSTimer *timerregs = (OSTimer*)OSTIMERREGS;
static int clockinited;
static void clockintr(Ureg*, void*);
+static uvlong when; /* scheduled time of next interrupt */
enum
{
@@ 34,7 35,7 @@ clockpower(int on)
if (on){
timerregs->ossr |= 1<<0;
timerregs->oier = 1<<0;
- timerregs->osmr[0] = timerregs->oscr + ClockFreq/HZ;
+ timerregs->osmr[0] = timerregs->oscr + Minfreq;
}
clockinited = on;
}
@@ 65,7 66,8 @@ clockinit(void)
(id>>16)&0xff, (id>>4)&0xfff, id&0xf);
/* post interrupt 1/HZ secs from now */
- timerregs->osmr[0] = timerregs->oscr + ClockFreq/HZ;
+ when = timerregs->oscr + Minfreq;
+ timerregs->osmr[0] = when;
timersinit();
@@ 95,35 97,29 @@ fastticks(uvlong *hz)
void
timerset(uvlong v)
{
- ulong when, tics; /* Must be unsigned! */
+ ulong next, tics; /* Must be unsigned! */
static int count;
- if (v == 0LL)
- when = timerregs->oscr + Minfreq;
- else {
- when = v;
+ next = v;
- /* post next interrupt: calculate # of tics from now */
- tics = when - timerregs->oscr - Maxfreq;
- if (tics > Minfreq){
- iprint("%lud %lud %lud %d\n", when, tics, timerregs->oscr, Minfreq);
- when = timerregs->oscr + Maxfreq;
- }
+ /* post next interrupt: calculate # of tics from now */
+ tics = next - timerregs->oscr - Maxfreq;
+ if (tics > Minfreq){
+ iprint("%lud %lud %lud %d\n", next, tics, timerregs->oscr, Minfreq);
+ next = timerregs->oscr + Maxfreq;
}
- timerregs->osmr[0] = when;
+ timerregs->osmr[0] = next;
}
static void
clockintr(Ureg *ureg, void*)
{
- static ulong count;
-
/* reset previous interrupt */
timerregs->ossr |= 1<<0;
+ when += Minfreq;
+ timerregs->osmr[0] = when; /* insurance */
- timerset(timerintr(ureg, nil));
- if ((count++ % 100) == 0)
- iprint("%lud ", timerregs->osmr[0] - timerregs->oscr);
+ timerintr(ureg, when);
}
void
M bitsy/fns.h => bitsy/fns.h +1 -1
@@ 103,7 103,7 @@ uchar* tarlookup(uchar*, char*, int*);
void timersinit(void);
void timeradd(Timer*);
void timerdel(Timer*);
-uvlong timerintr(Ureg *, void*);
+void timerintr(Ureg *, uvlong);
void timerset(uvlong);
void touser(void*);
void trapdump(char *tag);
M bitsy/power.c => bitsy/power.c +4 -4
@@ 173,7 173,7 @@ deepsleep(void) {
screenpower(0);
µcpower(0);
iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%ux\n", &xsp, xlink, power_pl);
- dumpitall();
+// dumpitall();
delay(1000);
uartpower(0);
rs232power(0);
@@ 206,7 206,7 @@ deepsleep(void) {
delay(100);
xlink = getcallerpc(&xlink);
iprint("\nresuming execution, sp = 0x%lux, pc = 0x%lux, psw = 0x%ux\n", &xsp, xlink, splhi());
- dumpitall();
+// dumpitall();
delay(1000);
// irpower(1);
// audiopower(1);
@@ 232,11 232,11 @@ powerkproc(void*)
xlink = getcallerpc(&xlink);
- iprint("call deepsleep, pc = 0x%lux, sp = 0x%lux\n", xlink, &xlink);
+// iprint("call deepsleep, pc = 0x%lux, sp = 0x%lux\n", xlink, &xlink);
deepsleep();
xlink1 = getcallerpc(&xlink1);
- iprint("deepsleep returned, pc = 0x%lux, sp = 0x%lux\n", xlink1, &xlink);
+// iprint("deepsleep returned, pc = 0x%lux, sp = 0x%lux\n", xlink1, &xlink);
delay(2000);