1 /*---------------------------------------------------------------------------*
2   Project:  TwlSDK - include - dsp
3   File:     dsp_if.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-09-17#$
14   $Rev: 8556 $
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:  Turn on power to the DSP block but do not reset it yet.
92                 You should call DSP_ResetOff() to boot 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 power to the DSP block.
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:  Boots the DSP if it is in 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:  Boots the DSP if it is in the Reset state.
165 
166   Arguments:    bitmap: Enables interrupts for receiving data from a DSP bitmap.
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:  Resets the interface registers.
184                 This should be called from the Reset state.
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 receiving data from the DSP.
203 
204   Arguments:    dataNo:     Target data register (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 receiving data from the DSP.
221 
222   Arguments:    dataNo:     Target data register (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:  Whether the DSP received data that has been sent.
239 
240   Arguments:    dataNo:     Target data register (0-2)
241 
242   Returns:      None.
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:  Whether data has been sent from the DSP.
258 
259   Arguments:    dataNo:     Target data register (0-2)
260 
261   Returns:      None.
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:     Target data register (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:     Target data register (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:       One of the DSPFifoIntr values
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:       One of the DSPFifoIntr values
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 to the DSP memory space.
351 
352   Arguments:    memsel: One of the DSPFifoMemSel values
353                 dest:   Destination address (in half words).
354                         If you want to set the high address, ask the DSP to set
355                         the DMA register.
356                 src:    Data to send.
357                 size:   Data length to send (in half words).
358                 flags:  Bitwise OR of DSPFifoFlag values to specify a special mode
359                         without DSP_FIFO_FLAG_RECV_UNIT_*
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 to the DSP memory space normally.
376 
377   Arguments:    memsel: One of the DSPFifoMemSel values
378                 dest:   Destination address (in half words).
379                         If you want to set the high address, ask the DSP to set
380                         the DMA register.
381                 src:    Data to send.
382                 size:   Data length to send (in half words).
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 memory space.
398 
399   Arguments:    memsel: One of the DSPFifoMemSel values without a PROGRAM area
400                 dest:   Data to receive.
401                 src:    Source address (in half words).
402                         If you want to set the high address, ask the DSP to set
403                         the DMA register.
404                 size:   Data length to receive (in half words).
405                         Ignored unless in continuous mode
406                 flags:  Bitwise OR of DSPFifoFlag values to specify a special mode
407 
408   Returns:      None.
409  *---------------------------------------------------------------------------*/
410 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)411 SDK_INLINE void DSP_RecvFifoEx(DSPFifoMemSel memsel, u16 *dest, u16 src, int size, u16 flags)
412 {
413     if (OS_IsRunOnTwl() == TRUE)
414     {
415         DSP_RecvFifoExCore(memsel, dest, src, size, flags);
416     }
417 }
418 
419 /*---------------------------------------------------------------------------*
420   Name:         DSP_RecvFifo
421 
422   Description:  Reads data from the DSP memory space normally.
423 
424   Arguments:    memsel: One of the DSPFifoMemSel values
425                 dest:   Data to receive.
426                 src:    Source address (in half words).
427                         If you want to set the high address, ask the DSP to set
428                         the DMA register.
429                 size:   Data length to receive (in half words).
430 
431   Returns:      None.
432  *---------------------------------------------------------------------------*/
DSP_RecvFifo(DSPFifoMemSel memsel,u16 * dest,u16 src,int size)433 static inline void DSP_RecvFifo(DSPFifoMemSel memsel, u16* dest, u16 src, int size)
434 {
435     if (OS_IsRunOnTwl() == TRUE)
436     {
437         DSP_RecvFifoExCore(memsel, dest, src, size, 0);
438     }
439 }
440 
441 /*---------------------------------------------------------------------------*
442   Name:         DSP_SetCommandReg
443 
444   Description:  Sets the command register to signal to the DSP.
445 
446   Arguments:    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:  Gets the reply register to be received from the DSP.
463 
464   Arguments:    None.
465 
466   Returns:      data.
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:  Sets the semaphore to signal to the DSP.
482                 NOTE: The received semaphore is an individual register.
483 
484   Arguments:    mask:       Bit mask to set
485 
486   Returns:      None.
487  *---------------------------------------------------------------------------*/
488 void DSP_SetSemaphoreCore(u16 mask);
DSP_SetSemaphore(u16 mask)489 SDK_INLINE void DSP_SetSemaphore(u16 mask)
490 {
491     if (OS_IsRunOnTwl() == TRUE)
492     {
493         DSP_SetSemaphoreCore(mask);
494     }
495 }
496 
497 /*---------------------------------------------------------------------------*
498   Name:         DSP_GetSemaphore
499 
500   Description:  Gets the semaphore to be received from the DSP.
501                 NOTE: The sent semaphore is an individual register
502 
503   Arguments:    None.
504 
505   Returns:      The bit mask set by the DSP
506  *---------------------------------------------------------------------------*/
507 u16 DSP_GetSemaphoreCore(void);
DSP_GetSemaphore(void)508 SDK_INLINE u16 DSP_GetSemaphore(void)
509 {
510     if (OS_IsRunOnTwl() == TRUE)
511     {
512         return DSP_GetSemaphoreCore();
513     }
514     return 0;
515 }
516 
517 /*---------------------------------------------------------------------------*
518   Name:         DSP_ClearSemaphore
519 
520   Description:  Clears the semaphore to be received from the DSP.
521 
522   Arguments:    mask:       Bit mask to clear
523 
524   Returns:      None.
525  *---------------------------------------------------------------------------*/
526 void DSP_ClearSemaphoreCore(u16 mask);
DSP_ClearSemaphore(u16 mask)527 SDK_INLINE void DSP_ClearSemaphore(u16 mask)
528 {
529     if (OS_IsRunOnTwl() == TRUE)
530     {
531         DSP_ClearSemaphoreCore(mask);
532     }
533 }
534 
535 /*---------------------------------------------------------------------------*
536   Name:         DSP_MaskSemaphore
537 
538   Description:  Masks semaphores to send interrupts to the ARM9.
539 
540   Arguments:    mask:       Bit mask to disable interrupts
541 
542   Returns:      None.
543  *---------------------------------------------------------------------------*/
544 void DSP_MaskSemaphoreCore(u16 mask);
DSP_MaskSemaphore(u16 mask)545 SDK_INLINE void DSP_MaskSemaphore(u16 mask)
546 {
547     if (OS_IsRunOnTwl() == TRUE)
548     {
549         DSP_MaskSemaphoreCore(mask);
550     }
551 }
552 
553 /*---------------------------------------------------------------------------*
554   Name:         DSP_CheckSemaphoreRequest
555 
556   Description:  Whether there is requested interrupt by a semaphore.
557 
558   Arguments:    None.
559 
560   Returns:      TRUE if requested.
561  *---------------------------------------------------------------------------*/
562 BOOL DSP_CheckSemaphoreRequestCore(void);
DSP_CheckSemaphoreRequest(void)563 SDK_INLINE BOOL DSP_CheckSemaphoreRequest(void)
564 {
565     if (OS_IsRunOnTwl() == TRUE)
566     {
567         return DSP_CheckSemaphoreRequestCore();
568     }
569     return FALSE;
570 }
571 
572 #if defined(DSP_SUPPORT_OBSOLETE_LOADER)
573 /*---------------------------------------------------------------------------*
574  * The following is a discontinued candidate interface that is not thought to be used at the present
575  *---------------------------------------------------------------------------*/
576 
577 /*---------------------------------------------------------------------------*
578   Name:         DSP_LoadFileAuto
579 
580   Description:  Loads a DSP program in the COFF format and assigns the required WRAM to the DSP.
581 
582   Arguments:    image:     COFF file
583 
584   Returns:      TRUE if success
585  *---------------------------------------------------------------------------*/
586 BOOL DSP_LoadFileAutoCore(const void *image);
DSP_LoadFileAuto(const void * image)587 SDK_INLINE BOOL DSP_LoadFileAuto(const void *image)
588 {
589     if (OS_IsRunOnTwl() == TRUE)
590     {
591         return DSP_LoadFileAutoCore(image);
592     }
593     return FALSE;
594 }
595 
596 #endif
597 
598 
599 /*===========================================================================*/
600 
601 #ifdef __cplusplus
602 } /* extern "C" */
603 #endif
604 
605 #endif /* TWL_DSP_IF_H_ */
606