Various minor clean-ups for mrobe
[kugel-rb.git] / firmware / target / arm / tms320dm320 / mrobe-500 / pcm-mr500.c
blob153b589b611e08e755d3cce472460875b90b914a
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 and 2009 by Karl Kurbjun
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include <stdlib.h>
22 #include "system.h"
23 #include "kernel.h"
24 #include "logf.h"
25 #include "audio.h"
26 #include "sound.h"
27 #include "file.h"
28 #include "dsp-target.h"
29 #include "dsp/ipc.h"
30 #include "mmu-arm.h"
32 /* These are global to save some latency when pcm_play_dma_get_peak_buffer is
33 * called.
35 static void *start;
36 static size_t size;
38 void pcm_postinit(void)
40 audiohw_postinit();
43 /* Return the current location in the SDRAM to SARAM transfer along with the
44 * number of bytes read in the current buffer (count). There is latency with
45 * this method equivalent to ~ the size of the SARAM buffer since there is
46 * another buffer between your ears and this calculation, but this works for
47 * key clicks and an approximate peak meter.
49 const void * pcm_play_dma_get_peak_buffer(int *count)
51 int cnt = DSP_(_sdem_level);
53 unsigned long addr = (unsigned long) start +cnt;
55 *count = (cnt & 0xFFFFF) >> 1;
56 return (void *)((addr + 2) & ~3);
59 void pcm_play_dma_init(void)
61 IO_INTC_IRQ0 = 1 << 11;
62 IO_INTC_EINT0 |= 1 << 11;
64 /* Set this as a FIQ */
65 IO_INTC_FISEL0 |= 1 << 11;
67 IO_DSPC_HPIB_CONTROL = 1 << 10 | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 3 | 1 << 0;
69 dsp_reset();
70 dsp_load(dsp_image);
71 dsp_wake();
74 void pcm_dma_apply_settings(void)
76 audiohw_set_frequency(pcm_fsel);
79 /* Note that size is actually limited to the size of a short right now due to
80 * the implementation on the DSP side (and the way that we access it)
82 void pcm_play_dma_start(const void *addr, size_t size)
84 unsigned long sdem_addr=(unsigned long)addr - CONFIG_SDRAM_START;
85 /* Initialize codec. */
86 DSP_(_sdem_addrl) = sdem_addr & 0xffff;
87 DSP_(_sdem_addrh) = sdem_addr >> 16;
88 DSP_(_sdem_dsp_size) = size;
89 DSP_(_dma0_stopped)=0;
91 dsp_wake();
94 void pcm_play_dma_stop(void)
96 DSP_(_dma0_stopped)=1;
97 dsp_wake();
100 void pcm_play_lock(void)
105 void pcm_play_unlock(void)
110 void pcm_play_dma_pause(bool pause)
112 if (pause)
114 DSP_(_dma0_stopped)=2;
115 dsp_wake();
117 else
119 DSP_(_dma0_stopped)=0;
120 dsp_wake();
124 size_t pcm_get_bytes_waiting(void)
126 return DSP_(_sdem_dsp_size)-DSP_(_sdem_level);
129 /* Only used when debugging */
130 static char buffer[80];
132 void DSPHINT(void) __attribute__ ((section(".icode")));
133 void DSPHINT(void)
135 unsigned int i;
137 IO_INTC_FIQ0 = 1 << 11;
139 switch (dsp_message.msg)
141 case MSG_DEBUGF:
142 /* DSP stores one character per word. */
143 for (i = 0; i < sizeof(buffer); i++)
145 buffer[i] = dsp_message.payload.debugf.buffer[i];
148 DEBUGF("DSP: %s", buffer);
149 break;
151 case MSG_REFILL:
152 /* Buffer empty. Try to get more. */
153 pcm_play_get_more_callback(&start, &size);
155 if (size != 0)
157 unsigned long sdem_addr=(unsigned long)start - CONFIG_SDRAM_START;
158 /* Flush any pending cache writes */
159 clean_dcache_range(start, size);
161 /* set the new DMA values */
162 DSP_(_sdem_addrl) = sdem_addr & 0xffff;
163 DSP_(_sdem_addrh) = sdem_addr >> 16;
164 DSP_(_sdem_dsp_size) = size;
166 DEBUGF("pcm_sdram at 0x%08lx, sdem_addr 0x%08lx",
167 (unsigned long)start, (unsigned long)sdem_addr);
170 break;
171 default:
172 DEBUGF("DSP: unknown msg 0x%04x", dsp_message.msg);
173 break;
176 /* Re-Activate the channel */
177 dsp_wake();
179 DEBUGF("DSP: %s", buffer);