• R/O
  • HTTP
  • SSH
  • HTTPS

spike-ad: Commit

Overo用のspiドライバ
/dev/spi-ad
サブCPU基板からSPIでADデータを取得する。


Commit MetaInfo

Revisão1f5c05c93fbbd72da48e941ceba380b831493563 (tree)
Hora2011-12-16 11:21:50
AutorNaoya Takamura <ntaka206@user...>
CommiterNaoya Takamura

Mensagem de Log

add semaphore for spi_txbuf

Mudança Sumário

Diff

--- a/spike-ad.c
+++ b/spike-ad.c
@@ -92,7 +92,6 @@ static struct irq_device irq_dev;
9292
9393 struct spike_dev {
9494 spinlock_t spi_lock;
95- struct semaphore spi_sem;
9695 struct semaphore fop_sem;
9796 dev_t devt;
9897 struct cdev cdev;
@@ -120,10 +119,18 @@ DECLARE_TASKLET(spike_tasklet, spike_tasklet_func, 0);
120119 //
121120 /**** SPI送信データ バッファ ******************************************
122121 */
123-// 送信データ(CMD for PIC)
124-#define SPI_TX_MAX (64)
125-static unsigned char spitxbuf[SPI_TX_MAX];
126-static int spi_tx_len;
122+#define SPI_TX_MAX (64) // SPI送信データの最大長
123+
124+// 送信データバッファ(CMD for PIC)
125+typedef struct {
126+ unsigned char txbuf[SPI_TX_MAX];
127+ int tx_len; // SPIで送信するデータ長
128+ struct semaphore txbuf_sem;
129+} SpiTxBuf;
130+
131+static SpiTxBuf spi_txbuf;
132+
133+
127134
128135 //
129136 /**** SPI受信データ リングバッファ ******************************************
@@ -255,15 +262,17 @@ static int spike_queue_spi_write(void)
255262 spike_ctl.msg.complete = spike_spi_completion_handler;
256263 spike_ctl.msg.context = NULL;
257264
258- /* write some toggling bit patterns, doesn't really matter */
259265 memset(spike_ctl.tx_buff, 0, SPI_BUFF_SIZE);
260- spike_ctl.tx_buff[0] = '$';
266+// spike_ctl.tx_buff[0] = '$';
261267 memset(spike_ctl.rx_buff, 0, SPI_BUFF_SIZE);
262268
263- // TXコマンドセット
264- memcpy(spike_ctl.tx_buff, spitxbuf, spi_tx_len);
265- // TXコマンドクリア
266- memset(spitxbuf, 0, SPI_TX_MAX);
269+ if (down_interruptible(&spi_txbuf.txbuf_sem))
270+ return -ERESTARTSYS;
271+ // TXコマンドセット
272+ memcpy(spike_ctl.tx_buff, spi_txbuf.txbuf, spi_txbuf.tx_len);
273+ // TXコマンドクリア
274+ memset(spi_txbuf.txbuf, 0, SPI_TX_MAX);
275+ up(&spi_txbuf.txbuf_sem);
267276
268277 spike_ctl.transfer.tx_buf = spike_ctl.tx_buff;
269278 spike_ctl.transfer.rx_buf = spike_ctl.rx_buff;
@@ -466,20 +475,28 @@ static long spike_file_ioctl(struct file *file, unsigned int cmd, unsigned long
466475 switch(cmd) {
467476 // SPI送信データ長セット
468477 case CMD_TX_LEN:
469- if (copy_from_user(&spi_tx_len, (void *)arg, sizeof(int))) {
478+ if (down_interruptible(&spi_txbuf.txbuf_sem))
479+ return -ERESTARTSYS;
480+ if (copy_from_user(&spi_txbuf.tx_len, (void *)arg, sizeof(int))) {
470481 printk(KERN_ALERT "spike_file_ioctl(): copy_from_user() failed\n");
482+ up(&spi_txbuf.txbuf_sem);
471483 return -EFAULT;
472484 }
473-printk(KERN_INFO "spike_file_ioctl: CMD_TX_LEN %d\n", spi_tx_len);
474- if (spi_tx_len > SPI_TX_MAX) spi_tx_len = SPI_TX_MAX;
485+printk(KERN_INFO "spike_file_ioctl: CMD_TX_LEN %d\n", spi_txbuf.tx_len);
486+ if (spi_txbuf.tx_len > SPI_TX_MAX) spi_txbuf.tx_len = SPI_TX_MAX;
487+ up(&spi_txbuf.txbuf_sem);
475488 return 0;
476489 // SPI送信データセット
477490 case CMD_TX_SET:
478- if (copy_from_user(&spitxbuf, (void *)arg, spi_tx_len)) {
491+ if (down_interruptible(&spi_txbuf.txbuf_sem))
492+ return -ERESTARTSYS;
493+ if (copy_from_user(&spi_txbuf.txbuf, (void *)arg, spi_txbuf.tx_len)) {
479494 printk(KERN_ALERT "spike_file_ioctl(): copy_from_user() failed\n");
495+ up(&spi_txbuf.txbuf_sem);
480496 return -EFAULT;
481497 }
482-printk(KERN_INFO "spike_file_ioctl: CMD_TX_SET %02X %02X %02X %02X\n", spitxbuf[0], spitxbuf[1], spitxbuf[2], spitxbuf[3]);
498+printk(KERN_INFO "spike_file_ioctl: CMD_TX_SET %02X %02X %02X %02X\n", spi_txbuf.txbuf[0], spi_txbuf.txbuf[1], spi_txbuf.txbuf[2], spi_txbuf.txbuf[3]);
499+ up(&spi_txbuf.txbuf_sem);
483500 return 0;
484501 // SPI受信データ返す
485502 case CMD_RX_GET:
@@ -530,24 +547,22 @@ static const struct file_operations spike_fops = {
530547
531548 static int spike_probe(struct spi_device *spi_device)
532549 {
533- if (down_interruptible(&spike_dev.spi_sem))
534- return -EBUSY;
550+ unsigned long flags;
535551
552+ spin_lock_irqsave(&spike_dev.spi_lock, flags);
536553 spike_dev.spi_device = spi_device;
537-
538- up(&spike_dev.spi_sem);
554+ spin_unlock_irqrestore(&spike_dev.spi_lock, flags);
539555
540556 return 0;
541557 }
542558
543559 static int spike_remove(struct spi_device *spi_device)
544560 {
545- if (down_interruptible(&spike_dev.spi_sem))
546- return -EBUSY;
547-
548- spike_dev.spi_device = NULL;
561+ unsigned long flags;
549562
550- up(&spike_dev.spi_sem);
563+ spin_lock_irqsave(&spike_dev.spi_lock, flags);
564+ spike_dev.spi_device = NULL;
565+ spin_unlock_irqrestore(&spike_dev.spi_lock, flags);
551566
552567 return 0;
553568 }
@@ -816,7 +831,6 @@ static int __init spike_init(void)
816831 memset(&spike_dev, 0, sizeof(spike_dev));
817832 memset(&spike_ctl, 0, sizeof(spike_ctl));
818833
819- sema_init(&spike_dev.spi_sem, 1);
820834 sema_init(&spike_dev.fop_sem, 1);
821835 spin_lock_init(&spike_dev.spi_lock);
822836
@@ -824,10 +838,10 @@ static int __init spike_init(void)
824838 sema_init(&irq_dev.sem, 1);
825839
826840 // TXコマンドクリア
827- memset(spitxbuf, 0, SPI_TX_MAX);
841+ memset(&spi_txbuf, 0, sizeof(spi_txbuf));
842+ sema_init(&spi_txbuf.txbuf_sem, 1);
828843
829844 finfo.f_version = 0; // 未使用マーク
830- spi_tx_len = 0;
831845 // リングバッファ初期化
832846 ring_init();
833847
Show on old repository browser