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