1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - MB - demos - multiboot
3 File: main.c
4
5 Copyright 2006-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-09-18#$
14 $Rev: 8573 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17
18 //--------------------------------------------------------------------
19 // Channel determination sample during multiboot
20 //
21 // Because calculation of the signal usage rate can only be used in the wireless IDLE state, it is necessary to decide on the channel as pre-processing before starting MB during multi-boot.
22 //
23 //
24 //
25 // MBM_MeasureChannel in this sample is structured so that if called from the wireless power OFF state, it will internally calculate the optimal channel and return the result after control returns to the wireless power OFF state.
26 //
27 //
28 //
29 // (*Another method is to use MB_StartParentFromIdle and MB_EndToIdle, which were added to NITRO-SDK2.0rc2)
30 //
31 //--------------------------------------------------------------------
32
33
34 #include <nitro.h>
35
36 #include "mb_measure_channel.h"
37
38
39 static void my_callback(MBMCallback * cb);
40 static vu16 channel_setting = 0;
41 static int prog_state;
42
43
44 /******************************************************************************/
45 /* Functions */
46
47 /* V-Blank interrupt process */
VBlankIntr(void)48 static void VBlankIntr(void)
49 {
50 //---- Interrupt check flag
51 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
52 }
53
54 /* Main */
NitroMain()55 void NitroMain()
56 {
57 /* OS initialization */
58 OS_Init();
59 OS_InitThread();
60 OS_InitTick();
61 OS_InitAlarm();
62 FX_Init();
63
64 /* GX initialization */
65 GX_Init();
66 GX_DispOff();
67 GXS_DispOff();
68
69 { /* Memory allocation initialization */
70 OSHeapHandle heapHandle; // Heap handle
71 enum
72 { MAIN_HEAP_SIZE = 0x80000 };
73 void *heapStart, *nstart;
74 nstart = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 16);
75 OS_SetMainArenaLo(nstart);
76 heapStart = OS_AllocFromMainArenaLo((u32)MAIN_HEAP_SIZE, 32);
77 heapHandle =
78 OS_CreateHeap(OS_ARENA_MAIN, heapStart, (void *)((u32)heapStart + MAIN_HEAP_SIZE));
79 if (heapHandle < 0)
80 {
81 OS_Panic("ARM9: Fail to create heap...\n");
82 }
83 heapHandle = OS_SetCurrentHeap(OS_ARENA_MAIN, heapHandle);
84 }
85
86 /* V-Blank interrupt configuration */
87 (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
88 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
89 (void)OS_EnableIrqMask(OS_IE_FIFO_RECV);
90 (void)OS_EnableIrq();
91 (void)OS_EnableInterrupts();
92 (void)GX_VBlankIntr(TRUE);
93
94 /* Start display */
95 GX_DispOn();
96 GXS_DispOn();
97 G2_SetBG0Offset(0, 0);
98
99 channel_setting = 0;
100
101 {
102 void *wm_sys_buf_ptr = OS_Alloc(WM_SYSTEM_BUF_SIZE);
103 MBM_MeasureChannel((u8 *)wm_sys_buf_ptr, my_callback);
104 while (channel_setting == 0)
105 {
106 OS_WaitVBlankIntr();
107 }
108 OS_Free(wm_sys_buf_ptr);
109 }
110
111 /* Main loop */
112 for (;;)
113 {
114 OS_WaitVBlankIntr();
115 }
116 }
117
118
my_callback(MBMCallback * cb)119 static void my_callback(MBMCallback * cb)
120 {
121 channel_setting = 1;
122 if (cb->errcode == MBM_MEASURE_SUCCESS)
123 {
124 OS_TPrintf("measure channel = %d\n", cb->channel);
125 }
126 else
127 {
128 OS_TPrintf("get measure channel fail\n");
129 }
130 }
131