1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - WXC - demos - wxc-dataShare
3   File:     common.c
4 
5   Copyright 2005-2009 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:: 2007-11-15#$
14   $Rev: 2414 $
15   $Author: hatamoto_minoru $
16  *---------------------------------------------------------------------------*/
17 
18 
19 #include <nitro.h>
20 
21 #include "common.h"
22 #include "disp.h"
23 
24 void VBlankIntr(void);
25 
26 /*---------------------------------------------------------------------------*
27   Name:         CommonInit
28 
29   Description:  Common initialization functions.
30 
31   Arguments:    None.
32 
33   Returns:      None.
34  *---------------------------------------------------------------------------*/
CommonInit(void)35 void CommonInit(void)
36 {
37     /* OS initialization */
38     OS_Init();
39     OS_InitTick();
40     OS_InitAlarm();
41     FX_Init();
42 
43     /* GX initialization */
44     GX_Init();
45     GX_DispOff();
46     GXS_DispOff();
47 
48     /* V-Blank interrupt configuration */
49     (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
50     (void)OS_EnableIrqMask(OS_IE_V_BLANK);
51     (void)OS_EnableIrqMask(OS_IE_FIFO_RECV);
52     (void)GX_VBlankIntr(TRUE);
53 
54     (void)OS_EnableIrq();
55     (void)OS_EnableInterrupts();
56 
57     {                                  /* FS initialization */
58         static u32 fs_tablework[0x100 / 4];
59         FS_Init(FS_DMA_NOT_USE);
60         (void)FS_LoadTable(fs_tablework, sizeof(fs_tablework));
61     }
62 }
63 
64 
65 /*---------------------------------------------------------------------------*
66   Name:         InitAllocateSystem
67 
68   Description:  Initializes the memory allocation system in the main memory arena.
69 
70   Arguments:    None.
71 
72   Returns:      None.
73  *---------------------------------------------------------------------------*/
InitAllocateSystem(void)74 void InitAllocateSystem(void)
75 {
76     void *tempLo;
77     OSHeapHandle hh;
78 
79     // Based on the premise that OS_Init has been already called
80     tempLo = OS_InitAlloc(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi(), 1);
81     OS_SetArenaLo(OS_ARENA_MAIN, tempLo);
82     hh = OS_CreateHeap(OS_ARENA_MAIN, OS_GetMainArenaLo(), OS_GetMainArenaHi());
83     if (hh < 0)
84     {
85         OS_Panic("ARM9: Fail to create heap...\n");
86     }
87     hh = OS_SetCurrentHeap(OS_ARENA_MAIN, hh);
88 }
89