2010-03-30 05:46:47     Does it need to clean the SPORT FIFO before setting TSPEN?

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

2010-03-30 05:46:47     Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87848   

 

I modified the driver/char/bfin_sport.c to operate the SPORT directly to play audio without using the uclinux sound driver for the purpose of reducing the latency.

 

Now it can play correctly, but my application needs to pause and play the audio randomly, so I added 2 ioctl SPORT_IOC_PAUSE, and SPORT_IOC_RESUME,

 

in the PAUSE

 

dev->regs->tcr1 &= ~TSPEN;

 

SSYNC();

 

disable_dma(dev->dma_tx_chan);

 

 

 

in the RESUME

 

enable_dma(dev->dma_tx_chan);

 

dev->regs->tcr1 |= TSPEN;

 

SSYNC();

 

 

 

if the application keep PAUSE/RESUME for 10 times there is some noise, but keep PAUSE/RESUME for several time, the noise disappear, the noise occur periodly when PAUSE/RESUME.

 

so I wonder if the noise caused by the data remain in the last PAUSE, if there is a way to clean the FIFO before setting TSPEN?

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-30 15:18:06     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Robin Getz (UNITED STATES)

Message: 87866   

 

Zhi:

 

Doing something silly - like trying to write an audio driver, without using the audio subsystem - isn't going to get supported - so I think you are on your own.

 

If you need hardware support (which it appears you do - ask on ez.analog.com).

 

 

 

Can you decscribe what brought you down this path? (why you feel you need to do this?)

 

-Robin

QuoteReplyEditDelete

 

 

2010-03-30 19:23:54     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87869   

 

Robin,

 

In my product there is a play/pause key, the system must respond the action of this key very quickly, press this key to play the audio, press again to pause. When in PAUSE action, the audio should be disappeared in 30ms, as well, in PLAY action, the audio should be appeared immediately.

 

I tried to use the uclinux driver before, I opened the /dev/dsp, in PLAY action I keep calling write(/dev/dsp, buffer), in PAUSE action, stop calling write, but the voice dissappears more than 1 second later.

 

I traced the audio driver, and found, it uses the descriptor based DMA, there are 0x16 element, size of each element is 0x8000, when I stop calling write, there are many data in DMA list.

 

So I modified bfin_sport.c to do this, now it works very well in responding the key action, except there is some noise when pressing the PLAY/PAUSE key many times.

 

Do you have some suggestion?

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-30 21:32:22     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Robin Getz (UNITED STATES)

Message: 87872   

 

Zhi:

 

Depending on what you are doing - you can reduce the number of DMA buffers - which will reduce the latency between a play event and things coming out the audio jack.

 

Cliff might have some other thoughts...

 

-Robin

QuoteReplyEditDelete

 

 

2010-03-30 22:08:14     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87874   

 

Robin,

 

Yes, you are right, reducing the DMA buffer can solve this problem, but please read bf5xx-i2s-pcm.c, the bf5xx_pcm_prepare function, it is controlled by soc-core.

 

Cliff, what do you think?

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-31 00:08:57     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Cliff Cai (CHINA)

Message: 87880   

 

Hi Zhiqiang,

 

There are two ways to reduce the DMA buffer size

 

1.your application supports peroid_size tuning,like aplay it can use  --period_size = xx to make it.

 

2.reduce  value of  "period_bytes_max"  in source code see.bf5xx-i2s-pcm.c

 

 

 

Cliff

QuoteReplyEditDelete

 

 

2010-03-31 01:25:13     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87886   

 

Cliff,

 

I will try that way this afternoon, but I think it is infeasible by reducing the period_bytes, becase the time to play a peroid of audio must be greater than the system tick frequency, the default system tick frequency is 250Hz, that period is 4ms, 4ms needs about 600 bytes of audio data, so the mininum size of period_bytes must be greater than 600 bytes. Another problem is, no way to control the number of DMA element.

 

Using the bfin_sport.c is very straightforward, when I want to stop, only clear the TSPEN bit, and set it to start. And it works very well now except the noise after setting/clean the TSPEN bit many times later.

 

