summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tms320dm320/dsp-dm320.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/tms320dm320/dsp-dm320.c')
-rw-r--r--firmware/target/arm/tms320dm320/dsp-dm320.c167
1 files changed, 162 insertions, 5 deletions
diff --git a/firmware/target/arm/tms320dm320/dsp-dm320.c b/firmware/target/arm/tms320dm320/dsp-dm320.c
index bc05eff24f..20391baf56 100644
--- a/firmware/target/arm/tms320dm320/dsp-dm320.c
+++ b/firmware/target/arm/tms320dm320/dsp-dm320.c
@@ -23,7 +23,9 @@
23#include "system.h" 23#include "system.h"
24#include "debug.h" 24#include "debug.h"
25#include "string.h" 25#include "string.h"
26#include "file.h"
26#include "dsp-target.h" 27#include "dsp-target.h"
28#include "dsp/ipc.h"
27 29
28/* A "DSP image" is an array of these, terminated by raw_data_size_half = 0. */ 30/* A "DSP image" is an array of these, terminated by raw_data_size_half = 0. */
29struct dsp_section { 31struct dsp_section {
@@ -33,7 +35,9 @@ struct dsp_section {
33}; 35};
34 36
35/* Must define struct dsp_section before including the image. */ 37/* Must define struct dsp_section before including the image. */
36#include "dsp_image_helloworld.h" 38#include "dsp/dsp-image.h"
39
40#define dsp_message (*(volatile struct ipc_message *)&DSP_(_status))
37 41
38#ifdef DEBUG 42#ifdef DEBUG
39static void dsp_status(void) 43static void dsp_status(void)
@@ -127,27 +131,180 @@ static void dsp_load(const struct dsp_section *im)
127 } 131 }
128} 132}
129 133
134static signed short *the_rover = (signed short *)0x1900000;
135static unsigned int index_rover = 0;
136static signed short __attribute__((aligned (16))) pcm_buffer[PCM_SIZE / 2];
137
130void dsp_init(void) 138void dsp_init(void)
131{ 139{
140 unsigned long sdem_addr;
141 int fd;
142 int bytes;
143
144
132 IO_INTC_IRQ0 = 1 << 11; 145 IO_INTC_IRQ0 = 1 << 11;
133 IO_INTC_EINT0 |= 1 << 11; 146 IO_INTC_EINT0 |= 1 << 11;
134 147
135 IO_DSPC_HPIB_CONTROL = 1 << 10 | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 3 | 1 << 0; 148 IO_DSPC_HPIB_CONTROL = 1 << 10 | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 3 | 1 << 0;
136 149
137 dsp_reset(); 150 dsp_reset();
138 dsp_load(dsp_image_helloworld); 151 dsp_load(dsp_image);
152
153 /* Initialize codec. */
154 sdem_addr = (unsigned long)pcm_buffer - CONFIG_SDRAM_START;
155 DEBUGF("pcm_sdram at 0x%08lx, sdem_addr 0x%08lx",
156 (unsigned long)pcm_buffer, (unsigned long)sdem_addr);
157 DSP_(_sdem_addrl) = sdem_addr & 0xffff;
158 DSP_(_sdem_addrh) = sdem_addr >> 16;
159
160 fd = open("/test.raw", O_RDONLY);
161 bytes = read(fd, the_rover, 4*1024*1024);
162 close(fd);
163
164 DEBUGF("read %d rover bytes", bytes);
165
166 #if 0
167 {
168 unsigned int i;
169 memset(pcm_buffer, 0x80, PCM_SIZE);
170 for (i = 0; i < 8192; i++) {
171 signed short val = 0;
172 /*if (i < PCM_SIZE/4/2) {
173 val = 128*(i%256);
174 } else {
175 val = 2*128*128-128*(i%256);
176 }*/
177 val = 128*(i%256);
178 pcm_buffer[2*i] = pcm_buffer[2*i+1] = val;
179 }
180 clean_dcache();
181
182
183 {
184 unsigned int i;
185 volatile signed short *pdata = &DSP_(_data);
186 DEBUGF("dsp__data at %08x", pdata);
187 for (i = 0; i < 4096; i++) {
188 pdata[2*i]=pdata[2*i+1]=(i&1)*32767;
189 }
190 for (i = 4096; i < 8192; i++) {
191 pdata[2*i]=pdata[2*i+1]=0;
192 }
193 }
194 #endif
195
196#ifdef IPC_SIZES
197 DEBUGF("dsp_message at 0x%08x", &dsp_message);
198 DEBUGF("sizeof(ipc_message)=%uB offset(ipc_message.payload)=%uB",
199 sizeof(struct ipc_message), (int)&((struct ipc_message*)0)->payload);
200#endif
201
202#ifdef INIT_MSG
203 /* Prepare init message. */
204
205 /* DSP accesses MUST be done a word at a time. */
206 dsp_message.msg = MSG_INIT;
207
208 sdem_addr = (unsigned long)pcm_sdram - CONFIG_SDRAM_START;
209 DEBUGF("pcm_sdram at 0x%08x, sdem_addr 0x%08x", pcm_sdram, sdem_addr);
210 dsp_message.payload.init.sdem_addrl = sdem_addr & 0xffff;
211 dsp_message.payload.init.sdem_addrh = sdem_addr >> 16;
212
213 DEBUGF("dsp_message: %04x %04x %04x %04x",
214 ((unsigned short *)&dsp_message)[0],
215 ((unsigned short *)&dsp_message)[1],
216 ((unsigned short *)&dsp_message)[2],
217 ((unsigned short *)&dsp_message)[3]);
218#endif
219
139} 220}
140 221
141void DSPHINT(void) 222void DSPHINT(void)
142{ 223{
143 unsigned int i; 224 unsigned int i;
144 char buffer[80]; 225 char buffer[80];
226 static unsigned short level = 2;
227
228 unsigned short *pcm_topbottom, *pcm_topbottom_end;
229
145 230
146 IO_INTC_IRQ0 = 1 << 11; 231 IO_INTC_IRQ0 = 1 << 11;
147 232
148 /* DSP stores one character per word. */ 233
149 for (i = 0; i < sizeof(buffer); i++) { 234 switch (dsp_message.msg)
150 buffer[i] = (&DSP_(_status))[i]; 235 {
236 case MSG_DEBUGF:
237 /* DSP stores one character per word. */
238 for (i = 0; i < sizeof(buffer); i++)
239 {
240 buffer[i] = dsp_message.payload.debugf.buffer[i];
241 }
242
243 /* Release shared area to DSP. */
244 dsp_wake();
245
246 DEBUGF("DSP: %s", buffer);
247 break;
248 case MSG_REFILL:
249 DEBUGF("DSP: DMA0 with topbottom=%u (fill at %04lx)",
250 dsp_message.payload.refill.topbottom,
251 (unsigned long)pcm_buffer +
252 dsp_message.payload.refill.topbottom);
253 pcm_topbottom = pcm_buffer + dsp_message.payload.refill.topbottom / 2;
254
255 /*
256 i = 0;
257 while (i < PCM_SIZE/4) {
258 unsigned int j;
259 for (j = 0; j < level; j++) {
260 pcm_topbottom[i+j] = -32768;
261 }
262 for (j = level; j < 2*level; j++) {
263 pcm_topbottom[i+j] = 32767;
264 }
265 i += 2*level;
266 }
267
268 level += 2;
269 if (level > 256) {
270 level = 2;
271 }*/
272
273 memcpy(pcm_topbottom, the_rover + index_rover, PCM_SIZE/2);
274 index_rover += PCM_SIZE/4;
275 if (index_rover >= 2*1024*1024) {
276 index_rover = 0;
277 }
278
279 /*
280 pcm_topbottom = &p_pcm_sdram[dsp_message.payload.refill.topbottom/2];
281 DEBUGF("DSP: tofill begins: %04x %04x %04x %04x",
282 pcm_topbottom[0],
283 pcm_topbottom[1],
284 pcm_topbottom[2],
285 pcm_topbottom[3]
286 );
287 pcm_topbottom_end = &p_pcm_sdram[(dsp_message.payload.refill.topbottom+PCM_SIZE/2)/2];
288 DEBUGF("DSP: tofill ends: %04x %04x %04x %04x",
289 pcm_topbottom_end[-4],
290 pcm_topbottom_end[-3],
291 pcm_topbottom_end[-2],
292 pcm_topbottom_end[-1]
293 );
294 */
295
296 /*
297 DEBUGF("DSP: DMA0: SD %04x:%04x -> DSP %04x:%04x, TRG %04x",
298 dsp_message.payload.refill._SDEM_ADDRH,
299 dsp_message.payload.refill._SDEM_ADDRL,
300 dsp_message.payload.refill._DSP_ADDRH,
301 dsp_message.payload.refill._DSP_ADDRL,
302 dsp_message.payload.refill._DMA_TRG);
303 */
304 break;
305 default:
306 DEBUGF("DSP: unknown msg 0x%04x", dsp_message.msg);
307 break;
151 } 308 }
152 309
153 /* Release shared area to DSP. */ 310 /* Release shared area to DSP. */