world leader in high performance signal processing
Trace: » bfin_sport

Blackfin SPORT Driver

The Blackfin processor often has multiple synchronous serial ports, or SPORTs. The driver exports one interface to user space per SPORT, /dev/sport0 for SPORT0, etc… It provides a common implementation for users who have simple requirements to read and write data through the SPORT. Code is located in driver/char/bfin_sport.c

The driver also supports TDM mode read and write, unlike the normal mode of SPORT operation, the clock for multichannel mode is not available on TSCLK. For this mode, you can see the clk on RSCLK and this signal is internally distributed to the transmitter portion of the SPORT and TFS is used as “transmit data valid” signal which is active during transmission of data. Hardware designer need to take care of this when the SPORT is designed to function in TDM mode.

For people who have more demanding requirements, the existing driver serves as a base for you to extend and customize. Refer to it at linux-2.6.x/sound/blackfin/bfin_sport.c.

Userspace Interface

There is a sample application in uClinux-dist/user/blkfin-test/sport_test/sport_test.c. This is designed to send a wave file directly to the AD73311 audio codec by running the command sport_test -t sample.wav. The wave file must be in a mono, 8k sample rate, 16 bit sample bit format.

This sample application can also record a wave file from the AD73311 by running the command sport_test -r another.wav. This recorded wave file is in the same format as mentioned above.

By default, the sport_test code uses GPIO 4 for the AD73311 CS pin and SPORT0 (via /dev/sport0). To run the test, firstly connect ad73311 sound card to STAMP and configure the CS pin as jumpers_setting_on_ad73311_card (Do NOT load the “snd-ad73311” sound driver, it is not needed here). Data is transfered directly via SPORT.

If the TDM mode is enabled, internal clock is chosen, you can remove the AD73311 card and observe the TDM waveform with an oscilloscope on the SPORT interface.

Steps to operate the interface.

  1. Open the sport device first.
    	sport = open("/dev/sport0", O_RDWR, 0);
    	if (sport < 0) {
    		fprintf(stderr, "Failed to open " SPORT);
    		return -1;
    	}
  2. Fill a structure in type struct sport_config to prepare to configure the sport controller. Call IOCTL to write the configuration data into sport's registers. The header file linux/bfin_sport.h also need to be included. About how to fill the structure, maybe you need to study the “SPORT controller” section in Blackfin Processor Hardware Reference. If there are too much data to read and write, it is better to enable dma_enabled field.
    	struct sport_config config;
    	memset(&config, 0, sizeof (struct sport_config));
    	config.fsync = 1;
    	config.word_len = 16;
    	config.dma_enabled = 1;
     
    	/* Write control data to ad73311's control register by write operation*/
    	if (ioctl (sport, SPORT_IOC_CONFIG, &config) < 0) {
    		fprintf(stderr, "failed to config sport\n");
    		close(sport);
    		return -1;
    	}
  3. Read and write data through sport. these are just like operations on other character devices.
  4. After finish using the device, close it.