1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - demos - simple-1
3   File:     main.c
4 
5   Copyright 2007-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-12-08#$
14   $Rev: 9555 $
15   $Author: kitase_hirotake $
16  *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18 
19 #define COUNT OS_MilliSecondsToTicks( 1000 )
20 
21 OSAlarm alarm;
22 int alarmCount = 0;
23 
24 void alarmCallback(void* arg);
25 void VBlankIntr(void);
26 
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 	OS_InitTick();
41 	OS_InitAlarm();
42 
43 	//---- interrupt setting
44 	OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
45 	(void)OS_EnableIrqMask(OS_IE_V_BLANK);
46 	(void)OS_EnableIrq();
47 	(void)GX_VBlankIntr(TRUE);
48 
49 	OS_Printf("*** start simple-1 demo\n");
50 
51 	OS_SetPeriodicAlarm( &alarm, COUNT, COUNT, alarmCallback, NULL );
52 
53 	while( alarmCount <= 10 )
54 	{
55 		static u16 prevButton = 0;
56 		u16 button = PAD_Read();
57 		u16 trigger = (u16)((button ^ prevButton) & button);
58 		prevButton = button;
59 
60         SVC_WaitVBlankIntr();
61 
62 		if ( trigger & PAD_BUTTON_A )
63 		{
64 			OS_Printf("pushed A.\n");
65 		}
66 	}
67 
68 	OS_Printf("***End of demo\n");
69 	OS_Terminate();
70 }
71 
72 
73 /*---------------------------------------------------------------------------*
74   Name:         alarmCallback
75 
76   Description:  main
77 
78   Arguments:    None
79 
80   Returns:      None
81  *---------------------------------------------------------------------------*/
alarmCallback(void * arg)82 void alarmCallback(void* arg)
83 {
84 #pragma unused(arg)
85 	OS_Printf( "alarm callback (%d)\n", alarmCount );
86 	alarmCount ++;
87 }
88 
89 /*---------------------------------------------------------------------------*
90   Name:         VBlankIntr
91 
92   Description:  main
93 
94   Arguments:    None
95 
96   Returns:      None
97  *---------------------------------------------------------------------------*/
VBlankIntr(void)98 void VBlankIntr(void)
99 {
100 	OS_SetIrqCheckFlag(OS_IE_V_BLANK);
101 }
102 
103