I think that noise is caused by the surplus bits remain in SPORT FIFO in the last CLEANNING TSPEN bit, that mean clear the TSPEN bit when in playing, there must be surplus bits remains in FIFO, in the next time setting TSPEN, the data will be shifted by the surplus bits, do you think so?

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-31 02:36:32     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 87887   

 

When you pause the sport, you should stop TX DMA first and disable TSPEN only after the TX buffer is empty.

QuoteReplyEditDelete

 

 

2010-03-31 03:25:19     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87903   

 

Cliff,

 

BRAVO!!! I adjusted the parameter in bf5xx-i2s-pcm.c, now it is incredibly good, the latency is between 25ms-45ms, almost meet the requirement, do you think is there something can be improved?

 

I can adjust the parameters in bf5xx-i2s-pcm.c for the latency lower than 30ms, but sometimes there is noise.

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-31 03:34:38     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87904   

 

Sonic,

 

Yes, I tried that way, just changing the calling sequence,

 

disable_dma(dev->dma_tx_chan);

 

SSYNC();

 

dev->regs->tcr1 &= ~TSPEN;

 

SSYNC();

 

this will cause kernel panic. I tried to add local_irq_save, but still kernel panic.

 

do you know what to cause the kernel panic?

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-31 05:54:18     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 87913   

 

I have no idea on your panic. But, you didn't tried that way. You should poll the tx buffer empty bit before disable the SPORT.

QuoteReplyEditDelete

 

 

2010-03-31 09:10:58     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87921   

 

sonic,

 

I did try,

 

disabledma;

 

while (!(status & TUVF))

 

   udelay(1);

 

  status = dev->regs->stat;

 

}

 

but as I mentioned, disable DMA before clear the TSPEN will cause kernel panic, that is why I asked you what to cause the panic.

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-03-31 13:57:26     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Robin Getz (UNITED STATES)

Message: 87932   

 

Zhi:

 

See - ask the right question - get the proper solution - no nasty hacks.

 

Do you think people will notice the difference between 30ms and 45ms? Seems for human interface - it should be OK.

 

-Robin

QuoteReplyEditDelete

 

 

2010-03-31 19:19:21     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 87942   

 

Robin,

 

The uclinux audio driver works very good now except the latency, and 30ms latency is not my requirement, it is our client's requirement, they said an experienced audio engineer can find out that difference only by ear. I don't believe that. :-)

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-01 00:13:00     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 87944   

 

I have no idea. You have to debug by yourself via a JTAG tool.

QuoteReplyEditDelete

 

 

2010-04-01 11:03:44     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Robin Getz (UNITED STATES)

Message: 87983   

 

Zhi:

 

OK - 30ms it is - you said now it was 25-45? Was there anything specific about the times that it was 45? (network traffic? other interrupts in the system? etc?)

 

-Robin

QuoteReplyEditDelete

 

 

2010-04-02 05:56:27     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Cliff Cai (CHINA)

Message: 88028   

 

Hi Zhiqiang,

 

if you get some noise while tune period_bytes_max,also try to tune the periods_max and buffer_btyes_max.the relationship looks like:

 

period_bytes_max * periods_max = buffer_bytes_max

 

 

 

Cliff

QuoteReplyEditDelete

 

 

2010-04-02 11:41:26     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88039   

 

Robin,

 

This product consist of a main board that has a BFin DSP in it and a control panel that there is a MCU in it, the connection between this 2 units through UART.

 

And I checked, the latency for starting play is always 8-10ms, that mean the time when I press the play button in control panel to the audio come out is 8-10ms. So I think the latency for stopping come from the audio driver.

 

The default system tick for uclinux is 250Hz, that mean the maxinum latency for main board is 4ms.

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-02 11:48:30     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88040   

 

Cliff,

 

Thanks, I have adjusted that 2 parameters. Now when in 30-45ms latency, no matter which parameter I set will cause noise, I think it reach this limitation now without adjust the system tick. Do you think so?

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-05 09:44:21     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Robin Getz (UNITED STATES)

Message: 88097   

 

ZhangZQ:

 

Based on the way that audio currently works - never drop a sample...

 

When you are playing a file, and hit pause - the DMA buffers drain - since you never want to loose any audio data on the output. When things start again (hit play), things resume from the file.

 

