From 31149b2ffb6b73f7d9c6f1e0c2e69c7f244e831d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 20 May 2012 09:16:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4220 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/LPC11xx/spi_lld.h | 8 +++---- os/hal/platforms/LPC13xx/spi_lld.c | 46 ++++++++++++++++++++++++++++++++++++++ os/hal/platforms/LPC13xx/spi_lld.h | 43 ++++++++++++++++++++++++++++++++--- 3 files changed, 90 insertions(+), 7 deletions(-) (limited to 'os/hal') diff --git a/os/hal/platforms/LPC11xx/spi_lld.h b/os/hal/platforms/LPC11xx/spi_lld.h index 633a272be..5f2cf0561 100644 --- a/os/hal/platforms/LPC11xx/spi_lld.h +++ b/os/hal/platforms/LPC11xx/spi_lld.h @@ -195,14 +195,14 @@ /** * @brief SSP0 clock. */ -#define LPC11xx_SERIAL_SSP0_PCLK \ - (LPC11xx_MAINCLK / LPC11xx_SERIAL_SSP0CLKDIV) +#define LPC11xx_SPI_SSP0_PCLK \ + (LPC11xx_MAINCLK / LPC11xx_SPI_SSP0CLKDIV) /** * @brief SSP1 clock. */ -#define LPC11xx_SERIAL_SSP1_PCLK \ - (LPC11xx_MAINCLK / LPC11xx_SERIAL_SSP1CLKDIV) +#define LPC11xx_SPI_SSP1_PCLK \ + (LPC11xx_MAINCLK / LPC11xx_SPI_SSP1CLKDIV) /*===========================================================================*/ /* Driver data structures and types. */ diff --git a/os/hal/platforms/LPC13xx/spi_lld.c b/os/hal/platforms/LPC13xx/spi_lld.c index c158fee2a..b6950ff39 100644 --- a/os/hal/platforms/LPC13xx/spi_lld.c +++ b/os/hal/platforms/LPC13xx/spi_lld.c @@ -40,6 +40,11 @@ SPIDriver SPID1; #endif +#if LPC13xx_SPI_USE_SSP1 || defined(__DOXYGEN__) +/** @brief SPI2 driver identifier.*/ +SPIDriver SPID2; +#endif + /*===========================================================================*/ /* Driver local variables. */ /*===========================================================================*/ @@ -143,6 +148,22 @@ CH_IRQ_HANDLER(VectorF4) { } #endif +#if LPC13xx_SPI_USE_SSP1 || defined(__DOXYGEN__) +/** + * @brief SSP1 interrupt handler. + * + * @isr + */ +CH_IRQ_HANDLER(Vector124) { + + CH_IRQ_PROLOGUE(); + + spi_serve_interrupt(&SPID2); + + CH_IRQ_EPILOGUE(); +} +#endif + /*===========================================================================*/ /* Driver exported functions. */ /*===========================================================================*/ @@ -168,6 +189,14 @@ void spi_lld_init(void) { LPC_IOCON->PIO0_8 = 0xC1; /* MISO0 without resistors. */ LPC_IOCON->PIO0_9 = 0xC1; /* MOSI0 without resistors. */ #endif /* LPC13xx_SPI_USE_SSP0 */ + +#if LPC13xx_SPI_USE_SSP1 + spiObjectInit(&SPID2); + SPID2.ssp = LPC_SSP1; + LPC_IOCON->PIO2_1 = 0xC2; /* SCK1 without resistors. */ + LPC_IOCON->PIO2_2 = 0xC2; /* MISO1 without resistors. */ + LPC_IOCON->PIO2_3 = 0xC2; /* MOSI1 without resistors. */ +#endif /* LPC13xx_SPI_USE_SSP0 */ } /** @@ -189,6 +218,15 @@ void spi_lld_start(SPIDriver *spip) { nvicEnableVector(SSP0_IRQn, CORTEX_PRIORITY_MASK(LPC13xx_SPI_SSP0_IRQ_PRIORITY)); } +#endif +#if LPC13xx_SPI_USE_SSP1 + if (&SPID2 == spip) { + LPC_SYSCON->SSP1CLKDIV = LPC13xx_SPI_SSP1CLKDIV; + LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 18); + LPC_SYSCON->PRESETCTRL |= 4; + nvicEnableVector(SSP1_IRQn, + CORTEX_PRIORITY_MASK(LPC13xx_SPI_SSP1_IRQ_PRIORITY)); + } #endif } /* Configuration.*/ @@ -219,6 +257,14 @@ void spi_lld_stop(SPIDriver *spip) { LPC_SYSCON->SSP0CLKDIV = 0; nvicDisableVector(SSP0_IRQn); } +#endif +#if LPC13xx_SPI_USE_SSP1 + if (&SPID2 == spip) { + LPC_SYSCON->PRESETCTRL &= ~4; + LPC_SYSCON->SYSAHBCLKCTRL &= ~(1 << 18); + LPC_SYSCON->SSP1CLKDIV = 0; + nvicDisableVector(SSP1_IRQn); + } #endif } } diff --git a/os/hal/platforms/LPC13xx/spi_lld.h b/os/hal/platforms/LPC13xx/spi_lld.h index 0e72950ca..6277b891f 100644 --- a/os/hal/platforms/LPC13xx/spi_lld.h +++ b/os/hal/platforms/LPC13xx/spi_lld.h @@ -118,6 +118,15 @@ #define LPC13xx_SPI_USE_SSP0 TRUE #endif +/** + * @brief SPI2 driver enable switch. + * @details If set to @p TRUE the support for device SSP1 is included. + * @note The default is @p TRUE. + */ +#if !defined(LPC13xx_SPI_USE_SSP1) || defined(__DOXYGEN__) +#define LPC13xx_SPI_USE_SSP1 FALSE +#endif + /** * @brief SSP0 PCLK divider. */ @@ -125,6 +134,13 @@ #define LPC13xx_SPI_SSP0CLKDIV 1 #endif +/** + * @brief SSP1 PCLK divider. + */ +#if !defined(LPC13xx_SPI_SSP1CLKDIV) || defined(__DOXYGEN__) +#define LPC13xx_SPI_SSP1CLKDIV 1 +#endif + /** * @brief SPI0 interrupt priority level setting. */ @@ -132,6 +148,13 @@ #define LPC13xx_SPI_SSP0_IRQ_PRIORITY 5 #endif +/** + * @brief SPI1 interrupt priority level setting. + */ +#if !defined(LPC13xx_SPI_SSP1_IRQ_PRIORITY) || defined(__DOXYGEN__) +#define LPC13xx_SPI_SSP1_IRQ_PRIORITY 1 +#endif + /** * @brief Overflow error hook. * @details The default action is to stop the system. @@ -155,7 +178,11 @@ #error "invalid LPC13xx_SPI_SSP0CLKDIV setting" #endif -#if !LPC13xx_SPI_USE_SSP0 +#if (LPC13xx_SPI_SSP1CLKDIV < 1) || (LPC13xx_SPI_SSP1CLKDIV > 255) +#error "invalid LPC13xx_SPI_SSP1CLKDIV setting" +#endif + +#if !LPC13xx_SPI_USE_SSP0 && !LPC13xx_SPI_USE_SSP1 #error "SPI driver activated but no SPI peripheral assigned" #endif @@ -168,8 +195,14 @@ /** * @brief SSP0 clock. */ -#define LPC13xx_SERIAL_SSP0_PCLK \ - (LPC13xx_MAINCLK / LPC13xx_SERIAL_SSP0CLKDIV) +#define LPC13xx_SPI_SSP0_PCLK \ + (LPC13xx_MAINCLK / LPC13xx_SPI_SSP0CLKDIV) + +/** + * @brief SSP1 clock. + */ +#define LPC13xx_SPI_SSP1_PCLK \ + (LPC13xx_MAINCLK / LPC13xx_SPI_SSP1CLKDIV) /*===========================================================================*/ /* Driver data structures and types. */ @@ -281,6 +314,10 @@ struct SPIDriver { extern SPIDriver SPID1; #endif +#if LPC13xx_SPI_USE_SSP1 && !defined(__DOXYGEN__) +extern SPIDriver SPID2; +#endif + #ifdef __cplusplus extern "C" { #endif -- cgit v1.2.3