[rtems commit] bsp/atsam: Add SC16IS752 support

Sebastian Huber sebh at rtems.org
Fri Dec 16 10:30:13 UTC 2016


Module:    rtems
Branch:    master
Commit:    08f1d2f79bc6bdd24bd4f322f348bb1b4555f0dc
Changeset: http://git.rtems.org/rtems/commit/?id=08f1d2f79bc6bdd24bd4f322f348bb1b4555f0dc

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Dec 15 15:37:00 2016 +0100

bsp/atsam: Add SC16IS752 support

---

 c/src/lib/libbsp/arm/atsam/Makefile.am         |  2 +
 c/src/lib/libbsp/arm/atsam/include/sc16is752.h | 67 ++++++++++++++++++++
 c/src/lib/libbsp/arm/atsam/preinstall.am       |  4 ++
 c/src/lib/libbsp/arm/atsam/spi/sc16is752.c     | 85 ++++++++++++++++++++++++++
 4 files changed, 158 insertions(+)

diff --git a/c/src/lib/libbsp/arm/atsam/Makefile.am b/c/src/lib/libbsp/arm/atsam/Makefile.am
index e783023..7f0ed87 100644
--- a/c/src/lib/libbsp/arm/atsam/Makefile.am
+++ b/c/src/lib/libbsp/arm/atsam/Makefile.am
@@ -55,6 +55,7 @@ include_bsp_HEADERS += include/atsam-i2c.h
 include_bsp_HEADERS += include/i2c.h
 include_bsp_HEADERS += include/atsam-spi.h
 include_bsp_HEADERS += include/spi.h
+include_bsp_HEADERS += include/sc16is752.h
 include_bsp_HEADERS += include/power.h
 
 include_libchipdir = $(includedir)/libchip
@@ -441,6 +442,7 @@ libbsp_a_SOURCES += i2c/atsam_i2c_init.c
 # SPI
 libbsp_a_SOURCES += spi/atsam_spi_bus.c
 libbsp_a_SOURCES += spi/atsam_spi_init.c
+libbsp_a_SOURCES += spi/sc16is752.c
 
 # RTC
 libbsp_a_SOURCES += ../../shared/tod.c
diff --git a/c/src/lib/libbsp/arm/atsam/include/sc16is752.h b/c/src/lib/libbsp/arm/atsam/include/sc16is752.h
new file mode 100644
index 0000000..31f9660
--- /dev/null
+++ b/c/src/lib/libbsp/arm/atsam/include/sc16is752.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <info at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef LIBBSP_ARM_ATSAM_SC16IS752_H
+#define LIBBSP_ARM_ATSAM_SC16IS752_H
+
+#include <libchip/chip.h>
+
+#include <dev/serial/sc16is752.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct {
+  sc16is752_spi_context base;
+  Pin irq_pin;
+} atsam_sc16is752_spi_context;
+
+/**
+ * @brief Creates an SPI connected SC16IS752 device.
+ *
+ * This devices uses the interrupt server, see
+ * rtems_interrupt_server_initialize().
+ *
+ * The device claims the interrupt of the PIO block.
+ *
+ * @param[in] ctx The device context.  May have an arbitrary content.
+ * @param[in] device_path The device file path for the new device.
+ * @param[in] mode The SC16IS752 mode.
+ * @param[in] input_frequency The input frequency in Hertz of the SC16IS752
+ *   chip.  See XTAL1 and XTAL2 pins.
+ * @param[in] spi_path The SPI bus device path.
+ * @param[in] spi_chip_select The SPI chip select (starts with 1, not 0).
+ * @param[in] spi_speed_hz The SPI bus speed in Hertz.
+ * @param[in] irq_pin The interrupt pin, e.g. { PIO_PD28, PIOD, ID_PIOD,
+ *   PIO_INPUT, PIO_IT_LOW_LEVEL }.
+ *
+ * @return See sc16is752_spi_create().
+ */
+int atsam_sc16is752_spi_create(
+  atsam_sc16is752_spi_context *ctx,
+  const char                  *device_path,
+  sc16is752_mode               mode,
+  uint32_t                     input_frequency,
+  const char                  *spi_path,
+  uint8_t                      spi_chip_select,
+  uint32_t                     spi_speed_hz,
+  const Pin                    *irq_pin
+);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBBSP_ARM_ATSAM_SC16IS752_H */
diff --git a/c/src/lib/libbsp/arm/atsam/preinstall.am b/c/src/lib/libbsp/arm/atsam/preinstall.am
index e758252..15ccdfd 100644
--- a/c/src/lib/libbsp/arm/atsam/preinstall.am
+++ b/c/src/lib/libbsp/arm/atsam/preinstall.am
@@ -149,6 +149,10 @@ $(PROJECT_INCLUDE)/bsp/spi.h: include/spi.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/spi.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/spi.h
 
