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