使用spi-bitbang驱动程序

问题描述 投票:0回答:1

我正在编写一个内核模块以读写SPI设备(CC1200)。我的linux设备没有本地SPI,因此我尝试对总线进行位冲击。

我发现linux具有内置的bitbang代码(linux / spi / spi_bitbang.h),但是我对如何设置它感到困惑。它需要像spi_device和spi_master这样的结构,每个都需要结构设备,而结构又需要kobject等更多结构,其中大多数我不知道如何处理它们,以及简单的位敲打如何需要它们。

我已经在网上寻找示例,但我发现根本没有。不是单独使用所包含的bitbang代码,只有一些引用是“简单”的]

我将非常感谢您的帮助,也许bitbang lib甚至不是好方法。也许我可以自己编写(如何高效地执行?我有4个核心,但是它在后台运行很多东西)

感谢

c linux kernel spi
1个回答
0
投票

由于SPI的特性,其中数据由主机提供时钟并读取,因此主机的位缓冲驱动程序没有任何问题,因为从设备应该不能以稳定的时钟进行中继。但是,当然这取决于从设备是否可以在实践中使用。

如果您使用的是Linux内核,则无需实现自己的位驱动程序,因为已经有一个spi-gpio.c

我猜测如何启动和运行它是通过定义要在GPIO中使用的devicetree引脚,然后该驱动程序将能够充当任何其他物理层驱动程序。

[我快速浏览了drivers/spi/spi-gpio.c源代码,甚至有简短的用户指南,如何直接使用内联方式访问GPIO引脚,而无需使用通用的GPIO层开销。

/*
 * Because the overhead of going through four GPIO procedure calls
 * per transferred bit can make performance a problem, this code
 * is set up so that you can use it in either of two ways:
 *
 *   - The slow generic way:  set up platform_data to hold the GPIO
 *     numbers used for MISO/MOSI/SCK, and issue procedure calls for
 *     each of them.  This driver can handle several such busses.
 *
 *   - The quicker inlined way:  only helps with platform GPIO code
 *     that inlines operations for constant GPIOs.  This can give
 *     you tight (fast!) inner loops, but each such bus needs a
 *     new driver.  You'll define a new C file, with Makefile and
 *     Kconfig support; the C code can be a total of six lines:
 *
 *    #define DRIVER_NAME  "myboard_spi2"
 *    #define  SPI_MISO_GPIO  119
 *    #define  SPI_MOSI_GPIO  120
 *    #define  SPI_SCK_GPIO   121
 *    #define  SPI_N_CHIPSEL  4
 *    #include "spi-gpio.c"
 */

PS,您确定您的平台没有spi,我与HiSilicon合作的所有SoC都有一个。我会先仔细检查一次

© www.soinside.com 2019 - 2024. All rights reserved.