Port-amiga archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Keyboard lockup with NetBSD5



Michael L. Hitch wrote:

>    Actually, I think the timecounter code could have affected this.
>     The delay() routine was completely rewritten.  I'm not sure how
> accurate the old version was, or how accurate the new one is.

I would have assumed that delay() works, because the rest of the system
seems to function correctly. But now as you mention it, I had a closer look
on delay(). And after a few minutes I came to the conclusion that either I
don't understand the routine, or there is something wrong with it:

while (remaining > 0) {
        cur_tick = clk_gettick();
        if (cur_tick > initial_tick)
                remaining -= amiga_clk_interval - (cur_tick - initial_tick);
        else
                remaining -= initial_tick - cur_tick;
        initial_tick = cur_tick;
}

Let's assume, for simplicity, amiga_clk_interval is 1000. Then clk_gettick()
returns a monotonically increasing value from 0 to 999.

remaining is the number of ticks to wait and initial_tick was determined at
function entry.

Example 1: initial_tick was determined as 999, then the counter continues to
run and we get a cur_tick of 1. As cur_tick is not greater than
initial_tick, remaining will be decreased by initial_tick-cur_tick => 998,
although the counter only run for 2 ticks! That's wrong!

Example 2: Now initial_tick is 1, the next cur_tick is 2. This time cur_tick
is greater than initial_tick and remaining gets decremented by
amiga_clk_interval-(cur_tick-initial_tick) => 1000-(2-1) => 997. Wrong
again!

Seems that the author of the delay() function had a decreasing tick counter
in mind...

When I am right that this here is wrong, it would explain the keyboard
timing problems partly. ;)


>    Re that 2000 usec delay used apparently came from me when the Amiga
>    1200 support was added.  Presumably that was needed to make the 1200
> I had access to at the time,

Did you ever find out why it was necessary? In the AmigaOS source a
handshaking delay of 85us is used, as recommended in the Hardware Reference
Manual, and it works fine for all A1200 models.

-- 
    _  Frank Wille (frank%phoenix.owl.de@localhost)
 _ //  http://sun.hasenbraten.de/~frank/
 \X/   Phx @ #AmigaGer



Home | Main Index | Thread Index | Old Index