source: rtems/cpukit/include/dev/serial/sc16is752.h @ 2be6ab7f

5
Last change on this file since 2be6ab7f was 2be6ab7f, checked in by Sebastian Huber <sebastian.huber@…>, on 06/14/19 at 05:41:36

dev/sc16is752: Add set/get EFCR IO controls

  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifndef _DEV_SERIAL_SC16IS752_H
16#define _DEV_SERIAL_SC16IS752_H
17
18#include <sys/ioccom.h>
19
20#include <rtems/termiostypes.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26/**
27 * @defgroup SC16IS752 SC16IS752 Serial Device Driver
28 *
29 * @ingroup TermiostypesSupport
30 */
31
32typedef enum {
33  SC16IS752_MODE_RS232,
34
35  /* Enable RS485 mode */
36  SC16IS752_MODE_RS485,
37
38  /* Enable RS485 mode, enable the transmitter to control the #RTS pin */
39  SC16IS752_MODE_RS485_RTS,
40
41  /*
42   * Enable RS485 mode, enable the transmitter to control the #RTS pin, invert
43   * RTS signal (#RTS = 1 during transmission and #RTS = 0 during reception)
44   */
45  SC16IS752_MODE_RS485_RTS_INV
46} sc16is752_mode;
47
48typedef struct sc16is752_context sc16is752_context;
49
50/**
51 * @brief SC16IS752 device context.
52 */
53struct sc16is752_context {
54  rtems_termios_device_context base;
55
56  /**
57   * @brief Writes a register.
58   *
59   * Internal handler.
60   */
61  int (*write_reg)(
62    sc16is752_context *ctx,
63    uint8_t addr,
64    const uint8_t *data,
65    size_t len
66  );
67
68  /**
69   * @brief Reads a register.
70   *
71   * Internal handler.
72   */
73  int (*read_reg)(
74    sc16is752_context *ctx,
75    uint8_t addr,
76    uint8_t *data,
77    size_t len
78  );
79
80  /**
81   * @brief Reads two registers.
82   *
83   * Internal handler.
84   */
85  int (*read_2_reg)(
86    sc16is752_context *ctx,
87    uint8_t addr_0,
88    uint8_t addr_1,
89    uint8_t data[2]
90  );
91
92  /**
93   * @brief First open.
94   *
95   * Internal handler.
96   */
97  bool (*first_open)(sc16is752_context *ctx);
98
99  /**
100   * @brief Last close.
101   *
102   * Internal handler.
103   */
104  void (*last_close)(sc16is752_context *ctx);
105
106  /**
107   * @brief Shall install the interrupt handler.
108   *
109   * Must be initialized by the user before the device creation.
110   */
111  bool (*install_irq)(sc16is752_context *ctx);
112
113  /**
114   * @brief Shall remove the interrupt handler.
115   *
116   * Must be initialized by the user before the device creation.
117   */
118  void (*remove_irq)(sc16is752_context *ctx);
119
120  /**
121   * @brief Device mode.
122   *
123   * Must be initialized by the user before the device creation.
124   */
125  sc16is752_mode mode;
126
127  /**
128   * @brief Input frequency in Hertz (dependent on crystal, see XTAL1 and XTAL2
129   * pins).
130   *
131   * Must be initialized by the user before the device creation.
132   */
133  uint32_t input_frequency;
134
135  /**
136   * @brief Corresponding Termios structure.
137   *
138   * Internal variable.
139   */
140  rtems_termios_tty *tty;
141
142  /**
143   * @brief Shadow Interrupt Enable Register (IER).
144   *
145   * Internal variable.
146   */
147  uint8_t ier;
148
149  /**
150   * @brief Characters placed into transmit FIFO.
151   *
152   * Internal variable.
153   */
154  uint8_t tx_in_progress;
155
156  /**
157   * @brief Count of free characters in the transmit FIFO.
158   *
159   * Internal variable.
160   */
161  uint8_t tx_fifo_free;
162
163  /**
164   * @brief Shadow Line Control Register (LCR).
165   *
166   * Internal variable.
167   */
168  uint8_t lcr;
169
170  /**
171   * @brief Shadow Extra Features Control Register (EFCR).
172   *
173   * Internal variable.
174   */
175  uint8_t efcr;
176};
177
178/**
179 * @brief SC16IS752 SPI context.
180 */
181typedef struct {
182  sc16is752_context base;
183
184  /**
185   * @brief The SPI bus device file descriptor.
186   *
187   * Internal variable.
188   */
189  int fd;
190
191  /**
192   * @brief The SPI device chip select.
193   *
194   * Must be initialized by the user before the call to sc16is752_spi_create().
195   */
196  uint8_t cs;
197
198  /**
199   * @brief The SPI bus speed in Hertz.
200   *
201   * Must be initialized by the user before the call to sc16is752_spi_create().
202   */
203  uint32_t speed_hz;
204
205  /**
206   * @brief The SPI bus device path.
207   *
208   * Must be initialized by the user before the call to sc16is752_spi_create().
209   */
210  const char *spi_path;
211} sc16is752_spi_context;
212
213/**
214 * @brief SC16IS752 I2C context.
215 */
216typedef struct {
217  sc16is752_context base;
218
219  /**
220   * @brief The I2C bus device file descriptor.
221   *
222   * Internal variable.
223   */
224  int fd;
225
226  /**
227   * @brief The I2C bus device path.
228   *
229   * Must be initialized before the call to sc16is752_i2c_create().
230   */
231  const char *bus_path;
232} sc16is752_i2c_context;
233
234const rtems_termios_device_handler sc16is752_termios_handler;
235
236/**
237 * @brief The interrupt handler for receive and transmit operations.
238 *
239 * @param[in] arg The device context.
240 */
241void sc16is752_interrupt_handler(void *arg);
242
243/**
244 * @brief Creates an SPI connected SC16IS752 device.
245 *
246 * @param[in] ctx The SPI SC16IS752 device context.
247 * @param[in] device_path The device file path for the new device.
248 *
249 * @retval RTEMS_SUCCESSFUL Successful operation.
250 * @retval other See rtems_termios_device_install().
251 */
252rtems_status_code sc16is752_spi_create(
253  sc16is752_spi_context *ctx,
254  const char            *device_path
255);
256
257/**
258 * @brief Enables the sleep mode if non-zero, otherwise disables it.
259 *
260 * The sleep mode is disabled by default.
261 */
262#define SC16IS752_SET_SLEEP_MODE _IOW('d', 0, int)
263
264/**
265 * @brief Set the I/O Control bits except for the SRESET.
266 *
267 * Note that it will not be possible to set the SRESET. Otherwise the driver
268 * might would have an undefined state.
269 */
270#define SC16IS752_SET_IOCONTROL _IOW('d', 1, uint8_t)
271
272/**
273 * @brief Set the I/O pins direction register.
274 */
275#define SC16IS752_SET_IODIR _IOW('d', 2, uint8_t)
276
277/**
278 * @brief Set the I/O pins state register.
279 */
280#define SC16IS752_SET_IOSTATE _IOW('d', 3, uint8_t)
281
282/**
283 * @brief Set the EFCR register.
284 */
285#define SC16IS752_SET_EFCR _IOW('d', 4, uint8_t)
286
287/**
288 * @brief Returns non-zero in case the sleep mode is enabled, otherwise zero.
289 */
290#define SC16IS752_GET_SLEEP_MODE _IOR('d', 0, int)
291
292/**
293 * @brief Read the I/O Control register.
294 */
295#define SC16IS752_GET_IOCONTROL _IOR('d', 1, uint8_t)
296
297/**
298 * @brief Read the I/O pins direction register.
299 */
300#define SC16IS752_GET_IODIR _IOR('d', 2, uint8_t)
301
302/**
303 * @brief Read the I/O pins state register.
304 */
305#define SC16IS752_GET_IOSTATE _IOR('d', 3, uint8_t)
306
307/**
308 * @brief Read the EFCR register.
309 */
310#define SC16IS752_GET_EFCR _IOR('d', 4, uint8_t)
311
312/**
313 * @brief Bits for the IOCONTROL register.
314 * @{
315 */
316#define SC16IS752_IOCONTROL_SRESET (1u << 3)
317#define SC16IS752_IOCONTROL_GPIO_3_0_OR_MODEM (1u << 2)
318#define SC16IS752_IOCONTROL_GPIO_7_4_OR_MODEM (1u << 1)
319#define SC16IS752_IOCONTROL_IOLATCH (1u << 0)
320/**
321 * @}
322 */
323
324#ifdef __cplusplus
325}
326#endif /* __cplusplus */
327
328#endif /* _DEV_SERIAL_SC16IS752_H */
Note: See TracBrowser for help on using the repository browser.