Install crosstools into its own directory. Tools dir much cleaner now.
[AROS.git] / test / frequencies.c
blobc1a68becd18d49036b4bdd1cda7d111de5d45260
1 #include <devices/timer.h>
2 #include <exec/execbase.h>
3 #include <dos/dos.h>
4 #include <proto/exec.h>
5 #include <proto/timer.h>
7 #include <stdio.h>
9 int __nocommandline = 1;
11 int main(void)
13 struct MsgPort *mp;
14 struct timerequest *req;
16 printf("exec.library v%u.%u\n", SysBase->LibNode.lib_Version, SysBase->LibNode.lib_Revision);
17 printf("VBlank frequency: %u\n", SysBase->VBlankFrequency);
18 printf("PSU frequency: %u\n", SysBase->PowerSupplyFrequency);
19 printf("EClock frequency: %u\n\n", (unsigned int)SysBase->ex_EClockFrequency);
21 mp = CreateMsgPort();
22 if (mp) {
23 req = (struct timerequest *)CreateIORequest(mp, sizeof(struct timerequest));
24 if (req) {
25 if (!OpenDevice("timer.device", UNIT_VBLANK, &req->tr_node, 0))
27 struct Device *TimerBase = req->tr_node.io_Device;
28 struct EClockVal clock, oclock;
29 struct timeval tv, otv;
30 ULONG seconds;
32 printf("timer.device v%u.%u\n", TimerBase->dd_Library.lib_Version, TimerBase->dd_Library.lib_Revision);
33 printf("EClock frequency reported: %u\n\n", (unsigned int)ReadEClock(&clock));
34 ReadEClock(&clock);
35 GetSysTime(&tv);
36 seconds = tv.tv_secs + 10;
37 while (!(SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) && tv.tv_secs < seconds) {
38 oclock.ev_hi = clock.ev_hi;
39 oclock.ev_lo = clock.ev_lo;
40 otv.tv_secs = tv.tv_secs;
41 otv.tv_micro = tv.tv_micro;
42 ReadEClock(&clock);
43 GetSysTime(&tv);
44 if (oclock.ev_hi > clock.ev_hi || (oclock.ev_hi == clock.ev_hi && oclock.ev_lo > clock.ev_lo)) {
45 printf("\n\nFAIL: EClock old: %08x.%08x new: %08x.%08x\n", (unsigned int)oclock.ev_hi, (unsigned int)oclock.ev_lo, (unsigned int)clock.ev_hi, (unsigned int)clock.ev_lo);
46 break;
48 if (otv.tv_secs > tv.tv_secs || (otv.tv_secs == tv.tv_secs && otv.tv_micro >= tv.tv_micro) || tv.tv_micro >= 1000000) {
49 printf("\n\nFAIL: SysTime old: %u.%06u new: %u.%06u\n", (unsigned int)otv.tv_secs, (unsigned int)otv.tv_micro, (unsigned int)tv.tv_secs, (unsigned int)tv.tv_micro);
50 break;
52 printf("%08x.%08x %u.%06u\r", (unsigned int)clock.ev_hi, (unsigned int)clock.ev_lo, (unsigned int)tv.tv_secs, (unsigned int)tv.tv_micro);
54 printf("\n\n");
56 CloseDevice(&req->tr_node);
58 else
59 printf("Failed to open timer.device!\n");
61 DeleteIORequest(req);
62 } else
63 printf("Failed to create IORequest!\n");
65 DeleteMsgPort(mp);
66 } else
67 printf("Failed to create message port!\n");
69 return 0;