changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: bcm: cleanup clock code

changeset 6850: c3a500ff9c5f
parent 6849: d340bc23fc98
child 6851: 817828d0da99
author: cinap_lenrek@felloff.net
date: Sun, 28 Oct 2018 06:09:05 +0100
files: sys/src/9/bcm/clock.c
description: bcm: cleanup clock code

- disable local clock on interrupt to prevent accidents when reenabling
- always regitster local clock interrupt handler, even for cpu0
- simplify microdelay()
- don't mess with watchdog
     1.1--- a/sys/src/9/bcm/clock.c
     1.2+++ b/sys/src/9/bcm/clock.c
     1.3@@ -98,7 +98,7 @@ localclockintr(Ureg *ureg, void *)
     1.4 {
     1.5 	if(m->machno == 0)
     1.6 		panic("cpu0: Unexpected local generic timer interrupt");
     1.7-	cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask|Enable);
     1.8+	cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
     1.9 	timerintr(ureg, 0);
    1.10 }
    1.11 
    1.12@@ -109,10 +109,6 @@ clockshutdown(void)
    1.13 
    1.14 	tm = (Armtimer*)ARMTIMER;
    1.15 	tm->ctl = 0;
    1.16-	if(cpuserver)
    1.17-		wdogfeed();
    1.18-	else
    1.19-		wdogoff();
    1.20 }
    1.21 
    1.22 void
    1.23@@ -125,10 +121,11 @@ clockinit(void)
    1.24 	if(((cprdsc(0, CpID, CpIDfeat, 1) >> 16) & 0xF) != 0) {
    1.25 		/* generic timer supported */
    1.26 		if(m->machno == 0){
    1.27-			*(ulong*)(ARMLOCAL + Localctl) = 0;				/* input clock is 19.2Mhz crystal */
    1.28+			*(ulong*)(ARMLOCAL + Localctl) = 0;		/* input clock is 19.2Mhz crystal */
    1.29 			*(ulong*)(ARMLOCAL + Prescaler) = 0x06aaaaab;	/* divide by (2^31/Prescaler) for 1Mhz */
    1.30 		}
    1.31 		cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
    1.32+		intrenable(IRQcntpns, localclockintr, nil, 0, "clock");
    1.33 	}
    1.34 
    1.35 	tn = (Systimers*)SYSTIMERS;
    1.36@@ -150,8 +147,7 @@ clockinit(void)
    1.37 		tm->load = 0;
    1.38 		tm->ctl = TmrPrescale1|CntEnable|CntWidth32;
    1.39 		intrenable(IRQtimer3, clockintr, nil, 0, "clock");
    1.40-	}else
    1.41-		intrenable(IRQcntpns, localclockintr, nil, 0, "clock");
    1.42+	}
    1.43 }
    1.44 
    1.45 void
    1.46@@ -230,14 +226,10 @@ ulong
    1.47 void
    1.48 microdelay(int n)
    1.49 {
    1.50-	Systimers *tn;
    1.51-	u32int now, diff;
    1.52+	ulong now;
    1.53 
    1.54-	diff = n + 1;
    1.55-	tn = (Systimers*)SYSTIMERS;
    1.56-	now = tn->clo;
    1.57-	while(tn->clo - now < diff)
    1.58-		;
    1.59+	now = µs();
    1.60+	while(µs() - now < n);
    1.61 }
    1.62 
    1.63 void