2 Copyright © 2013, The AROS Development Team. All rights reserved
6 #include <aros/debug.h>
8 #include <proto/exec.h>
10 /* We want all other bases obtained from our base */
13 #include <proto/timer.h>
15 #include <exec/types.h>
16 #include <devices/timer.h>
22 BOOL
ata_Calibrate(struct IORequest
* tmr
, struct ataBase
*base
)
25 register ULONG scale
= 0x8000; // min iterations...
26 volatile register ULONG t
= 1;
27 struct timeval t1
, t2
;
28 struct Device
*TimerBase
= tmr
->io_Device
;
30 D(bug("[ATA ] Calibration started\n"));
32 while (scale
<= 0x80000000)
36 for (x
= 1; x
< scale
; x
++)
37 t
= (((t
+ x
) * t
) - x
) / x
; // add, mul, sub, div, trivial benchmark.
43 // ok, it's going to be totally insane, if secs > 1.
46 bug("[ATA ] micro wait useless.\n");
51 * we expect at least 10000 times longer period, which should be 'achievable'
52 * unlikely we will cross the magic boundary here of 4 billion instructions in 10 millisecond (yielding 400'000MIPS?)
53 * on the other side, if we go as low as 1, then 4 iterations of add/sub/mul/div is perfectly fine yielding a bit more than 400ns...
56 if (t2
.tv_micro
>= 10000)
61 D(bug("[ATA ] Executed %ld ops in %ldus\n", scale
, t2
.tv_micro
));
63 // always round up to the next value.. so 30.9 -> 31, 5.1 -> 6, etc
64 x
= (x
+ t2
.tv_micro
- 1) / t2
.tv_micro
;
67 bug("[ATA ] Approximate number of iterations per 100 nanoseconds: %ld\n", x
);
68 base
->ata_ItersPer100ns
= x
;
72 void ata_WaitNano(register ULONG ns
, struct ataBase
*base
)
74 volatile register ULONG t
= 1;
76 ns
*= base
->ata_ItersPer100ns
;
79 t
= (((t
+ ns
) * t
) - ns
) / ns
; // add, mul, sub, div, trivial benchmark.