1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - OS - demos - waitIrq-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-12-08#$
14   $Rev: 9555 $
15   $Author: kitase_hirotake $
16  *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18 
19 #define  STACK_SIZE     1024
20 #define  THREAD1_PRIO   17
21 
22 OSThread thread1;
23 u32      stack1[STACK_SIZE / sizeof(u32)];
24 
25 void VBlankIntr(void);
26 void proc1(void *arg);
27 
28 //================================================================================
29 /*---------------------------------------------------------------------------*
30   Name:         NitroMain
31 
32   Description:  main
33 
34   Arguments:    None
35 
36   Returns:      None
37  *---------------------------------------------------------------------------*/
NitroMain()38 void NitroMain()
39 {
40     s32     n;
41 
42     OS_Init();
43     OS_InitThread();
44 
45     //---- create thread1
46     OS_CreateThread(&thread1, proc1, NULL, stack1 + STACK_SIZE / sizeof(u32), STACK_SIZE, THREAD1_PRIO);
47     OS_WakeupThreadDirect(&thread1);
48 
49     //---- VBlank setting
50     (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
51     (void)OS_EnableIrqMask(OS_IE_V_BLANK);
52     (void)OS_EnableIrq();
53     (void)GX_VBlankIntr(TRUE);
54 
55     //---- main loop
56     for (n = 0; n < 5; n++)
57     {
58         // while waiting vblank, lower priority thread runs and display 'X'.
59         // if vblank interrupt occurred, return here immidiately.
60 
61         OS_Printf("\n[loop %d]", n);
62         OS_WaitIrq(TRUE, OS_IE_V_BLANK);
63     }
64 
65     OS_Printf("\n");
66     OS_Printf("==== Finish sample.\n");
67     OS_Terminate();
68 }
69 
70 //--------------------------------------------------------------------------------
71 //    V-Blank interrupt handler
72 //
VBlankIntr(void)73 void VBlankIntr(void)
74 {
75     OS_SetIrqCheckFlag(OS_IE_V_BLANK);
76 }
77 
78 //--------------------------------------------------------------------------------
79 //    proc1
80 //
proc1(void * arg)81 void proc1(void *arg)
82 {
83 #pragma unused(arg)
84     int     i = 0;
85 
86     while(1)
87     {
88         if ( ((i++) & 0xff) == 0 )
89         {
90             (void)OS_DisableInterrupts();
91             OS_Printf("X");
92             (void)OS_EnableInterrupts();
93         }
94     }
95 }
96 
97 /*====== End of main.c ======*/
98