diff options
Diffstat (limited to 'firmware/test/i2c')
-rw-r--r-- | firmware/test/i2c/Makefile | 53 | ||||
-rw-r--r-- | firmware/test/i2c/app.lds | 36 | ||||
-rw-r--r-- | firmware/test/i2c/gendata.c | 31 | ||||
-rw-r--r-- | firmware/test/i2c/main.c | 1280 |
4 files changed, 0 insertions, 1400 deletions
diff --git a/firmware/test/i2c/Makefile b/firmware/test/i2c/Makefile deleted file mode 100644 index 51e72b859b..0000000000 --- a/firmware/test/i2c/Makefile +++ /dev/null | |||
@@ -1,53 +0,0 @@ | |||
1 | CC = sh-elf-gcc | ||
2 | LD = sh-elf-ld | ||
3 | AR = sh-elf-ar | ||
4 | AS = sh-elf-as | ||
5 | OC = sh-elf-objcopy | ||
6 | |||
7 | FIRMWARE=../.. | ||
8 | |||
9 | INCLUDES=-I$(FIRMWARE) -I$(FIRMWARE)/common -I$(FIRMWARE)/drivers | ||
10 | |||
11 | TARGET = -DARCHOS_PLAYER_OLD=1 | ||
12 | |||
13 | CFLAGS = -g -W -Wall -m1 -save-temps -nostdlib -Wstrict-prototypes -fschedule-insns -fno-builtin $(INCLUDES) $(TARGET) -DDEBUG | ||
14 | AFLAGS += -small -relax | ||
15 | |||
16 | SRC := $(wildcard *.c) | ||
17 | OBJS := $(SRC:%.c=%.o) $(FIRMWARE)/crt0.o | ||
18 | DEPS:=.deps | ||
19 | DEPDIRS:=$(DEPS) | ||
20 | |||
21 | all : archos.mod | ||
22 | |||
23 | archos.elf : $(OBJS) app.lds | ||
24 | $(CC) -nostartfiles -o archos.elf $(OBJS) -lgcc -lrockbox -L$(FIRMWARE) -Tapp.lds -Wl,-Map,archos.map | ||
25 | |||
26 | archos.bin : archos.elf | ||
27 | $(OC) -O binary archos.elf archos.bin | ||
28 | |||
29 | archos.asm: archos.bin | ||
30 | sh2d -sh1 archos.bin > archos.asm | ||
31 | |||
32 | archos.mod : archos.bin | ||
33 | scramble archos.bin archos.mod | ||
34 | |||
35 | archos.mod.gz : archos.mod | ||
36 | gzip -f archos.mod | ||
37 | |||
38 | dist: | ||
39 | tar czvf dist.tar.gz Makefile main.c start.s app.lds | ||
40 | |||
41 | clean: | ||
42 | -rm -f $(OBJS) *.x *.i *.o *.s *.elf *.bin *.map *.mod *.bak *~ | ||
43 | -$(RM) -r $(DEPS) | ||
44 | |||
45 | $(DEPS)/%.d: %.c | ||
46 | @$(SHELL) -c 'for d in $(DEPDIRS); do { if [ ! -d $$d ]; then mkdir $$d; fi; }; done' | ||
47 | @echo "Updating dependencies for $<" | ||
48 | @$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< \ | ||
49 | |sed '\''s|\($*\)\.o[ :]*|\1.o $(<:%.c=%.d) : |g'\'' > $@; \ | ||
50 | [ -s $@ ] || rm -f $@' | ||
51 | |||
52 | -include $(SRC:%.c=$(DEPS)/%.d) | ||
53 | |||
diff --git a/firmware/test/i2c/app.lds b/firmware/test/i2c/app.lds deleted file mode 100644 index b8a341a8ae..0000000000 --- a/firmware/test/i2c/app.lds +++ /dev/null | |||
@@ -1,36 +0,0 @@ | |||
1 | ENTRY(start) | ||
2 | OUTPUT_FORMAT(elf32-sh) | ||
3 | SECTIONS | ||
4 | { | ||
5 | .text 0x09010000 : | ||
6 | { | ||
7 | KEEP(*(.vectors)) | ||
8 | . = ALIGN(0x200); | ||
9 | *(.init.text) | ||
10 | } | ||
11 | |||
12 | .text : | ||
13 | { | ||
14 | *(.text) | ||
15 | } | ||
16 | |||
17 | .data : | ||
18 | { | ||
19 | *(.rodata) | ||
20 | *(.data) | ||
21 | } | ||
22 | |||
23 | .rodata : | ||
24 | { | ||
25 | *(.rodata) | ||
26 | } | ||
27 | |||
28 | .bss : | ||
29 | { | ||
30 | _edata = .; | ||
31 | *(.bss) | ||
32 | *(COMMON) | ||
33 | _end = .; | ||
34 | _stack = . + 0x80000; | ||
35 | } | ||
36 | } | ||
diff --git a/firmware/test/i2c/gendata.c b/firmware/test/i2c/gendata.c deleted file mode 100644 index dc5989ee66..0000000000 --- a/firmware/test/i2c/gendata.c +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | |||
3 | int main(int argc, char *argv[]) | ||
4 | { | ||
5 | FILE *f; | ||
6 | int i; | ||
7 | unsigned char buf[128000]; | ||
8 | |||
9 | f = fopen("mp.mp3", "r"); | ||
10 | |||
11 | if(f) | ||
12 | { | ||
13 | if(fread(buf, 1, 128000, f) < 128000) | ||
14 | { | ||
15 | fprintf(stderr, "FAN!\n"); | ||
16 | exit(1); | ||
17 | } | ||
18 | |||
19 | printf("int mp3datalen = 128000;\n"); | ||
20 | printf("unsigned char mp3data[128000] =\n{"); | ||
21 | for(i = 0;i < 128000;i++) | ||
22 | { | ||
23 | if(i % 8 == 0) | ||
24 | { | ||
25 | printf("\n"); | ||
26 | } | ||
27 | printf("0x%02x, ", buf[i]); | ||
28 | } | ||
29 | printf("};\n"); | ||
30 | } | ||
31 | } | ||
diff --git a/firmware/test/i2c/main.c b/firmware/test/i2c/main.c deleted file mode 100644 index 990369eae8..0000000000 --- a/firmware/test/i2c/main.c +++ /dev/null | |||
@@ -1,1280 +0,0 @@ | |||
1 | /*************************************************************************** | ||
2 | |||
3 | * __________ __ ___. | ||
4 | |||
5 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
6 | |||
7 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
8 | |||
9 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
10 | |||
11 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
12 | |||
13 | * \/ \/ \/ \/ \/ | ||
14 | |||
15 | * $Id$ | ||
16 | |||
17 | * | ||
18 | |||
19 | * Copyright (C) 2002 by Linus Nielsen Feltzing | ||
20 | |||
21 | * | ||
22 | |||
23 | |||
24 | * This program is free software; you can redistribute it and/or | ||
25 | * modify it under the terms of the GNU General Public License | ||
26 | * as published by the Free Software Foundation; either version 2 | ||
27 | * of the License, or (at your option) any later version. | ||
28 | |||
29 | * | ||
30 | |||
31 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
32 | |||
33 | * KIND, either express or implied. | ||
34 | |||
35 | * | ||
36 | |||
37 | ****************************************************************************/ | ||
38 | |||
39 | #include <stdio.h> | ||
40 | |||
41 | #include <stdlib.h> | ||
42 | |||
43 | #include <stdbool.h> | ||
44 | |||
45 | #include <string.h> | ||
46 | |||
47 | #include "i2c.h" | ||
48 | |||
49 | #include "mas35xx.h" | ||
50 | |||
51 | #include "dac3550a.h" | ||
52 | |||
53 | #include "sh7034.h" | ||
54 | |||
55 | #include "system.h" | ||
56 | |||
57 | #include "debug.h" | ||
58 | |||
59 | #include "kernel.h" | ||
60 | |||
61 | #include "thread.h" | ||
62 | |||
63 | #include "ata.h" | ||
64 | |||
65 | #include "disk.h" | ||
66 | |||
67 | #include "fat.h" | ||
68 | |||
69 | #include "file.h" | ||
70 | |||
71 | #include "dir.h" | ||
72 | |||
73 | #include "panic.h" | ||
74 | |||
75 | |||
76 | |||
77 | #ifndef MIN | ||
78 | |||
79 | #define MIN(a, b) (((a)<(b))?(a):(b)) | ||
80 | |||
81 | #endif | ||
82 | |||
83 | |||
84 | |||
85 | #define MPEG_PLAY 1 | ||
86 | |||
87 | #define MPEG_STOP 2 | ||
88 | |||
89 | #define MPEG_PAUSE 3 | ||
90 | |||
91 | #define MPEG_RESUME 4 | ||
92 | |||
93 | #define MPEG_NEED_DATA 100 | ||
94 | |||
95 | |||
96 | |||
97 | #define MP3_LOW_WATER 0x30000 | ||
98 | |||
99 | #define MP3_CHUNK_SIZE 0x20000 | ||
100 | |||
101 | |||
102 | |||
103 | unsigned int bass_table[] = | ||
104 | |||
105 | { | ||
106 | |||
107 | 0, | ||
108 | |||
109 | 0x800, /* 1dB */ | ||
110 | |||
111 | 0x10000, /* 2dB */ | ||
112 | |||
113 | 0x17c00, /* 3dB */ | ||
114 | |||
115 | 0x1f800, /* 4dB */ | ||
116 | |||
117 | 0x27000, /* 5dB */ | ||
118 | |||
119 | 0x2e400, /* 6dB */ | ||
120 | |||
121 | 0x35800, /* 7dB */ | ||
122 | |||
123 | 0x3c000, /* 8dB */ | ||
124 | |||
125 | 0x42800, /* 9dB */ | ||
126 | |||
127 | 0x48800, /* 10dB */ | ||
128 | |||
129 | 0x4e400, /* 11dB */ | ||
130 | |||
131 | 0x53800, /* 12dB */ | ||
132 | |||
133 | 0x58800, /* 13dB */ | ||
134 | |||
135 | 0x5d400, /* 14dB */ | ||
136 | |||
137 | 0x61800 /* 15dB */ | ||
138 | |||
139 | }; | ||
140 | |||
141 | |||
142 | |||
143 | unsigned int treble_table[] = | ||
144 | |||
145 | { | ||
146 | |||
147 | 0, | ||
148 | |||
149 | 0x5400, /* 1dB */ | ||
150 | |||
151 | 0xac00, /* 2dB */ | ||
152 | |||
153 | 0x10400, /* 3dB */ | ||
154 | |||
155 | 0x16000, /* 4dB */ | ||
156 | |||
157 | 0x1c000, /* 5dB */ | ||
158 | |||
159 | 0x22400, /* 6dB */ | ||
160 | |||
161 | 0x28400, /* 7dB */ | ||
162 | |||
163 | 0x2ec00, /* 8dB */ | ||
164 | |||
165 | 0x35400, /* 9dB */ | ||
166 | |||
167 | 0x3c000, /* 10dB */ | ||
168 | |||
169 | 0x42c00, /* 11dB */ | ||
170 | |||
171 | 0x49c00, /* 12dB */ | ||
172 | |||
173 | 0x51800, /* 13dB */ | ||
174 | |||
175 | 0x58400, /* 14dB */ | ||
176 | |||
177 | 0x5f800 /* 15dB */ | ||
178 | |||
179 | }; | ||
180 | |||
181 | |||
182 | |||
183 | unsigned char fliptable[] = | ||
184 | |||
185 | { | ||
186 | |||
187 | 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, | ||
188 | |||
189 | 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, | ||
190 | |||
191 | 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, | ||
192 | |||
193 | 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, | ||
194 | |||
195 | 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, | ||
196 | |||
197 | 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, | ||
198 | |||
199 | 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, | ||
200 | |||
201 | 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, | ||
202 | |||
203 | 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, | ||
204 | |||
205 | 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, | ||
206 | |||
207 | 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, | ||
208 | |||
209 | 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, | ||
210 | |||
211 | 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, | ||
212 | |||
213 | 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, | ||
214 | |||
215 | 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, | ||
216 | |||
217 | 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, | ||
218 | |||
219 | 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, | ||
220 | |||
221 | 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, | ||
222 | |||
223 | 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, | ||
224 | |||
225 | 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, | ||
226 | |||
227 | 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, | ||
228 | |||
229 | 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, | ||
230 | |||
231 | 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, | ||
232 | |||
233 | 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, | ||
234 | |||
235 | 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, | ||
236 | |||
237 | 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, | ||
238 | |||
239 | 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, | ||
240 | |||
241 | 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, | ||
242 | |||
243 | 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, | ||
244 | |||
245 | 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, | ||
246 | |||
247 | 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, | ||
248 | |||
249 | 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff | ||
250 | |||
251 | }; | ||
252 | |||
253 | |||
254 | |||
255 | extern unsigned int stack[]; | ||
256 | |||
257 | /* Place the MP3 data right after the stack */ | ||
258 | |||
259 | |||
260 | |||
261 | #define MP3BUF_LEN 0x100000 /* 1 Mbyte */ | ||
262 | |||
263 | |||
264 | |||
265 | unsigned char *mp3buf = (unsigned char *)stack; | ||
266 | |||
267 | |||
268 | |||
269 | char *tracks[100]; | ||
270 | |||
271 | int num_tracks; | ||
272 | |||
273 | |||
274 | |||
275 | int mp3buf_write; | ||
276 | |||
277 | int mp3buf_read; | ||
278 | |||
279 | int last_dma_chunk_size; | ||
280 | |||
281 | |||
282 | |||
283 | bool dma_on; /* The DMA is active */ | ||
284 | |||
285 | bool playing; /* We are playing an MP3 stream */ | ||
286 | |||
287 | bool filling; /* We are filling the buffer with data from disk */ | ||
288 | |||
289 | |||
290 | |||
291 | struct event_queue mpeg_queue SHAREDBSS_ATTR; | ||
292 | |||
293 | |||
294 | |||
295 | static void mas_poll_start(unsigned int interval_in_ms); | ||
296 | |||
297 | void mpeg_thread(void); | ||
298 | |||
299 | |||
300 | |||
301 | void reset_mp3_buffer(void) | ||
302 | |||
303 | { | ||
304 | |||
305 | mp3buf_read = 0; | ||
306 | |||
307 | mp3buf_write = 0; | ||
308 | |||
309 | } | ||
310 | |||
311 | |||
312 | |||
313 | void setup_sci0(void) | ||
314 | |||
315 | { | ||
316 | |||
317 | /* PB15 is I/O, PB14 is IRQ6, PB12 is SCK0 */ | ||
318 | |||
319 | PBCR1 = (PBCR1 & 0x0cff) | 0x1200; | ||
320 | |||
321 | |||
322 | |||
323 | /* Set PB12 to output */ | ||
324 | |||
325 | PBIOR |= 0x1000; | ||
326 | |||
327 | |||
328 | |||
329 | /* Disable serial port */ | ||
330 | |||
331 | SCR0 = 0x00; | ||
332 | |||
333 | |||
334 | |||
335 | /* Synchronous, no prescale */ | ||
336 | |||
337 | SMR0 = 0x80; | ||
338 | |||
339 | |||
340 | |||
341 | /* Set baudrate 1Mbit/s */ | ||
342 | |||
343 | BRR0 = 0x03; | ||
344 | |||
345 | |||
346 | |||
347 | /* use SCK as serial clock output */ | ||
348 | |||
349 | SCR0 = 0x01; | ||
350 | |||
351 | |||
352 | |||
353 | /* Clear FER and PER */ | ||
354 | |||
355 | SSR0 &= 0xe7; | ||
356 | |||
357 | |||
358 | |||
359 | /* Set interrupt ITU2 and SCI0 priority to 0 */ | ||
360 | |||
361 | IPRD &= 0x0ff0; | ||
362 | |||
363 | |||
364 | |||
365 | /* set IRQ6 and IRQ7 to edge detect */ | ||
366 | |||
367 | ICR |= 0x03; | ||
368 | |||
369 | |||
370 | |||
371 | /* set PB15 and PB14 to inputs */ | ||
372 | |||
373 | PBIOR &= 0x7fff; | ||
374 | |||
375 | PBIOR &= 0xbfff; | ||
376 | |||
377 | |||
378 | |||
379 | /* set IRQ6 prio 8 and IRQ7 prio 0 */ | ||
380 | |||
381 | IPRB = ( IPRB & 0xff00 ) | 0x0080; | ||
382 | |||
383 | |||
384 | |||
385 | /* Enable End of DMA interrupt at prio 8 */ | ||
386 | |||
387 | IPRC = (IPRC & 0xf0ff) | 0x0800; | ||
388 | |||
389 | |||
390 | |||
391 | /* Enable Tx (only!) */ | ||
392 | |||
393 | SCR0 |= 0x20; | ||
394 | |||
395 | } | ||
396 | |||
397 | |||
398 | |||
399 | |||
400 | |||
401 | void init_dma(void) | ||
402 | |||
403 | { | ||
404 | |||
405 | SAR3 = (unsigned int) mp3buf + mp3buf_read; | ||
406 | |||
407 | DAR3 = 0x5FFFEC3; | ||
408 | |||
409 | CHCR3 &= ~0x0002; /* Clear interrupt */ | ||
410 | |||
411 | CHCR3 = 0x1504; /* Single address destination, TXI0, IE=1 */ | ||
412 | |||
413 | last_dma_chunk_size = MIN(65536, mp3buf_write - mp3buf_read); | ||
414 | |||
415 | DTCR3 = last_dma_chunk_size & 0xffff; | ||
416 | |||
417 | DMAOR = 0x0001; /* Enable DMA */ | ||
418 | |||
419 | CHCR3 |= 0x0001; /* Enable DMA IRQ */ | ||
420 | |||
421 | } | ||
422 | |||
423 | |||
424 | |||
425 | void start_dma(void) | ||
426 | |||
427 | { | ||
428 | |||
429 | SCR0 |= 0x80; | ||
430 | |||
431 | dma_on = true; | ||
432 | |||
433 | } | ||
434 | |||
435 | |||
436 | |||
437 | void stop_dma(void) | ||
438 | |||
439 | { | ||
440 | |||
441 | SCR0 &= 0x7f; | ||
442 | |||
443 | dma_on = false; | ||
444 | |||
445 | } | ||
446 | |||
447 | |||
448 | |||
449 | void dma_tick(void) | ||
450 | |||
451 | { | ||
452 | |||
453 | /* Start DMA if it isn't running */ | ||
454 | |||
455 | if(playing && !dma_on) | ||
456 | |||
457 | { | ||
458 | |||
459 | if(PBDR & 0x4000) | ||
460 | |||
461 | { | ||
462 | |||
463 | if(!(SCR0 & 0x80)) | ||
464 | |||
465 | start_dma(); | ||
466 | |||
467 | } | ||
468 | |||
469 | } | ||
470 | |||
471 | } | ||
472 | |||
473 | |||
474 | |||
475 | void bitswap(unsigned char *data, int length) | ||
476 | |||
477 | { | ||
478 | |||
479 | int i; | ||
480 | |||
481 | for(i = 0;i < length;i++) | ||
482 | |||
483 | { | ||
484 | |||
485 | data[i] = fliptable[data[i]]; | ||
486 | |||
487 | } | ||
488 | |||
489 | } | ||
490 | |||
491 | |||
492 | |||
493 | int main(void) | ||
494 | |||
495 | { | ||
496 | |||
497 | char buf[40]; | ||
498 | |||
499 | char str[32]; | ||
500 | |||
501 | int i=0; | ||
502 | |||
503 | DIR *d; | ||
504 | |||
505 | struct dirent *dent; | ||
506 | |||
507 | char *tmp; | ||
508 | |||
509 | int volume, bass, treble; | ||
510 | |||
511 | unsigned short frame_count; | ||
512 | |||
513 | |||
514 | |||
515 | /* Clear it all! */ | ||
516 | |||
517 | SSR1 &= ~(SCI_RDRF | SCI_ORER | SCI_PER | SCI_FER); | ||
518 | |||
519 | |||
520 | |||
521 | /* This enables the serial Rx interrupt, to be able to exit into the | ||
522 | |||
523 | debugger when you hit CTRL-C */ | ||
524 | |||
525 | SCR1 |= 0x40; | ||
526 | |||
527 | SCR1 &= ~0x80; | ||
528 | |||
529 | |||
530 | |||
531 | IPRE |= 0xf000; /* Highest priority */ | ||
532 | |||
533 | |||
534 | |||
535 | i2c_init(); | ||
536 | |||
537 | |||
538 | |||
539 | dma_on = true; | ||
540 | |||
541 | |||
542 | |||
543 | kernel_init(); | ||
544 | |||
545 | |||
546 | |||
547 | enable_irq(); | ||
548 | |||
549 | |||
550 | |||
551 | setup_sci0(); | ||
552 | |||
553 | |||
554 | |||
555 | i=mas_readmem(MAS_BANK_D1,0xff6,(unsigned long*)buf,2); | ||
556 | |||
557 | if (i) { | ||
558 | |||
559 | debugf("Error - mas_readmem() returned %d\n", i); | ||
560 | |||
561 | while(1); | ||
562 | |||
563 | } | ||
564 | |||
565 | |||
566 | |||
567 | i = buf[0] | buf[1] << 8; | ||
568 | |||
569 | debugf("MAS version: %x\n", i); | ||
570 | |||
571 | i = buf[4] | buf[5] << 8; | ||
572 | |||
573 | debugf("MAS revision: %x\n", i); | ||
574 | |||
575 | |||
576 | |||
577 | i=mas_readmem(MAS_BANK_D1,0xff9,(unsigned long*)buf,7); | ||
578 | |||
579 | if (i) { | ||
580 | |||
581 | debugf("Error - mas_readmem() returned %d\n", i); | ||
582 | |||
583 | while(1); | ||
584 | |||
585 | } | ||
586 | |||
587 | |||
588 | |||
589 | for(i = 0;i < 7;i++) | ||
590 | |||
591 | { | ||
592 | |||
593 | str[i*2+1] = buf[i*4]; | ||
594 | |||
595 | str[i*2] = buf[i*4+1]; | ||
596 | |||
597 | } | ||
598 | |||
599 | str[i*2] = 0; | ||
600 | |||
601 | debugf("Description: %s\n", str); | ||
602 | |||
603 | |||
604 | |||
605 | i=mas_writereg(0x3b, 0x20); | ||
606 | |||
607 | if (i < 0) { | ||
608 | |||
609 | debugf("Error - mas_writereg() returned %d\n", i); | ||
610 | |||
611 | while(1); | ||
612 | |||
613 | } | ||
614 | |||
615 | |||
616 | |||
617 | i = mas_run(1); | ||
618 | |||
619 | if (i < 0) { | ||
620 | |||
621 | debugf("Error - mas_run() returned %d\n", i); | ||
622 | |||
623 | while(1); | ||
624 | |||
625 | } | ||
626 | |||
627 | |||
628 | |||
629 | i = ata_init(); | ||
630 | |||
631 | debugf("ata_init() returned %d\n", i); | ||
632 | |||
633 | |||
634 | |||
635 | i = disk_init(); | ||
636 | |||
637 | debugf("disk_init() returned %d\n", i); | ||
638 | |||
639 | |||
640 | |||
641 | debugf("part[0] starts at sector %d\n", part[0].start); | ||
642 | |||
643 | |||
644 | |||
645 | i = fat_mount(IF_MV(0,) IF_MD(0,) part[0].start); | ||
646 | |||
647 | debugf("fat_mount() returned %d\n", i); | ||
648 | |||
649 | |||
650 | |||
651 | num_tracks = 0; | ||
652 | |||
653 | if((d = opendir("/"))) | ||
654 | |||
655 | { | ||
656 | |||
657 | while((dent = readdir(d))) | ||
658 | |||
659 | { | ||
660 | |||
661 | debugf("%s\n", dent->d_name); | ||
662 | |||
663 | i = strlen(dent->d_name); | ||
664 | |||
665 | tmp = dent->d_name + i - 4; | ||
666 | |||
667 | debugf("%s\n", tmp); | ||
668 | |||
669 | if(!stricmp(tmp, ".mp3")) | ||
670 | |||
671 | { | ||
672 | |||
673 | tmp = malloc(i+1); | ||
674 | |||
675 | if(tmp) | ||
676 | |||
677 | { | ||
678 | |||
679 | debugf("Adding track %s\n", dent->d_name); | ||
680 | |||
681 | snprintf(tmp, i+1, "/%s", dent->d_name); | ||
682 | |||
683 | tracks[num_tracks++] = tmp; | ||
684 | |||
685 | } | ||
686 | |||
687 | else | ||
688 | |||
689 | { | ||
690 | |||
691 | panicf("Out of memory\n"); | ||
692 | |||
693 | } | ||
694 | |||
695 | } | ||
696 | |||
697 | } | ||
698 | |||
699 | closedir(d); | ||
700 | |||
701 | } | ||
702 | |||
703 | |||
704 | |||
705 | debugf("Number of tracks: %d\n"); | ||
706 | |||
707 | |||
708 | |||
709 | queue_init(&mpeg_queue); | ||
710 | |||
711 | |||
712 | |||
713 | create_thread(mpeg_thread, stack - 0x2000, 0x4000, 0); | ||
714 | |||
715 | |||
716 | |||
717 | mas_poll_start(2); | ||
718 | |||
719 | |||
720 | |||
721 | debugf("let's play...\n"); | ||
722 | |||
723 | |||
724 | |||
725 | queue_post(&mpeg_queue, MPEG_PLAY, 0); | ||
726 | |||
727 | |||
728 | |||
729 | volume = 0x2c; | ||
730 | |||
731 | |||
732 | |||
733 | if(dac_config(0x04) < 0) | ||
734 | |||
735 | debugf("DAC write failed\n"); | ||
736 | |||
737 | |||
738 | |||
739 | if(dac_volume(volume) < 0) | ||
740 | |||
741 | debugf("DAC write failed\n"); | ||
742 | |||
743 | |||
744 | |||
745 | bass = 12; | ||
746 | |||
747 | treble = 8; | ||
748 | |||
749 | |||
750 | |||
751 | mas_writereg(MAS_REG_KPRESCALE, 0xe9400); | ||
752 | |||
753 | mas_writereg(MAS_REG_KBASS, bass_table[bass]); | ||
754 | |||
755 | mas_writereg(MAS_REG_KTREBLE, treble_table[treble]); | ||
756 | |||
757 | |||
758 | |||
759 | while(1) | ||
760 | |||
761 | { | ||
762 | |||
763 | sleep(HZ*4); | ||
764 | |||
765 | } | ||
766 | |||
767 | } | ||
768 | |||
769 | |||
770 | |||
771 | void IRQ6(void) __attribute__((interrupt_handler)); | ||
772 | |||
773 | void IRQ6(void) | ||
774 | |||
775 | { | ||
776 | |||
777 | stop_dma(); | ||
778 | |||
779 | } | ||
780 | |||
781 | |||
782 | |||
783 | void DEI3(void) __attribute__((interrupt_handler)); | ||
784 | |||
785 | void DEI3(void) | ||
786 | |||
787 | { | ||
788 | |||
789 | int unplayed_space_left; | ||
790 | |||
791 | int space_until_end_of_buffer; | ||
792 | |||
793 | |||
794 | |||
795 | if(playing) | ||
796 | |||
797 | { | ||
798 | |||
799 | mp3buf_read += last_dma_chunk_size; | ||
800 | |||
801 | if(mp3buf_read >= MP3BUF_LEN) | ||
802 | |||
803 | mp3buf_read = 0; | ||
804 | |||
805 | |||
806 | |||
807 | unplayed_space_left = mp3buf_write - mp3buf_read; | ||
808 | |||
809 | if(unplayed_space_left < 0) | ||
810 | |||
811 | unplayed_space_left = MP3BUF_LEN + unplayed_space_left; | ||
812 | |||
813 | |||
814 | |||
815 | space_until_end_of_buffer = MP3BUF_LEN - mp3buf_read; | ||
816 | |||
817 | |||
818 | |||
819 | if(!filling && unplayed_space_left < MP3_LOW_WATER) | ||
820 | |||
821 | { | ||
822 | |||
823 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | ||
824 | |||
825 | } | ||
826 | |||
827 | |||
828 | |||
829 | if(unplayed_space_left) | ||
830 | |||
831 | { | ||
832 | |||
833 | last_dma_chunk_size = MIN(65536, unplayed_space_left); | ||
834 | |||
835 | last_dma_chunk_size = MIN(last_dma_chunk_size, space_until_end_of_buffer); | ||
836 | |||
837 | DTCR3 = last_dma_chunk_size & 0xffff; | ||
838 | |||
839 | SAR3 = (unsigned int)mp3buf + mp3buf_read; | ||
840 | |||
841 | } | ||
842 | |||
843 | else | ||
844 | |||
845 | { | ||
846 | |||
847 | debugf("No more MP3 data. Stopping.\n"); | ||
848 | |||
849 | CHCR3 = 0; /* Stop DMA interrupt */ | ||
850 | |||
851 | } | ||
852 | |||
853 | } | ||
854 | |||
855 | |||
856 | |||
857 | CHCR3 &= ~0x0002; /* Clear DMA interrupt */ | ||
858 | |||
859 | } | ||
860 | |||
861 | |||
862 | |||
863 | static void mas_poll_start(unsigned int interval_in_ms) | ||
864 | |||
865 | { | ||
866 | |||
867 | unsigned int count; | ||
868 | |||
869 | |||
870 | |||
871 | count = FREQ / 1000 / 8 * interval_in_ms; | ||
872 | |||
873 | |||
874 | |||
875 | if(count > 0xffff) | ||
876 | |||
877 | { | ||
878 | |||
879 | panicf("Error! The MAS poll interval is too long (%d ms)\n", | ||
880 | |||
881 | interval_in_ms); | ||
882 | |||
883 | return; | ||
884 | |||
885 | } | ||
886 | |||
887 | |||
888 | |||
889 | /* We are using timer 1 */ | ||
890 | |||
891 | |||
892 | |||
893 | TSTR &= ~0x02; /* Stop the timer */ | ||
894 | |||
895 | TSNC &= ~0x02; /* No synchronization */ | ||
896 | |||
897 | TMDR &= ~0x02; /* Operate normally */ | ||
898 | |||
899 | |||
900 | |||
901 | TCNT1 = 0; /* Start counting at 0 */ | ||
902 | |||
903 | GRA1 = count; | ||
904 | |||
905 | TCR1 = 0x23; /* Clear at GRA match, sysclock/8 */ | ||
906 | |||
907 | |||
908 | |||
909 | /* Enable interrupt on level 2 */ | ||
910 | |||
911 | IPRC = (IPRC & ~0x000f) | 0x0002; | ||
912 | |||
913 | |||
914 | |||
915 | TSR1 &= ~0x02; | ||
916 | |||
917 | TIER1 = 0xf9; /* Enable GRA match interrupt */ | ||
918 | |||
919 | |||
920 | |||
921 | TSTR |= 0x02; /* Start timer 2 */ | ||
922 | |||
923 | } | ||
924 | |||
925 | |||
926 | |||
927 | void IMIA1(void) __attribute__((interrupt_handler)); | ||
928 | |||
929 | void IMIA1(void) | ||
930 | |||
931 | { | ||
932 | |||
933 | dma_tick(); | ||
934 | |||
935 | TSR1 &= ~0x01; | ||
936 | |||
937 | } | ||
938 | |||
939 | |||
940 | |||
941 | int track_index = 0; | ||
942 | |||
943 | char *peek_next_track(int index) | ||
944 | |||
945 | { | ||
946 | |||
947 | if(track_index < num_tracks) | ||
948 | |||
949 | return tracks[track_index+index]; | ||
950 | |||
951 | else | ||
952 | |||
953 | return NULL; | ||
954 | |||
955 | } | ||
956 | |||
957 | |||
958 | |||
959 | void next_track(void) | ||
960 | |||
961 | { | ||
962 | |||
963 | track_index++; | ||
964 | |||
965 | } | ||
966 | |||
967 | |||
968 | |||
969 | int mpeg_file = -1; | ||
970 | |||
971 | |||
972 | |||
973 | int new_file(void) | ||
974 | |||
975 | { | ||
976 | |||
977 | char *trackname; | ||
978 | |||
979 | |||
980 | |||
981 | trackname = peek_next_track(0); | ||
982 | |||
983 | |||
984 | |||
985 | debugf("playing %s\n", trackname); | ||
986 | |||
987 | mpeg_file = open(trackname, O_RDONLY); | ||
988 | |||
989 | if(mpeg_file < 0) | ||
990 | |||
991 | { | ||
992 | |||
993 | debugf("Couldn't open file\n"); | ||
994 | |||
995 | return -1; | ||
996 | |||
997 | } | ||
998 | |||
999 | return 0; | ||
1000 | |||
1001 | } | ||
1002 | |||
1003 | |||
1004 | |||
1005 | void mpeg_thread(void) | ||
1006 | |||
1007 | { | ||
1008 | |||
1009 | struct queue_event ev; | ||
1010 | |||
1011 | int len; | ||
1012 | |||
1013 | int free_space_left; | ||
1014 | |||
1015 | int amount_to_read; | ||
1016 | |||
1017 | bool play_pending; | ||
1018 | |||
1019 | |||
1020 | |||
1021 | play_pending = false; | ||
1022 | |||
1023 | playing = false; | ||
1024 | |||
1025 | |||
1026 | |||
1027 | while(1) | ||
1028 | |||
1029 | { | ||
1030 | |||
1031 | debugf("S\n"); | ||
1032 | |||
1033 | queue_wait(&mpeg_queue, &ev); | ||
1034 | |||
1035 | switch(ev.id) | ||
1036 | |||
1037 | { | ||
1038 | |||
1039 | case MPEG_PLAY: | ||
1040 | |||
1041 | /* Stop the current stream */ | ||
1042 | |||
1043 | play_pending = false; | ||
1044 | |||
1045 | playing = false; | ||
1046 | |||
1047 | stop_dma(); | ||
1048 | |||
1049 | |||
1050 | |||
1051 | reset_mp3_buffer(); | ||
1052 | |||
1053 | |||
1054 | |||
1055 | new_file(); | ||
1056 | |||
1057 | |||
1058 | |||
1059 | /* Make it read more data */ | ||
1060 | |||
1061 | filling = true; | ||
1062 | |||
1063 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | ||
1064 | |||
1065 | |||
1066 | |||
1067 | /* Tell the file loading code that we want to start playing | ||
1068 | |||
1069 | as soon as we have some data */ | ||
1070 | |||
1071 | play_pending = true; | ||
1072 | |||
1073 | break; | ||
1074 | |||
1075 | |||
1076 | |||
1077 | case MPEG_STOP: | ||
1078 | |||
1079 | /* Stop the current stream */ | ||
1080 | |||
1081 | playing = false; | ||
1082 | |||
1083 | stop_dma(); | ||
1084 | |||
1085 | break; | ||
1086 | |||
1087 | |||
1088 | |||
1089 | case MPEG_PAUSE: | ||
1090 | |||
1091 | /* Stop the current stream */ | ||
1092 | |||
1093 | playing = false; | ||
1094 | |||
1095 | stop_dma(); | ||
1096 | |||
1097 | break; | ||
1098 | |||
1099 | |||
1100 | |||
1101 | case MPEG_RESUME: | ||
1102 | |||
1103 | /* Stop the current stream */ | ||
1104 | |||
1105 | playing = true; | ||
1106 | |||
1107 | start_dma(); | ||
1108 | |||
1109 | break; | ||
1110 | |||
1111 | |||
1112 | |||
1113 | case MPEG_NEED_DATA: | ||
1114 | |||
1115 | free_space_left = mp3buf_read - mp3buf_write; | ||
1116 | |||
1117 | |||
1118 | |||
1119 | /* We interpret 0 as "empty buffer" */ | ||
1120 | |||
1121 | if(free_space_left <= 0) | ||
1122 | |||
1123 | free_space_left = MP3BUF_LEN + free_space_left; | ||
1124 | |||
1125 | |||
1126 | |||
1127 | if(free_space_left <= MP3_CHUNK_SIZE) | ||
1128 | |||
1129 | { | ||
1130 | |||
1131 | debugf("0\n"); | ||
1132 | |||
1133 | ata_spindown(-1); | ||
1134 | |||
1135 | filling = false; | ||
1136 | |||
1137 | break; | ||
1138 | |||
1139 | } | ||
1140 | |||
1141 | |||
1142 | |||
1143 | amount_to_read = MIN(MP3_CHUNK_SIZE, free_space_left); | ||
1144 | |||
1145 | amount_to_read = MIN(MP3BUF_LEN - mp3buf_write, amount_to_read); | ||
1146 | |||
1147 | |||
1148 | |||
1149 | /* Read in a few seconds worth of MP3 data. We don't want to | ||
1150 | |||
1151 | read too large chunks because the bitswapping will take | ||
1152 | |||
1153 | too much time. We must keep the DMA happy and also give | ||
1154 | |||
1155 | the other threads a chance to run. */ | ||
1156 | |||
1157 | debugf("R\n"); | ||
1158 | |||
1159 | len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); | ||
1160 | |||
1161 | if(len) | ||
1162 | |||
1163 | { | ||
1164 | |||
1165 | debugf("B\n"); | ||
1166 | |||
1167 | bitswap(mp3buf + mp3buf_write, len); | ||
1168 | |||
1169 | |||
1170 | |||
1171 | mp3buf_write += len; | ||
1172 | |||
1173 | if(mp3buf_write >= MP3BUF_LEN) | ||
1174 | |||
1175 | { | ||
1176 | |||
1177 | mp3buf_write = 0; | ||
1178 | |||
1179 | debugf("W\n"); | ||
1180 | |||
1181 | } | ||
1182 | |||
1183 | |||
1184 | |||
1185 | /* Tell ourselves that we want more data */ | ||
1186 | |||
1187 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | ||
1188 | |||
1189 | |||
1190 | |||
1191 | /* And while we're at it, see if we have startet playing | ||
1192 | |||
1193 | yet. If not, do it. */ | ||
1194 | |||
1195 | if(play_pending) | ||
1196 | |||
1197 | { | ||
1198 | |||
1199 | play_pending = false; | ||
1200 | |||
1201 | playing = true; | ||
1202 | |||
1203 | |||
1204 | |||
1205 | init_dma(); | ||
1206 | |||
1207 | start_dma(); | ||
1208 | |||
1209 | } | ||
1210 | |||
1211 | } | ||
1212 | |||
1213 | else | ||
1214 | |||
1215 | { | ||
1216 | |||
1217 | close(mpeg_file); | ||
1218 | |||
1219 | |||
1220 | |||
1221 | /* Make sure that the write pointer is at a word | ||
1222 | |||
1223 | boundary */ | ||
1224 | |||
1225 | mp3buf_write &= 0xfffffffe; | ||
1226 | |||
1227 | |||
1228 | |||
1229 | next_track(); | ||
1230 | |||
1231 | if(new_file() < 0) | ||
1232 | |||
1233 | { | ||
1234 | |||
1235 | /* No more data to play */ | ||
1236 | |||
1237 | debugf("Finished playing\n"); | ||
1238 | |||
1239 | playing = false; | ||
1240 | |||
1241 | ata_spindown(-1); | ||
1242 | |||
1243 | filling = false; | ||
1244 | |||
1245 | } | ||
1246 | |||
1247 | else | ||
1248 | |||
1249 | { | ||
1250 | |||
1251 | /* Tell ourselves that we want more data */ | ||
1252 | |||
1253 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | ||
1254 | |||
1255 | } | ||
1256 | |||
1257 | } | ||
1258 | |||
1259 | break; | ||
1260 | |||
1261 | } | ||
1262 | |||
1263 | } | ||
1264 | |||
1265 | } | ||
1266 | |||
1267 | |||
1268 | |||
1269 | /* Newlib trap honeypot */ | ||
1270 | |||
1271 | void __trap34(void) | ||
1272 | |||
1273 | { | ||
1274 | |||
1275 | debugf("newlib trap34\n"); | ||
1276 | |||
1277 | while(1); | ||
1278 | |||
1279 | } | ||
1280 | |||