forgotten commit.
[AROS.git] / test / frequencies.c
blobb50c4dfbb1b048114ce62de7d1d13da7a5e88677
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <devices/timer.h>
7 #include <exec/execbase.h>
8 #include <dos/dos.h>
9 #include <proto/exec.h>
10 #include <proto/timer.h>
12 #include <stdio.h>
14 int __nocommandline = 1;
16 int main(void)
18 struct MsgPort *mp;
19 struct timerequest *req;
21 printf("exec.library v%u.%u\n", SysBase->LibNode.lib_Version, SysBase->LibNode.lib_Revision);
22 printf("VBlank frequency: %u\n", SysBase->VBlankFrequency);
23 printf("PSU frequency: %u\n", SysBase->PowerSupplyFrequency);
24 printf("EClock frequency: %u\n\n", (unsigned int)SysBase->ex_EClockFrequency);
26 mp = CreateMsgPort();
27 if (mp) {
28 req = (struct timerequest *)CreateIORequest(mp, sizeof(struct timerequest));
29 if (req) {
30 if (!OpenDevice("timer.device", UNIT_VBLANK, &req->tr_node, 0))
32 struct Device *TimerBase = req->tr_node.io_Device;
33 struct EClockVal clock, oclock;
34 struct timeval tv, otv;
35 ULONG seconds;
37 printf("timer.device v%u.%u\n", TimerBase->dd_Library.lib_Version, TimerBase->dd_Library.lib_Revision);
38 printf("EClock frequency reported: %u\n\n", (unsigned int)ReadEClock(&clock));
39 ReadEClock(&clock);
40 GetSysTime(&tv);
41 seconds = tv.tv_secs + 10;
42 while (!(SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) && tv.tv_secs < seconds) {
43 oclock.ev_hi = clock.ev_hi;
44 oclock.ev_lo = clock.ev_lo;
45 otv.tv_secs = tv.tv_secs;
46 otv.tv_micro = tv.tv_micro;
47 ReadEClock(&clock);
48 GetSysTime(&tv);
49 if (oclock.ev_hi > clock.ev_hi || (oclock.ev_hi == clock.ev_hi && oclock.ev_lo > clock.ev_lo)) {
50 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);
51 break;
53 if (otv.tv_secs > tv.tv_secs || (otv.tv_secs == tv.tv_secs && otv.tv_micro >= tv.tv_micro) || tv.tv_micro >= 1000000) {
54 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);
55 break;
57 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);
59 printf("\n\n");
61 CloseDevice(&req->tr_node);
63 else
64 printf("Failed to open timer.device!\n");
66 DeleteIORequest(req);
67 } else
68 printf("Failed to create IORequest!\n");
70 DeleteMsgPort(mp);
71 } else
72 printf("Failed to create message port!\n");
74 return 0;