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_ */