2009-10-31 21:37:31     spi_test.c confusions

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

2009-10-31 21:37:31     spi_test.c confusions

鹏 肖 (CHINA)

Message: 81958   




I am reading  spi-tes.c in /uClinux-dist-2008R1-RC8/user/blkfin-test/spi-test, and I have confusions about the do_msg.


static void do_msg(int fd, int len)


struct spi_ioc_transfer xfer[2];

unsigned char  buf[32], *bp;

int   status;


memset(xfer, 0, sizeof xfer);/*把xfer所指的区域全部设为0*/

memset(buf, 0, sizeof buf);/*把buf所指的区域全部设为0*/


if (len > sizeof buf)

  len = sizeof buf;


buf[0] = 0xaa;

xfer[0].tx_buf = (__u64) buf;

xfer[0].len = 1;


xfer[1].rx_buf = (__u64) buf;

xfer[1].len = len;


status = ioctl(fd, SPI_IOC_MESSAGE(1), xfer);

if (status < 0) {





printf("response(%2d, %2d): ", len, status);

for (bp = buf; len; len--)

  printf(" %02x", *bp++);




I can compile the kernel and the device is showing up in /dev/spidev0.1. So I chang the SPI_IOC_MESSAGE(2) to SPI_IOC_MESSAGE(1), I do not edit anything else.


My question is  what is the differences between SPI_IOC_MESSAGE(1) and SPI_IOC_MESSAGE(2)? And where is the response date from? I think it just reads the buf again,and how to test whether the date is transfered or not?






2009-11-01 15:35:26     Re: spi_test.c confusions

Mike Frysinger (UNITED STATES)

Message: 81979   


spidev is simply a user interface to the spi functions.  the userspace spi conventions are the same as the kernel spi conventions.


in other words, read the documentation, both in the wiki and in the header (linux/spidev.h):





2009-11-01 15:38:26     Re: spi_test.c confusions

Mike Frysinger (UNITED STATES)

Message: 81980   


also, you're posting to the wrong forum.  your question is about a kernel driver, not hardware, and so should be posted to the kernel forum.