From e8a8870d1dce4d5c978098715786802f586edf58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Date: Fri, 15 Nov 2013 15:58:44 +0100 Subject: [PATCH] cc2538: spi: Add enable and disable functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes it possible to reduce the power consumption when the SPI is unused. Signed-off-by: Benoît Thébaudeau --- cpu/cc2538/dev/spi.c | 17 +++++++++++++++-- cpu/cc2538/spi-arch.h | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cpu/cc2538/dev/spi.c b/cpu/cc2538/dev/spi.c index 42cf76999..191c77a62 100644 --- a/cpu/cc2538/dev/spi.c +++ b/cpu/cc2538/dev/spi.c @@ -74,8 +74,7 @@ void spi_init(void) { - /* Enable the SSI peripheral */ - REG(SYS_CTRL_RCGCSSI) |= 1; + spi_enable(); /* Start by disabling the peripheral before configuring it */ REG(SSI0_BASE + SSI_CR1) = 0; @@ -110,4 +109,18 @@ spi_init(void) /* Enable the SSI */ REG(SSI0_BASE + SSI_CR1) |= SSI_CR1_SSE; } +/*---------------------------------------------------------------------------*/ +void +spi_enable(void) +{ + /* Enable the clock for the SSI peripheral */ + REG(SYS_CTRL_RCGCSSI) |= 1; +} +/*---------------------------------------------------------------------------*/ +void +spi_disable(void) +{ + /* Gate the clock for the SSI peripheral */ + REG(SYS_CTRL_RCGCSSI) &= ~1; +} /** @} */ diff --git a/cpu/cc2538/spi-arch.h b/cpu/cc2538/spi-arch.h index 3bace13d4..85eb058c1 100644 --- a/cpu/cc2538/spi-arch.h +++ b/cpu/cc2538/spi-arch.h @@ -57,6 +57,21 @@ #define SPI_WAITFOREORx() do { \ while(!(REG(SSI0_BASE + SSI_SR) & SSI_SR_RNE)); \ } while (0) +/*---------------------------------------------------------------------------*/ +/** \name Arch-specific SPI functions + * @{ + */ + +/** \brief Enables the SPI peripheral + */ +void spi_enable(void); + +/** \brief Disables the SPI peripheral + * \note Call this function to save power when the SPI is unused. + */ +void spi_disable(void); + +/** @} */ #endif /* SPI_ARCH_H_ */