1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - CARD - libraries
3   File:     card_command.h
4 
5   Copyright 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-12-17#$
14   $Rev: 11258 $
15   $Author: yada $
16 
17  *---------------------------------------------------------------------------*/
18 #ifndef NITRO_LIBRARIES_CARD_COMMAND_H__
19 #define NITRO_LIBRARIES_CARD_COMMAND_H__
20 
21 
22 #include <nitro/card/common.h>
23 #include <nitro/card/backup.h>
24 
25 #include <nitro/pxi.h>
26 #include <nitro/os.h>
27 
28 
29 #ifdef __cplusplus
30 extern  "C"
31 {
32 #endif
33 
34 
35 /*---------------------------------------------------------------------------*/
36 /* Constants */
37 
38 // Backup device functionality (used internally)
39 #define CARD_BACKUP_CAPS_AVAILABLE          (u32)(CARD_BACKUP_CAPS_READ - 1)
40 #define CARD_BACKUP_CAPS_READ               (u32)(1 << CARD_REQ_READ_BACKUP)
41 #define CARD_BACKUP_CAPS_WRITE              (u32)(1 << CARD_REQ_WRITE_BACKUP)
42 #define CARD_BACKUP_CAPS_PROGRAM            (u32)(1 << CARD_REQ_PROGRAM_BACKUP)
43 #define CARD_BACKUP_CAPS_VERIFY             (u32)(1 << CARD_REQ_VERIFY_BACKUP)
44 #define CARD_BACKUP_CAPS_ERASE_PAGE         (u32)(1 << CARD_REQ_ERASE_PAGE_BACKUP)
45 #define CARD_BACKUP_CAPS_ERASE_SECTOR       (u32)(1 << CARD_REQ_ERASE_SECTOR_BACKUP)
46 #define CARD_BACKUP_CAPS_ERASE_CHIP         (u32)(1 << CARD_REQ_ERASE_CHIP_BACKUP)
47 #define CARD_BACKUP_CAPS_READ_STATUS        (u32)(1 << CARD_REQ_READ_STATUS)
48 #define CARD_BACKUP_CAPS_WRITE_STATUS       (u32)(1 << CARD_REQ_WRITE_STATUS)
49 #define CARD_BACKUP_CAPS_ERASE_SUBSECTOR    (u32)(1 << CARD_REQ_ERASE_SUBSECTOR_BACKUP)
50 
51 
52 /*---------------------------------------------------------------------------*/
53 /* Declarations */
54 
55 // Parameters for sending and receiving PXI command requests.
56 typedef struct CARDiCommandArg
57 {
58     CARDResult result;                 /* Return value */
59     CARDBackupType type;               /* Device type */
60     u32     id;                        /* Card ID. */
61     u32     src;                       /* Transfer source */
62     u32     dst;                       /* Transfer destination */
63     u32     len;                       /* Transfer length */
64 
65     struct
66     {
67         /* Memory property */
68         u32     total_size;            /* Memory capacity (BYTE) */
69         u32     sect_size;             /* Write-sector (BYTE) */
70         u32     subsect_size;          /* Write-sector (BYTE) */
71         u32     page_size;             /* Write-page (BYTE) */
72         u32     addr_width;            /* Address width on command (BYTE) */
73         /* Maximum wait-time (as LCD-V-COUNT tick) */
74         u32     program_page;
75         u32     write_page;
76         u32     write_page_total;
77         u32     erase_chip;
78         u32     erase_chip_total;
79         u32     erase_sector;
80         u32     erase_sector_total;
81         u32     erase_subsector;
82         u32     erase_subsector_total;
83         u32     erase_page;
84         /* Initial parameter of status register */
85         u8      initial_status;
86         u8      padding1[3];
87         u32     caps;
88         u8      padding2[4];
89     }
90     spec;
91 
92 }
93 CARDiCommandArg;
94 
95 SDK_COMPILER_ASSERT(sizeof(CARDiCommandArg) % 32 == 0);
96 
97 
98 /*---------------------------------------------------------------------------*/
99 /* Functions */
100 
101 /*---------------------------------------------------------------------------*
102   Name:         CARDi_SendPxi
103 
104   Description:  Sends a PXI FIFO word.
105 
106   Arguments:    data       Data to send
107 
108   Returns:      None.
109  *---------------------------------------------------------------------------*/
CARDi_SendPxi(u32 data)110 SDK_INLINE void CARDi_SendPxi(u32 data)
111 {
112     while (PXI_SendWordByFifo(PXI_FIFO_TAG_FS, data, TRUE) < 0)
113     {
114     }
115 }
116 
117 #if	defined(SDK_ARM7)
118 /*---------------------------------------------------------------------------*
119   Name:         CARDi_LockMutexForARM7
120 
121   Description:  Mutex lock used for exclusive CARD access by ARM7
122 
123   Arguments:    None.
124 
125   Returns:      None.
126  *---------------------------------------------------------------------------*/
127 void CARDi_LockMutexForARM7(void);
128 
129 /*---------------------------------------------------------------------------*
130   Name:         CARDi_UnlockMutexForARM7
131 
132   Description:  Mutex unlock for exclusive CARD access by ARM7
133 
134   Arguments:    None.
135 
136   Returns:      None.
137  *---------------------------------------------------------------------------*/
138 void CARDi_UnlockMutexForARM7(void);
139 #endif // if defined(SDK_ARM7)
140 
141 /*---------------------------------------------------------------------------*
142   Name:         CARDi_OnFifoRecv
143 
144   Description:  PXI FIFO word receive callback.
145 
146   Arguments:    tag: PXI tag (always PXI_FIFO_TAG_FS)
147                 data: Receive data
148                 err: Error bit (according to old specs)
149 
150   Returns:      None.
151  *---------------------------------------------------------------------------*/
152 void    CARDi_OnFifoRecv(PXIFifoTag tag, u32 data, BOOL err);
153 
154 
155 #ifdef __cplusplus
156 } // extern "C"
157 #endif
158 
159 
160 #endif // NITRO_LIBRARIES_CARD_COMMAND_H__
161