summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-10-09 13:25:03 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-10-09 13:25:03 +0000
commit33060d00c20c81a7600914b14c3e4838c0b4a9f6 (patch)
treeea13e57fe00d397d84c8bf6e82fd870ac3ec5464
parent2bfd326fc98c5952da547a9bea0236f6381a9ca7 (diff)
downloadrockbox-33060d00c20c81a7600914b14c3e4838c0b4a9f6.tar.gz
rockbox-33060d00c20c81a7600914b14c3e4838c0b4a9f6.zip
New version of the DMA underrun handling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2547 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/mpeg.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 884ba87a71..104b6c5011 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -54,7 +54,6 @@ extern void bitswap(unsigned char *data, int length);
54#define MPEG_NEED_DATA 100 54#define MPEG_NEED_DATA 100
55#define MPEG_SWAP_DATA 101 55#define MPEG_SWAP_DATA 101
56#define MPEG_TRACK_CHANGE 102 56#define MPEG_TRACK_CHANGE 102
57#define MPEG_DMA_UNDERRUN 103
58 57
59extern char* playlist_peek(int steps); 58extern char* playlist_peek(int steps);
60extern int playlist_next(int steps); 59extern int playlist_next(int steps);
@@ -434,6 +433,8 @@ static bool playing; /* We are playing an MP3 stream */
434static bool play_pending; /* We are about to start playing */ 433static bool play_pending; /* We are about to start playing */
435static bool is_playing; /* We are (attempting to) playing MP3 files */ 434static bool is_playing; /* We are (attempting to) playing MP3 files */
436static bool filling; /* We are filling the buffer with data from disk */ 435static bool filling; /* We are filling the buffer with data from disk */
436static bool dma_underrun; /* True when the DMA has stopped because of
437 slow disk reading (read error, shaking) */
437 438
438static int mpeg_file; 439static int mpeg_file;
439 440
@@ -490,7 +491,7 @@ static int dbg_cnt2us(unsigned int cnt)
490} 491}
491#endif 492#endif
492 493
493static int get_unplayed_space(void) 494int get_unplayed_space(void)
494{ 495{
495 int space = mp3buf_write - mp3buf_read; 496 int space = mp3buf_write - mp3buf_read;
496 if (space < 0) 497 if (space < 0)
@@ -537,6 +538,7 @@ static void init_dma(void)
537 DTCR3 = last_dma_chunk_size & 0xffff; 538 DTCR3 = last_dma_chunk_size & 0xffff;
538 DMAOR = 0x0001; /* Enable DMA */ 539 DMAOR = 0x0001; /* Enable DMA */
539 CHCR3 |= 0x0001; /* Enable DMA IRQ */ 540 CHCR3 |= 0x0001; /* Enable DMA IRQ */
541 dma_underrun = false;
540} 542}
541 543
542static void start_dma(void) 544static void start_dma(void)
@@ -639,13 +641,19 @@ void DEI3(void)
639 } 641 }
640 else 642 else
641 { 643 {
642 DEBUGF("No more MP3 data. Stopping.\n"); 644 /* Check if the end of data is because of a hard disk error.
643 645 If there is an open file handle, we are still playing music.
644 /* Check if the end of data is because of a hard disk error */ 646 If not, the last file has been loaded, and the file handle is
645 if(filling) 647 closed. */
646 queue_post(&mpeg_queue, MPEG_DMA_UNDERRUN, 0); 648 if(mpeg_file >= 0)
649 {
650 DEBUGF("DMA underrun.\n");
651 dma_underrun = true;
652 }
647 else 653 else
648 { 654 {
655 DEBUGF("No more MP3 data. Stopping.\n");
656
649 queue_post(&mpeg_queue, MPEG_TRACK_CHANGE, 0); 657 queue_post(&mpeg_queue, MPEG_TRACK_CHANGE, 0);
650 playing = false; 658 playing = false;
651 is_playing = false; 659 is_playing = false;
@@ -1239,7 +1247,7 @@ static void mpeg_thread(void)
1239 1247
1240 /* And while we're at it, see if we have started 1248 /* And while we're at it, see if we have started
1241 playing yet. If not, do it. */ 1249 playing yet. If not, do it. */
1242 if(play_pending) 1250 if(play_pending || dma_underrun)
1243 { 1251 {
1244 /* If the filling has stopped, and we still haven't reached 1252 /* If the filling has stopped, and we still haven't reached
1245 the watermark, the file must be smaller than the 1253 the watermark, the file must be smaller than the
@@ -1305,6 +1313,7 @@ static void mpeg_thread(void)
1305 DEBUGF("R\n"); 1313 DEBUGF("R\n");
1306 t1 = current_tick; 1314 t1 = current_tick;
1307 len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); 1315 len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read);
1316
1308 if(len > 0) 1317 if(len > 0)
1309 { 1318 {
1310 t2 = current_tick; 1319 t2 = current_tick;
@@ -1365,10 +1374,6 @@ static void mpeg_thread(void)
1365 track_change(); 1374 track_change();
1366 break; 1375 break;
1367 1376
1368 case MPEG_DMA_UNDERRUN:
1369 CHCR3 |= 0x0001; /* Enable the DMA interrupt */
1370 break;
1371
1372 case SYS_USB_CONNECTED: 1377 case SYS_USB_CONNECTED:
1373 stop_playing(); 1378 stop_playing();
1374#ifndef SIMULATOR 1379#ifndef SIMULATOR