source: rtems/bsps/arm/beagle/include/bsp/spi.h @ ecf62845

5
Last change on this file since ecf62845 was ecf62845, checked in by Pierre-Louis Garnier <garnie_a@…>, on 02/25/19 at 22:30:09

arm/beagle: SPI driver

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup arm_beagle
5 *
6 * @brief SPI support API.
7 *
8 * Based on bsps/m68k/gen68360/spi/m360_spi.h
9 */
10
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
44typedef struct BEAGLE_SPI_BufferDescriptor_ {
45    unsigned short      status;
46    unsigned short      length;
47    volatile void       *buffer;
48} BEAGLE_SPI_BufferDescriptor_t;
49
50typedef struct beagle_spi_softc {
51  int                     initialized;
52  rtems_id                task_id;
53  uintptr_t               regs_base;
54  rtems_vector_number     irq;
55} beagle_spi_softc_t;
56
57typedef struct {
58  rtems_libi2c_bus_t  bus_desc;
59  beagle_spi_softc_t softc;
60} beagle_spi_desc_t;
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,
128  rtems_vector_number irq
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 */
Note: See TracBrowser for help on using the repository browser.