]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/bcm/clock.c
merge
[plan9front.git] / sys / src / 9 / bcm / clock.c
index f67209bdf74b465b9a94f8ce6985a6c94f4b0b9d..168eac9eb025d79001873fbab0195f49a9743dad 100644 (file)
@@ -28,7 +28,6 @@ enum {
 
        Localctl        = 0x00,
        Prescaler       = 0x08,
-       Localintpending = 0x60,
 
        SystimerFreq    = 1*Mhz,
        MaxPeriod       = SystimerFreq / HZ,
@@ -98,7 +97,6 @@ localclockintr(Ureg *ureg, void *)
 {
        if(m->machno == 0)
                panic("cpu0: Unexpected local generic timer interrupt");
-       cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask|Enable);
        timerintr(ureg, 0);
 }
 
@@ -109,10 +107,6 @@ clockshutdown(void)
 
        tm = (Armtimer*)ARMTIMER;
        tm->ctl = 0;
-       if(cpuserver)
-               wdogfeed();
-       else
-               wdogoff();
 }
 
 void
@@ -120,15 +114,22 @@ clockinit(void)
 {
        Systimers *tn;
        Armtimer *tm;
-       u32int t0, t1, tstart, tend;
+       ulong t0, t1, tstart, tend;
 
        if(((cprdsc(0, CpID, CpIDfeat, 1) >> 16) & 0xF) != 0) {
                /* generic timer supported */
+               cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysval, ~0);
                if(m->machno == 0){
-                       *(ulong*)(ARMLOCAL + Localctl) = 0;                             /* input clock is 19.2Mhz crystal */
-                       *(ulong*)(ARMLOCAL + Prescaler) = 0x06aaaaab;   /* divide by (2^31/Prescaler) for 1Mhz */
+                       cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
+
+                       /* input clock is 19.2Mhz crystal */
+                       *(ulong*)(ARMLOCAL + Localctl) = 0;
+                       /* divide by (2^31/Prescaler) */
+                       *(ulong*)(ARMLOCAL + Prescaler) = (((uvlong)SystimerFreq<<31)/19200000)&~1UL;
+               } else {
+                       cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Enable);
+                       intrenable(IRQcntpns, localclockintr, nil, BUSUNKNOWN, "clock");
                }
-               cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Imask);
        }
 
        tn = (Systimers*)SYSTIMERS;
@@ -136,7 +137,7 @@ clockinit(void)
        do{
                t0 = lcycles();
        }while(tn->clo == tstart);
-       tend = tstart + 10000;
+       tend = tstart + (SystimerFreq/100);
        do{
                t1 = lcycles();
        }while(tn->clo != tend);
@@ -144,14 +145,15 @@ clockinit(void)
        m->cpuhz = 100 * t1;
        m->cpumhz = (m->cpuhz + Mhz/2 - 1) / Mhz;
        m->cyclefreq = m->cpuhz;
+
        if(m->machno == 0){
                tn->c3 = tn->clo - 1;
+               intrenable(IRQtimer3, clockintr, nil, BUSUNKNOWN, "clock");
+
                tm = (Armtimer*)ARMTIMER;
                tm->load = 0;
                tm->ctl = TmrPrescale1|CntEnable|CntWidth32;
-               intrenable(IRQtimer3, clockintr, nil, 0, "clock");
-       }else
-               intrenable(IRQcntpns, localclockintr, nil, 0, "clock");
+       }
 }
 
 void
@@ -167,10 +169,9 @@ timerset(uvlong next)
                period = MinPeriod;
        else if(period > MaxPeriod)
                period = MaxPeriod;
-       if(m->machno > 0){
+       if(m->machno)
                cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysval, period);
-               cpwrsc(0, CpTIMER, CpTIMERphys, CpTIMERphysctl, Enable);
-       }else{
+       else{
                tn = (Systimers*)SYSTIMERS;
                tn->c3 = tn->clo + period;
        }
@@ -230,14 +231,10 @@ ulong
 void
 microdelay(int n)
 {
-       Systimers *tn;
-       u32int now, diff;
+       ulong now;
 
-       diff = n + 1;
-       tn = (Systimers*)SYSTIMERS;
-       now = tn->clo;
-       while(tn->clo - now < diff)
-               ;
+       now = µs();
+       while(µs() - now < n);
 }
 
 void