From 7160e1dbd2e61ef89ca93d1d6ab9a748b9e18f01 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Fri, 2 Mar 2018 19:36:22 +0000 Subject: [PATCH] Change the way of configuring SPI controller count --- arch/cpu/cc2538/cc2538-def.h | 2 ++ arch/cpu/cc2538/dev/spi-hal-arch.c | 2 +- arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h | 2 ++ arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c | 4 ++-- os/dev/spi-hal.c | 22 +++++++++++----------- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/arch/cpu/cc2538/cc2538-def.h b/arch/cpu/cc2538/cc2538-def.h index 32aed6111..e4c7451a6 100644 --- a/arch/cpu/cc2538/cc2538-def.h +++ b/arch/cpu/cc2538/cc2538-def.h @@ -58,6 +58,8 @@ #define TSCH_CONF_HW_FRAME_FILTERING 0 #endif /* MAC_CONF_WITH_TSCH */ /*---------------------------------------------------------------------------*/ +#define SPI_CONF_CONTROLLER_COUNT 2 +/*---------------------------------------------------------------------------*/ /* Path to CMSIS header */ #define CMSIS_CONF_HEADER_PATH "cc2538_cm3.h" diff --git a/arch/cpu/cc2538/dev/spi-hal-arch.c b/arch/cpu/cc2538/dev/spi-hal-arch.c index 7b1469f0a..0c98ff35a 100644 --- a/arch/cpu/cc2538/dev/spi-hal-arch.c +++ b/arch/cpu/cc2538/dev/spi-hal-arch.c @@ -92,7 +92,7 @@ typedef struct spi_locks_s { } spi_locks_t; /* One lock per SPI controller */ -spi_locks_t board_spi_locks_spi[BOARD_SPI_CONTROLLERS] = { { MUTEX_STATUS_UNLOCKED, NULL } }; +spi_locks_t board_spi_locks_spi[SPI_CONTROLLER_COUNT] = { { MUTEX_STATUS_UNLOCKED, NULL } }; /*---------------------------------------------------------------------------*/ static void diff --git a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h index 7b914ac1e..15db03448 100644 --- a/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h +++ b/arch/cpu/cc26xx-cc13xx/cc13xx-cc26xx-def.h @@ -104,5 +104,7 @@ /*---------------------------------------------------------------------------*/ #define GPIO_HAL_CONF_ARCH_SW_TOGGLE 0 /*---------------------------------------------------------------------------*/ +#define SPI_CONF_CONTROLLER_COUNT 2 +/*---------------------------------------------------------------------------*/ #endif /* CC13XX_CC26XX_DEF_H_ */ /*---------------------------------------------------------------------------*/ diff --git a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c index c67c0d484..89c3e1c7a 100644 --- a/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c +++ b/arch/cpu/cc26xx-cc13xx/dev/spi-hal-arch.c @@ -42,10 +42,10 @@ typedef struct spi_locks_s { } spi_locks_t; /* One lock per SPI controller */ -spi_locks_t board_spi_locks_spi[BOARD_SPI_CONTROLLERS] = { { MUTEX_STATUS_UNLOCKED, NULL } }; +spi_locks_t board_spi_locks_spi[SPI_CONTROLLER_COUNT] = { { MUTEX_STATUS_UNLOCKED, NULL } }; /* Arch-specific properties of each SPI controller */ -static const board_spi_controller_t spi_controller[BOARD_SPI_CONTROLLERS] = { +static const board_spi_controller_t spi_controller[SPI_CONTROLLER_COUNT] = { { .ssi_base = SSI0_BASE, .power_domain = PRCM_DOMAIN_SERIAL, diff --git a/os/dev/spi-hal.c b/os/dev/spi-hal.c index 532e9323f..f4810a97a 100644 --- a/os/dev/spi-hal.c +++ b/os/dev/spi-hal.c @@ -48,7 +48,7 @@ spi_acquire(spi_device_t *dev) { spi_status_t r; - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -67,7 +67,7 @@ spi_release(spi_device_t *dev) { spi_status_t r; - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -96,7 +96,7 @@ spi_deselect(spi_device_t *dev) bool spi_has_bus(spi_device_t *dev) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return false; } @@ -106,7 +106,7 @@ spi_has_bus(spi_device_t *dev) spi_status_t spi_write_byte(spi_device_t *dev, uint8_t data) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -120,7 +120,7 @@ spi_write_byte(spi_device_t *dev, uint8_t data) spi_status_t spi_write(spi_device_t *dev, const uint8_t *data, int size) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -134,7 +134,7 @@ spi_write(spi_device_t *dev, const uint8_t *data, int size) spi_status_t spi_read_byte(spi_device_t *dev, uint8_t *buf) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -148,7 +148,7 @@ spi_read_byte(spi_device_t *dev, uint8_t *buf) spi_status_t spi_read(spi_device_t *dev, uint8_t *buf, int size) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -162,7 +162,7 @@ spi_read(spi_device_t *dev, uint8_t *buf, int size) spi_status_t spi_read_skip(spi_device_t *dev, int size) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -178,7 +178,7 @@ spi_transfer(spi_device_t *dev, const uint8_t *wdata, int wsize, uint8_t *rbuf, int rsize, int ignore) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -201,7 +201,7 @@ spi_status_t spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) { spi_status_t status; - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; } @@ -223,7 +223,7 @@ spi_read_register(spi_device_t *dev, uint8_t reg, uint8_t *data, int size) spi_status_t spi_strobe(spi_device_t *dev, uint8_t strobe, uint8_t *result) { - if(dev == NULL || dev->spi_controller >= BOARD_SPI_CONTROLLERS) { + if(dev == NULL || dev->spi_controller >= SPI_CONTROLLER_COUNT) { return SPI_DEV_STATUS_EINVAL; }