1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - MI
3   File:     mi_ndma.h
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:: 2008-10-16#$
14   $Rev: 8978 $
15   $Author: yada $
16  *---------------------------------------------------------------------------*/
17 #ifndef TWL_COMMON_MI_DMA_H_
18 #define TWL_COMMON_MI_DMA_H_
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 //--------------------------------------------------------------------------------
25 #define MIi_SRC_INC         (MI_NDMA_SRC_INC      | MI_NDMA_SRC_RELOAD_DISABLE)
26 #define MIi_SRC_DEC         (MI_NDMA_SRC_DEC      | MI_NDMA_SRC_RELOAD_DISABLE)
27 #define MIi_SRC_FIX         (MI_NDMA_SRC_FIX      | MI_NDMA_SRC_RELOAD_DISABLE)
28 #define MIi_SRC_FILLDATA  	(MI_NDMA_SRC_FILLDATA | MI_NDMA_SRC_RELOAD_DISABLE)
29 
30 #define MIi_DEST_INC        (MI_NDMA_DEST_INC     | MI_NDMA_DEST_RELOAD_DISABLE)
31 #define MIi_DEST_DEC        (MI_NDMA_DEST_DEC     | MI_NDMA_DEST_RELOAD_DISABLE)
32 #define MIi_DEST_FIX        (MI_NDMA_DEST_FIX     | MI_NDMA_DEST_RELOAD_DISABLE)
33 #define MIi_DEST_INC_RELOAD (MI_NDMA_SRC_INC      | MI_NDMA_DEST_RELOAD_ENABLE)
34 
35 #define MIi_IMM             (MI_NDMA_IMM_MODE_ON)
36 
37 #define MIi_CONT            (MI_NDMA_CONTINUOUS_ON)
38 
39 typedef enum
40 {
41 	MIi_NDMA_TYPE_FILL      = 0,
42 	MIi_NDMA_TYPE_COPY      = 1,
43 	MIi_NDMA_TYPE_SEND      = 2,
44 	MIi_NDMA_TYPE_RECV      = 3,
45 	MIi_NDMA_TYPE_PIPE		= 4,
46 
47 	MIi_NDMA_TYPE_HBLANK    = 5,
48 	MIi_NDMA_TYPE_HBLANK_IF = 6,
49 	MIi_NDMA_TYPE_MMCOPY    = 7,
50 	MIi_NDMA_TYPE_GXCOPY    = 8,
51 	MIi_NDMA_TYPE_GXCOPY_IF = 9,
52 	MIi_NDMA_TYPE_CAMERACONT= 10
53 
54 } MIiNDmaType;
55 
56 extern MINDmaConfig MIi_NDmaConfig[ MI_NDMA_MAX_NUM + 1 ];
57 
58 //================================================================================
59 //          CALLBACK
60 //================================================================================
MIi_CallCallback(MINDmaCallback callback,void * arg)61 static inline void MIi_CallCallback(MINDmaCallback callback, void *arg)
62 {
63     if (callback)
64     {
65         (callback) (arg);
66     }
67 }
68 
69 //================================================================================
70 //         ASSERT
71 //================================================================================
72 #define MIi_ASSERT_DMANO( dmaNo )        SDK_ASSERTMSG( (dmaNo) <= MI_DMA_MAX_NUM, "illegal DMA No." )
73 #define MIi_ASSERT_MUL2( size )          SDK_ASSERTMSG( ((size) & 1) == 0, "size & 1 must be 0" )
74 #define MIi_ASSERT_MUL4( size )          SDK_ASSERTMSG( ((size) & 3) == 0, "size & 3 must be 0" )
75 #define MIi_ASSERT_SRC_ALIGN512( src )   SDK_ASSERTMSG( ((u32)(src) & 511) == 0, "source address must be in 512-byte alignment" )
76 #define MIi_ASSERT_SRC_ALIGN4( src )     SDK_ASSERTMSG( ((u32)(src) & 3) == 0, "source address must be in 4-byte alignment" )
77 #define MIi_ASSERT_SRC_ALIGN2( src )     SDK_ASSERTMSG( ((u32)(src) & 1) == 0, "source address must be in 2-byte alignment" )
78 #define MIi_ASSERT_DEST_ALIGN4( dest )   SDK_ASSERTMSG( ((u32)(dest) & 3) == 0, "destination address must be in 4-byte alignment" )
79 #define MIi_ASSERT_DEST_ALIGN2( dest )   SDK_ASSERTMSG( ((u32)(dest) & 1) == 0, "destination address must be in 2-byte alignment" )
80 #define MIi_ASSERT_TIMERNO( timerNo )    SDK_ASSERTMSG( (timerNo) <= 3, "illegal Timer No." );
81 
82 
83 //================================================================================
84 //         CHECK
85 //================================================================================
86 //----------------------------------------------------------------
87 //      Check if specified area is in ITCM/DTCM.
88 //      (.c code is in common/src/mi_dma.c)
89 //
90 #if defined( SDK_ARM9 ) && defined( SDK_DEBUG )
91 void    MIi_CheckAddressInTCM(u32 addr, u32 size);
92 #define MIi_WARNING_ADDRINTCM( addr, size )  MIi_CheckAddressInTCM( (u32)addr, (u32)size )
93 #else
94 #define MIi_WARNING_ADDRINTCM( addr, size )  ((void)0)
95 #endif
96 
97 
98 //----------------------------------------------------------------
99 //      for DMA check
100 //      (must avoid multiple auto start DMA)
101 //
102 #ifdef SDK_ARM9
103 //void    MIi_CheckAnotherAutoDMA(u32 dmaNo, u32 dmaType);
104 #endif
105 
106 //================================================================================
107 //         CHECK
108 //================================================================================
109 void MIi_NDma_withConfig_Dev(MIiNDmaType ndmaType,
110                              u32 ndmaNo,
111                              const void* src,
112                              void* dest,
113                              u32 data,
114                              u32 size,
115                              const MINDmaConfig *config,
116                              MINDmaDevice dev,
117                              u32 enable );
118 
119 void MIi_NDmaAsync_withConfig_Dev(MIiNDmaType ndmaType,
120                                   u32 ndmaNo,
121                                   const void* src,
122                                   void* dest,
123                                   u32 data,
124                                   u32 size,
125                                   MINDmaCallback callback,
126                                   void *arg,
127                                   const MINDmaConfig *config,
128                                   MINDmaDevice dev,
129                                   u32 enable );
130 
MIi_NDma(MIiNDmaType ndmaType,u32 ndmaNo,const void * src,void * dest,u32 data,u32 size,u32 enable)131 static inline void MIi_NDma(MIiNDmaType ndmaType,
132                             u32 ndmaNo,
133                             const void* src,
134                             void* dest,
135                             u32 data,
136                             u32 size,
137                             u32 enable )
138 {
139     MIi_NDma_withConfig_Dev( ndmaType, ndmaNo,
140                              src, dest, data, size,
141                              &MIi_NDmaConfig[ndmaNo], MIi_NDMA_TIMING_IMMIDIATE, enable );
142 }
143 
144 
MIi_NDmaAsync(MIiNDmaType ndmaType,u32 ndmaNo,const void * src,void * dest,u32 data,u32 size,MINDmaCallback callback,void * arg,u32 enable)145 static inline void MIi_NDmaAsync(MIiNDmaType ndmaType,
146                                  u32 ndmaNo,
147                                  const void* src,
148                                  void* dest,
149                                  u32 data,
150                                  u32 size,
151                                  MINDmaCallback callback,
152                                  void *arg,
153                                  u32 enable )
154 {
155     MIi_NDmaAsync_withConfig_Dev( ndmaType, ndmaNo,
156                                   src, dest, data, size,
157                                   callback, arg,
158                                   &MIi_NDmaConfig[ndmaNo], MIi_NDMA_TIMING_IMMIDIATE, enable );
159 }
160 
161 
162 
163 
164 
165 #ifdef __cplusplus
166 } /* extern "C" */
167 #endif
168 
169 /* MI_COMMON_MI_DMA_H_ */
170 #endif
171 
172