1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Linus Nielsen Feltzing 2002-11-25 00:02:54 +00:00
parent d0c958a861
commit 2c0b72f103

View file

@ -42,6 +42,7 @@ extern void bitswap(unsigned char *data, int length);
static void init_recording(void); static void init_recording(void);
static void init_playback(void); static void init_playback(void);
static void start_recording(void); static void start_recording(void);
static void stop_recording(void);
#endif #endif
#ifndef SIMULATOR #ifndef SIMULATOR
@ -629,6 +630,45 @@ long timing_info_index = 0;
long timing_info[1024]; long timing_info[1024];
bool inverted_pr; bool inverted_pr;
unsigned long num_rec_bytes; unsigned long num_rec_bytes;
void drain_dma_buffer(void)
{
if(inverted_pr)
{
while((*((volatile unsigned char *)PBDR_ADDR) & 0x40))
{
PADR |= 0x800;
while(*((volatile unsigned char *)PBDR_ADDR) & 0x80);
/* It must take at least 5 cycles before
the data is read */
asm(" nop\n nop\n nop\n");
asm(" nop\n nop\n nop\n");
PADR &= ~0x800;
while(!(*((volatile unsigned char *)PBDR_ADDR) & 0x80));
}
}
else
{
while((*((volatile unsigned char *)PBDR_ADDR) & 0x40))
{
PADR &= ~0x800;
while(*((volatile unsigned char *)PBDR_ADDR) & 0x80);
/* It must take at least 5 cycles before
the data is read */
asm(" nop\n nop\n nop\n");
asm(" nop\n nop\n nop\n");
PADR |= 0x800;
while(!(*((volatile unsigned char *)PBDR_ADDR) & 0x80));
}
}
}
#endif #endif
static void dma_tick (void) __attribute__ ((section (".icode"))); static void dma_tick (void) __attribute__ ((section (".icode")));
@ -702,6 +742,7 @@ static void dma_tick(void)
/* It must take at least 5 cycles before /* It must take at least 5 cycles before
the data is read */ the data is read */
asm(" nop\n nop\n nop\n");
mp3buf[mp3buf_write++] = *(unsigned char *)0x4000000; mp3buf[mp3buf_write++] = *(unsigned char *)0x4000000;
if(mp3buf_write >= mp3buflen) if(mp3buf_write >= mp3buflen)
@ -1656,7 +1697,7 @@ static void mpeg_thread(void)
case MPEG_STOP: case MPEG_STOP:
DEBUGF("MPEG_STOP\n"); DEBUGF("MPEG_STOP\n");
demand_irq_enable(false); demand_irq_enable(false);
is_recording = false; stop_recording();
/* Save the remaining data in the buffer */ /* Save the remaining data in the buffer */
stop_pending = true; stop_pending = true;
@ -1970,9 +2011,6 @@ static void init_playback(void)
void mpeg_record(char *filename) void mpeg_record(char *filename)
{ {
/* Read the current frame */
mas_readmem(MAS_BANK_D0, 0xfd0, &record_start_frame, 1);
num_rec_bytes = 0; num_rec_bytes = 0;
is_recording = true; is_recording = true;
queue_post(&mpeg_queue, MPEG_RECORD, (void*)filename); queue_post(&mpeg_queue, MPEG_RECORD, (void*)filename);
@ -1980,10 +2018,35 @@ void mpeg_record(char *filename)
static void start_recording(void) static void start_recording(void)
{ {
unsigned long val;
/* Stop monitoring and record for real */
mas_readmem(MAS_BANK_D0, 0x7f1, &val, 1);
val &= ~(1 << 10);
val |= 1;
mas_writemem(MAS_BANK_D0, 0x7f1, &val, 1);
/* Read the current frame */
mas_readmem(MAS_BANK_D0, 0xfd0, &record_start_frame, 1);
stop_pending = false; stop_pending = false;
saving = false; saving = false;
} }
static void stop_recording(void)
{
unsigned long val;
is_recording = false;
/* Start monitoring */
mas_readmem(MAS_BANK_D0, 0x7f1, &val, 1);
val |= (1 << 10) | 1;
mas_writemem(MAS_BANK_D0, 0x7f1, &val, 1);
drain_dma_buffer();
}
unsigned long mpeg_num_recorded_frames(void) unsigned long mpeg_num_recorded_frames(void)
{ {
unsigned long val; unsigned long val;
@ -2554,7 +2617,8 @@ void mpeg_set_recording_options(int frequency, int quality,
DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f0, %x)\n", val); DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f0, %x)\n", val);
val = (((source < 2)?1:2) << 8) | /* Input select */ val = ((1 << 10) | /* Monitoring on */
((source < 2)?1:2) << 8) | /* Input select */
(1 << 5) | /* SDO strobe invert */ (1 << 5) | /* SDO strobe invert */
((is_mpeg1?0:1) << 3) | ((is_mpeg1?0:1) << 3) |
(1 << 2) | /* Inverted SIBC clock signal */ (1 << 2) | /* Inverted SIBC clock signal */
@ -2563,6 +2627,8 @@ void mpeg_set_recording_options(int frequency, int quality,
DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f1, %x)\n", val); DEBUGF("mas_writemem(MAS_BANK_D0, 0x7f1, %x)\n", val);
drain_dma_buffer();
if(source == 0) /* Mic */ if(source == 0) /* Mic */
{ {
/* Copy left channel to right (mono mode) */ /* Copy left channel to right (mono mode) */