1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - NWM - libraries
3   File:     nwm_end.c
4 
5   Copyright 2007-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:: 2009-06-04#$
14   $Rev: 10698 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 
18 #include <twl.h>
19 #include "nwm_common_private.h"
20 #include "nwm_arm9_private.h"
21 
22 
23 /*---------------------------------------------------------------------------*
24   Name:         NWM_End
25 
26   Description:  Shuts down the NWM library.
27                 This is a synchronous function that only shuts down processing on the ARM9.
28 
29   Arguments:    None.
30 
31   Returns:      NWMRetCode: Returns the processing result.
32  *---------------------------------------------------------------------------*/
33 
NWM_End(void)34 NWMRetCode NWM_End(void)
35 {
36     NWMRetCode result;
37     OSIntrMode e;
38     extern NWMArm9Buf *nwm9buf;
39     extern u8 nwmInitialized;
40 
41     SDK_NULL_ASSERT(nwm9buf);
42 
43     // This can only run in the INITIALIZED state
44     result = NWMi_CheckState(1, NWM_STATE_INITIALIZED);
45     NWM_CHECK_RESULT(result);
46 
47     e = OS_DisableInterrupts();
48 
49     nwm9buf->status->state = NWM_STATE_NONE;  // As an exception, set the initial state here alone (this was originally done by the ARM7)
50 
51     // Clears the FIFO buffer writable flag
52     NWMi_ClearFifoRecvFlag();
53 
54     PXI_SetFifoRecvCallback(PXI_FIFO_TAG_WMW, NULL);
55     nwm9buf = 0;
56 
57     // Normal end
58     nwmInitialized = 0;
59     (void)OS_RestoreInterrupts(e);
60     return NWM_RETCODE_SUCCESS;
61 }
62