Is it acceptable in your platform to loose audio samples between play/resume?

 

-Robin

QuoteReplyEditDelete

 

 

2010-04-06 09:27:23     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88147   

 

Robin,

 

Loose audio sample is not acceptable. And I check the current driver, it does not loose sample.

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-07 06:45:22     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Robin Getz (UNITED STATES)

Message: 88185   

 

ZhangZQ:

 

Correct - the current audio driver does not miss any samples - but that is why it has some latency. Userspace gives ALSA some buffers to play - and ALSA stacks them up.

 

If you don't want to loose any samples between pause/play - then alsa must drain all it's samples - and there isn't any way (I don't think) to reduce the latency between pressing pause, and having audio stop.

 

Does that make sense?

 

The only way might be to extend the interface to understand the difference between pause (where it could pause the DMA, and resume later) and stop (when it needs to let things drain, so if you start a different stream, it doesn't play the old stream).

 

-Robin

QuoteReplyEditDelete

 

 

2010-04-07 09:01:43     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88188   

 

Robin,

 

> If you don't want to loose any samples between pause/play - then alsa must drain all it's samples - and there isn't any way (I don't think) to reduce the latency between pressing pause, and having audio stop.

 

Another way is to access SPORT directly as mentioned in the beginning of this thread, and as you said, "where it could pause the DMA, and resume later", so I paused audio by these step,

 

dev->regs->tcr1 &= ~TSPEN;

 

disable_dma(dev->dma_tx_chan);

 

and resume by these steps,

 

enable_dma(dev->dma_tx_chan);

 

dev->regs->tcr1 |= TSPEN;

 

By using this way, the latency can be less than 15ms, and no any samples loosed, this works very well actually, but I just don't know why there are some noise after pause and play about 10 times later.

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-08 00:04:44     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 88207   

 

What kind of noise after 10 times? continous noise? pulse noise at the beginning?

QuoteReplyEditDelete

 

 

2010-04-08 01:39:34     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88210   

 

Sonic,

 

That is the continous noise, and the noise will be disapperred about PAUSE/PLAY 4 times later, when that noise disappearred, it will occur again PAUSE/PLAY about 10 times later, and so on. It is hard to describe that noise, and I have not found out what is that noise.

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-08 03:06:09     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 88214   

 

Maybe you stop sport in the middle of a 16bit byte transfer. When you restart, the codec mismatch the beginning of a data stream.

QuoteReplyEditDelete

 

 

2010-04-08 08:56:10     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88231   

 

Sonic,

 

Yes, I did think so, and that is why I start this thread to ask "Does it need to clean the SPORT FIFO before setting TSPEN?"

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-08 23:16:14     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 88236   

 

Yes, you should clean FIFO before restart.

 

But, TX shift register other the FIFO may be the problem.

QuoteReplyEditDelete

 

 

2010-04-08 23:54:31     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88237   

 

Sonic,

 

But I found not way to clean the SPORT FIFO in the hardware manual. Can you show me how to do this?

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-09 00:21:23     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 88239   

 

You can try to append a dummy data 0xFFFF into your audio stream before you stop TX. Then, when you stop TX, your audio stream bits just move out of the shift register.

QuoteReplyEditDelete

 

 

2010-04-09 02:25:57     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Zhi Qiang Zhang (CHINA)

Message: 88241   

 

Sonic,

 

Thank you very much for your suggestion, but I want to know did you try that way  or that is your imagination only?

 

If the noise is caused by the surplus bits remain in FIFO, no matter what and how many data to be appended the surplus bits still remain, because you can't control how many bits to be appended.

 

In my application, after the noise occur, it will remain until PAUSE/PLAY.

 

 

 

Regards,

 

ZhangZQ

QuoteReplyEditDelete

 

 

2010-04-09 02:53:47     Re: Does it need to clean the SPORT FIFO before setting TSPEN?

Sonic Zhang (CHINA)

Message: 88244   

 

It has nothing to do with the remain surplus bits, but with the byte boundary mismatch.

 

The dummy data 0xffff ensure bits on TX line is finished on the byte boundary.

 

Please refer to the bfin_sport_uart.c driver under driver/serial/ folder.

Attachments

    Outcomes