1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - OS - demos - alarm-1
3 File: main.c
4
5 Copyright 2003-2008 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 $Date:: 2008-04-01#$
14 $Rev: 5205 $
15 $Author: yada $
16 *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18
19 #define ALARM_COUNT (OS_MilliSecondsToTicks(1000))
20
21 static OSAlarm alarm;
22 static BOOL called = FALSE;
23 static int pushCounter = 0;
24
25 void VBlankIntr(void);
26 void alarmCallback(void *arg);
27
28 /*---------------------------------------------------------------------------*
29 Name: NitroMain
30
31 Description: main
32
33 Arguments: None
34
35 Returns: None
36 *---------------------------------------------------------------------------*/
NitroMain(void)37 void NitroMain(void)
38 {
39 OS_Init();
40 GX_Init();
41
42 // ---- initialize tick system
43 OS_InitTick();
44 // ---- initialize alarm system
45 OS_InitAlarm();
46
47 //---- setup VBlank
48 (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
49 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
50 (void)OS_EnableIrq();
51 (void)GX_VBlankIntr(TRUE);
52
53 OS_Printf("Push [A] to start alarm.\n");
54
55 while (1)
56 {
57 u16 padData;
58
59 OS_WaitVBlankIntr();
60 padData = PAD_Read();
61
62 if (padData & PAD_BUTTON_A && !called)
63 {
64 pushCounter++;
65 called = TRUE;
66
67 //---- setting alarm
68 OS_CreateAlarm(&alarm);
69 OS_SetAlarm(&alarm, ALARM_COUNT, &alarmCallback, (void *)pushCounter);
70
71 OS_Printf("set alarm\n");
72 }
73 }
74 }
75
76
77 /*---------------------------------------------------------------------------*
78 Name: alarmCallback
79
80 Description: callback for alarm interrupt
81
82 Arguments: arg : user setting argument
83
84 Returns: None
85 *---------------------------------------------------------------------------*/
alarmCallback(void * arg)86 void alarmCallback(void *arg)
87 {
88 #ifdef SDK_FINALROM
89 #pragma unused( arg )
90 #endif
91 OS_Printf(">>> called alarm callback. arg=%d\n", arg);
92 called = FALSE;
93 }
94
95 /*---------------------------------------------------------------------------*
96 Name: VBlankIntr
97
98 Description: VBlank interrupt handler
99
100 Arguments: None
101
102 Returns: None
103 *---------------------------------------------------------------------------*/
VBlankIntr(void)104 void VBlankIntr(void)
105 {
106 //---- check interrupt flag
107 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
108 }
109
110 /*====== End of main.c ======*/
111