微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > s5pv210与stm32 spi通信

s5pv210与stm32 spi通信

时间:11-19 来源:互联网 点击:
ng;missing = copy_to_user(buf, spidev->buffer, status);if (missing == status)status = -EFAULT;elsestatus = status - missing;}mutex_unlock(&spidev->buf_lock);return status;}/* Write-only message with current device setup */static ssize_tspidev_write(struct file *filp, const char __user *buf,size_t count, loff_t *f_pos){struct spidev_data *spidev;ssize_t status = 0;unsigned long missing;/* chipselect only toggles at start or end of operation */if (count > bufsiz)return -EMSGSIZE;spidev = filp->private_data;mutex_lock(&spidev->buf_lock);missing = copy_from_user(spidev->buffer, buf, count);if (missing == 0) {status = spidev_sync_write(spidev, count);} elsestatus = -EFAULT;mutex_unlock(&spidev->buf_lock);return status;}static int spidev_message(struct spidev_data *spidev,struct spi_ioc_transfer *u_xfers, unsigned n_xfers){struct spi_message msg;struct spi_transfer *k_xfers;struct spi_transfer *k_tmp;struct spi_ioc_transfer *u_tmp;unsigned n, total;u8 *buf;int status = -EFAULT;spi_message_init(&msg);k_xfers = kcalloc(n_xfers, sizeof(*k_tmp), GFP_KERNEL);if (k_xfers == NULL)return -ENOMEM;/* Construct spi_message, copying any tx data to bounce buffer.* We walk the array of user-provided transfers, using each one* to initialize a kernel version of the same transfer.*/buf = spidev->buffer;total = 0;for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;n;n--, k_tmp++, u_tmp++) {k_tmp->len = u_tmp->len;total += k_tmp->len;if (total > bufsiz) {status = -EMSGSIZE;goto done;}if (u_tmp->rx_buf) {k_tmp->rx_buf = buf;if (!access_ok(VERIFY_WRITE, (u8 __user *)(uintptr_t) u_tmp->rx_buf,u_tmp->len))goto done;}if (u_tmp->tx_buf) {k_tmp->tx_buf = buf;if (copy_from_user(buf, (const u8 __user *)(uintptr_t) u_tmp->tx_buf,u_tmp->len))goto done;}buf += k_tmp->len;k_tmp->cs_change = !!u_tmp->cs_change;k_tmp->bits_per_word = u_tmp->bits_per_word;k_tmp->delay_usecs = u_tmp->delay_usecs;k_tmp->speed_hz = u_tmp->speed_hz;#ifdef VERBOSEdev_dbg(&spidev->spi->dev," xfer len %zd %s%s%s%dbits %u usec %uHz\n",u_tmp->len,u_tmp->rx_buf ? "rx " : "",u_tmp->tx_buf ? "tx " : "",u_tmp->cs_change ? "cs " : "",u_tmp->bits_per_word ? : spidev->spi->bits_per_word,u_tmp->delay_usecs,u_tmp->speed_hz ? : spidev->spi->max_speed_hz);#endifspi_message_add_tail(k_tmp, &msg);}printk("%s :----line is %d\n",__func__,__LINE__);status = spidev_sync(spidev, &msg);printk("%s :----line is %d\n",__func__,__LINE__);if (status < 0)goto done;/* copy any rx data out of bounce buffer */buf = spidev->buffer;for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) {if (u_tmp->rx_buf) {if (__copy_to_user((u8 __user *)(uintptr_t) u_tmp->rx_buf, buf,u_tmp->len)) {status = -EFAULT;goto done;}}buf += u_tmp->len;}status = total;done:kfree(k_xfers);return status;}static DECLARE_WAIT_QUEUE_HEAD(gzsd_spi_wait);static irqreturn_t gzsd_spiread(int irq, void *dev_id){struct spidev_data *spidev = (struct spidev_data *)dev_id;//dev_err(&spidev->spi->dev, "is spi dev now.\n");disable_irq_nosync(irq);flag_poll = 1;//printk("%s:------------line is %d\n",__func__,__LINE__);#if 1wake_up_interruptible(&spidev->rqueue);#elsewake_up(&gzsd_spi_wait);#endif//wake_up_interruptible_sync(&spidev->rqueue);//wake_up(&spidev->rqueue);enable_irq(irq);return IRQ_HANDLED;}unsigned int gzsd_poll(struct file *filp, poll_table *wait){struct spidev_data *spidev;spidev = filp->private_data;unsigned int mask = 0;//printk("%s:------------line is %d\n",__func__,__LINE__);#if 1poll_wait(filp, &spidev->rqueue, wait);#elsepoll_wait(filp, &gzsd_spi_wait, wait);#endifif(flag_poll) {mask = POLLIN | POLLRDNORM; //can be re

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top