1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - demos - mi - wramManager-1
3 File: main.c
4
5 Copyright 2007 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-09#$
14 $Rev: 9590 $
15 $Author: yada $
16 *---------------------------------------------------------------------------*/
17 #include <twl.h>
18
19 void VBlankIntr(void);
20 void DisplayWramStatus(void);
21
22 /*---------------------------------------------------------------------------*
23 Name: TwlMain
24
25 Description: main
26
27 Arguments: None
28
29 Returns: None
30 *---------------------------------------------------------------------------*/
NitroMain(void)31 void NitroMain(void)
32 {
33 OS_Init();
34
35 OS_Printf("*** start wramManager-1 demo\n");
36
37 //---- interrupt setting
38 OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
39 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
40 (void)OS_EnableIrq();
41 (void)GX_VBlankIntr(TRUE);
42
43 //---- set free shared WRAM allocated to ARM9
44 (void)MI_FreeWram_B( MI_WRAM_ARM9 );
45 (void)MI_CancelWram_B( MI_WRAM_ARM9 );
46 (void)MI_FreeWram_C( MI_WRAM_ARM9 );
47 (void)MI_CancelWram_C( MI_WRAM_ARM9 );
48
49 //---- display each WRAM area
50 OS_Printf("WRAM-A (%x-%x)\n", MI_GetWramMapStart_A(), MI_GetWramMapEnd_A() );
51 OS_Printf("WRAM-B (%x-%x)\n", MI_GetWramMapStart_B(), MI_GetWramMapEnd_B() );
52 OS_Printf("WRAM-C (%x-%x)\n\n", MI_GetWramMapStart_C(), MI_GetWramMapEnd_C() );
53 DisplayWramStatus();
54
55 while(1)
56 {
57 {
58 static u16 preButton = 0;
59 u16 button = PAD_Read();
60 u16 trigger;
61
62 trigger = (u16)( (preButton ^ button) & button );
63 preButton = button;
64
65 if ( trigger & PAD_BUTTON_A )
66 {
67 static int i=0;
68
69 OS_Printf("*** (%d) ", i);
70 switch(i)
71 {
72 case 0:
73 {
74 u32 addr = MI_AllocWram_B( MI_WRAM_SIZE_64KB, MI_WRAM_ARM9 );
75 OS_Printf("alloc for ARM9 from WRAM_B: addr=%x\n", addr);
76 }
77 break;
78 case 1:
79 {
80 u32 addr = MI_AllocWram_B( MI_WRAM_SIZE_64KB, MI_WRAM_ARM7 );
81 OS_Printf("alloc for ARM7 from WRAM_B: addr=%x\n", addr);
82 }
83 break;
84 case 2:
85 {
86 u32 addr = MI_AllocWram_B( MI_WRAM_SIZE_64KB, MI_WRAM_DSP );
87 OS_Printf("alloc for DSP from WRAM_B: addr=%x\n", addr);
88 }
89 break;
90 case 3:
91 {
92 int x = MI_FreeWram_B( MI_WRAM_ARM7 );
93 OS_Printf("free %d blocks all ARM7 slot from WRAM_B\n", x );
94 }
95 break;
96 case 4:
97 {
98 u32 addr = MI_AllocWram_B( MI_WRAM_SIZE_64KB, MI_WRAM_ARM9 );
99 OS_Printf("alloc for ARM9 from WRAM_B: addr=%x\n", addr);
100 }
101 break;
102 case 5:
103 {
104 int x = MI_FreeWram_B( MI_WRAM_ARM9 );
105 OS_Printf("free %d blocks all ARM9 slot from WRAM_B\n", x );
106 }
107 break;
108 case 6:
109 {
110 u32 addr = MI_AllocWramSlot_B( 1, MI_WRAM_SIZE_64KB, MI_WRAM_ARM9 );
111 OS_Printf("alloc for ARM9 from WRAM_B: addr=%x (64KB from slot 1)\n", addr );
112 }
113 break;
114 case 7:
115 {
116 int x = MI_SwitchWramSlot_B( 2, MI_WRAM_SIZE_64KB, MI_WRAM_ARM9, MI_WRAM_DSP );
117 OS_Printf("switch %d blocks in WRAM_B from ARM9 to DSP (64KB from slot 2)\n", x );
118 }
119 break;
120 }
121 i++;
122
123 DisplayWramStatus();
124 if ( i>7 )
125 {
126 OS_Printf("*** End of demo\n");
127 OS_Terminate();
128 }
129 }
130 }
131 }
132 }
133
134 /*---------------------------------------------------------------------------*
135 Name: DisplayWramStatus
136
137 Description: display status of wram manager
138
139 Arguments: None
140
141 Returns: None
142 *---------------------------------------------------------------------------*/
143 static char* getMasterStr( MIWramProc m );
144 static char* getEnableStr( MIWramEnable en );
145 static char* getBoolStr( BOOL b );
146
DisplayWramStatus(void)147 void DisplayWramStatus(void)
148 {
149 int n;
150
151 //---- WRAM-A
152 OS_Printf("WRAM-A:reserve");
153 for( n=0; n<MI_WRAM_A_MAX_NUM; n++ )
154 {
155 OS_Printf("[%s]", getMasterStr( MI_GetWramReservation_A(n) ) );
156 }
157 OS_Printf("\nWRAM-A:alloc ");
158 for( n=0; n<MI_WRAM_A_MAX_NUM; n++ )
159 {
160 if ( MI_GetWramBankEnable_A(n) )
161 {
162 OS_Printf("[%s]", getMasterStr(MI_GetWramBankMaster_A(n)) );
163 }
164 else
165 {
166 OS_Printf("[----]");
167 }
168 }
169
170 //---- WRAM-B
171 OS_Printf("\nWRAM-B:reserve");
172 for( n=0; n<MI_WRAM_B_MAX_NUM; n++ )
173 {
174 OS_Printf("[%s]", getMasterStr( MI_GetWramReservation_B(n) ) );
175 }
176 OS_Printf("\nWRAM-B:alloc ");
177 for( n=0; n<MI_WRAM_B_MAX_NUM; n++ )
178 {
179 if ( MI_GetWramBankEnable_B(n) )
180 {
181 OS_Printf("[%s]", getMasterStr(MI_GetWramBankMaster_B(n)) );
182 }
183 else
184 {
185 OS_Printf("[----]");
186 }
187 }
188
189 //---- WRAM-C
190 OS_Printf("\nWRAM-C:reserve");
191 for( n=0; n<MI_WRAM_C_MAX_NUM; n++ )
192 {
193 OS_Printf("[%s]", getMasterStr( MI_GetWramReservation_C(n) ) );
194 }
195 OS_Printf("\nWRAM-C:alloc ");
196 for( n=0; n<MI_WRAM_C_MAX_NUM; n++ )
197 {
198 if ( MI_GetWramBankEnable_C(n) )
199 {
200 OS_Printf("[%s]", getMasterStr(MI_GetWramBankMaster_C(n)) );
201 }
202 else
203 {
204 OS_Printf("[----]");
205 }
206 }
207 OS_Printf("\n\n");
208
209 }
210
getMasterStr(MIWramProc m)211 static char* getMasterStr( MIWramProc m )
212 {
213 static char strARM9[] = "ARM9";
214 static char strARM7[] = "ARM7";
215 static char strDSP[] = "DSP ";
216 static char strNA[] = "----";
217
218 switch( m )
219 {
220 case MI_WRAM_ARM9: return strARM9;
221 case MI_WRAM_ARM7: return strARM7;
222 case MI_WRAM_DSP: return strDSP;
223 }
224 return strNA;
225 }
226
getEnableStr(MIWramEnable en)227 static char* getEnableStr( MIWramEnable en )
228 {
229 static char strEnable[] = "o";
230 static char strDisable[] = "x";
231 static char strNA[] = "-";
232
233 switch( en )
234 {
235 case MI_WRAM_ENABLE: return strEnable;
236 case MI_WRAM_DISABLE: return strDisable;
237 }
238 return strNA;
239 }
240
241
getBoolStr(BOOL b)242 static char* getBoolStr( BOOL b )
243 {
244 static char strTrue[] = "o";
245 static char strFalse[] = "x";
246
247 return b? strTrue: strFalse;
248 }
249
250
251
252 /*---------------------------------------------------------------------------*
253 Name: VBlankIntr
254
255 Description: interrupt handler of V-Blank
256
257 Arguments: None
258
259 Returns: None
260 *---------------------------------------------------------------------------*/
VBlankIntr(void)261 void VBlankIntr(void)
262 {
263 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
264 }
265