aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/LPC13xx
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-20 09:16:12 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-05-20 09:16:12 +0000
commit31149b2ffb6b73f7d9c6f1e0c2e69c7f244e831d (patch)
treeb207dfb2b3b2e68cf48409d5e51898514303217f /os/hal/platforms/LPC13xx
parent9be1c67db2a0004db4458d0b5fa7fd31c1868a34 (diff)
downloadChibiOS-31149b2ffb6b73f7d9c6f1e0c2e69c7f244e831d.tar.gz
ChibiOS-31149b2ffb6b73f7d9c6f1e0c2e69c7f244e831d.tar.bz2
ChibiOS-31149b2ffb6b73f7d9c6f1e0c2e69c7f244e831d.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4220 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/LPC13xx')
-rw-r--r--os/hal/platforms/LPC13xx/spi_lld.c46
-rw-r--r--os/hal/platforms/LPC13xx/spi_lld.h43
2 files changed, 86 insertions, 3 deletions
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 */
}
/**
@@ -190,6 +219,15 @@ void spi_lld_start(SPIDriver *spip) {
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.*/
spip->ssp->CR1 = 0;
@@ -220,6 +258,14 @@ void spi_lld_stop(SPIDriver *spip) {
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
@@ -119,6 +119,15 @@
#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.
*/
#if !defined(LPC13xx_SPI_SSP0CLKDIV) || defined(__DOXYGEN__)
@@ -126,6 +135,13 @@
#endif
/**
+ * @brief SSP1 PCLK divider.
+ */
+#if !defined(LPC13xx_SPI_SSP1CLKDIV) || defined(__DOXYGEN__)
+#define LPC13xx_SPI_SSP1CLKDIV 1
+#endif
+
+/**
* @brief SPI0 interrupt priority level setting.
*/
#if !defined(LPC13xx_SPI_SSP0_IRQ_PRIORITY) || defined(__DOXYGEN__)
@@ -133,6 +149,13 @@
#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