1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - OS - demos - thread-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-02#$
14 $Rev: 5265 $
15 $Author: yada $
16 *---------------------------------------------------------------------------*/
17 #include <nitro.h>
18
19 #define STACK_SIZE 1024
20
21 void proc1(void *arg);
22 void proc2(void *arg);
23
24 OSThread thread1;
25 OSThread thread2;
26
27 u64 stack1[STACK_SIZE / sizeof(u64)];
28 u64 stack2[STACK_SIZE / sizeof(u64)];
29
30 #define THREAD1_PRIO 10
31 #define THREAD2_PRIO 11
32
33
34 //================================================================================
35 /*---------------------------------------------------------------------------*
36 Name: NitroMain
37
38 Description: main
39
40 Arguments: None
41
42 Returns: None
43 *---------------------------------------------------------------------------*/
NitroMain(void)44 void NitroMain(void)
45 {
46 s32 n;
47
48 OS_Init();
49 OS_InitThread();
50
51 OS_CreateThread(&thread1, proc1, (void *)0x111, stack1 + STACK_SIZE / sizeof(u64), STACK_SIZE, THREAD1_PRIO);
52 OS_CreateThread(&thread2, proc2, (void *)0x222, stack2 + STACK_SIZE / sizeof(u64), STACK_SIZE, THREAD2_PRIO);
53
54 OS_DumpThreadList();
55
56 OS_WakeupThreadDirect(&thread1);
57 OS_WakeupThreadDirect(&thread2);
58
59 for (n = 0; n < 5; n++)
60 {
61 OS_Printf("Idle\n");
62 OS_WakeupThreadDirect(&thread2);
63 }
64
65 OS_Printf("==== Finish sample.\n");
66
67 OS_Terminate();
68 }
69
70 //--------------------------------------------------------------------------------
71 // proc1
72 //
proc1(void * arg)73 void proc1(void *arg)
74 {
75 #ifdef SDK_FINALROM
76 #pragma unused( arg )
77 #endif
78 while (1)
79 {
80 OS_Printf("Thread1 (%x)\n", (u32)arg);
81 OS_SleepThread(NULL);
82 }
83 }
84
85 //--------------------------------------------------------------------------------
86 // proc2
87 //
proc2(void * arg)88 void proc2(void *arg)
89 {
90 #ifdef SDK_FINALROM
91 #pragma unused( arg )
92 #endif
93 while (1)
94 {
95 OS_Printf("Thread2 (%x)\n", (u32)arg);
96 OS_SleepThread(NULL);
97 OS_WakeupThreadDirect(&thread1);
98 }
99 }
100
101 /*====== End of main.c ======*/
102