2011-04-19 02:43:10     BF518F SPORT read issue

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

2011-04-19 02:43:10     BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 99968   

 

Hi all,

 

I've been trying to hack the sport_test.c example to be used with i2s to pull raw data from microphones through the blackfin sport. It seems to work up to a point (the initialization, etc works), until it comes to actually reading data from the sport. It's strange, because the while loop seems to work the first time 'read' is called on the sport, but fails and hangs in the next cycle of the loop, freezing the program. I've attached the relevant excerpt below (I think...):

 

 

 

        while (left > 0) {

            temp1 = left > BUF_LEN ? BUF_LEN : left;

 

            if ((temp2 = read(sport_fd, buffer, temp1)) < 0) // <------------- This is where GDB points for the error

                errp("reading from sport failed");

 

            write(data_fd, buffer, temp1);

            left -= temp2;

 

        }

 

 

 

GDB output:

 

Program received signal SIGINT, Interrupt.

0x02ccd78a in __libc_read (fd=<value optimized out>, buf=0x2a6c004, count=4096)

    at libc/sysdeps/linux/common/read.c:15

15    _syscall3(ssize_t, __libc_read, int, fd, __ptr_t, buf, size_t, count);

(gdb) where

#0  0x02ccd78a in __libc_read (fd=<value optimized out>, buf=0x2a6c004,

    count=4096) at libc/sysdeps/linux/common/read.c:15

#1  0x02c62c8a in main () at bfin_test.c:96

 

 

 

 

Any input would be helpful! I'm not experienced at all, so I easily could be doing something wrong, even if it's simple. In my code, I inserted basic print flags, which also indicated that something was up with the sport 'read', but I couldn't figure out exactly what was up with it.

 

 

 

Thanks!

 

 

 

-Sohan

QuoteReplyEditDelete

 

 

2011-04-19 03:12:30     Re: BF518F SPORT read issue

Mike Frysinger (UNITED STATES)

Message: 99973   

 

the raw SPORT driver doesnt really protect the user from improper configuration.  if the SPORT is configured properly from userspace, then doing a read() when the kernel driver cant acquire more data will cause userspace to "hang".  it isnt really hanging, it's simply waiting for the kernel to provide it data which is the correct behavior ... after all, you didnt specify O_NONBLOCK or anything.

 

in other words, make sure your SPORT ioctl config matches the data stream, and that the data stream is correct.

QuoteReplyEditDelete

 

 

2011-04-19 03:17:02     Re: BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 99974   

 

Hmm ok... I THOUGHT I configured it properly, but I definitely might have messed up. I was trying to use the I2S mode, and when I looked through the driver code, it seemed like setting the I2S mode would be sufficient to handle most of the basic configurations. I've posted my config below... feel free to correct!

 

 

 

    memset(&config, 0, sizeof(struct sport_config));

  printf("sport config \n\r");

 

    config.mode = I2S_MODE;

    config.int_clk = 1;

    config.serial_clk = 19;

    config.data_format = NORM_FORMAT;

    config.word_len = 16;

    config.dma_enabled = 1;

 

    /* Configure sport controller by ioctl */

    printf("ioctl call\n\r");

    if (ioctl(sport_fd, SPORT_IOC_CONFIG, &config) < 0)

        errp("ioctl('%s', SPORT_IOC_CONFIG) failed", sport_path);

 

 

 

Thanks!

 

 

 

Sohan

QuoteReplyEditDelete

 

 

2011-04-19 04:10:19     Re: BF518F SPORT read issue

Aaron Wu (CHINA)

Message: 99998   

 

Why did you set your config.serial_clk = 19 to such a low value? do you intend to use 19 Hz?

QuoteReplyEditDelete

 

 

2011-04-19 05:40:04     Re: BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 99999   

 

Oops... I thought that was the divider. My intent was to run the  mics at 3 MHz... think this might be causing the weird read error?

QuoteReplyEditDelete

 

 

2011-04-19 06:15:16     Re: BF518F SPORT read issue

Aaron Wu (CHINA)

Message: 100000   

 

Have a try and share us the feedback please.

QuoteReplyEditDelete

 

 

2011-04-19 10:17:20     Re: BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 100004   

 

Nope, didn't fix the read the next time... do you think my config settings are ok? I posted them above... maybe I'll try tweaking them. It did change the output I got slightly... now the buffer for the first run contained 'o-1.'

QuoteReplyEditDelete

 

 

2011-04-19 19:21:47     Re: BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 100010   

 

So any ideas on what's causing the read error? I tried changing some of the settings, but I was under the impression (from looking at the bfin_sport.c code) that I2S_MODE sets most of the SPORT settings that are necessary. The error doesn't cause the entire board to freeze or reboot, just the program to freeze until I kill it. Would really appreciate any help on this... I'm quite stuck, haha.

 

 

 

Thanks,

 

Sohan

QuoteReplyEditDelete

 

 

2011-04-19 23:32:07     Re: BF518F SPORT read issue

Aaron Wu (CHINA)

Message: 100014   

 

Can't tell exactly what the problem is but guess you may do some test to narrow down the problem, like if it works well in other mode other than the I2S? if it works without DMA, where exactly does it block in the read, due to the rx interrupt not triggered or something else? May need to set up a scope to check if the clock is present and correct. Also as Mike said the test code itself does not protect the user from improper configuration, so enable the debug info to dump the registers value and compare them with that described in HRM I2S mode.

QuoteReplyEditDelete

 

 

2011-04-19 23:39:19     Re: BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 100015   

 

Hi Aaron,

 

 

 

Thanks for the advice! I'll try running it on other modes later, w/ and w/o DMA and let you know what happens. Forgive my inexperience, but... how exactly would one dump the SPORT registers? Can I do that using gdb? I think I tried to do that in gdb while running the test code, but it didn't seem to work, and I'm quite sure I didn't do it properly... would appreciate some (relatively easy to follow) guidance!

 

Thanks!

QuoteReplyEditDelete

 

 

2011-04-19 23:59:27     Re: BF518F SPORT read issue

Aaron Wu (CHINA)

Message: 100016   

 

We already has some lines like "pr_debug("tcr1:0x%x, tcr2:0x%x ......"  in the driver code, add any more register you want to observe. To enable the pr_debug information you may set some CFLAGS for example by adding a line like" CFLAGS_bfin_sport.o := -DDEBUG" at the end of   drivers/char/Makefile, then use dmesg to view the debug infor.

QuoteReplyEditDelete

 

 

2011-04-20 00:59:52     Re: BF518F SPORT read issue

Sohan Mikkilineni (UNITED STATES)

Message: 100017   

 

When I did what you asked about with DMA disabled, I got this:

 

bfin_sport: tcr1:0x4602, tcr2:0x20f, rcr1:0x4602, rcr2:0x20f

mcmc1:0x0, mcmc2:0x0, mtcs0:0x0, mrcs0:0x0

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

bfin_sport: Complete called in dma rx irq handler

bfin_sport: sport_read count:4096

 

Which kind of confuses me, because I definitely disabled DMA in this one. However, it seems like the read loop is actually working with the DMA disabled, but it appears to be collecting data to the buffer really slowly...

QuoteReplyEditDelete

Attachments

    Outcomes