1 /*---------------------------------------------------------------------------*
2 Project: NitroSDK - OS - demos - callTrace-2
3 File: main.c
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 $NoKeywords: $
8 *---------------------------------------------------------------------------*/
9 #include <nitro.h>
10
11 int test1(int a);
12 int test2(int a);
13 int test3(int a);
14 void test4(int a);
15 void test5(int a);
16
17 //---- thread
18 #define STACK_SIZE 1024
19
20 void proc1(void *arg);
21 void proc2(void *arg);
22
23 OSThread thread1;
24 OSThread thread2;
25
26 u64 stack1[STACK_SIZE / sizeof(u64)];
27 u64 stack2[STACK_SIZE / sizeof(u64)];
28
29 #define THREAD1_PRIO 10
30 #define THREAD2_PRIO 11
31
32 #define MYTRACEBUFFER_SIZE 0x400
33 u32 myTraceBuffer0[MYTRACEBUFFER_SIZE / sizeof(u32)];
34 u32 myTraceBuffer1[MYTRACEBUFFER_SIZE / sizeof(u32)];
35 u32 myTraceBuffer2[MYTRACEBUFFER_SIZE / sizeof(u32)];
36
__PROFILE_ENTRY(void)37 SDK_WEAK_SYMBOL asm void __PROFILE_ENTRY( void ){ bx lr }
__PROFILE_EXIT(void)38 SDK_WEAK_SYMBOL asm void __PROFILE_EXIT( void ){ bx lr }
39
40 //================================================================
41
42 //----------------------------------------------------------------
43 // test1
44 //
test1(int a)45 int test1(int a)
46 {
47 return test2(a + 1);
48 }
49
50 //----------------------------------------------------------------
51 // test2
52 //
test2(int a)53 int test2(int a)
54 {
55 return test3(a + 2);
56 }
57
58 //----------------------------------------------------------------
59 // test3
60 //
test3(int a)61 int test3(int a)
62 {
63 OS_DumpCallTrace();
64 return a + 4;
65 }
66
67 //----------------------------------------------------------------
68 // test4
69 //
test4(int a)70 void test4(int a)
71 {
72 test5(a + 3);
73 return;
74 }
75
76 //----------------------------------------------------------------
77 // test5
78 //
test5(int a)79 void test5(int a)
80 {
81 #pragma unused( a )
82 return;
83 }
84
85 //================================================================================
86 /*---------------------------------------------------------------------------*
87 Name: NitroMain
88
89 Description: main
90
91 Arguments: None
92
93 Returns: None
94 *---------------------------------------------------------------------------*/
95 #pragma profile off
NitroMain(void)96 void NitroMain(void)
97 {
98 s32 n;
99
100 OS_Init();
101 OS_CreateThread(&thread1, proc1, NULL, stack1 + STACK_SIZE / sizeof(u64), STACK_SIZE,
102 THREAD1_PRIO);
103 OS_CreateThread(&thread2, proc2, NULL, stack2 + STACK_SIZE / sizeof(u64), STACK_SIZE,
104 THREAD2_PRIO);
105 OS_WakeupThreadDirect(&thread1);
106 OS_WakeupThreadDirect(&thread2);
107
108 OS_InitCallTrace(&myTraceBuffer0, MYTRACEBUFFER_SIZE, OS_CALLTRACE_LOG);
109
110 for (n = 0; n < 5; n++)
111 {
112 OS_Printf("Idle\n");
113 OS_WakeupThreadDirect(&thread2);
114
115 test4(n);
116 }
117
118 //---- display all thread trace
119 {
120 OS_Printf("----------------\n");
121 OS_Printf("---- thread 1: trace\n");
122 OS_DumpThreadCallTrace(&thread1);
123 OS_Printf("---- thread 2: trace\n");
124 OS_DumpThreadCallTrace(&thread2);
125 OS_Printf("---- idle thread: trace\n");
126 OS_DumpThreadCallTrace(NULL);
127 }
128
129 OS_Printf("==== Finish sample.\n");
130 OS_Terminate();
131 }
132
133 /*---------------------------------------------------------------------------*
134 Name: proc1
135
136 Description: procedure of thread1
137
138 Arguments: None
139
140 Returns: None
141 *---------------------------------------------------------------------------*/
proc1(void * arg)142 void proc1(void *arg)
143 {
144 #pragma unused(arg)
145
146 static int cnt = 0;
147
148 OS_InitCallTrace(&myTraceBuffer1, MYTRACEBUFFER_SIZE, OS_CALLTRACE_STACK);
149 while (1)
150 {
151 OS_Printf("thread1\n");
152 if (cnt++ == 3)
153 {
154 (void)test1(0x100);
155 }
156 OS_SleepThread(NULL);
157 }
158 }
159
160 /*---------------------------------------------------------------------------*
161 Name: proc2
162
163 Description: procedure of thread2
164
165 Arguments: None
166
167 Returns: None
168 *---------------------------------------------------------------------------*/
proc2(void * arg)169 void proc2(void *arg)
170 {
171 #pragma unused(arg)
172
173 static int cnt = 0;
174
175 OS_InitCallTrace(&myTraceBuffer2, MYTRACEBUFFER_SIZE, OS_CALLTRACE_STACK);
176 while (1)
177 {
178 OS_Printf("thread2\n");
179 if (cnt++ == 3)
180 {
181 (void)test1(0x200);
182 }
183 OS_SleepThread(NULL);
184 OS_WakeupThreadDirect(&thread1);
185 }
186 }
187
188 /*====== End of main.c ======*/
189