int spi_write_then_read (struct …

//发送n_tx个字节的命令到spi从机,并从spi从机中读取n_rx字节的数据到缓冲区

int spi_write_then_read(struct spi_device *spi,
                const u8 *txbuf, unsigned n_tx,
                u8 *rxbuf, unsigned n_rx)
{
        static DECLARE_MUTEX(lock);

        int                     status;
        struct spi_message      message;
        struct spi_transfer     x[2];
        u8                      *local_buf;

       
        if ((n_tx + n_rx) > SPI_BUFSIZ)//SPI_BUFSIZ == 32
                return -EINVAL;

     
        spi_message_init(&message);//INIT_LIST_HEAD(&message->transfers);
        memset(x, 0, sizeof x);
     
        if (n_tx) {
                x[0].len = n_tx;
                spi_message_add_tail(&x[0], &message);//list_add_tail(&t->transfer_list, &m->transfers);
        }
        if (n_rx) {
                x[1].len = n_rx;
                spi_message_add_tail(&x[1], &message);
      

你可能感兴趣的:(int spi_write_then_read (struct …)