[rtems commit] bsp/atsam: Simplify SPI initialization
Sebastian Huber
sebh at rtems.org
Wed Dec 14 12:10:18 UTC 2016
Module: rtems
Branch: master
Commit: 62e1e0ff03c366c09f70ac2e1f11cea6620987ac
Changeset: http://git.rtems.org/rtems/commit/?id=62e1e0ff03c366c09f70ac2e1f11cea6620987ac
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Wed Dec 14 07:37:49 2016 +0100
bsp/atsam: Simplify SPI initialization
---
c/src/lib/libbsp/arm/atsam/include/atsam-spi.h | 8 ++---
c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c | 47 +++++++++----------------
c/src/lib/libbsp/arm/atsam/spi/atsam_spi_init.c | 4 +--
3 files changed, 23 insertions(+), 36 deletions(-)
diff --git a/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h b/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h
index 3d02c51..548dd54 100644
--- a/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h
+++ b/c/src/lib/libbsp/arm/atsam/include/atsam-spi.h
@@ -23,10 +23,10 @@ extern "C" {
int spi_bus_register_atsam(
const char *bus_path,
- Spi *register_base,
- rtems_vector_number irq,
- const Pin *pins,
- size_t pin_count
+ uint8_t spi_peripheral_id,
+ Spi *spi_regs,
+ const Pin *pins,
+ size_t pin_count
);
#ifdef __cplusplus
diff --git a/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c b/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c
index 468e4ec..99df45e 100644
--- a/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c
+++ b/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_bus.c
@@ -40,7 +40,6 @@ typedef struct {
spi_bus base;
Spi *regs;
rtems_vector_number irq;
- uint32_t board_id;
uint32_t msg_todo;
const spi_ioc_transfer *msgs;
rtems_id task_id;
@@ -170,7 +169,7 @@ static void atsam_configure_spi(atsam_spi_bus *bus)
SPID_Configure(
&bus->SpiDma,
bus->regs,
- bus->board_id,
+ bus->SpiDma.spiId,
(SPI_MR_DLYBCS(delay_cs) |
SPI_MR_MSTR |
SPI_MR_MODFDIS |
@@ -512,47 +511,35 @@ static int atsam_spi_setup(spi_bus *base)
return 0;
}
-static void atsam_spi_init(
- atsam_spi_bus *bus,
- const Pin *pins,
- size_t pin_count
-)
-{
- PIO_Configure(pins, pin_count);
- ENABLE_PERIPHERAL(bus->board_id);
- XDMAD_Initialize(&bus->Dma, 0);
- bus->base.mode = 0;
- bus->base.bits_per_word = 8;
- bus->base.speed_hz = bus->base.max_speed_hz;
- bus->base.delay_usecs = 1;
- bus->base.cs = 1;
-
- atsam_configure_spi(bus);
- atsam_set_dmac(bus);
-}
-
int spi_bus_register_atsam(
- const char *bus_path,
- Spi *register_base,
- rtems_vector_number irq,
- const Pin *pins,
- size_t pin_count
+ const char *bus_path,
+ uint8_t spi_peripheral_id,
+ Spi *spi_regs,
+ const Pin *pins,
+ size_t pin_count
)
{
atsam_spi_bus *bus;
rtems_status_code sc;
- uint32_t board_id = (uint32_t) irq;
bus = (atsam_spi_bus *) spi_bus_alloc_and_init(sizeof(*bus));
if (bus == NULL) {
return -1;
}
- bus->regs = register_base;
- bus->board_id = board_id;
+ bus->base.bits_per_word = 8;
+ bus->base.speed_hz = bus->base.max_speed_hz;
+ bus->base.delay_usecs = 1;
+ bus->base.cs = 1;
+ bus->regs = spi_regs;
bus->irq = ID_XDMAC;
+ bus->SpiDma.spiId = spi_peripheral_id;
- atsam_spi_init(bus, pins, pin_count);
+ PIO_Configure(pins, pin_count);
+ PMC_EnablePeripheral(spi_peripheral_id);
+ XDMAD_Initialize(&bus->Dma, 0);
+ atsam_configure_spi(bus);
+ atsam_set_dmac(bus);
sc = rtems_interrupt_handler_install(
bus->irq,
diff --git a/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_init.c b/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_init.c
index 71e8658..09440f2 100644
--- a/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_init.c
+++ b/c/src/lib/libbsp/arm/atsam/spi/atsam_spi_init.c
@@ -68,8 +68,8 @@ int atsam_register_spi_0(void)
return spi_bus_register_atsam(
ATSAM_SPI_0_BUS_PATH,
- SPI0,
ID_SPI0,
+ SPI0,
pins,
RTEMS_ARRAY_SIZE(pins)
);
@@ -92,8 +92,8 @@ int atsam_register_spi_1(void)
return spi_bus_register_atsam(
ATSAM_SPI_1_BUS_PATH,
- SPI1,
ID_SPI1,
+ SPI1,
pins,
RTEMS_ARRAY_SIZE(pins)
);
More information about the vc
mailing list