1 #if 0 2 /*---------------------------------------------------------------------------* 3 Project: TwlSDK - MI 4 File: mi_card.c 5 6 Copyright 2003-2008 Nintendo. All rights reserved. 7 8 These coded instructions, statements, and computer programs contain 9 proprietary information of Nintendo of America Inc. and/or Nintendo 10 Company Ltd., and are protected by Federal copyright law. They may 11 not be disclosed to third parties or copied or duplicated in any form, 12 in whole or in part, without the prior written consent of Nintendo. 13 14 $Date:: 2008-09-18#$ 15 $Rev: 8573 $ 16 $Author: okubata_ryoma $ 17 *---------------------------------------------------------------------------*/ 18 19 20 #include <nitro/os.h> 21 #include <nitro/mi/card.h> 22 23 24 /********************************************************************/ 25 /* Variables */ 26 27 // Variables for card exclusive processing 28 typedef struct 29 { 30 BOOL is_init; // Initialized 31 u16 lock_id; //Lock ID 32 u16 padding; 33 MIDmaCallback dma_callback; 34 } 35 MIi_CardParam; 36 37 static MIi_CardParam mii_card_param; 38 39 40 /********************************************************************/ 41 /* Functions */ 42 43 // Initialize card access via MI 44 static void MIi_InitCard(void) 45 { 46 MIi_CardParam *const p = &mii_card_param; 47 OSIntrMode bak_psr = OS_DisableInterrupts(); 48 49 if (!p->is_init) 50 { 51 s32 lock_id = OS_GetLockID(); 52 53 #ifndef SDK_FINALROM 54 if (lock_id < 0) 55 { 56 OS_Panic("Invalid lock ID."); 57 } 58 #endif 59 p->is_init = TRUE; 60 p->lock_id = (u16)lock_id; 61 } 62 (void)OS_RestoreInterrupts(bak_psr); 63 } 64 65 // Allocate device using exclusive control of processor 66 void MIi_LockCard(void) 67 { 68 // Initialize here if necessary, if that is convenient 69 MIi_InitCard(); 70 CARD_LockRom(mii_card_param.lock_id); 71 } 72 73 // Release the device using exclusive control of processor 74 void MIi_UnlockCard(void) 75 { 76 SDK_ASSERT(mii_card_param.is_init); 77 CARD_UnlockRom(mii_card_param.lock_id); 78 } 79 80 // Unlock the MI itself before user callback 81 static void MIi_OnAsyncEnd(void *arg) 82 { 83 MIi_UnlockCard(); 84 { 85 MIDmaCallback func = mii_card_param.dma_callback; 86 mii_card_param.dma_callback = NULL; 87 if (func) 88 (*func) (arg); 89 } 90 } 91 92 // Load the card (asynchronous) 93 void MIi_ReadCardAsync(u32 dmaNo, const void *src, void *dst, u32 size, 94 MIDmaCallback callback, void *arg) 95 { 96 MIi_LockCard(); 97 mii_card_param.dma_callback = callback; 98 (void)CARD_ReadRomAsync(dmaNo, src, dst, size, MIi_OnAsyncEnd, arg); 99 } 100 101 #endif //#if 0 102