diff --git a/apps/recorder/pcm_record.c b/apps/recorder/pcm_record.c index d1dc031..9d54489 100644 --- a/apps/recorder/pcm_record.c +++ b/apps/recorder/pcm_record.c @@ -21,6 +21,7 @@ #include "pcm_record.h" #include "system.h" #include "kernel.h" +#define LOGF_ENABLE #include "logf.h" #include "thread.h" #include @@ -308,7 +309,10 @@ unsigned long pcm_rec_status(void) ret |= AUDIO_STATUS_PAUSE; if (errors) + { ret |= AUDIO_STATUS_ERROR; + logf("pcmrec errors: 0x%x", errors); + } if (warnings) ret |= AUDIO_STATUS_WARNING; diff --git a/firmware/export/config-fuze.h b/firmware/export/config-fuze.h index 2a438ec..3c943f4 100644 --- a/firmware/export/config-fuze.h +++ b/firmware/export/config-fuze.h @@ -10,7 +10,7 @@ #define HW_SAMPR_CAPS SAMPR_CAP_ALL /* define this if you have recording possibility */ -//#define HAVE_RECORDING +#define HAVE_RECORDING #define REC_SAMPR_CAPS SAMPR_CAP_ALL diff --git a/firmware/target/arm/as3525/pcm-as3525.c b/firmware/target/arm/as3525/pcm-as3525.c index 26e018c..4f8f95c 100644 --- a/firmware/target/arm/as3525/pcm-as3525.c +++ b/firmware/target/arm/as3525/pcm-as3525.c @@ -188,18 +188,19 @@ static int rec_locked = 0; static unsigned int *rec_start_addr; static size_t rec_size; +static void dma_rec_callback(void); void pcm_rec_lock(void) { if(++rec_locked == 1) - VIC_INT_EN_CLEAR = INTERRUPT_I2SIN; + VIC_INT_EN_CLEAR = INTERRUPT_DMAC; } void pcm_rec_unlock(void) { if(--rec_locked == 0) - VIC_INT_ENABLE |= INTERRUPT_I2SIN; + VIC_INT_ENABLE |= INTERRUPT_DMAC; } @@ -212,7 +213,10 @@ void pcm_record_more(void *start, size_t size) void pcm_rec_dma_stop(void) { - VIC_INT_EN_CLEAR = INTERRUPT_I2SIN; + dma_disable_channel(1); + rec_size = 0; + + //dma_release(); /* called too many times */ I2SOUT_CONTROL &= ~(1<<5); /* source = i2soutif fifo */ CGU_AUDIO &= ~((1<<23)|(1<<11)); @@ -222,38 +226,39 @@ void pcm_rec_dma_stop(void) void INT_I2SIN(void) { - register int status; - register pcm_more_callback_type2 more_ready; + const int status = I2SIN_STATUS; + panicf("I2SIN :%s %s error", + (status & (1<<0)) ? "pop" : "", + (status & (1<<6)) ? "push" : "" + ); +} - status = I2SIN_STATUS; -#if 0 /* FIXME */ - if ( status & ((1<<6)|(1<<0)) ) /* errors */ - panicf("i2sin error: 0x%x = %s %s", status, - (status & (1<<6)) ? "push" : "", - (status & (1<<0)) ? "pop" : "" - ); -#endif +static void rec_start_pcm(void) +{ + const unsigned int *addr = rec_start_addr; + size_t size = rec_size; + if(size > MAX_TRANSFER) + size = MAX_TRANSFER; - while (((I2SIN_RAW_STATUS & (1<<5)) == 0) && rec_size) - { - /* 14 bits per sample = 1 32 bits word */ - *rec_start_addr++ = *I2SIN_DATA; - rec_size -= 4; - } + rec_size -= size; + rec_start_addr += size; - I2SIN_CLEAR = status; + CGU_PERI |= CGU_I2SIN_APB_CLOCK_ENABLE|CGU_I2SOUT_APB_CLOCK_ENABLE; + CGU_AUDIO |= ((1<<23)|(1<<11)); - if(!rec_size) - { - more_ready = pcm_callback_more_ready; - if(!more_ready || more_ready(0) < 0) - { - /* Finished recording */ - pcm_rec_dma_stop(); - pcm_rec_dma_stopped_callback(); - } - } + dump_dcache_range((void*)addr, size); /* dump cache entries */ + dma_enable_channel(1, (void*)I2SIN_DATA, (void*)addr, DMA_PERI_I2SIN, + DMAC_FLOWCTRL_DMAC_PERI_TO_MEM, false, true, size >> 2, DMA_S1, + dma_rec_callback); + + I2SOUT_CONTROL |= 1<<5; /* source = loopback from i2sin fifo */ + + I2SIN_CLEAR = I2SIN_MASK = (1<<6)|(1<<0); /* push/pop errors */ + + /* 14 bits samples, i2c clk src = I2SOUTIF, sdata src = AFE, + * data valid at positive edge of SCLK, dma enabled */ + I2SIN_CONTROL = (1<<5) | (1<<2) | (1<<11); } @@ -262,23 +267,26 @@ void pcm_rec_dma_start(void *addr, size_t size) rec_start_addr = addr; rec_size = size; - CGU_PERI |= CGU_I2SIN_APB_CLOCK_ENABLE|CGU_I2SOUT_APB_CLOCK_ENABLE; - CGU_AUDIO |= ((1<<23)|(1<<11)); + dma_retain(); - I2SOUT_CONTROL |= 1<<5; /* source = loopback from i2sin fifo */ + rec_start_pcm(); +} - /* 14 bits samples, i2c clk src = I2SOUTIF, sdata src = AFE, - * data valid at positive edge of SCLK */ - I2SIN_CONTROL = (1<<5) | (1<<2); - unsigned long tmp; - while ( ( I2SIN_RAW_STATUS & ( 1<<5 ) ) == 0 ) - tmp = *I2SIN_DATA; /* FLUSH FIFO */ - I2SIN_CLEAR = (1<<6)|(1<<0); /* push error, pop error */ - I2SIN_MASK = (1<<6) | (1<<0) | - (1<<3) | (1<<2) | (1<<1); /* half full, almost full, full */ +static void dma_rec_callback(void) +{ + if(!rec_size) + { + register pcm_more_callback_type2 more_ready = pcm_callback_more_ready; + if(!more_ready || more_ready(0) < 0) + { + /* Finished recording */ + pcm_rec_dma_stop(); + pcm_rec_dma_stopped_callback(); + } + } - VIC_INT_ENABLE |= INTERRUPT_I2SIN; + rec_start_pcm(); }