1 /*---------------------------------------------------------------------------*
2 Project: Dolphin OS Overview - Timer demo
3 File: timerdemo.c
4
5 Copyright 1998, 1999 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Log: timerdemo.c,v $
14 Revision 1.2 02/20/2006 04:13:11 mitu
15 changed include path from dolphin/ to revolution/.
16
17 Revision 1.1 01/13/2006 11:24:13 hiratsu
18 Initial check in.
19
20
21 4 9/03/01 20:04:00 Shiki
22 Updated.
23
24 3 3/16/00 7:26p Shiki
25 Revised to use Alarm API instead of Timer API.
26
27 2 3/16/00 7:03p Shiki
28 Revised to include <private/OSTimer.h>
29
30 2 9/10/99 4:35p Tian
31 added function prototype
32
33 1 6/07/99 1:53p Tianli01
34 Initial check-n
35 $NoKeywords: $
36 *---------------------------------------------------------------------------*/
37
38 /*---------------------------------------------------------------------------*
39 This program shows how to set up and use the alarm
40 Does not function in emulator.
41 *---------------------------------------------------------------------------*/
42 #include <revolution.h>
43
44 #define PERIOD 5 // sec
45
46 OSAlarm Alarm;
47
AlarmHandler(OSAlarm * alarm,OSContext * context)48 static void AlarmHandler(OSAlarm* alarm, OSContext* context)
49 {
50 #pragma unused( alarm, context )
51 OSTime t;
52
53 t = OSGetTime();
54 OSReport("Alarm at %lld.%03lld [sec]\n",
55 OSTicksToSeconds(t),
56 OSTicksToMilliseconds(t) % 1000);
57 }
58
main(void)59 void main(void)
60 {
61 OSTime now;
62
63 now = OSGetTime();
64 OSReport("The time now is %lld.%03lld [sec]\n",
65 OSTicksToSeconds(now),
66 OSTicksToMilliseconds(now) % 1000);
67 OSReport("Initializing period to %d [sec]\n", PERIOD);
68
69 OSCreateAlarm(&Alarm);
70 OSSetPeriodicAlarm(
71 &Alarm, // pointer to alarm
72 now, // start counting immediately
73 OSSecondsToTicks(PERIOD), // set 5 sec period
74 AlarmHandler); // alarm handler to be called at every
75 // PERIOD sec
76
77 for (;;)
78 {
79
80 }
81 }
82