forked from Imagelibrary/rtems
bsp/atsam: Add SC16IS752 support
This commit is contained in:
@@ -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
|
||||
|
||||
67
c/src/lib/libbsp/arm/atsam/include/sc16is752.h
Normal file
67
c/src/lib/libbsp/arm/atsam/include/sc16is752.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <info@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 */
|
||||
@@ -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
|
||||
|
||||
85
c/src/lib/libbsp/arm/atsam/spi/sc16is752.c
Normal file
85
c/src/lib/libbsp/arm/atsam/spi/sc16is752.c
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@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);
|
||||
}
|
||||
Reference in New Issue
Block a user