1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - include - dsp
3 File: dsp_if.h
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 #ifndef TWL_DSP_IF_H_
19 #define TWL_DSP_IF_H_
20
21 #include <twl/types.h>
22 #include <twl/hw/ARM9/ioreg_DSP.h>
23 #include <nitro/os/common/emulator.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /*===========================================================================*/
30
31 /*---------------------------------------------------------------------------*
32 Constant definitions
33 *---------------------------------------------------------------------------*/
34 typedef enum
35 {
36 DSP_FIFO_MEMSEL_DATA = (0x0 << REG_DSP_PCFG_MEMSEL_SHIFT),
37 DSP_FIFO_MEMSEL_MMIO = (0x1 << REG_DSP_PCFG_MEMSEL_SHIFT),
38 DSP_FIFO_MEMSEL_PROGRAM = (0x5 << REG_DSP_PCFG_MEMSEL_SHIFT)
39 }
40 DSPFifoMemSel;
41
42 typedef enum
43 {
44 DSP_FIFO_RECV_2B = (0x0 << REG_DSP_PCFG_DRS_SHIFT),
45 DSP_FIFO_RECV_16B = (0x1 << REG_DSP_PCFG_DRS_SHIFT),
46 DSP_FIFO_RECV_32B = (0x2 << REG_DSP_PCFG_DRS_SHIFT),
47 DSP_FIFO_RECV_CONTINUOUS = (0x3 << REG_DSP_PCFG_DRS_SHIFT)
48 }
49 DSPFifoRecvLength;
50
51 typedef enum
52 {
53 DSP_FIFO_INTR_SEND_EMPTY = REG_DSP_PCFG_WFEIE_MASK,
54 DSP_FIFO_INTR_SEND_FULL = REG_DSP_PCFG_WFFIE_MASK,
55 DSP_FIFO_INTR_RECV_NOT_EMPTY = REG_DSP_PCFG_RFNEIE_MASK,
56 DSP_FIFO_INTR_RECV_FULL = REG_DSP_PCFG_RFFIE_MASK
57 }
58 DSPFifoIntr;
59
60 // For complex API
61 typedef enum
62 {
63 DSP_FIFO_FLAG_SRC_INC = (0UL << 0),
64 DSP_FIFO_FLAG_SRC_FIX = (1UL << 0),
65
66 DSP_FIFO_FLAG_DEST_INC = (0UL << 1),
67 DSP_FIFO_FLAG_DEST_FIX = (1UL << 1),
68
69 DSP_FIFO_FLAG_RECV_UNIT_CONTINUOUS = (0UL << 8),
70 DSP_FIFO_FLAG_RECV_UNIT_2B = (1UL << 8),
71 DSP_FIFO_FLAG_RECV_UNIT_16B = (2UL << 8),
72 DSP_FIFO_FLAG_RECV_UNIT_32B = (3UL << 8),
73 DSP_FIFO_FLAG_RECV_MASK = (3UL << 8)
74 }
75 DSPFifoFlag;
76
77 // Support the load process for old specifications a little longer.
78 #define DSP_SUPPORT_OBSOLETE_LOADER
79
80 /*---------------------------------------------------------------------------*
81 Structure definitions
82 *---------------------------------------------------------------------------*/
83
84 /*---------------------------------------------------------------------------*
85 Function definitions
86 *---------------------------------------------------------------------------*/
87
88 /*---------------------------------------------------------------------------*
89 Name: DSP_PowerOn
90
91 Description: Turns on the DSP and configures it to be in the reset state.
92 You must call DSP_ResetOff() to start the DSP.
93
94 Arguments: None.
95
96 Returns: None.
97 *---------------------------------------------------------------------------*/
98 void DSP_PowerOnCore(void);
DSP_PowerOn(void)99 SDK_INLINE void DSP_PowerOn(void)
100 {
101 if (OS_IsRunOnTwl() == TRUE)
102 {
103 DSP_PowerOnCore();
104 }
105 }
106
107 /*---------------------------------------------------------------------------*
108 Name: DSP_PowerOff
109
110 Description: Turns off the DSP.
111
112 Arguments: None.
113
114 Returns: None.
115 *---------------------------------------------------------------------------*/
116 void DSP_PowerOffCore(void);
DSP_PowerOff(void)117 SDK_INLINE void DSP_PowerOff(void)
118 {
119 if (OS_IsRunOnTwl() == TRUE)
120 {
121 DSP_PowerOffCore();
122 }
123 }
124
125 /*---------------------------------------------------------------------------*
126 Name: DSP_ResetOn
127
128 Description: Resets the DSP.
129
130 Arguments: None.
131
132 Returns: None.
133 *---------------------------------------------------------------------------*/
134 void DSP_ResetOnCore(void);
DSP_ResetOn(void)135 SDK_INLINE void DSP_ResetOn(void)
136 {
137 if (OS_IsRunOnTwl() == TRUE)
138 {
139 DSP_ResetOnCore();
140 }
141 }
142
143 /*---------------------------------------------------------------------------*
144 Name: DSP_ResetOff
145
146 Description: Starts the DSP from the reset state.
147
148 Arguments: None.
149
150 Returns: None.
151 *---------------------------------------------------------------------------*/
152 void DSP_ResetOffCore(void);
DSP_ResetOff(void)153 SDK_INLINE void DSP_ResetOff(void)
154 {
155 if (OS_IsRunOnTwl() == TRUE)
156 {
157 DSP_ResetOffCore();
158 }
159 }
160
161 /*---------------------------------------------------------------------------*
162 Name: DSP_ResetOffEx
163
164 Description: Starts the DSP from the reset state.
165
166 Arguments: bitmap: Bitmap of the reply registers and semaphores that allow interrupts from the DSP to the ARM9
167
168 Returns: None.
169 *---------------------------------------------------------------------------*/
170 void DSP_ResetOffExCore(u16 bitmap);
DSP_ResetOffEx(u16 bitmap)171 SDK_INLINE void DSP_ResetOffEx(u16 bitmap)
172 {
173 if (OS_IsRunOnTwl() == TRUE)
174 {
175 DSP_ResetOffExCore(bitmap);
176 }
177 }
178
179
180 /*---------------------------------------------------------------------------*
181 Name: DSP_ResetInterface
182
183 Description: Initializes the registers.
184 You must call this function when the DSP is reset.
185
186 Arguments: None.
187
188 Returns: None.
189 *---------------------------------------------------------------------------*/
190 void DSP_ResetInterfaceCore(void);
DSP_ResetInterface(void)191 SDK_INLINE void DSP_ResetInterface(void)
192 {
193 if (OS_IsRunOnTwl() == TRUE)
194 {
195 DSP_ResetInterfaceCore();
196 }
197 }
198
199 /*---------------------------------------------------------------------------*
200 Name: DSP_EnableRecvDataInterrupt
201
202 Description: Enables interrupts for the specified reply register.
203
204 Arguments: dataNo: Reply register number (0-2)
205
206 Returns: None.
207 *---------------------------------------------------------------------------*/
208 void DSP_EnableRecvDataInterruptCore(u32 dataNo);
DSP_EnableRecvDataInterrupt(u32 dataNo)209 SDK_INLINE void DSP_EnableRecvDataInterrupt(u32 dataNo)
210 {
211 if (OS_IsRunOnTwl() == TRUE)
212 {
213 DSP_EnableRecvDataInterruptCore(dataNo);
214 }
215 }
216
217 /*---------------------------------------------------------------------------*
218 Name: DSP_DisableRecvDataInterrupt
219
220 Description: Disables interrupts for the specified reply register.
221
222 Arguments: dataNo: Reply register number (0-2)
223
224 Returns: None.
225 *---------------------------------------------------------------------------*/
226 void DSP_DisableRecvDataInterruptCore(u32 dataNo);
DSP_DisableRecvDataInterrupt(u32 dataNo)227 SDK_INLINE void DSP_DisableRecvDataInterrupt(u32 dataNo)
228 {
229 if (OS_IsRunOnTwl() == TRUE)
230 {
231 DSP_DisableRecvDataInterruptCore(dataNo);
232 }
233 }
234
235 /*---------------------------------------------------------------------------*
236 Name: DSP_SendDataIsEmpty
237
238 Description: Checks whether the DSP has received data for the specified command register.
239
240 Arguments: dataNo: Command register number (0-2)
241
242 Returns: TRUE if the DSP has already received data.
243 *---------------------------------------------------------------------------*/
244 BOOL DSP_SendDataIsEmptyCore(u32 dataNo);
DSP_SendDataIsEmpty(u32 dataNo)245 SDK_INLINE BOOL DSP_SendDataIsEmpty(u32 dataNo)
246 {
247 if (OS_IsRunOnTwl() == TRUE)
248 {
249 return DSP_SendDataIsEmptyCore(dataNo);
250 }
251 return FALSE;
252 }
253
254 /*---------------------------------------------------------------------------*
255 Name: DSP_RecvDataIsReady
256
257 Description: Checks whether data was sent from the DSP to the specified reply register.
258
259 Arguments: dataNo: Reply register number (0-2)
260
261 Returns: TRUE if the DSP has sent data.
262 *---------------------------------------------------------------------------*/
263 BOOL DSP_RecvDataIsReadyCore(u32 dataNo);
DSP_RecvDataIsReady(u32 dataNo)264 SDK_INLINE BOOL DSP_RecvDataIsReady(u32 dataNo)
265 {
266 if (OS_IsRunOnTwl() == TRUE)
267 {
268 return DSP_RecvDataIsReadyCore(dataNo);
269 }
270 return FALSE;
271 }
272
273 /*---------------------------------------------------------------------------*
274 Name: DSP_SendData
275
276 Description: Sends data to the DSP.
277
278 Arguments: dataNo: Command register number (0-2)
279 data: Data to send
280
281 Returns: None.
282 *---------------------------------------------------------------------------*/
283 void DSP_SendDataCore(u32 dataNo, u16 data);
DSP_SendData(u32 dataNo,u16 data)284 SDK_INLINE void DSP_SendData(u32 dataNo, u16 data)
285 {
286 if (OS_IsRunOnTwl() == TRUE)
287 {
288 DSP_SendDataCore(dataNo, data);
289 }
290 }
291
292 /*---------------------------------------------------------------------------*
293 Name: DSP_RecvData
294
295 Description: Receives data from the DSP.
296
297 Arguments: dataNo: Reply register number (0-2)
298
299 Returns: The received data.
300 *---------------------------------------------------------------------------*/
301 u16 DSP_RecvDataCore(u32 dataNo);
DSP_RecvData(u32 dataNo)302 SDK_INLINE u16 DSP_RecvData(u32 dataNo)
303 {
304 if (OS_IsRunOnTwl() == TRUE)
305 {
306 return DSP_RecvDataCore(dataNo);
307 }
308 return 0;
309 }
310
311 /*---------------------------------------------------------------------------*
312 Name: DSP_EnableFifoInterrupt
313
314 Description: Enables FIFO interrupts.
315
316 Arguments: type: Cause of the FIFO interrupt
317
318 Returns: None.
319 *---------------------------------------------------------------------------*/
320 void DSP_EnableFifoInterruptCore(DSPFifoIntr type);
DSP_EnableFifoInterrupt(DSPFifoIntr type)321 SDK_INLINE void DSP_EnableFifoInterrupt(DSPFifoIntr type)
322 {
323 if (OS_IsRunOnTwl() == TRUE)
324 {
325 DSP_EnableFifoInterruptCore(type);
326 }
327 }
328
329 /*---------------------------------------------------------------------------*
330 Name: DSP_DisableFifoInterrupt
331
332 Description: Disables FIFO interrupts.
333
334 Arguments: type: Cause of the FIFO interrupt
335
336 Returns: None.
337 *---------------------------------------------------------------------------*/
338 void DSP_DisableFifoInterruptCore(DSPFifoIntr type);
DSP_DisableFifoInterrupt(DSPFifoIntr type)339 SDK_INLINE void DSP_DisableFifoInterrupt(DSPFifoIntr type)
340 {
341 if (OS_IsRunOnTwl() == TRUE)
342 {
343 DSP_DisableFifoInterruptCore(type);
344 }
345 }
346
347 /*---------------------------------------------------------------------------*
348 Name: DSP_SendFifoEx
349
350 Description: Writes data in the DSP's memory space.
351
352 Arguments: memsel: Memory space in which to write data
353 dest: Address to write to (half-word).
354 If the most-significant 16 bits are set, values must be set in the DMA register in advance.
355
356 src: Data to write
357 size: Length of the data to write (half-word)
358 flags: You can select a write mode other than DSP_FIFO_FLAG_RECV_UNIT_* from DSPFifoFlag
359
360
361 Returns: None.
362 *---------------------------------------------------------------------------*/
363 void DSP_SendFifoExCore(DSPFifoMemSel memsel, u16 dest, const u16 *src, int size, u16 flags);
DSP_SendFifoEx(DSPFifoMemSel memsel,u16 dest,const u16 * src,int size,u16 flags)364 SDK_INLINE void DSP_SendFifoEx(DSPFifoMemSel memsel, u16 dest, const u16 *src, int size, u16 flags)
365 {
366 if (OS_IsRunOnTwl() == TRUE)
367 {
368 DSP_SendFifoExCore(memsel, dest, src, size, flags);
369 }
370 }
371
372 /*---------------------------------------------------------------------------*
373 Name: DSP_SendFifo
374
375 Description: Writes data in the DSP's memory space.
376
377 Arguments: memsel: Memory space in which to write data
378 dest: Address to write to (half-word).
379 If the most-significant 16 bits are set, values must be set in the DMA register ahead of time.
380
381 src: Data to write
382 size: Length of the data to write (half-word)
383
384 Returns: None.
385 *---------------------------------------------------------------------------*/
DSP_SendFifo(DSPFifoMemSel memsel,u16 dest,const u16 * src,int size)386 static inline void DSP_SendFifo(DSPFifoMemSel memsel, u16 dest, const u16 *src, int size)
387 {
388 if (OS_IsRunOnTwl() == TRUE)
389 {
390 DSP_SendFifoExCore(memsel, dest, src, size, 0);
391 }
392 }
393
394 /*---------------------------------------------------------------------------*
395 Name: DSP_RecvFifoEx
396
397 Description: Reads data from the DSP's memory space.
398
399 Arguments: memsel: Memory space to read data from (other than program memory)
400 dest: Address at which to receive data
401 src: Address from which the data was received (half-word)
402 If the most-significant 16 bits are set, values must be set in the DMA register ahead of time.
403
404 size: Data size to read (half-word)
405 flags: Select the read mode from DSPFifoFlag
406
407 Returns: None.
408 *---------------------------------------------------------------------------*/
409 void DSP_RecvFifoExCore(DSPFifoMemSel memsel, u16 *dest, u16 src, int size, u16 flags);
DSP_RecvFifoEx(DSPFifoMemSel memsel,u16 * dest,u16 src,int size,u16 flags)410 SDK_INLINE void DSP_RecvFifoEx(DSPFifoMemSel memsel, u16 *dest, u16 src, int size, u16 flags)
411 {
412 if (OS_IsRunOnTwl() == TRUE)
413 {
414 DSP_RecvFifoExCore(memsel, dest, src, size, flags);
415 }
416 }
417
418 /*---------------------------------------------------------------------------*
419 Name: DSP_RecvFifo
420
421 Description: Reads data from the DSP's memory space.
422
423 Arguments: memsel: Memory space to read data from (other than program memory)
424 dest: Address at which to receive data
425 src: Address from which the data was received (half-word)
426 If the most-significant 16 bits are set, values must be set in the DMA register ahead of time.
427
428 size: Data size to read (half-word)
429
430 Returns: None.
431 *---------------------------------------------------------------------------*/
DSP_RecvFifo(DSPFifoMemSel memsel,u16 * dest,u16 src,int size)432 static inline void DSP_RecvFifo(DSPFifoMemSel memsel, u16* dest, u16 src, int size)
433 {
434 if (OS_IsRunOnTwl() == TRUE)
435 {
436 DSP_RecvFifoExCore(memsel, dest, src, size, 0);
437 }
438 }
439
440 /*---------------------------------------------------------------------------*
441 Name: DSP_SetCommandReg
442
443 Description: Writes a value to a command register.
444
445 Arguments: regNo: Command register number (0-2)
446 data: Data
447
448 Returns: None.
449 *---------------------------------------------------------------------------*/
450 void DSP_SetCommandRegCore(u32 regNo, u16 data);
DSP_SetCommandReg(u32 regNo,u16 data)451 SDK_INLINE void DSP_SetCommandReg(u32 regNo, u16 data)
452 {
453 if (OS_IsRunOnTwl() == TRUE)
454 {
455 DSP_SetCommandRegCore(regNo, data);
456 }
457 }
458
459 /*---------------------------------------------------------------------------*
460 Name: DSP_GetReplyReg
461
462 Description: Reads a value from a reply register.
463
464 Arguments: regNo: Reply register number (0-2)
465
466 Returns: The data read.
467 *---------------------------------------------------------------------------*/
468 u16 DSP_GetReplyRegCore(u32 regNo);
DSP_GetReplyReg(u32 regNo)469 SDK_INLINE u16 DSP_GetReplyReg(u32 regNo)
470 {
471 if (OS_IsRunOnTwl() == TRUE)
472 {
473 return DSP_GetReplyRegCore(regNo);
474 }
475 return 0;
476 }
477
478 /*---------------------------------------------------------------------------*
479 Name: DSP_SetSemaphore
480
481 Description: Writes a value to the semaphore register for sending notifications from an ARM processor to the DSP.
482
483 Arguments: mask: Value to set
484
485 Returns: None.
486 *---------------------------------------------------------------------------*/
487 void DSP_SetSemaphoreCore(u16 mask);
DSP_SetSemaphore(u16 mask)488 SDK_INLINE void DSP_SetSemaphore(u16 mask)
489 {
490 if (OS_IsRunOnTwl() == TRUE)
491 {
492 DSP_SetSemaphoreCore(mask);
493 }
494 }
495
496 /*---------------------------------------------------------------------------*
497 Name: DSP_GetSemaphore
498
499 Description: Reads the value of the semaphore register for sending notifications from the DSP to an ARM processor.
500
501 Arguments: None.
502
503 Returns: The value written to the semaphore by the DSP.
504 *---------------------------------------------------------------------------*/
505 u16 DSP_GetSemaphoreCore(void);
DSP_GetSemaphore(void)506 SDK_INLINE u16 DSP_GetSemaphore(void)
507 {
508 if (OS_IsRunOnTwl() == TRUE)
509 {
510 return DSP_GetSemaphoreCore();
511 }
512 return 0;
513 }
514
515 /*---------------------------------------------------------------------------*
516 Name: DSP_ClearSemaphore
517
518 Description: Clears the value of the semaphore register for sending notifications from the DSP to an ARM processor.
519
520 Arguments: mask: Bits to clear
521
522 Returns: None.
523 *---------------------------------------------------------------------------*/
524 void DSP_ClearSemaphoreCore(u16 mask);
DSP_ClearSemaphore(u16 mask)525 SDK_INLINE void DSP_ClearSemaphore(u16 mask)
526 {
527 if (OS_IsRunOnTwl() == TRUE)
528 {
529 DSP_ClearSemaphoreCore(mask);
530 }
531 }
532
533 /*---------------------------------------------------------------------------*
534 Name: DSP_MaskSemaphore
535
536 Description: Sets bits that correspond to interrupts to disable in the semaphore register for sending notifications from the DSP to an ARM processor.
537
538 Arguments: mask: Bits corresponding to interrupts to disable
539
540 Returns: None.
541 *---------------------------------------------------------------------------*/
542 void DSP_MaskSemaphoreCore(u16 mask);
DSP_MaskSemaphore(u16 mask)543 SDK_INLINE void DSP_MaskSemaphore(u16 mask)
544 {
545 if (OS_IsRunOnTwl() == TRUE)
546 {
547 DSP_MaskSemaphoreCore(mask);
548 }
549 }
550
551 /*---------------------------------------------------------------------------*
552 Name: DSP_CheckSemaphoreRequest
553
554 Description: Checks whether there is an interrupt request from the semaphore register.
555
556 Arguments: None.
557
558 Returns: TRUE if there is a request.
559 *---------------------------------------------------------------------------*/
560 BOOL DSP_CheckSemaphoreRequestCore(void);
DSP_CheckSemaphoreRequest(void)561 SDK_INLINE BOOL DSP_CheckSemaphoreRequest(void)
562 {
563 if (OS_IsRunOnTwl() == TRUE)
564 {
565 return DSP_CheckSemaphoreRequestCore();
566 }
567 return FALSE;
568 }
569
570 #if defined(DSP_SUPPORT_OBSOLETE_LOADER)
571 /*---------------------------------------------------------------------------*
572 * The following shows candidate interfaces for termination because they are considered not to be currently in use
573 *---------------------------------------------------------------------------*/
574
575 /*---------------------------------------------------------------------------*
576 Name: DSP_LoadFileAuto
577
578 Description: Loads a COFF format DSP program and assigns the necessary WRAM to DSP.
579
580 Arguments: image: COFF file
581
582 Returns: TRUE on success.
583 *---------------------------------------------------------------------------*/
584 BOOL DSP_LoadFileAutoCore(const void *image);
DSP_LoadFileAuto(const void * image)585 SDK_INLINE BOOL DSP_LoadFileAuto(const void *image)
586 {
587 if (OS_IsRunOnTwl() == TRUE)
588 {
589 return DSP_LoadFileAutoCore(image);
590 }
591 return FALSE;
592 }
593
594 #endif
595
596
597 /*===========================================================================*/
598
599 #ifdef __cplusplus
600 } /* extern "C" */
601 #endif
602
603 #endif /* TWL_DSP_IF_H_ */
604