1 /*---------------------------------------------------------------------------*
2 Project: NitroSDK - OS - demos - functionCost-3
3 File: main.c
4
5 Copyright 2003-2008 Nintendo. All rights reserved.
6
7 $NoKeywords: $
8 *---------------------------------------------------------------------------*/
9 #include <nitro.h>
10
11 void test1(void);
12 void test2(void);
13 void test3(void);
14 void test_sleep(void);
15
16 #define MYCOSTBUFFER_SIZE 0x3000
17 #define MYSTATBUFFER_SIZE 0x300
18
19 u32 myCostBuffer[MYCOSTBUFFER_SIZE / sizeof(u32)];
20 u32 myCostBuffer1[MYCOSTBUFFER_SIZE / sizeof(u32)];
21 u32 myCostBuffer2[MYCOSTBUFFER_SIZE / sizeof(u32)];
22
23 u32 myStatBuffer[MYSTATBUFFER_SIZE / sizeof(u32)];
24
25 //---- thread
26 #define STACK_SIZE 1024
27
28 void proc1(void *arg);
29 void proc2(void *arg);
30
31 OSThread thread1;
32 OSThread thread2;
33
34 u64 stack1[STACK_SIZE / sizeof(u64)];
35 u64 stack2[STACK_SIZE / sizeof(u64)];
36
37 #define THREAD1_PRIO 10
38 #define THREAD2_PRIO 11
39
40 //================================================================================
41 /*---------------------------------------------------------------------------*
42 Name: NitroMain
43
44 Description: main
45
46 Arguments: None
47
48 Returns: None
49 *---------------------------------------------------------------------------*/
50 #pragma profile off
NitroMain(void)51 void NitroMain(void)
52 {
53 int n;
54
55 OS_Init();
56 OS_InitTick();
57 (void)OS_EnableIrq();
58
59 //---- init thread
60 //OS_InitThread(); <- maybe done in OS_Init() already.
61 OS_CreateThread(&thread1, proc1, (void *)0x111, stack1 + STACK_SIZE / sizeof(u64), STACK_SIZE,
62 THREAD1_PRIO);
63 OS_CreateThread(&thread2, proc2, (void *)0x222, stack2 + STACK_SIZE / sizeof(u64), STACK_SIZE,
64 THREAD2_PRIO);
65 OS_WakeupThreadDirect(&thread1);
66 OS_WakeupThreadDirect(&thread2);
67
68 //---- init functionCost
69 OS_InitFunctionCost(&myCostBuffer, MYCOSTBUFFER_SIZE);
70 OS_InitStatistics(&myStatBuffer, MYSTATBUFFER_SIZE);
71
72 for (n = 0; n < 100; n++)
73 {
74 test3();
75 OS_WakeupThreadDirect(&thread2);
76 }
77
78 //---- calculate cost
79 OS_CalcStatistics(&myStatBuffer);
80
81 //---- display all thread functionCost
82 OS_DumpStatistics(&myStatBuffer);
83
84
85 OS_Printf("==== Finish sample.\n");
86 OS_Terminate();
87 }
88
89 #pragma profile reset
90
91 //--------------------------------------------------------------------------------
92 // proc1
93 //
proc1(void * arg)94 void proc1(void *arg)
95 {
96 #pragma unused( arg )
97
98 //---- init functionCost
99 OS_InitFunctionCost(&myCostBuffer1, MYCOSTBUFFER_SIZE);
100
101 while (1)
102 {
103 test1();
104 test_sleep();
105
106 //---- calculate cost
107 OS_CalcStatistics(&myStatBuffer);
108 }
109 }
110
111 //--------------------------------------------------------------------------------
112 // proc2
113 //
proc2(void * arg)114 void proc2(void *arg)
115 {
116 #pragma unused( arg )
117
118 //---- init functionCost
119 OS_InitFunctionCost(&myCostBuffer2, MYCOSTBUFFER_SIZE);
120
121 while (1)
122 {
123 test2();
124 OS_SleepThread(NULL);
125 OS_WakeupThreadDirect(&thread1);
126
127 //---- calculate cost
128 OS_CalcStatistics(&myStatBuffer);
129 }
130 }
131
132 //================================================================
133 //----------------------------------------------------------------
134 // test1
135 //
test1(void)136 void test1(void)
137 {
138 test2();
139 }
140
141 //----------------------------------------------------------------
142 // test2
143 //
test2(void)144 void test2(void)
145 {
146 test3();
147 }
148
149 //----------------------------------------------------------------
150 // test3
151 //
test3(void)152 void test3(void)
153 {
154 return;
155 }
156
157 //----------------------------------------------------------------
158 // test_sleep
159 //
test_sleep(void)160 void test_sleep(void)
161 {
162 OS_SleepThread(NULL);
163 }
164
165 /*====== End of main.c ======*/
166