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

s5pv210与stm32 spi通信

时间:11-19 来源:互联网 点击:
spi通信不支持从设备主动给主设备发送数据,所以我把spi的用户空间驱动改了一下,实现过程是这样的,用一个中断来响应从设备的要求,即当STM32要主动给主设备发送数据的时候,将中断脚拉低,用户空间检测到中断后,主动给STM32发送一个空数据,这样spi就能读到STM32所要发送的数据了。SPI通信发数据与接数据是同时进行的,这个大家可以看下SPI协议。

以下我我修改的用户空间的驱动:

/** spidev.c -- simple synchronous userspace interface to SPI devices** Copyright (C) 2006 SWAPP*	Andrea Paterniani * Copyright (C) 2007 David Brownell (simplification, cleanup)** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include #include #include #include #include #include #include #include #include #include #include #include interrupt.h>#include #include #include #include #include #include #include #include #define	SPI_IRQ			IRQ_EINT(2)#define	IRQSTATE		S5PV210_GPH0(2)#define BUF_SIZE		38u8 gzsd_buffer[BUF_SIZE];struct spi_transfer	*gk_xfers;struct spi_ioc_transfer	*g_uxfers;/** This supports acccess to SPI devices using normal userspace I/O calls.* Note that while traditional UNIX/POSIX I/O semantics are half duplex,* and often mask message boundaries, full SPI support requires full duplex* transfers.  There are several kinds of internal message boundaries to* handle chipselect management and other protocol options.** SPI has a character major number assigned.  We allocate minor numbers* dynamically using a bitmask.  You must use hotplug tools, such as udev* (or mdev with busybox) to create and destroy the /dev/spidevB.C device* nodes, since there is no fixed association of minor numbers with any* particular SPI bus or device.*/#define SPIDEV_MAJOR			153	/* assigned */#define N_SPI_MINORS			32	/* ... up to 256 */static DECLARE_BITMAP(minors, N_SPI_MINORS);/* Bit masks for spi_device.mode management.  Note that incorrect* settings for some settings can cause *lots* of trouble for other* devices on a shared bus:**  - CS_HIGH ... this device will be active when it shouldnt be*  - 3WIRE ... when active, it wont behave as it should*  - NO_CS ... there will be no explicit message boundaries; this*	is completely incompatible with the shared bus model*  - READY ... transfers may proceed when they shouldnt.** REVISIT should changing those flags be privileged?*/#define SPI_MODE_MASK		(SPI_CPHA | SPI_CPOL | SPI_CS_HIGH \| SPI_LSB_FIRST | SPI_3WIRE | SPI_LOOP \| SPI_NO_CS | SPI_READY)struct spidev_data {dev_t			devt;spinlock_t		spi_lock;struct spi_device	*spi;struct list_head	device_entry;/* buffer is NULL unless this device is open (users > 0) */struct mutex		buf_lock;unsigned		users;u8			*buffer;int irq;//add by daowait_queue_head_t rqueue;};static flag_poll = 0;static LIST_HEAD(device_list);static DEFINE_MUTEX(device_list_lock);static unsigned bufsiz = 4096;module_param(bufsiz, uint, S_IRUGO);MODULE_PAR            

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

网站地图

Top