RTEMS 7.0-rc1
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0+-with-RTEMS-exception */
2
13/*
14 * Copyright (c) 2018 Pierre-Louis Garnier <garnie_a@epita.fr>
15 *
16 * The license and distribution terms for this file may be
17 * found in the file LICENSE in this distribution or at
18 * http://www.rtems.org/license/LICENSE.
19 */
20
21#ifndef LIBBSP_ARM_BEAGLE_SPI_H
22#define LIBBSP_ARM_BEAGLE_SPI_H
23
24#include <bsp.h>
25#include <rtems/libi2c.h>
26#include <rtems/irq.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif /* __cplusplus */
31
32#define BBB_SPI_TIMEOUT 1000
33
34#define BBB_SPI_0_BUS_PATH "/dev/spi-0"
35
36#define BBB_SPI_0_IRQ AM335X_INT_SPI0INT
37
38typedef enum {
39 SPI0,
40 SPI1,
41 SPI_COUNT
42} bbb_spi_id_t;
43
44
45
47 unsigned short status;
48 unsigned short length;
49 volatile void *buffer;
51
52typedef struct beagle_spi_softc {
53 int initialized;
54 rtems_id task_id;
55 uintptr_t regs_base;
58
59typedef struct {
60 rtems_libi2c_bus_t bus_desc;
63
64/*
65 * Initialize the driver
66 *
67 * Returns: o = ok or error code
68 */
69rtems_status_code beagle_spi_init
70(
71 rtems_libi2c_bus_t *bh /* bus specifier structure */
72);
73
74/*
75 * Receive some bytes from SPI device
76 *
77 * Returns: number of bytes received or (negative) error code
78 */
79int beagle_spi_read_bytes
80(
81 rtems_libi2c_bus_t *bh, /* bus specifier structure */
82 unsigned char *buf, /* buffer to store bytes */
83 int len /* number of bytes to receive */
84);
85
86/*
87 * Send some bytes to SPI device
88 *
89 * Returns: number of bytes sent or (negative) error code
90 */
91int beagle_spi_write_bytes
92(
93 rtems_libi2c_bus_t *bh, /* bus specifier structure */
94 unsigned char *buf, /* buffer to send */
95 int len /* number of bytes to send */
96);
97
98/*
99 * Set SPI to desired baudrate/clock mode/character mode
100 *
101 * Returns: rtems_status_code
102 */
103rtems_status_code beagle_spi_set_tfr_mode
104(
105 rtems_libi2c_bus_t *bh, /* bus specifier structure */
106 const rtems_libi2c_tfr_mode_t *tfr_mode /* transfer mode info */
107);
108
109/*
110 * Perform selected ioctl function for SPI
111 *
112 * Returns: rtems_status_code
113 */
114int beagle_spi_ioctl
115(
116 rtems_libi2c_bus_t *bh, /* bus specifier structure */
117 int cmd, /* ioctl command code */
118 void *arg /* additional argument array */
119);
120
121/*
122 * Register SPI bus and devices
123 *
124 * Returns: Bus number or error code
125 */
126rtems_status_code bsp_register_spi
127(
128 const char *bus_path,
129 uintptr_t register_base,
131);
132
133static inline rtems_status_code bbb_register_spi_0(void)
134{
135 return bsp_register_spi(
136 BBB_SPI_0_BUS_PATH,
137 AM335X_SPI0_BASE,
138 BBB_SPI_0_IRQ
139 );
140}
141
142#ifdef __cplusplus
143}
144#endif /* __cplusplus */
145
146#endif /* LIBBSP_ARM_BEAGLE_SPI_H */
Interrupt Handler Support.
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
rtems_status_code
This enumeration provides status codes for directives of the Classic API.
Definition: status.h:85
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
Legacy I2C Library.
Definition: spi.h:46
Definition: spi.h:59
Definition: spi.h:52
Definition: libi2c.h:163
Definition: libi2c.h:462