2 Copyright © 2013, The AROS Development Team. All rights reserved
6 #include <exec/types.h>
7 #include <devices/timer.h>
9 #include <proto/exec.h>
10 #include <aros/debug.h>
11 #include <proto/timer.h>
16 BOOL
ata_Calibrate(struct IORequest
* tmr
, struct ataBase
*base
)
19 register ULONG scale
= 0x8000; // min iterations...
20 volatile register ULONG t
= 1;
21 struct timeval t1
, t2
;
22 struct Device
*TimerBase
= tmr
->io_Device
;
24 D(bug("[ATA ] Calibration started\n"));
26 while (scale
<= 0x80000000)
30 for (x
= 1; x
< scale
; x
++)
31 t
= (((t
+ x
) * t
) - x
) / x
; // add, mul, sub, div, trivial benchmark.
37 // ok, it's going to be totally insane, if secs > 1.
40 bug("[ATA ] micro wait useless.\n");
45 * we expect at least 10000 times longer period, which should be 'achievable'
46 * unlikely we will cross the magic boundary here of 4 billion instructions in 10 millisecond (yielding 400'000MIPS?)
47 * 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...
50 if (t2
.tv_micro
>= 10000)
55 D(bug("[ATA ] Executed %ld ops in %ldus\n", scale
, t2
.tv_micro
));
57 // always round up to the next value.. so 30.9 -> 31, 5.1 -> 6, etc
58 x
= (x
+ t2
.tv_micro
- 1) / t2
.tv_micro
;
61 bug("[ATA ] Approximate number of iterations per 100 nanoseconds: %ld\n", x
);
62 base
->ata_ItersPer100ns
= x
;
66 void ata_WaitNano(register ULONG ns
, struct ataBase
*base
)
68 volatile register ULONG t
= 1;
70 ns
*= base
->ata_ItersPer100ns
;
73 t
= (((t
+ ns
) * t
) - ns
) / ns
; // add, mul, sub, div, trivial benchmark.