2009-04-09 10:11:56     question about Alsa architecture

Document created by Aaronwu Employee on Aug 14, 2013
Version 1Show Document
  • View in full screen mode

2009-04-09 10:11:56     question about Alsa architecture

liang wang (CHINA)

Message: 72467   

Dear sir

I am now transplant a char driver to alsa architecture

my codec is vs1053 a spi codec. and I can't use DMA transmit data!

I see the explanation in the LINUX device driver.pdf as follow:

Variables of type dma_addr_t should be treated as opaque by the driver;the only allowable operations are to pass them to the DMA support routines and to the device itself .Aa a bus address ,dma_addr_t may lead to unexpected problems if used directly by the CPU.

If I  don't use DMA ,how Can I use spi_write() to write the audio data start from substream->runtime ->dma_addr to the spi bus?? The substream audio data address is type of dma_addr_t ,I don't know how to deal it! Can you give me some advice?

 

and I see the document writing-an-alsa-driver.pdf .I see Chapter 11 .Buffer and Memory Management ->Externel Hardware Buffers

some chips have their own hardware buffers and the DMA transfer from the host memory is not available. In such a case, you need to either

1) copy/set the audio data directly to the external hardwarebuffer, or

2) make an intermediate buffer and copy/set the data from it to the external hardware buffer in interrupts (or in tasklets, preferably).

The first case works fine if the external hardware buffer is enough large. This method doesn’t need any

extra buffers and thus is more effective. You need to define the copy and silence callbacks for the data

transfer.(however My codec buffer is 32B )

static int playback_copy(struct snd_pcm_substream *substream, int channel,

snd_pcm_uframes_t pos, void *src, snd_pcm_uframes_t count);

 

Is that mean if  I don/t use DMA I must realize the playback_copy?

I must copy the data to runtime->dma_area from user space? After that I must send data to my codec from runtime->dma_area?

 

Thank you !

TranslateQuoteReplyEditDelete

 

 

2009-04-09 22:44:34     Re: question about Alsa architecture

Cliff Cai (CHINA)

Message: 72491   

 

You should allocate buffers for up layer use locally,and assign the pointers of these buffers to runtime->dma_area(two for both playback and capture).Up layer will store the data to be played in the buffer,or  use the data stored here for record.What you need to implement are 'copy' callbacks which are used to  deal with the buffers mentioned above.

 

Cliff

QuoteReplyEditDelete

 

 

2009-04-10 00:58:52     Re: question about Alsa architecture

liang wang (CHINA)

Message: 72492   

 

Thank you!You mean without DMA,the alsa arch can be implemented

 

static struct snd_pcm_ops snd_card_vs1003_playback_ops = {

    .open            = snd_card_vs1003_open,

    .close            = snd_card_vs1003_close,

    .ioctl            = snd_pcm_lib_ioctl,

    .hw_params            = snd_vs1003_hw_params,

    .hw_free            = snd_vs1003_hw_free,

    .prepare        = snd_vs1003_prepare,

    .trigger        = snd_vs1003_trigger,

    .pointer        = snd_vs1003_pointer,

        .copy =        snd_vs1003_pcm_playback_copy,

    .silence =    snd_vs1003_pcm_playback_silence,

};

 

 

static int snd_vs1003_pcm_playback_copy(struct snd_pcm_substream *substream,

                     int voice,

                     snd_pcm_uframes_t pos,

                     void __user *src,

                     snd_pcm_uframes_t count)

{

 

   copy_from_user(runtime->dma_area + pos, src, len);

  (because audio data is from userspace application)     ...........

 

}

 

In the trigger callback I use

 

spi_write(spi,runtime->dma_area) ;

 

to write the audio data to spi_bus.

 

Is this way will ok?Can you give me a small example ?

 

 

TranslateQuoteReplyEditDelete

 

 

2009-04-12 10:29:57     Re: question about Alsa architecture

liang wang (CHINA)

Message: 72548   

 

I have another question the buffer which is defined in following struct :buffer_bytes_max = 64*1024, when and which function allocate the buffer??

 

static struct snd_pcm_hardware snd_sa11xx_uda1341_playback =

{

.info   = (SNDRV_PCM_INFO_INTERLEAVED |

       SNDRV_PCM_INFO_BLOCK_TRANSFER |

       SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |

       SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),

.formats  = SNDRV_PCM_FMTBIT_S16_LE,

.rates   = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\

                                   SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |\

       SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\

       SNDRV_PCM_RATE_KNOT),

.rate_min  = 8000,

.rate_max  = 48000,

.channels_min  = 2,

.channels_max  = 2,

.buffer_bytes_max = 64*1024,

 

 

TranslateQuoteReplyEditDelete

 

 

2009-04-12 22:56:38     Re: question about Alsa architecture

liang wang (CHINA)

Message: 72560   

 

.buffer_bytes_max = 64*1024,

 

My codec only can send 32Byte audio data to it one time,Does this field  is set to 32??

 

Or it is allocated by up layer ?not related to the hardware?

 

then in the playback  callback function  I must send  64*1024 byte audio data to the codec in 2*1024 times?

TranslateQuoteReplyEditDelete

 

 

2009-04-12 23:06:32     Re: question about Alsa architecture

Cliff Cai (CHINA)

Message: 72561   

 

see ad1836.c ,I think you'd better ask your problem in alsa mailing list to get accurare answers,Since we have no experience in you way.

 

 

 

Cliff

QuoteReplyEditDelete

 

 

2009-04-13 05:22:53     Re: question about Alsa architecture

liang wang (CHINA)

Message: 72571   

 

Thank you Cliff Cai!

Attachments

    Outcomes