1 /*---------------------------------------------------------------------------*
2 Project: TWLSDK - demos - MI - ndma-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:: 2007-09-27#$
14 $Rev: 1202 $
15 $Author: yada $
16 *---------------------------------------------------------------------------*/
17 #include <twl.h>
18
19 void memDump(void* addr, int size);
20 void VBlankIntr(void);
21 void MyNDMACallback(void* arg);
22
23 u8 src[0x1000] ATTRIBUTE_ALIGN(32) = {0};
24 u8 dest[0x1000] ATTRIBUTE_ALIGN(32) = {0};
25
26 volatile int flag = 0;
27
28 //================================================================================
29 /*---------------------------------------------------------------------------*
30 Name: NitroMain
31
32 Description: main
33
34 Arguments: None
35
36 Returns: None
37 *---------------------------------------------------------------------------*/
NitroMain(void)38 void NitroMain(void)
39 {
40 OS_Init();
41
42 OS_Printf("*** start ndma-1 demo\n");
43
44 //---- DMA global config
45 MI_InitNDmaConfig();
46
47 //---- interrupt setting
48 (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr);
49 (void)OS_EnableIrqMask(OS_IE_V_BLANK);
50 (void)OS_EnableIrq();
51 (void)GX_VBlankIntr(TRUE);
52
53 //----------------------------------------------------------------
54 // demo1
55 OS_Printf( "memory fill using NDMA\n" );
56
57 memDump( &dest[0], 0x20 );
58
59 OS_Printf("fill with 0x12345678\n");
60
61 //---- DMA fill
62 DC_InvalidateRange( &dest[0], 0x20 );
63 MI_NDmaFill( 0, &dest[0], 0x12345678, 0x20 );
64
65 memDump( &dest[0], 0x20 );
66
67 //----------------------------------------------------------------
68 // demo2
69 OS_Printf( "\nmemory copy using NDMA\n" );
70
71 {
72 int n;
73 for( n=0; n<0x20; n++ )
74 {
75 src[n] = (u8)(n*5);
76 }
77 }
78
79 OS_Printf("src\n");
80 memDump( &src[0], 0x20 );
81 OS_Printf("dest\n");
82 memDump( &dest[0], 0x20 );
83 OS_Printf("copy\n");
84
85 //---- DMA copy
86 DC_FlushRange( &src[0], 0x20 );
87 DC_InvalidateRange( &dest[0], 0x20 );
88 MI_NDmaCopy( 0, &src[0], &dest[0], 0x20 );
89
90 memDump( &dest[0], 0x20 );
91
92 //----------------------------------------------------------------
93 // demo3
94 OS_Printf( "\nmemory copy using async NDMA\n" );
95
96 MI_CpuFill8( &dest[0], 0, 0x100 );
97 {
98 int n;
99 for( n=0; n<0x20; n++ )
100 {
101 src[n] = (u8)(n*2);
102 }
103 }
104
105 OS_Printf("src\n");
106 memDump( &src[0], 0x20 );
107 OS_Printf("dest\n");
108 memDump( &dest[0], 0x20 );
109 OS_Printf("copy async\n");
110
111 DC_FlushRange( &src[0], 0x20 );
112 DC_InvalidateRange( &dest[0], 0x20 );
113 MI_NDmaCopyAsync(0,&src[0], &dest[0], 0x20, MyNDMACallback, (void*)&flag );
114
115 memDump( &dest[0], 0x20 );
116
117 while(flag==0)
118 {
119 OS_Printf("waiting...\n");
120 }
121
122 //----------------------------------------------------------------
123 OS_Printf("*** End of demo\n");
124 OS_Terminate();
125 }
126
127 /*---------------------------------------------------------------------------*
128 Name: memDump
129
130 Description: dump memory
131
132 Arguments: addr : address
133 size : size ( byte )
134
135 Returns: None
136 *---------------------------------------------------------------------------*/
memDump(void * addr,int size)137 void memDump(void* addr, int size)
138 {
139 int n;
140 u8* p = (u8*)addr;
141
142 while(1)
143 {
144 OS_Printf( "%08X : ", p );
145 for( n=0; n<16; n++ )
146 {
147 OS_Printf(" %02X", *(u8*)p );
148 p++;
149 size--;
150 if ( size == 0 )
151 {
152 break;
153 }
154 }
155 OS_Printf("\n");
156 if ( size == 0 )
157 {
158 break;
159 }
160 }
161 }
162
163 /*---------------------------------------------------------------------------*
164 Name: VBlankIntr
165
166 Description: VBlank interrupt handler
167
168 Arguments: None
169
170 Returns: None
171 *---------------------------------------------------------------------------*/
VBlankIntr(void)172 void VBlankIntr(void)
173 {
174 //---- check interrupt flag
175 OS_SetIrqCheckFlag(OS_IE_V_BLANK);
176 }
177
178
179 /*---------------------------------------------------------------------------*
180 Name: MyNDmaCallback
181
182 Description: NDMA callback
183
184 Arguments: arg :
185
186 Returns: None
187 *---------------------------------------------------------------------------*/
MyNDMACallback(void * arg)188 void MyNDMACallback(void* arg)
189 {
190 int* p = (int*)arg;
191 *p = 1;
192 }
193
194
195 /*====== End of main.c ======*/
196
197