M:Robe 500: Improve audio DMA shutdown for Pause/Stop and significantly reduce the size of the DSP code.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23817 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2009-12-02 04:30:08 +00:00
parent f0092e739e
commit 30c3382a48
12 changed files with 240 additions and 241 deletions

View file

@ -37,10 +37,8 @@ static void dsp_status(void)
DEBUGF("dsp_status(): clkc_hpib=%u clkc_dsp=%u", DEBUGF("dsp_status(): clkc_hpib=%u clkc_dsp=%u",
!!(IO_CLK_MOD0 & (1 << 11)), !!(IO_CLK_MOD0 & (1 << 10))); !!(IO_CLK_MOD0 & (1 << 11)), !!(IO_CLK_MOD0 & (1 << 10)));
DEBUGF("dsp_status(): irq_dsphint=%u 7fff=%04x scratch_status=%04x" DEBUGF("dsp_status(): irq_dsphint=%u 7fff=%04x scratch_status=%04x",
" acked=%04x", (IO_INTC_IRQ0 >> IRQ_DSPHINT) & 1, DSP_(0x7fff), DSP_(_status));
(IO_INTC_IRQ0 >> IRQ_DSPHINT) & 1, DSP_(0x7fff), DSP_(_status),
DSP_(_acked));
#define B(f,w,b,m) if ((w & (1 << b)) == 0) \ #define B(f,w,b,m) if ((w & (1 << b)) == 0) \
strcat(f, "!"); \ strcat(f, "!"); \
strcat(f, #m "|"); strcat(f, #m "|");

View file

@ -28,17 +28,27 @@
volatile struct ipc_message status; volatile struct ipc_message status;
extern int waiting; #if defined(HAVE_DEBUG)
volatile int acked; static int acked;
#endif
interrupt void handle_int0(void) { interrupt void handle_int0(void) {
IFR = 1; IFR = 1;
#if defined(HAVE_DEBUG)
acked = 1; acked = 1;
#endif
waiting = 0; waiting = 0;
if(dma0_stopped==0) if(dma0_stopped==0)
{ {
if(!(DMPREC&0x01)) if(!(DMPREC&0x01))
{ {
/* Give the HPIB access to refill first */
rebuffer();
/* Start the MCBSP DMA */
DMPREC |= 1; DMPREC |= 1;
audiohw_start(); audiohw_start();
} }
@ -47,15 +57,20 @@ interrupt void handle_int0(void) {
rebuffer(); rebuffer();
} }
} }
else
{
rebuffer();
}
} }
void startack(void) #if defined(HAVE_DEBUG)
static void startack(void)
{ {
acked = 0; acked = 0;
int_arm(); int_arm();
} }
void waitack(void) static void waitack(void)
{ {
/* Wait until ARM has picked up data. */ /* Wait until ARM has picked up data. */
while (!acked) while (!acked)
@ -78,3 +93,4 @@ void debugf(const char *fmt, ...) {
acked = 2; acked = 2;
} }
#endif

View file

@ -26,9 +26,6 @@
extern volatile struct ipc_message status; extern volatile struct ipc_message status;
void startack(void);
void waitack(void);
void debugf(const char *fmt, ...); void debugf(const char *fmt, ...);
inline void int_arm(void) { inline void int_arm(void) {

View file

@ -23,178 +23,201 @@
#include "registers.h" #include "registers.h"
#include "arm.h" #include "arm.h"
#include "dma.h" #include "ipc.h"
/* This is placed at the right (aligned) address using linker.cmd. */ /* Size of data buffer in words (16 bit) */
#define DSP_BUFFER_SIZE (0x1000)
/* Put the "data" buffer in it's own .dma section so that it can
* be handled in the linker.cmd. */
#pragma DATA_SECTION (data, ".dma") #pragma DATA_SECTION (data, ".dma")
#define DSP_BUFFER_SIZE PCM_SIZE/2 /* This is the "data" buffer on the DSP side used for SARAM to McBSP (IIS) */
static signed short data[DSP_BUFFER_SIZE];
/* This is the buffer on the DSP side used for SARAM to McBSP (IIS) */ /* These two describe the location of the buffer on the ARM (set in DSPHINT) */
signed short data[DSP_BUFFER_SIZE];
/* These two describe the location of the buffer on the ARM (set in DSPHINT
* and dspinit)
*/
volatile unsigned short sdem_addrh; volatile unsigned short sdem_addrh;
volatile unsigned short sdem_addrl; volatile unsigned short sdem_addrl;
/* This is the size of the ARM buffer (set in DSPHINT and dspinit) */ /* This is the size of the ARM buffer (set in DSPHINT) */
volatile unsigned short sdem_dsp_size; volatile unsigned short sdem_dsp_size;
/* These two variables keep track of the buffer level in the DSP, dsp_level, /* These two variables keep track of the buffer level in the DSP, dsp_level,
* (SARAM to McBSP) and the level on the ARM buffer (sdem_level). * (SARAM to McBSP) and the level on the ARM buffer (sdem_level).
*/ * sdem_level is used in the main firmware to keep track of the current
unsigned short dsp_level=0; * playback status. dsp_level is only used in this function. */
unsigned short sdem_level=0; static unsigned short dsp_level;
volatile unsigned short sdem_level;
/* This is used to keep track of the last SDRAM to SARAM transfer */ /* This is used to keep track of the last SDRAM to SARAM transfer */
unsigned short last_size; static unsigned short last_size;
/* This tells us which half of the DSP buffer (data) is free */ /* This tells us which half of the DSP buffer (data) is free */
unsigned short dma0_unlocked; static unsigned short dma0_unlocked;
volatile unsigned short dma0_stopped=1; /* This is used by the ARM to flag playback status and start/stop the DMA
* transfers. */
volatile unsigned short dma0_stopped;
short waiting=0; /* This is used to effectively flag whether the ARM has new data ready or not */
/* rebuffer sets up the next SDRAM to SARAM transfer and tells the ARM when it short waiting;
* is done with a buffer.
*/
/* Notes: The upper limit on larger buffers is the size of a short. If larger
/* rebuffer sets up the next SDRAM to SARAM transfer and tells the ARM when DMA
* needs a new buffer.
*
* Note: The upper limit on larger buffers is the size of a short. If larger
* buffer sizes are needed the code on the ARM side needs to be changed to * buffer sizes are needed the code on the ARM side needs to be changed to
* update a full long. * update a full long.
*/ */
void rebuffer(void) void rebuffer(void)
{ {
unsigned long sdem_addr; unsigned long sdem_addr;
if(dma0_stopped==1) /* Stop */ if(dma0_stopped==1 || dma0_stopped==2) /* Stop / Pause */
{ {
DMPREC&=0xFFFE; /* Stop MCBSP DMA0 */ /* Stop MCBSP DMA0 */
audiohw_stop(); DMPREC &= 0xFFFE;
DMSFC0 = 2 << 12 | 1 << 11; /* Shut the transmitter down */
sdem_level=0; audiohw_stop();
return;
}
if(dsp_level==DSP_BUFFER_SIZE || sdem_level==sdem_dsp_size) /* Stop the HPIB transfer if it is running */
{ DMA_TRG = 0;
if(dma0_stopped==2) /* Pause */
{
DMPREC&=0xFFFE; /* Stop MCBSP DMA0 */
audiohw_stop();
return;
}
}
/* If the sdem_level is equal to the buffer size the ARM code gave /* Reset the following variables for DMA restart */
* (sdem_dsp_size) then reset the size and ask the arm for another buffer sdem_level = 0;
*/ dsp_level = 0;
if(sdem_level==sdem_dsp_size) last_size = 0;
{
sdem_level=0;
/* Get a new buffer (location and size) from ARM */ return;
status.msg = MSG_REFILL; }
waiting=1;
startack(); /* If the sdem_level is equal to the buffer size the ARM code gave
} * (sdem_dsp_size) then reset the size and ask the arm for another buffer
*/
if(sdem_level == sdem_dsp_size)
{
sdem_level=0;
if(!waiting) /* Get a new buffer (location and size) from ARM */
{ status.msg = MSG_REFILL;
/* Size is in bytes (but forced 32 bit transfers */ waiting=1;
if( (dsp_level + (sdem_dsp_size - sdem_level) ) > DSP_BUFFER_SIZE)
{
last_size = DSP_BUFFER_SIZE-dsp_level;
}
else
{
last_size = sdem_dsp_size-sdem_level;
}
/* DSP addresses are 16 bit (word) */ /* trigger DSPHINT on the ARM */
DSP_ADDRL = (unsigned short)data + (dma0_unlocked >> 1) + (dsp_level>>1); int_arm();
DSP_ADDRH = 0; }
/* SDRAM addresses are 8 bit (byte) if(!waiting)
* Warning: These addresses are forced to 32 bit alignment! {
*/ /* Size is in bytes (but forced 32 bit transfers). Comparison is
sdem_addr = ((unsigned long)sdem_addrh << 16 | sdem_addrl) + sdem_level; * against DSP_BUFFER_SIZE because it is in words and this needs to
SDEM_ADDRL = sdem_addr & 0xffff; * compare against half the total size in bytes. */
SDEM_ADDRH = sdem_addr >> 16; if( dsp_level + sdem_dsp_size - sdem_level > DSP_BUFFER_SIZE)
{
last_size = DSP_BUFFER_SIZE - dsp_level;
}
else
{
last_size = sdem_dsp_size - sdem_level;
}
/* Set the size of the SDRAM to SARAM transfer (demac transfer) */ /* DSP addresses are 16 bit (word). dsp_level is in bytes so it needs to
DMA_SIZE = last_size; * be converted to words. */
DSP_ADDRL = (unsigned short)data + dma0_unlocked + (dsp_level >> 1);
DSP_ADDRH = 0;
DMA_CTRL = 0; /* SDRAM addresses are 8 bit (byte)
* Warning: These addresses are forced to 32 bit alignment!
*/
sdem_addr = ((unsigned long)sdem_addrh << 16 | sdem_addrl) + sdem_level;
SDEM_ADDRL = sdem_addr & 0xffff;
SDEM_ADDRH = sdem_addr >> 16;
/* These are just debug signals that are not used/needed right now */ /* Set the size of the SDRAM to SARAM transfer (demac transfer) */
status.payload.refill._DMA_TRG = DMA_TRG; DMA_SIZE = last_size;
status.payload.refill._SDEM_ADDRH = SDEM_ADDRH;
status.payload.refill._SDEM_ADDRL = SDEM_ADDRL;
status.payload.refill._DSP_ADDRH = DSP_ADDRH;
status.payload.refill._DSP_ADDRL = DSP_ADDRL;
/* Start the demac transfer */ DMA_CTRL = 0;
DMA_TRG = 1;
} /* These are just debug signals that are not used/needed right now */
status.payload.refill._DMA_TRG = DMA_TRG;
status.payload.refill._SDEM_ADDRH = SDEM_ADDRH;
status.payload.refill._SDEM_ADDRL = SDEM_ADDRL;
status.payload.refill._DSP_ADDRH = DSP_ADDRH;
status.payload.refill._DSP_ADDRL = DSP_ADDRL;
/* Start the demac transfer */
DMA_TRG = 1;
}
} }
/* This interupt handler is for the SARAM (on DSP) to McBSP IIS DMA transfer. /* This interupt handler is for the SARAM (on DSP) to McBSP IIS DMA transfer.
* It interupts at 1/2 empty and empty so that we can start filling a new buffer * It interupts at 1/2 empty and empty so that we can start filling a new buffer
* from SDRAM when a half is free. dsp_level should always be full when this * from SDRAM when a half is free. dsp_level should always be full when this
* interupt occurs except for the initial start. * interupt occurs except for the initial start. */
*/
interrupt void handle_dma0(void) interrupt void handle_dma0(void)
{ {
/* Byte offset to half-buffer locked by DMA0. /* Byte offset to half-buffer locked by DMA0.
0 for top, PCM_SIZE/2 for bottom */ 0 for top, DSP_BUFFER_SIZE/2 for bottom */
unsigned short dma0_locked; unsigned short dma0_locked;
IFR = 1 << 6; IFR = 1 << 6;
/* DMSRC0 is the beginning of the DMA0-locked SARAM half-buffer. */ /* DMSRC0 is the beginning of the DMA0-locked SARAM half-buffer. */
DMSA = 0x00 /* DMSRC0 */; DMSA = 0x00 /* DMSRC0 (banked register, see page 133 of SPRU302B */;
dma0_locked = (DMSDN << 1) & (DSP_BUFFER_SIZE);
dma0_unlocked = dma0_locked ^ (DSP_BUFFER_SIZE);
dsp_level = 0; /* Note that these address offsets (dma0_locked and dma0_unlocked are in
* words. */
dma0_locked = DMSDN & (DSP_BUFFER_SIZE>>1);
dma0_unlocked = dma0_locked ^ (DSP_BUFFER_SIZE>>1);
dsp_level = 0;
/* Start the SDRAM to SARAM copy */ /* Start the SDRAM to SARAM copy */
rebuffer(); rebuffer();
} }
/* This interupt handler runs every time a DMA transfer is complete from SDRAM /* This interupt handler runs every time a DMA transfer is complete from SDRAM
* to the SARAM buffer. It is used to update the SARAM buffer level * to the SARAM buffer. It is used to update the SARAM buffer level
* (dsp_level), the SDRAM buffer level (sdem_level) and to rebuffer if the dsp * (dsp_level), the SDRAM buffer level (sdem_level) and to rebuffer if the dsp
* buffer is not full. * buffer is not full. */
*/
interrupt void handle_dmac(void) { interrupt void handle_dmac(void) {
IFR = 1 << 11; IFR = 1 << 11; /* Clear interrupt */
dsp_level+=last_size; /* dsp_level and sdem_level are in bytes */
sdem_level+=last_size; dsp_level += last_size;
sdem_level += last_size;
if(dsp_level<DSP_BUFFER_SIZE) /* compare to DSP_BUFFER_SIZE without a divide because it is in words and
* we want half the total size in bytes. */
if(dsp_level < DSP_BUFFER_SIZE)
{ {
rebuffer(); rebuffer();
} }
} }
void dma_init(void) { void dma_init(void) {
/* Initialize some of the global variables to known values avoiding the
* .cinit section. */
dsp_level = 0;
sdem_level = 0;
last_size = 0;
dma0_unlocked = 0;
dma0_stopped = 1;
waiting = 0;
/* Configure SARAM to McBSP DMA */ /* Configure SARAM to McBSP DMA */
/* Event XEVT0, 32-bit transfers, 0 frame count */ /* Event XEVT0, 32-bit transfers, 0 frame count */
DMSFC0 = 2 << 12 | 1 << 11; DMSFC0 = 2 << 12 | 1 << 11;
/* Interrupts generated, Half and full buffer. /* Interrupts generated, Half and full buffer.
* ABU mode, From data space with postincrement, to data space with no * ABU mode, From data space with postincrement, to data space with no
* change * change
*/ */
DMMCR0 = 1 << 14 | 1 << 13 | DMMCR0 = 1 << 14 | 1 << 13 |
1 << 12 | 1 << 8 | 1 << 6 | 1; 1 << 12 | 1 << 8 | 1 << 6 | 1;
/* Set the source (incrementing) location */ /* Set the source (incrementing) location */
DMSRC0 = (unsigned short)&data; DMSRC0 = (unsigned short)&data;

View file

@ -22,9 +22,10 @@
#ifndef DMA_H #ifndef DMA_H
#define DMA_H #define DMA_H
#include "ipc.h"
void dma_init(void); void dma_init(void);
void rebuffer(void);
extern int waiting;
extern volatile unsigned short dma0_stopped; extern volatile unsigned short dma0_stopped;

File diff suppressed because one or more lines are too long

View file

@ -34,15 +34,15 @@
#define PACKED #define PACKED
#endif #endif
#define PCM_SIZE 0x8000 /* bytes */ /* Define this if you want to use debugf on the DSP. This consumes quite a bit
* of space so it is disabled by default. */
/* #define HAVE_DEBUG */
struct sdram_buffer { struct sdram_buffer {
unsigned long addr; unsigned long addr;
unsigned short bytes; unsigned short bytes;
} PACKED; } PACKED;
#define SDRAM_BUFFERS 4
struct ipc_message { struct ipc_message {
unsigned short msg; unsigned short msg;
union { union {

View file

@ -2,28 +2,38 @@
-x -x
-stack 0x1000 -stack 0x1000
-heap 0x100 -heap 0x100
-l rts500.lib
/* The rtx500.lib should be included if you want proper initialization,
* currently the program is setup so that it is not necessary to save space.
* reset vector should jump to _c_int00 if initialization is needed.
*
* -l rts500.lib*/
MEMORY MEMORY
{ {
PAGE 0: PAGE 0:
DARAM: origin = 80h, length = 7F80h DARAM (RWIX): origin = 80h, length = 7F00h
SARAM: origin = 8000h, length = 4000h VECS (RIX) : origin = 7F80h, length = 80h
/* SARAM can be read and written to, but it cannot execute and does not need
* to be initialized. */
SARAM (RW) : origin = 8000h, length = 4000h
} }
SECTIONS SECTIONS
{ {
.text PAGE 0 .text > DARAM PAGE 0
.cinit PAGE 0 .cinit > DARAM PAGE 0
.switch PAGE 0 .switch > DARAM PAGE 0
.data > DARAM PAGE 0
.bss PAGE 0 .bss > DARAM PAGE 0
.const PAGE 0 .const > DARAM PAGE 0
.sysmem PAGE 0 .sysmem > DARAM PAGE 0
.stack PAGE 0 .stack > DARAM PAGE 0
.vectors : PAGE 0 load = 7F80h .vectors > VECS PAGE 0
/* DMA buffers for ABU mode must start on a 2*size boundary. */ /* DMA buffers for ABU mode must start on a 2*size boundary. */
.dma : PAGE 0 load = 0x8000 .dma > SARAM PAGE 0
} }

View file

@ -24,7 +24,6 @@
#include "ipc.h" #include "ipc.h"
#include "dma.h" #include "dma.h"
#include "audio.h" #include "audio.h"
#include <math.h>
void main(void) { void main(void) {
TCR = 1 << 4; /* Stop the timer. */ TCR = 1 << 4; /* Stop the timer. */
@ -36,7 +35,9 @@ void main(void) {
dma_init(); dma_init();
#if defined(HAVE_DEBUG)
debugf("DSP inited..."); debugf("DSP inited...");
#endif
for (;;) { for (;;) {
asm(" IDLE 1"); asm(" IDLE 1");
@ -45,13 +46,6 @@ void main(void) {
} }
/* Obsoleted/testing snippets: */ /* Obsoleted/testing snippets: */
#ifdef REMAP_VECTORS
/* Remap vectors to 0x3F80 (set in linker.cmd). */
PMST = (PMST & 0x7f) | 0x3F80;
/* Make sure working interrupts aren't a fluke. */
memset((unsigned short *)0x7f80, 0, 0x80);
#endif
#ifdef DATA_32_SINE #ifdef DATA_32_SINE
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {

View file

@ -40,8 +40,10 @@ void audiohw_start(void)
/* Trigger first XEVT0 */ /* Trigger first XEVT0 */
SPCR20 |= 1; SPCR20 |= 1;
} }
audiohw_stop(void)
void audiohw_stop(void)
{ {
/* Reset the transmitter */ /* Reset the transmitter */
SPCR20&=0xFFFE; SPCR20&=0xFFFE;
} }

View file

@ -27,13 +27,17 @@
; External Functions ; External Functions
.global _handle_int0 .global _handle_int0
.global _c_int00 .global _main
.global _handle_dma0 .global _handle_dma0
.global _handle_dmac .global _handle_dmac
.sect ".vectors" .sect ".vectors"
; Reset Interrupt ; Reset Interrupt
RS_V: BD _c_int00 ; The rtx500.lib should be included if you want proper initialization,
; currently the program is setup so that it is not necessary to save space.
; reset vector should jump to _c_int00 instead of main if initialization is
; needed.
RS_V: BD _main
NOP NOP
NOP NOP

View file

@ -91,6 +91,7 @@ void pcm_play_dma_start(const void *addr, size_t size)
void pcm_play_dma_stop(void) void pcm_play_dma_stop(void)
{ {
DSP_(_dma0_stopped)=1; DSP_(_dma0_stopped)=1;
dsp_wake();
} }
void pcm_play_lock(void) void pcm_play_lock(void)
@ -108,6 +109,7 @@ void pcm_play_dma_pause(bool pause)
if (pause) if (pause)
{ {
DSP_(_dma0_stopped)=2; DSP_(_dma0_stopped)=2;
dsp_wake();
} }
else else
{ {