diff options
Diffstat (limited to 'firmware/mpeg.c')
-rw-r--r-- | firmware/mpeg.c | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index b834e5deac..feb12ca57f 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -350,10 +350,10 @@ static bool playing = false; | |||
350 | #else | 350 | #else |
351 | static int last_dma_tick = 0; | 351 | static int last_dma_tick = 0; |
352 | 352 | ||
353 | #ifdef HAVE_MAS3507D | ||
354 | |||
355 | static unsigned long mas_version_code; | 353 | static unsigned long mas_version_code; |
356 | 354 | ||
355 | #ifdef HAVE_MAS3507D | ||
356 | |||
357 | static unsigned int bass_table[] = | 357 | static unsigned int bass_table[] = |
358 | { | 358 | { |
359 | 0x9e400, /* -15dB */ | 359 | 0x9e400, /* -15dB */ |
@@ -621,6 +621,7 @@ static void stop_dma(void) | |||
621 | long timing_info_index = 0; | 621 | long timing_info_index = 0; |
622 | long timing_info[1024]; | 622 | long timing_info[1024]; |
623 | bool inverted_pr; | 623 | bool inverted_pr; |
624 | unsigned long num_rec_bytes; | ||
624 | #endif | 625 | #endif |
625 | 626 | ||
626 | static void dma_tick(void) | 627 | static void dma_tick(void) |
@@ -661,7 +662,6 @@ static void dma_tick(void) | |||
661 | PADR &= ~0x800; | 662 | PADR &= ~0x800; |
662 | 663 | ||
663 | /* It must take at least 5 cycles before the data is read */ | 664 | /* It must take at least 5 cycles before the data is read */ |
664 | |||
665 | mp3buf[mp3buf_write] = *(unsigned char *)0x4000000; | 665 | mp3buf[mp3buf_write] = *(unsigned char *)0x4000000; |
666 | 666 | ||
667 | if(inverted_pr) | 667 | if(inverted_pr) |
@@ -670,6 +670,7 @@ static void dma_tick(void) | |||
670 | PADR |= 0x800; | 670 | PADR |= 0x800; |
671 | 671 | ||
672 | /* It must take at least 4 cycles before the next loop */ | 672 | /* It must take at least 4 cycles before the next loop */ |
673 | num_rec_bytes++; | ||
673 | 674 | ||
674 | mp3buf_write++; | 675 | mp3buf_write++; |
675 | if(mp3buf_write >= mp3buflen) | 676 | if(mp3buf_write >= mp3buflen) |
@@ -1623,6 +1624,7 @@ static void mpeg_thread(void) | |||
1623 | demand_irq_enable(false); | 1624 | demand_irq_enable(false); |
1624 | if(mpeg_file >= 0) | 1625 | if(mpeg_file >= 0) |
1625 | close(mpeg_file); | 1626 | close(mpeg_file); |
1627 | mpeg_file = -1; | ||
1626 | 1628 | ||
1627 | #if 0 | 1629 | #if 0 |
1628 | { | 1630 | { |
@@ -1784,6 +1786,7 @@ static void init_recording(void) | |||
1784 | /* Stop the current stream */ | 1786 | /* Stop the current stream */ |
1785 | play_pending = false; | 1787 | play_pending = false; |
1786 | playing = false; | 1788 | playing = false; |
1789 | is_playing = false; | ||
1787 | stop_dma(); | 1790 | stop_dma(); |
1788 | 1791 | ||
1789 | reset_mp3_buffer(); | 1792 | reset_mp3_buffer(); |
@@ -1791,6 +1794,7 @@ static void init_recording(void) | |||
1791 | 1794 | ||
1792 | if(mpeg_file >= 0) | 1795 | if(mpeg_file >= 0) |
1793 | close(mpeg_file); | 1796 | close(mpeg_file); |
1797 | mpeg_file = -1; | ||
1794 | 1798 | ||
1795 | /* Init the recording variables */ | 1799 | /* Init the recording variables */ |
1796 | recording = false; | 1800 | recording = false; |
@@ -1801,8 +1805,19 @@ static void init_recording(void) | |||
1801 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); | 1805 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); |
1802 | do | 1806 | do |
1803 | { | 1807 | { |
1804 | mas_readmem(MAS_BANK_D0, 0x7f6, &val, 1); | 1808 | mas_readmem(MAS_BANK_D0, 0x7f7, &val, 1); |
1805 | } while(val); | 1809 | } while(val); |
1810 | |||
1811 | /* Perform black magic as described by the data sheet */ | ||
1812 | if((mas_version_code & 0xff) == 2) | ||
1813 | { | ||
1814 | DEBUGF("Performing MAS black magic for B2 version\n"); | ||
1815 | mas_writereg(0xa3, 0x98); | ||
1816 | mas_writereg(0x94, 0xfffff); | ||
1817 | val = 0; | ||
1818 | mas_writemem(MAS_BANK_D1, 0, &val, 1); | ||
1819 | mas_writereg(0xa3, 0x90); | ||
1820 | } | ||
1806 | 1821 | ||
1807 | /* Enable the Left A/D Converter */ | 1822 | /* Enable the Left A/D Converter */ |
1808 | mas_codec_writereg(0x0, 0xcccd); | 1823 | mas_codec_writereg(0x0, 0xcccd); |
@@ -1816,18 +1831,18 @@ static void init_recording(void) | |||
1816 | 1831 | ||
1817 | /* No mute */ | 1832 | /* No mute */ |
1818 | val = 0; | 1833 | val = 0; |
1819 | mas_writemem(MAS_BANK_D0,0x7f9,&val,1); | 1834 | mas_writemem(MAS_BANK_D0, 0x7f9, &val, 1); |
1820 | 1835 | ||
1821 | /* Set Demand mode and validate all settings */ | 1836 | /* Set Demand mode and validate all settings */ |
1822 | val = 0x25; | 1837 | val = 0x25; |
1823 | mas_writemem(MAS_BANK_D0,0x7f1,&val,1); | 1838 | mas_writemem(MAS_BANK_D0, 0x7f1, &val, 1); |
1824 | 1839 | ||
1825 | /* Start the encoder application */ | 1840 | /* Start the encoder application */ |
1826 | val = 0x40; | 1841 | val = 0x40; |
1827 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); | 1842 | mas_writemem(MAS_BANK_D0, 0x7f6, &val, 1); |
1828 | do | 1843 | do |
1829 | { | 1844 | { |
1830 | mas_readmem(MAS_BANK_D0, 0x7f6, &val, 1); | 1845 | mas_readmem(MAS_BANK_D0, 0x7f7, &val, 1); |
1831 | } while(!(val & 0x40)); | 1846 | } while(!(val & 0x40)); |
1832 | 1847 | ||
1833 | mpeg_mode = MPEG_ENCODER; | 1848 | mpeg_mode = MPEG_ENCODER; |
@@ -1839,14 +1854,12 @@ static void init_playback(void) | |||
1839 | { | 1854 | { |
1840 | unsigned long val; | 1855 | unsigned long val; |
1841 | 1856 | ||
1842 | mpeg_mode = MPEG_DECODER; | ||
1843 | |||
1844 | /* Stop the current application */ | 1857 | /* Stop the current application */ |
1845 | val = 0; | 1858 | val = 0; |
1846 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); | 1859 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); |
1847 | do | 1860 | do |
1848 | { | 1861 | { |
1849 | mas_readmem(MAS_BANK_D0, 0x7f6, &val, 1); | 1862 | mas_readmem(MAS_BANK_D0, 0x7f7, &val, 1); |
1850 | } while(val); | 1863 | } while(val); |
1851 | 1864 | ||
1852 | /* Enable the D/A Converter */ | 1865 | /* Enable the D/A Converter */ |
@@ -1867,6 +1880,12 @@ static void init_playback(void) | |||
1867 | /* Start the Layer2/3 decoder applications */ | 1880 | /* Start the Layer2/3 decoder applications */ |
1868 | val = 0x0c; | 1881 | val = 0x0c; |
1869 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); | 1882 | mas_writemem(MAS_BANK_D0,0x7f6,&val,1); |
1883 | do | ||
1884 | { | ||
1885 | mas_readmem(MAS_BANK_D0, 0x7f7, &val, 1); | ||
1886 | } while((val & 0x0c) != 0x0c); | ||
1887 | |||
1888 | mpeg_mode = MPEG_DECODER; | ||
1870 | 1889 | ||
1871 | DEBUGF("MAS Decoding application started\n"); | 1890 | DEBUGF("MAS Decoding application started\n"); |
1872 | } | 1891 | } |
@@ -1875,7 +1894,8 @@ void mpeg_record(char *filename) | |||
1875 | { | 1894 | { |
1876 | /* Read the current frame */ | 1895 | /* Read the current frame */ |
1877 | mas_readmem(MAS_BANK_D0, 0xfd0, &record_start_frame, 1); | 1896 | mas_readmem(MAS_BANK_D0, 0xfd0, &record_start_frame, 1); |
1878 | 1897 | ||
1898 | num_rec_bytes = 0; | ||
1879 | is_recording = true; | 1899 | is_recording = true; |
1880 | queue_post(&mpeg_queue, MPEG_RECORD, (void*)filename); | 1900 | queue_post(&mpeg_queue, MPEG_RECORD, (void*)filename); |
1881 | } | 1901 | } |
@@ -1902,6 +1922,14 @@ unsigned long mpeg_num_recorded_frames(void) | |||
1902 | return 0; | 1922 | return 0; |
1903 | } | 1923 | } |
1904 | } | 1924 | } |
1925 | |||
1926 | unsigned long mpeg_num_recorded_bytes(void) | ||
1927 | { | ||
1928 | if(is_recording) | ||
1929 | return num_rec_bytes; | ||
1930 | else | ||
1931 | return 0; | ||
1932 | } | ||
1905 | #endif | 1933 | #endif |
1906 | 1934 | ||
1907 | void mpeg_play(int offset) | 1935 | void mpeg_play(int offset) |
@@ -2502,6 +2530,10 @@ void mpeg_init(int volume, int bass, int treble, int balance, int loudness, int | |||
2502 | if(rc < 0) | 2530 | if(rc < 0) |
2503 | panicf("mas_ctrl_r: %d", rc); | 2531 | panicf("mas_ctrl_r: %d", rc); |
2504 | 2532 | ||
2533 | mas_version_code = mas_readver(); | ||
2534 | DEBUGF("MAS3587 derivate %d, version B%d\n", | ||
2535 | (mas_version_code & 0xff00) >> 8, mas_version_code & 0xff); | ||
2536 | |||
2505 | init_playback(); | 2537 | init_playback(); |
2506 | 2538 | ||
2507 | mpeg_sound_channel_config(MPEG_SOUND_STEREO); | 2539 | mpeg_sound_channel_config(MPEG_SOUND_STEREO); |