[PATCH 3/3] bsp/atsam: Use PIO for SC16IS752.
Christian Mauderer
christian.mauderer at embedded-brains.de
Tue Oct 15 15:10:01 UTC 2019
This allows to mix SC16IS752 chips with other interrupts.
---
bsps/arm/atsam/include/bsp/sc16is752.h | 3 +++
bsps/arm/atsam/spi/sc16is752.c | 44 ++++++++++++++++++----------------
2 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/bsps/arm/atsam/include/bsp/sc16is752.h b/bsps/arm/atsam/include/bsp/sc16is752.h
index 35d298a7ed..e8973efc46 100644
--- a/bsps/arm/atsam/include/bsp/sc16is752.h
+++ b/bsps/arm/atsam/include/bsp/sc16is752.h
@@ -15,6 +15,7 @@
#ifndef LIBBSP_ARM_ATSAM_SC16IS752_H
#define LIBBSP_ARM_ATSAM_SC16IS752_H
+#include <rtems/irq-extension.h>
#include <libchip/chip.h>
#include <dev/serial/sc16is752.h>
@@ -26,6 +27,8 @@ extern "C" {
typedef struct {
sc16is752_spi_context base;
Pin irq_pin;
+ rtems_interrupt_server_entry irqs_entry; /* Internal. Don't touch. */
+ rtems_interrupt_server_action irqs_action; /* Internal. Don't touch. */
} atsam_sc16is752_spi_context;
/**
diff --git a/bsps/arm/atsam/spi/sc16is752.c b/bsps/arm/atsam/spi/sc16is752.c
index b17f9ffc14..8d38fe92d6 100644
--- a/bsps/arm/atsam/spi/sc16is752.c
+++ b/bsps/arm/atsam/spi/sc16is752.c
@@ -17,34 +17,40 @@
#include <rtems/irq-extension.h>
-static void atsam_sc16i752_interrupt(void *arg)
+static void atsam_sc16i752_irqs_handler(void *arg)
{
atsam_sc16is752_spi_context *ctx = arg;
- sc16is752_interrupt_handler(&ctx->base.base);
+ sc16is752_interrupt_handler(&ctx->base.base);
+ PIO_EnableIt(&ctx->irq_pin);
+}
+
+static void atsam_sc16i752_interrupt(const Pin *pin, void *arg)
+{
+ atsam_sc16is752_spi_context *ctx = arg;
- /* Interrupt Status Register shall be read to clear the interrupt flag */
- ctx->irq_pin.pio->PIO_ISR;
+ if(PIO_ItIsActive(&ctx->irq_pin)) {
+ PIO_DisableIt(&ctx->irq_pin);
+ rtems_interrupt_server_entry_submit(&ctx->irqs_entry);
+ }
}
static bool atsam_sc16is752_install_interrupt(sc16is752_context *base)
{
atsam_sc16is752_spi_context *ctx = (atsam_sc16is752_spi_context *)base;
rtems_status_code sc;
+ uint8_t rv;
- PIO_Configure(&ctx->irq_pin, 1);
- PIO_EnableIt(&ctx->irq_pin);
+ sc = rtems_interrupt_server_entry_initialize(RTEMS_INTERRUPT_SERVER_DEFAULT,
+ &ctx->irqs_entry);
+ rtems_interrupt_server_action_prepend(&ctx->irqs_entry,
+ &ctx->irqs_action, atsam_sc16i752_irqs_handler, ctx);
- sc = rtems_interrupt_server_handler_install(
- RTEMS_ID_NONE,
- ctx->irq_pin.id,
- "Test",
- RTEMS_INTERRUPT_SHARED,
- atsam_sc16i752_interrupt,
- ctx
- );
+ rv = PIO_Configure(&ctx->irq_pin, 1);
+ PIO_ConfigureIt(&ctx->irq_pin, atsam_sc16i752_interrupt, ctx);
+ PIO_EnableIt(&ctx->irq_pin);
- return sc == RTEMS_SUCCESSFUL;
+ return (sc == RTEMS_SUCCESSFUL) && (rv == 1);
}
static void atsam_sc16is752_remove_interrupt(sc16is752_context *base)
@@ -52,12 +58,8 @@ 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
- );
+ PIO_DisableIt(&ctx->irq_pin);
+ sc = PIO_RemoveIt(&ctx->irq_pin, atsam_sc16i752_interrupt, ctx);
assert(sc == RTEMS_SUCCESSFUL);
}
--
2.16.4
More information about the devel
mailing list