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