summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-11-25 00:02:54 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-11-25 00:02:54 +0000
commit2c0b72f103e5d924da78f089cea778363e8d4bed (patch)
treefb06e8d05899737bfb5af1e5330ba9fffbbf64f3
parentd0c958a861633d3fe6e9a02ce8506fcf2f961ee5 (diff)
downloadrockbox-2c0b72f103e5d924da78f089cea778363e8d4bed.tar.gz
rockbox-2c0b72f103e5d924da78f089cea778363e8d4bed.zip
Saves battery when monitoring, no longer trashes the first frame, corrected DMA timing
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2885 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/mpeg.c76
1 files changed, 71 insertions, 5 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c
index 10316b93fb..b5d82897f0 100644
--- a/firmware/mpeg.c
+++ b/firmware/mpeg.c
@@ -42,6 +42,7 @@ extern void bitswap(unsigned char *data, int length);
42static void init_recording(void); 42static void init_recording(void);
43static void init_playback(void); 43static void init_playback(void);
44static void start_recording(void); 44static void start_recording(void);
45static void stop_recording(void);
45#endif 46#endif
46 47
47#ifndef SIMULATOR 48#ifndef SIMULATOR
@@ -629,6 +630,45 @@ long timing_info_index = 0;
629long timing_info[1024]; 630long timing_info[1024];
630bool inverted_pr; 631bool inverted_pr;
631unsigned long num_rec_bytes; 632unsigned long num_rec_bytes;
633
634void drain_dma_buffer(void)
635{
636 if(inverted_pr)
637 {
638 while((*((volatile unsigned char *)PBDR_ADDR) & 0x40))
639 {
640 PADR |= 0x800;
641
642 while(*((volatile unsigned char *)PBDR_ADDR) & 0x80);
643
644 /* It must take at least 5 cycles before
645 the data is read */
646 asm(" nop\n nop\n nop\n");
647 asm(" nop\n nop\n nop\n");
648 PADR &= ~0x800;
649
650 while(!(*((volatile unsigned char *)PBDR_ADDR) & 0x80));
651 }
652 }
653 else
654 {
655 while((*((volatile unsigned char *)PBDR_ADDR) & 0x40))
656 {
657 PADR &= ~0x800;
658
659 while(*((volatile unsigned char *)PBDR_ADDR) & 0x80);
660
661 /* It must take at least 5 cycles before
662 the data is read */
663 asm(" nop\n nop\n nop\n");
664 asm(" nop\n nop\n nop\n");
665
666 PADR |= 0x800;
667
668 while(!(*((volatile unsigned char *)PBDR_ADDR) & 0x80));
669 }
670 }
671}
632#endif 672#endif
633 673
634static void dma_tick (void) __attribute__ ((section (".icode"))); 674static void dma_tick (void) __attribute__ ((section (".icode")));
@@ -702,6 +742,7 @@ static void dma_tick(void)
702 742
703 /* It must take at least 5 cycles before 743 /* It must take at least 5 cycles before
704 the data is read */ 744 the data is read */
745 asm(" nop\n nop\n nop\n");
705 mp3buf[mp3buf_write++] = *(unsigned char *)0x4000000; 746 mp3buf[mp3buf_write++] = *(unsigned char *)0x4000000;
706 747
707 if(mp3buf_write >= mp3buflen) 748 if(mp3buf_write >= mp3buflen)
@@ -1656,7 +1697,7 @@ static void mpeg_thread(void)
1656 case MPEG_STOP: 1697 case MPEG_STOP:
1657 DEBUGF("MPEG_STOP\n"); 1698 DEBUGF("MPEG_STOP\n");
1658 demand_irq_enable(false); 1699 demand_irq_enable(false);
1659 is_recording = false; 1700 stop_recording();
1660 1701
1661 /* Save the remaining data in the buffer */ 1702 /* Save the remaining data in the buffer */
1662 stop_pending = true; 1703 stop_pending = true;
@@ -1970,9 +2011,6 @@ static void init_playback(void)
1970 2011
1971void mpeg_record(char *filename) 2012void mpeg_record(char *filename)
1972{ 2013{
1973 /* Read the current frame */
1974 mas_readmem(MAS_BANK_D0, 0xfd0, &record_start_frame, 1);
1975
1976 num_rec_bytes = 0; 2014 num_rec_bytes = 0;
1977 is_recording = true; 2015 is_recording = true;
1978 queue_post(&mpeg_queue, MPEG_RECORD, (void*)filename); 2016 queue_post(&mpeg_queue, MPEG_RECORD, (void*)filename);
@@ -1980,10 +2018,35 @@ void mpeg_record(char *filename)
1980 2018
1981static void start_recording(void) 2019static void start_recording(void)
1982{ 2020{
2021 unsigned long val;
2022
2023 /* Stop monitoring and record for real */
2024 mas_readmem(MAS_BANK_D0, 0x7f1, &val, 1);
2025 val &= ~(1 << 10);
2026 val |= 1;
2027 mas_writemem(MAS_BANK_D0, 0x7f1, &val, 1);
2028
2029 /* Read the current frame */
2030 mas_readmem(MAS_BANK_D0, 0xfd0, &record_start_frame, 1);
2031
1983 stop_pending = false; 2032 stop_pending = false;
1984 saving = false; 2033 saving = false;
1985} 2034}
1986 2035
2036static void stop_recording(void)
2037{
2038 unsigned long val;
2039
2040 is_recording = false;
2041
2042 /* Start monitoring */
2043 mas_readmem(MAS_BANK_D0, 0x7f1, &val, 1);
2044 val |= (1 << 10) | 1;
2045 mas_writemem(MAS_BANK_D0, 0x7f1, &val, 1);
2046
2047 drain_dma_buffer();
2048}
2049
1987unsigned long mpeg_num_recorded_frames(void) 2050unsigned long mpeg_num_recorded_frames(void)
1988{ 2051{
1989 unsigned long val; 2052 unsigned long val;
@@ -2554,7 +2617,8 @@ void mpeg_set_recording_options(int frequency, int quality,
2554 2617
2555 DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f0, %x)\n", val); 2618 DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f0, %x)\n", val);
2556 2619
2557 val = (((source < 2)?1:2) << 8) | /* Input select */ 2620 val = ((1 << 10) | /* Monitoring on */
2621 ((source < 2)?1:2) << 8) | /* Input select */
2558 (1 << 5) | /* SDO strobe invert */ 2622 (1 << 5) | /* SDO strobe invert */
2559 ((is_mpeg1?0:1) << 3) | 2623 ((is_mpeg1?0:1) << 3) |
2560 (1 << 2) | /* Inverted SIBC clock signal */ 2624 (1 << 2) | /* Inverted SIBC clock signal */
@@ -2563,6 +2627,8 @@ void mpeg_set_recording_options(int frequency, int quality,
2563 2627
2564 DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f1, %x)\n", val); 2628 DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f1, %x)\n", val);
2565 2629
2630 drain_dma_buffer();
2631
2566 if(source == 0) /* Mic */ 2632 if(source == 0) /* Mic */
2567 { 2633 {
2568 /* Copy left channel to right (mono mode) */ 2634 /* Copy left channel to right (mono mode) */