• R/O
  • HTTP
  • SSH
  • HTTPS

spike-ad: Commit

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


Commit MetaInfo

Revisãod122949f67bb66435f43c9f559cd9c751a6659ef (tree)
Hora2011-12-17 01:00:19
AutorNaoya Takamura <ntaka206@user...>
CommiterNaoya Takamura

Mensagem de Log

migrate from struct spi_txbuf to struct spike_ctl.
migrate from struct irq_dev to struct spike_ctl.
AD data用ring buferの変数をatomi_tにした。

Mudança Sumário

Diff

--- a/spike-ad.c
+++ b/spike-ad.c
@@ -44,6 +44,7 @@
4444 #include <linux/poll.h>
4545 #include <linux/wait.h>
4646 #include <linux/sched.h>
47+#include <asm/atomic.h>
4748
4849 #include "spike-ad.h"
4950
@@ -54,7 +55,7 @@
5455 #define SPI_BUS_CS0 0
5556 #define SPI_BUS_SPEED 500000 // Hz
5657
57-#define SPI_DATA_SIZE 965 // $含む PICから受信するデータ長
58+#define SPI_DATA_SIZE (965+1) // $含む PICから受信するデータ長 DMA問題のために+1byteしている
5859
5960 #define GPIO_DRDY_IN 144 // DRDY Input = GPIO144
6061
@@ -69,26 +70,29 @@
6970
7071 const char this_driver_name[] = MODULE_NAME;
7172
73+#define SPI_CMD_MAX (64) // SPI送信データの最大長
74+
75+// 送信データバッファ(CMD for PIC)
76+typedef struct {
77+} SpiTxBuf;
78+
7279 struct spike_control {
7380 struct spi_message msg;
7481 struct spi_transfer transfer;
7582 u32 busy; // 1=spi_async()終了待ち
7683 u32 spi_callbacks;
77-// u32 busy_counter;
7884 u8 *tx_buff;
7985 u8 *rx_buff;
8086 int received_len;
81-};
8287
83-static struct spike_control spike_ctl;
88+ int irq; // DRDY信号割り込み
8489
85-struct irq_device {
86- struct semaphore sem;
87- int irq;
90+ struct semaphore cmd_sem;
91+ u8 cmd_buf[SPI_CMD_MAX]; // 送信するコマンド
92+ int cmd_len; // SPIで送信するコマンド長
8893 };
8994
90-static struct irq_device irq_dev;
91-
95+static struct spike_control spike_ctl;
9296
9397 struct spike_dev {
9498 spinlock_t spi_lock;
@@ -117,22 +121,6 @@ void spike_tasklet_func(unsigned long data);
117121 DECLARE_TASKLET(spike_tasklet, spike_tasklet_func, 0);
118122
119123 //
120-/**** SPI送信データ バッファ ******************************************
121-*/
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-
134-
135-//
136124 /**** SPI受信データ リングバッファ ******************************************
137125 */
138126 #define RING_NUM (30) // リングバッファ個数
@@ -145,14 +133,14 @@ static unsigned char spibuf[RING_NUM][SPI_MAX];
145133 */
146134
147135 // 読み出し位置
148-static int ring_read;
136+static atomic_t ring_read;
149137 // 書き込み位置 データ受信で使用
150-static int ring_write;
138+static atomic_t ring_write;
151139
152140 void ring_init(void)
153141 {
154- ring_read = 0;
155- ring_write = ring_read;
142+ atomic_set(&ring_read, 0);
143+ atomic_set(&ring_write, 0);
156144 memset(spibuf, 0, sizeof(spibuf));
157145 }
158146 #define ring_clear() ring_read_set(ring_write_get())
@@ -160,34 +148,34 @@ void ring_init(void)
160148 // 読み出し位置
161149 int ring_read_get(void)
162150 {
163- return ring_read;
151+ return atomic_read(&ring_read);
164152 }
165153 void ring_read_set(int i)
166154 {
167- ring_read = i;
155+ atomic_set(&ring_read, i);
168156 }
169157 void ring_read_plus(void)
170158 {
171- ring_read++;
172- if (ring_read >= RING_NUM) ring_read = 0;
159+ atomic_inc(&ring_read);
160+ if (atomic_read(&ring_read) >= RING_NUM) atomic_set(&ring_read, 0);
173161 }
174162
175163 // 書き込み位置 受信で使用
176164 int ring_write_get(void)
177165 {
178- return ring_write;
166+ return atomic_read(&ring_write);
179167 }
180168 void ring_write_plus(void)
181169 {
182- ring_write++;
183- if (ring_write >= RING_NUM) ring_write = 0;
170+ atomic_inc(&ring_write);
171+ if (atomic_read(&ring_write) >= RING_NUM) atomic_set(&ring_write, 0);
184172 }
185173 // 読み込んでいないデータ数
186174 int ring_num_get(void)
187175 {
188176 int i;
189177
190- i = ring_write - ring_read;
178+ i = atomic_read(&ring_write) - atomic_read(&ring_read);
191179 if (i < 0) i += RING_NUM;
192180 return i;
193181 }
@@ -202,7 +190,7 @@ unsigned char* ring_get(int ptr)
202190 */
203191 void ring_zero(void)
204192 {
205- memset(spibuf[ring_write], 0, SPI_MAX);
193+ memset(spibuf[atomic_read(&ring_write)], 0, SPI_MAX);
206194 }
207195 /*
208196 パケットバッファフル?
@@ -263,16 +251,15 @@ static int spike_queue_spi_write(void)
263251 spike_ctl.msg.context = NULL;
264252
265253 memset(spike_ctl.tx_buff, 0, SPI_BUFF_SIZE);
266-// spike_ctl.tx_buff[0] = '$';
267254 memset(spike_ctl.rx_buff, 0, SPI_BUFF_SIZE);
268255
269- if (down_interruptible(&spi_txbuf.txbuf_sem))
256+ if (down_interruptible(&spike_ctl.cmd_sem))
270257 return -ERESTARTSYS;
271258 // TXコマンドセット
272- memcpy(spike_ctl.tx_buff, spi_txbuf.txbuf, spi_txbuf.tx_len);
259+ memcpy(spike_ctl.tx_buff, spike_ctl.cmd_buf, spike_ctl.cmd_len);
273260 // TXコマンドクリア
274- memset(spi_txbuf.txbuf, 0, SPI_TX_MAX);
275- up(&spi_txbuf.txbuf_sem);
261+ memset(spike_ctl.cmd_buf, 0, SPI_CMD_MAX);
262+ up(&spike_ctl.cmd_sem);
276263
277264 spike_ctl.transfer.tx_buf = spike_ctl.tx_buff;
278265 spike_ctl.transfer.rx_buf = spike_ctl.rx_buff;
@@ -475,28 +462,28 @@ static long spike_file_ioctl(struct file *file, unsigned int cmd, unsigned long
475462 switch(cmd) {
476463 // SPI送信データ長セット
477464 case CMD_TX_LEN:
478- if (down_interruptible(&spi_txbuf.txbuf_sem))
465+ if (down_interruptible(&spike_ctl.cmd_sem))
479466 return -ERESTARTSYS;
480- if (copy_from_user(&spi_txbuf.tx_len, (void *)arg, sizeof(int))) {
467+ if (copy_from_user(&spike_ctl.cmd_len, (void *)arg, sizeof(int))) {
481468 printk(KERN_ALERT "spike_file_ioctl(): copy_from_user() failed\n");
482- up(&spi_txbuf.txbuf_sem);
469+ up(&spike_ctl.cmd_sem);
483470 return -EFAULT;
484471 }
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);
472+printk(KERN_INFO "spike_file_ioctl: CMD_TX_LEN %d\n", spike_ctl.cmd_len);
473+ if (spike_ctl.cmd_len > SPI_CMD_MAX) spike_ctl.cmd_len = SPI_CMD_MAX;
474+ up(&spike_ctl.cmd_sem);
488475 return 0;
489476 // SPI送信データセット
490477 case CMD_TX_SET:
491- if (down_interruptible(&spi_txbuf.txbuf_sem))
478+ if (down_interruptible(&spike_ctl.cmd_sem))
492479 return -ERESTARTSYS;
493- if (copy_from_user(&spi_txbuf.txbuf, (void *)arg, spi_txbuf.tx_len)) {
480+ if (copy_from_user(&spike_ctl.cmd_buf, (void *)arg, spike_ctl.cmd_len)) {
494481 printk(KERN_ALERT "spike_file_ioctl(): copy_from_user() failed\n");
495- up(&spi_txbuf.txbuf_sem);
482+ up(&spike_ctl.cmd_sem);
496483 return -EFAULT;
497484 }
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);
485+printk(KERN_INFO "spike_file_ioctl: CMD_TX_SET %02X %02X %02X %02X\n", spike_ctl.cmd_buf[0], spike_ctl.cmd_buf[1], spike_ctl.cmd_buf[2], spike_ctl.cmd_buf[3]);
486+ up(&spike_ctl.cmd_sem);
500487 return 0;
501488 // SPI受信データ返す
502489 case CMD_RX_GET:
@@ -807,12 +794,12 @@ int spike_init_irq(void)
807794 {
808795 int result;
809796
810- irq_dev.irq = OMAP_GPIO_IRQ(GPIO_DRDY_IN);
811- result = request_irq(irq_dev.irq,
797+ spike_ctl.irq = OMAP_GPIO_IRQ(GPIO_DRDY_IN);
798+ result = request_irq(spike_ctl.irq,
812799 irq_handler,
813800 IRQF_TRIGGER_FALLING,
814801 "spike",
815- &irq_dev);
802+ &spike_ctl);
816803
817804 if (result < 0) {
818805 printk(KERN_ALERT "request_irq failed: %d\n", result);
@@ -823,7 +810,7 @@ int spike_init_irq(void)
823810 }
824811 void spike_free_irq(void)
825812 {
826- free_irq(irq_dev.irq, &irq_dev);
813+ free_irq(spike_ctl.irq, &spike_ctl);
827814 }
828815
829816 static int __init spike_init(void)
@@ -834,12 +821,7 @@ static int __init spike_init(void)
834821 sema_init(&spike_dev.fop_sem, 1);
835822 spin_lock_init(&spike_dev.spi_lock);
836823
837- memset(&irq_dev, 0, sizeof(irq_dev));
838- sema_init(&irq_dev.sem, 1);
839-
840- // TXコマンドクリア
841- memset(&spi_txbuf, 0, sizeof(spi_txbuf));
842- sema_init(&spi_txbuf.txbuf_sem, 1);
824+ sema_init(&spike_ctl.cmd_sem, 1);
843825
844826 finfo.f_version = 0; // 未使用マーク
845827 // リングバッファ初期化
Show on old repository browser