+$(PROJECT_INCLUDE)/bsp/sc16is752.h: include/sc16is752.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/sc16is752.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/sc16is752.h
+
 $(PROJECT_INCLUDE)/bsp/power.h: include/power.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
 	$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/power.h
 PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/power.h
diff --git a/c/src/lib/libbsp/arm/atsam/spi/sc16is752.c b/c/src/lib/libbsp/arm/atsam/spi/sc16is752.c
new file mode 100644
index 0000000..b17f9ff
--- /dev/null
+++ b/c/src/lib/libbsp/arm/atsam/spi/sc16is752.c
@@ -0,0 +1,85 @@
+
+/*
+ * Copyright (c) 2016 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#include <bsp/sc16is752.h>
+
+#include <rtems/irq-extension.h>
+
+static void atsam_sc16i752_interrupt(void *arg)
+{
+  atsam_sc16is752_spi_context *ctx = arg;
+
+  sc16is752_interrupt_handler(&ctx->base.base);
+
+  /* Interrupt Status Register shall be read to clear the interrupt flag */
+  ctx->irq_pin.pio->PIO_ISR;
+}
+
+static bool atsam_sc16is752_install_interrupt(sc16is752_context *base)
+{
+  atsam_sc16is752_spi_context *ctx = (atsam_sc16is752_spi_context *)base;
+  rtems_status_code sc;
+
+  PIO_Configure(&ctx->irq_pin, 1);
+  PIO_EnableIt(&ctx->irq_pin);
+
+  sc = rtems_interrupt_server_handler_install(
+    RTEMS_ID_NONE,
+    ctx->irq_pin.id,
+    "Test",
+    RTEMS_INTERRUPT_SHARED,
+    atsam_sc16i752_interrupt,
+    ctx
+  );
+
+  return sc == RTEMS_SUCCESSFUL;
+}
+
+static void atsam_sc16is752_remove_interrupt(sc16is752_context *base)
+{
+  atsam_sc16is752_spi_context *ctx = (atsam_sc16is752_spi_context *)base;
+  rtems_status_code sc;
+
+  sc = rtems_interrupt_server_handler_remove(
+    RTEMS_ID_NONE,
+    ctx->irq_pin.id,
+    atsam_sc16i752_interrupt,
+    ctx
+  );
+  assert(sc == RTEMS_SUCCESSFUL);
+}
+
+int atsam_sc16is752_spi_create(
+  atsam_sc16is752_spi_context *ctx,
+  const char *device_path,
+  sc16is752_mode mode,
+  uint32_t input_frequency,
+  const char *spi_path,
+  uint8_t spi_chip_select,
+  uint32_t spi_speed_hz,
+  const Pin *irq_pin
+)
+{
+  ctx->base.base.mode = mode;
+  ctx->base.base.input_frequency = input_frequency;
+  ctx->base.base.install_irq = atsam_sc16is752_install_interrupt;
+  ctx->base.base.remove_irq = atsam_sc16is752_remove_interrupt;
+  ctx->base.spi_path = spi_path;
+  ctx->base.cs = spi_chip_select;
+  ctx->base.speed_hz = spi_speed_hz;
+  ctx->irq_pin = *irq_pin;
+
+  return sc16is752_spi_create(&ctx->base, device_path);
+}



More information about the vc mailing list