RTEMS 6.1-rc7
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Copyright (C) 2016, 2017 embedded brains GmbH & Co. KG
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _DEV_SPI_SPI_H
37#define _DEV_SPI_SPI_H
38
39#include <linux/spi/spidev.h>
40
41#include <rtems.h>
42#include <rtems/seterr.h>
43#include <rtems/thread.h>
44
45#ifdef __cplusplus
46extern "C" {
47#endif /* __cplusplus */
48
50
51typedef struct spi_bus spi_bus;
52
68#define SPI_BUS_OBTAIN _IO(SPI_IOC_MAGIC, 13)
69
75#define SPI_BUS_RELEASE _IO(SPI_IOC_MAGIC, 23)
76
80struct spi_bus {
92 int (*transfer)(spi_bus *bus, const spi_ioc_transfer *msgs, uint32_t msg_count);
93
103 int (*setup)(spi_bus *bus);
104
110 void (*destroy)(spi_bus *bus);
111
115 rtems_recursive_mutex mutex;
116
120 uint32_t max_speed_hz;
121
125 uint32_t speed_hz;
126
131
135 uint8_t cs;
136
141
146
150 uint32_t mode;
151
156 uint16_t delay_usecs;
157
163 int (*ioctl)(spi_bus *bus, ioctl_command_t command, void *arg);
164};
165
181int spi_bus_init(spi_bus *bus);
182
200spi_bus *spi_bus_alloc_and_init(size_t size);
201
207void spi_bus_destroy(spi_bus *bus);
208
215
229 spi_bus *bus,
230 const char *bus_path
231);
232
235#ifdef __cplusplus
236}
237#endif /* __cplusplus */
238
239#endif /* _DEV_SPI_SPI_H */
spi_bus * spi_bus_alloc_and_init(size_t size)
Allocates a bus control from the heap and initializes it.
Definition: spi-bus.c:323
int spi_bus_init(spi_bus *bus)
Initializes a bus control.
Definition: spi-bus.c:316
int spi_bus_register(spi_bus *bus, const char *bus_path)
Registers a bus control.
Definition: spi-bus.c:248
void spi_bus_destroy_and_free(spi_bus *bus)
Destroys a bus control and frees its memory.
Definition: spi-bus.c:310
void spi_bus_destroy(spi_bus *bus)
Destroys a bus control.
Definition: spi-bus.c:305
This header file defines the RTEMS Classic API.
This header file defines macros to set errno and return minus one.
RTEMS Port of Linux SPI API.
SPI bus control.
Definition: spi.h:80
void(* destroy)(spi_bus *bus)
Destroys the bus.
Definition: spi.h:110
uint8_t cs
Indicates which device is selected by chip select.
Definition: spi.h:135
uint32_t mode
Current mode.
Definition: spi.h:150
uint16_t delay_usecs
Indicates the delay between transfers on different chip select devices.
Definition: spi.h:156
int(* transfer)(spi_bus *bus, const spi_ioc_transfer *msgs, uint32_t msg_count)
Transfers SPI messages.
Definition: spi.h:92
bool lsb_first
Indicates if LSB is supposed to be transmitted first.
Definition: spi.h:145
int(* ioctl)(spi_bus *bus, ioctl_command_t command, void *arg)
Driver specific ioctl.
Definition: spi.h:163
int(* setup)(spi_bus *bus)
Checks if maximum speed and bits per word are in a valid range for the device.
Definition: spi.h:103
bool cs_change
Indicates if chip select must be set high after transfer.
Definition: spi.h:130
uint32_t speed_hz
Indicates the speed of the current device message.
Definition: spi.h:125
rtems_recursive_mutex mutex
Mutex to protect the bus access.
Definition: spi.h:115
uint32_t max_speed_hz
Maximum Speed in Hz.
Definition: spi.h:120
uint8_t bits_per_word
Indicates the bits per word used on the device.
Definition: spi.h:140
SPI transfer message.
Definition: spidev.h:158
This header file provides the API of Self-Contained Objects.