1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - CTRDG - include
3   File:     ctrdg_sram.h
4 
5   Copyright 2003-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:: 2008-09-18#$
14   $Rev: 8573 $
15   $Author: okubata_ryoma $
16  *---------------------------------------------------------------------------*/
17 #ifndef NITRO_CTRDG_SRAM_H_
18 #define NITRO_CTRDG_SRAM_H_
19 
20 #include <nitro.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 /* For debugging */
27 //#ifndef __SRAM_DEBUG
28 #define CTRDG_AGB_SRAM_ADR          0x0A000000  /* SRAM leading address */
29 #define CTRDG_AGB_SRAM_SIZE_256K    0x00008000  /* 256K SRAM size */
30 #define CTRDG_AGB_SRAM_SIZE_512K    0x00010000  /* 512K SRAM size */
31 //#else
32 //#define CTRDG_AGB_SRAM_ADR        0x02018000
33 //#define CTRDG_AGB_SRAM_SIZE_256K    0x00000400
34 //#define CTRDG_AGB_SRAM_SIZE_512K    0x00000800
35 //#endif
36 
37 /* Max number of retries for the CTRDG_WriteAgbSramEx function */
38 #define CTRDG_AGB_SRAM_RETRY_MAX    3
39 
40 
41 /*------------------------------------------------------------------
42 --------------------------------------------------------------------*/
43 
44 /*------------------------------------------------------------------*/
45 /*          Data read                                          */
46 /*------------------------------------------------------------------*/
47 /*---------------------------------------------------------------------------*
48   Name:         CTRDG_ReadAgbSram
49                 CTRDG_ReadAgbSramAsync
50 
51                 Corresponding AGB function: extern void ReadSram(u8 *src, u8 *dst, u32 size)
52 
53   Description:  From the SRAM address specified in the argument, reads 'size' bytes worth of data to the working memory starting at the 'dst' address.
54 
55 
56   Arguments:    src: The read source SRAM address (address in the AGB memory map)
57                 dst: The work region address where the read data is stored (address in the AGB memory map)
58                 size: Read size in bytes
59                 callback: The callback function invoked when the read process is complete (only for asynchronous functions).
60 
61   Returns:      None.
62  *---------------------------------------------------------------------------*/
63 extern void CTRDG_ReadAgbSram(u32 src, void *dst, u32 size);
64 extern void CTRDG_ReadAgbSramAsync(u32 src, void *dst, u32 size, CTRDG_TASK_FUNC callback);
65 
66 
67 /*------------------------------------------------------------------*/
68 /*          Writing the data                                          */
69 /*------------------------------------------------------------------*/
70 /*---------------------------------------------------------------------------*
71   Name:         CTRDG_WriteAgbSram
72                 CTRDG_WriteAgbSramAsync
73 
74                 Corresponding AGB function: extern void WriteSram(u8 *dst, u8 *src, u32 size)
75 
76   Description:  From the work region address specified in the argument, writes 'size' bytes worth of data to SRAM starting at the 'dst' address.
77 
78 
79   Arguments:    dst: Write destination SRAM address (address in the AGB memory map)
80                 src: Write source work region address
81                 size: Write size in bytes
82                 callback: The callback function called when the write processes complete (only for asynchronous functions).
83 
84   Returns:      None.
85  *---------------------------------------------------------------------------*/
86 extern void CTRDG_WriteAgbSram(u32 dst, const void *src, u32 size);
87 extern void CTRDG_WriteAgbSramAsync(u32 dst, const void *src, u32 size, CTRDG_TASK_FUNC callback);
88 
89 
90 /*------------------------------------------------------------------*/
91 /*          Data verification                                        */
92 /*------------------------------------------------------------------*/
93 /*---------------------------------------------------------------------------*
94   Name:         CTRDG_VerifyAgbSram
95                 CTRDG_VerifyAgbSramAsync
96 
97                 Corresponding AGB function: extern u32 VerifySram(u8 *tgt, u8 *src, u32 size)
98 
99   Description:  Verifies the data from the work region's 'src' address with the data at SRAM's 'tgt' address in 'size' byte portions.
100                 This function returns a 0 when verifications end normally, and when a verification error occurs, it returns the address where the error occurred.
101 
102                 In addition, in the asynchronous versions, by referring to 'result', a member of the CTRDGTaskInfo structure that is an argument of the callback function returned after calling this routine, it is possible to know whether the verification process succeeded.
103 
104 
105   Arguments:    tgt: Pointer to the verify-target SRAM address (write destination data, address in the AGB memory map)
106                 src: Pointer to the verify-source work region address (the original data)
107                 size: Verify size in bytes
108                 callback: The callback function called when the verification process completes (only for asynchronous functions)
109 
110   Returns:      0     : Normal end
111                 Non-zero: Returns the device-side error address for a verify error. (only for synchronous functions)
112  *---------------------------------------------------------------------------*/
113 extern u32 CTRDG_VerifyAgbSram(u32 tgt, const void *src, u32 size);
114 extern void CTRDG_VerifyAgbSramAsync(u32 tgt, const void *src, u32 size, CTRDG_TASK_FUNC callback);
115 
116 
117 /*------------------------------------------------------------------*/
118 /*          Writing & Verifying the Data                              */
119 /*------------------------------------------------------------------*/
120 /*---------------------------------------------------------------------------*
121   Name:         CTRDG_WriteAndVerifyAgbSram
122                 CTRDG_WriteAndVerifyAgbSramAsync
123 
124                 Corresponding AGB function: extern u32 WriteSramEx(u8 *dst, u8 *src, u32 size)
125 
126   Description:  After performing writes internally with CTRDG_WriteAgbSram, performs verification with CTRDG_VerifyAgbSram; when errors occur, retries are made up to a maximum of CTRDG_AGB_SRAM_RETRY_MAX (defined in ctrdg_sram.h) times.
127 
128 
129                 In addition, in the asynchronous versions, by referring to 'result', a member of the CTRDGTaskInfo structure that is an argument of the callback function returned after calling this routine, it is possible to know whether the WriteAndVerify process succeeded.
130 
131 
132   Arguments:    dst: Write destination SRAM address (address in the AGB memory map)
133                 src: Write source work region address
134                 size: Write/verify size in bytes
135                 callback: Callback function called when the WriteAndVerify process completes (only for asynchronous functions)
136 
137   Returns:      0     : Normal end
138                 Non-zero: Returns the device-side error address for a verify error. (only for synchronous functions)
139  *---------------------------------------------------------------------------*/
140 extern u32 CTRDG_WriteAndVerifyAgbSram(u32 dst, const void *src, u32 size);
141 extern void CTRDG_WriteAndVerifyAgbSramAsync(u32 dst, const void *src, u32 size,
142                                              CTRDG_TASK_FUNC callback);
143 
144 
145 #ifdef __cplusplus
146 }      /* extern "C" */
147 #endif
148 
149 #endif /* NITRO_CTRDG_SRAM_H_ */
150