1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - include - dsp - common
3 File: byteaccess.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:: 2009-07-03#$
14 $Rev: 10855 $
15 $Author: yosizaki $
16 *---------------------------------------------------------------------------*/
17 #ifndef TWL_DSP_BYTEACCESS_H_
18 #define TWL_DSP_BYTEACCESS_H_
19
20
21 #ifdef SDK_TWL
22 #include <twl/types.h>
23 #include <twl/os.h>
24 #else
25 #include <dsp/types.h>
26 #endif
27
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33
34 /*---------------------------------------------------------------------------*/
35 /* Declarations */
36
37 // Type definitions to use when sharing data during inter-processor communication.
38 typedef u16 DSPAddr; // This type expresses an address in the DSP (2 bytes, 1 word)
39 typedef u16 DSPWord; // This type expresses a size in the DSP (2 bytes, 1 word)
40 typedef u16 DSPByte; // This type expresses a single-byte unit in the DSP (1 byte, 1 word)
41 typedef u32 DSPWord32; // This type expresses a size in the DSP (2 bytes, 1 word)
42 typedef u32 DSPByte32; // This type expresses a single-byte unit in the DSP (1 byte, 1 word)
43 typedef u32 DSPAddrInARM; // This type has converted DSP addresses into bytes
44
45 // Explicit Type-Conversion Macros
46 #define DSP_ADDR_TO_ARM(address) (u32)((address) << 1)
47 #define DSP_ADDR_TO_DSP(address) (u16)((u32)(address) >> 1)
48 #define DSP_WORD_TO_ARM(word) (u16)((word) << 1)
49 #define DSP_WORD_TO_DSP(word) (u16)((word) >> 1)
50 #define DSP_WORD_TO_ARM32(word) (u32)((word) << 1)
51 #define DSP_WORD_TO_DSP32(word) (u32)((word) >> 1)
52 #define DSP_32BIT_TO_ARM(value) (u32)(((u32)(value) >> 16) | ((u32)(value) << 16))
53 #define DSP_32BIT_TO_DSP(value) (u32)(((u32)(value) >> 16) | ((u32)(value) << 16))
54 #ifdef SDK_TWL
55 #define DSP_BYTE_TO_UNIT(byte) (u16)(byte)
56 #define DSP_UNIT_TO_BYTE(unit) (u16)(unit)
57 #else
58 #define DSP_BYTE_TO_UNIT(byte) (u16)((byte) >> 1)
59 #define DSP_UNIT_TO_BYTE(unit) (u16)((unit) << 1)
60 #endif
61
62 // The native size for sizeof(char) (this is 2 on the DSP and 1 on an ARM processor)
63 #define DSP_WORD_UNIT (3 - sizeof(DSPWord))
64
65
66 /*---------------------------------------------------------------------------*/
67 /* Functions */
68
69 #ifdef SDK_TWL
70
71 /*---------------------------------------------------------------------------*
72 Name: DSP_LoadWord
73
74 Description: Loads a single word (an even number of 16-bit units) from the DSP's data memory space.
75
76 Arguments: offset: The DSP address to transfer from (in words)
77
78 Returns: The loaded 16-bit data.
79 *---------------------------------------------------------------------------*/
DSP_LoadWord(DSPAddr offset)80 SDK_INLINE u16 DSP_LoadWord(DSPAddr offset)
81 {
82 u16 value;
83 OSIntrMode cpsr = OS_DisableInterrupts();
84 DSP_RecvFifo(DSP_FIFO_MEMSEL_DATA, &value, offset, DSP_WORD_TO_DSP(sizeof(u16)));
85 reg_DSP_PCFG &= ~(REG_DSP_PCFG_DRS_MASK | REG_DSP_PCFG_AIM_MASK);
86 (void)OS_RestoreInterrupts(cpsr);
87 return value;
88 }
89
90 /*---------------------------------------------------------------------------*
91 Name: DSP_StoreWord
92
93 Description: Writes a single word (an even number of 16-bit units) to the DSP's data memory space.
94
95 Arguments: offset: The DSP address to transfer to (in words)
96 value: The word value to write
97
98 Returns: None.
99 *---------------------------------------------------------------------------*/
DSP_StoreWord(DSPAddr offset,u16 value)100 SDK_INLINE void DSP_StoreWord(DSPAddr offset, u16 value)
101 {
102 OSIntrMode cpsr = OS_DisableInterrupts();
103 DSP_SendFifo(DSP_FIFO_MEMSEL_DATA, offset, &value, DSP_WORD_TO_DSP(sizeof(u16)));
104 // reg_DSP_PCFG &= ~(REG_DSP_PCFG_DRS_MASK | REG_DSP_PCFG_AIM_MASK);
105 (void)OS_RestoreInterrupts(cpsr);
106 }
107
108 /*---------------------------------------------------------------------------*
109 Name: DSP_Load8
110
111 Description: Loads 8 bits from the DSP's data memory space.
112
113 Arguments: offset: The DSP address to transfer from (in bytes)
114
115 Returns: The loaded 8-bit data.
116 *---------------------------------------------------------------------------*/
DSP_Load8(DSPAddrInARM offset)117 SDK_INLINE u8 DSP_Load8(DSPAddrInARM offset)
118 {
119 return (u8)(DSP_LoadWord(DSP_WORD_TO_DSP(offset)) >> ((offset & 1) << 3));
120 }
121
122 /*---------------------------------------------------------------------------*
123 Name: DSP_Load16
124
125 Description: Loads 16 bits from the DSP's data memory space.
126
127 Arguments: offset: The DSP address to transfer from (in bytes)
128
129 Returns: The loaded 16-bit data.
130 *---------------------------------------------------------------------------*/
131 u16 DSP_Load16(DSPAddrInARM offset);
132
133 /*---------------------------------------------------------------------------*
134 Name: DSP_Load32
135
136 Description: Loads 32 bits from the DSP's data memory space.
137
138 Arguments: offset: The DSP address to transfer from (in bytes)
139
140 Returns: The loaded 32-bit data.
141 *---------------------------------------------------------------------------*/
142 u32 DSP_Load32(DSPAddrInARM offset);
143
144 /*---------------------------------------------------------------------------*
145 Name: DSP_LoadData
146
147 Description: Loads data of an arbitrary length from the DSP's data memory space.
148
149 Arguments: offset: The DSP address to transfer from (in bytes)
150 buffer: Buffer to transfer data to
151 length: Size of the transmission
152
153 Returns: None.
154 *---------------------------------------------------------------------------*/
155 void DSP_LoadData(DSPAddrInARM offset, void *buffer, u32 length);
156
157 /*---------------------------------------------------------------------------*
158 Name: DSP_Store8
159
160 Description: Writes 8 bits to the DSP's data memory space.
161
162 Arguments: offset: The DSP address to transfer to (in bytes)
163 value: The 8-bit value to write
164
165 Returns: None.
166 *---------------------------------------------------------------------------*/
167 void DSP_Store8(DSPAddrInARM offset, u8 value);
168
169 /*---------------------------------------------------------------------------*
170 Name: DSP_Store16
171
172 Description: Writes 16 bits to the DSP's data memory space.
173
174 Arguments: offset: The DSP address to transfer to (in bytes)
175 value: The 16-bit value to write
176
177 Returns: None.
178 *---------------------------------------------------------------------------*/
179 void DSP_Store16(DSPAddrInARM offset, u16 value);
180
181 /*---------------------------------------------------------------------------*
182 Name: DSP_Store32
183
184 Description: Writes 32 bits to the DSP's data memory space.
185
186 Arguments: offset: The DSP address to transfer to (in bytes)
187 value: The 32-bit value to write
188
189 Returns: None.
190 *---------------------------------------------------------------------------*/
191 void DSP_Store32(DSPAddrInARM offset, u32 value);
192
193 /*---------------------------------------------------------------------------*
194 Name: DSP_StoreData
195
196 Description: Writes data of an arbitrary length to the DSP's data memory space.
197
198 Arguments: offset: The DSP address to transfer to (in bytes)
199 buffer: Buffer to transfer data from
200 length: Size of the transmission
201
202 Returns: None.
203 *---------------------------------------------------------------------------*/
204 void DSP_StoreData(DSPAddrInARM offset, const void *buffer, u32 length);
205
206
207 #endif // SDK_TWL
208
209
210 /*===========================================================================*/
211
212 #ifdef __cplusplus
213 } /* extern "C" */
214 #endif
215
216 #endif /* TWL_DSP_BYTEACCESS_H_ */
217