1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - demos - CARD - card-mrom
3   File:     main.c
4 
5   Copyright 2007-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:: 2009-07-17#$
14   $Rev: 10925 $
15   $Author: yosizaki $
16  *---------------------------------------------------------------------------*/
17 
18 
19 #include <nitro.h>
20 
21 
22 /*---------------------------------------------------------------------------*
23   Name:         NitroMain
24 
25   Description:  Main entry point.
26 
27   Arguments:    None.
28 
29   Returns:      None.
30  *---------------------------------------------------------------------------*/
NitroMain(void)31 void NitroMain(void)
32 {
33     FSFile      file[1];
34     OS_Init();
35     OS_InitTick();
36     CARD_Init();
37     (void)OS_EnableIrq();
38     (void)OS_EnableInterrupts();
39     FS_Init(FS_DMA_NOT_USE);
40 
41     // Repeat a large read access 10 times and measure the transfer speed.
42     // Use a CPU transfer because a DMA transfer has the overhead of an interrupt handler.
43     FS_InitFile(file);
44     if (!FS_OpenFile(file, "kart_title.32.wav"))
45     {
46         OS_TPanic("cannot open testfile!");
47     }
48     else
49     {
50         enum
51         { BUFFER_SIZE = 1 * 1024 * 1024 };
52         static u8   buf[BUFFER_SIZE];
53         int         i;
54         OSTick      t;
55         const u16   id = (u16)OS_GetLockID();
56         const u32   addr = FS_GetFileImageTop(file);
57 
58         CARD_LockRom(id);
59         for (i = 0; i < 10; ++i)
60         {
61             t = OS_GetTick();
62             CARD_ReadRom(MI_DMA_NOT_USE, (const void *)addr, buf, BUFFER_SIZE);
63             t = OS_GetTick() - t;
64             /* n[B/s] = 1[MB] / t[microsecond] */
65             OS_Printf("[%2d] ... %10.6f[B/s]\n", i + 1,
66                       1.0 * BUFFER_SIZE / OS_TicksToMicroSeconds(t));
67         }
68         CARD_UnlockRom(id);
69 
70         (void)FS_CloseFile(file);
71         OS_TPrintf("[end]\n");
72     }
73 
74     OS_Terminate();
75 }
76