From 31149b2ffb6b73f7d9c6f1e0c2e69c7f244e831d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 20 May 2012 09:16:12 +0000 Subject: [PATCH] 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 ++++++++++++++++++++++-- os/ports/GCC/ARMCMx/LPC13xx/vectors.c | 7 +++- os/ports/IAR/ARMCMx/LPC13xx/vectors.s | 6 ++++ os/ports/RVCT/ARMCMx/LPC13xx/vectors.s | 6 ++++ readme.txt | 1 + 7 files changed, 109 insertions(+), 8 deletions(-) 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 diff --git a/os/ports/GCC/ARMCMx/LPC13xx/vectors.c b/os/ports/GCC/ARMCMx/LPC13xx/vectors.c index 9c902c670..350e8d0aa 100644 --- a/os/ports/GCC/ARMCMx/LPC13xx/vectors.c +++ b/os/ports/GCC/ARMCMx/LPC13xx/vectors.c @@ -103,6 +103,8 @@ extern void Vector110(void); extern void Vector114(void); extern void Vector118(void); extern void Vector11C(void); +extern void Vector120(void); +extern void Vector124(void); #endif /** @@ -129,7 +131,8 @@ void (*_vectors[])(void) = { VectorE0, VectorE4, VectorE8, VectorEC, VectorF0, VectorF4, VectorF8, VectorFC, Vector100, Vector104, Vector108, Vector10C, - Vector110, Vector114, Vector118, Vector11C + Vector110, Vector114, Vector118, Vector11C, + Vector120, Vector124 }; /** @@ -218,5 +221,7 @@ void Vector110(void) __attribute__((weak, alias("_unhandled_exception"))); void Vector114(void) __attribute__((weak, alias("_unhandled_exception"))); void Vector118(void) __attribute__((weak, alias("_unhandled_exception"))); void Vector11C(void) __attribute__((weak, alias("_unhandled_exception"))); +void Vector120(void) __attribute__((weak, alias("_unhandled_exception"))); +void Vector124(void) __attribute__((weak, alias("_unhandled_exception"))); /** @} */ diff --git a/os/ports/IAR/ARMCMx/LPC13xx/vectors.s b/os/ports/IAR/ARMCMx/LPC13xx/vectors.s index ff8dc4993..9b764501b 100644 --- a/os/ports/IAR/ARMCMx/LPC13xx/vectors.s +++ b/os/ports/IAR/ARMCMx/LPC13xx/vectors.s @@ -104,6 +104,8 @@ __vector_table: DCD Vector114 DCD Vector118 DCD Vector11C + DCD Vector120 + DCD Vector124 /* * Default interrupt handlers. @@ -178,6 +180,8 @@ __vector_table: PUBWEAK Vector114 PUBWEAK Vector118 PUBWEAK Vector11C + PUBWEAK Vector120 + PUBWEAK Vector124 PUBLIC _unhandled_exception SECTION .text:CODE:REORDER(1) @@ -253,6 +257,8 @@ Vector110 Vector114 Vector118 Vector11C +Vector120 +Vector124 _unhandled_exception b _unhandled_exception diff --git a/os/ports/RVCT/ARMCMx/LPC13xx/vectors.s b/os/ports/RVCT/ARMCMx/LPC13xx/vectors.s index 2c5cf2dd1..eeefa3aab 100644 --- a/os/ports/RVCT/ARMCMx/LPC13xx/vectors.s +++ b/os/ports/RVCT/ARMCMx/LPC13xx/vectors.s @@ -99,6 +99,8 @@ __Vectors DCD Vector114 DCD Vector118 DCD Vector11C + DCD Vector120 + DCD Vector124 AREA |.text|, CODE, READONLY THUMB @@ -178,6 +180,8 @@ _unhandled_exception PROC EXPORT Vector114 [WEAK] EXPORT Vector118 [WEAK] EXPORT Vector11C [WEAK] + EXPORT Vector120 [WEAK] + EXPORT Vector124 [WEAK] NMIVector HardFaultVector @@ -249,6 +253,8 @@ Vector110 Vector114 Vector118 Vector11C +Vector120 +Vector124 b _unhandled_exception ENDP diff --git a/readme.txt b/readme.txt index e39eb2c0b..a09aee449 100644 --- a/readme.txt +++ b/readme.txt @@ -131,6 +131,7 @@ 3484947)(backported to 2.4.1). - FIX: Fixed various minor documentation errors (bug 3484942)(backported to 2.4.1). +- NEW: Added SSP1 capability to the LPC13xx SPI driver. - NEW: Updated vendor headers for LPC11xx and LPC13xx, the new headers support several new devices. - NEW: Demo for STM32F0-Discovery board.