aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-10-24 10:09:28 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2009-10-24 10:09:28 +0000
commitfb68f0d51775b7e0bafa82fa67573e652babb6a6 (patch)
tree98788291c76294f69bc497d890e82d56fde226bf /os
parent09194e6f2232390b16ed37c65cf750bd47bc4bf4 (diff)
downloadChibiOS-fb68f0d51775b7e0bafa82fa67573e652babb6a6.tar.gz
ChibiOS-fb68f0d51775b7e0bafa82fa67573e652babb6a6.tar.bz2
ChibiOS-fb68f0d51775b7e0bafa82fa67573e652babb6a6.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1251 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/io/platforms/STM32/pal_lld.h6
-rw-r--r--os/io/platforms/STM32/serial_lld.h6
-rw-r--r--os/io/platforms/STM32/spi_lld.c30
-rw-r--r--os/io/platforms/STM32/spi_lld.h44
-rw-r--r--os/io/spi.h11
-rw-r--r--os/io/templates/spi_lld.h8
6 files changed, 80 insertions, 25 deletions
diff --git a/os/io/platforms/STM32/pal_lld.h b/os/io/platforms/STM32/pal_lld.h
index 9c234cac3..479b5e856 100644
--- a/os/io/platforms/STM32/pal_lld.h
+++ b/os/io/platforms/STM32/pal_lld.h
@@ -27,17 +27,11 @@
#ifndef _PAL_LLD_H_
#define _PAL_LLD_H_
-/*
- * Tricks required to make the TRUE/FALSE declaration inside the library
- * compatible.
- */
-#ifndef __STM32F10x_H
#undef FALSE
#undef TRUE
#include <stm32f10x.h>
#define FALSE 0
#define TRUE (!FALSE)
-#endif
/*===========================================================================*/
/* I/O Ports Types and constants. */
diff --git a/os/io/platforms/STM32/serial_lld.h b/os/io/platforms/STM32/serial_lld.h
index ed80f8b5d..b5d32d605 100644
--- a/os/io/platforms/STM32/serial_lld.h
+++ b/os/io/platforms/STM32/serial_lld.h
@@ -27,17 +27,11 @@
#ifndef _SERIAL_LLD_H_
#define _SERIAL_LLD_H_
-/*
- * Tricks required to make the TRUE/FALSE declaration inside the library
- * compatible.
- */
-#ifndef __STM32F10x_H
#undef FALSE
#undef TRUE
#include <stm32f10x.h>
#define FALSE 0
#define TRUE (!FALSE)
-#endif
/*===========================================================================*/
/* Driver pre-compile time settings. */
diff --git a/os/io/platforms/STM32/spi_lld.c b/os/io/platforms/STM32/spi_lld.c
index 4ef99e1ed..5e8ef614e 100644
--- a/os/io/platforms/STM32/spi_lld.c
+++ b/os/io/platforms/STM32/spi_lld.c
@@ -27,11 +27,41 @@
#include <ch.h>
#include <spi.h>
+#include "nvic.h"
+#include "board.h"
+
+#if USE_STM32_SPI1 || defined(__DOXYGEN__)
+/** @brief SPI1 driver identifier.*/
+SPIDriver SPID1;
+#endif
+
+#if USE_STM32_SPI2 || defined(__DOXYGEN__)
+/** @brief SPI2 driver identifier.*/
+SPIDriver SPID2;
+#endif
+
/**
* @brief Low level SPI driver initialization.
*/
void spi_lld_init(void) {
+#if USE_STM32_SPI1
+ spiObjectInit(&SPID1);
+ SPID1.spd_spi = SPI1;
+ SPID1.spd_dmarx = DMA1_Channel2;
+ SPID1.spd_dmatx = DMA1_Channel3;
+ RCC->APB2ENR |= RCC_APB2ENR_SPI1EN;
+ GPIOA->CRH = (GPIOA->CRH & 0x000FFFFF) | 0xB4B00000;
+#endif
+
+#if USE_STM32_SPI2
+ spiObjectInit(&SPID2);
+ SPID2.spd_spi = SPI2;
+ SPID2.spd_dmarx = DMA1_Channel4;
+ SPID2.spd_dmatx = DMA1_Channel5;
+ RCC->APB1ENR |= RCC_APB1ENR_SPI2EN;
+ GPIOB->CRL = (GPIOB->CRL & 0x000FFFFF) | 0xB4B00000;
+#endif
}
/**
diff --git a/os/io/platforms/STM32/spi_lld.h b/os/io/platforms/STM32/spi_lld.h
index 26a70d0a4..23193bc0d 100644
--- a/os/io/platforms/STM32/spi_lld.h
+++ b/os/io/platforms/STM32/spi_lld.h
@@ -27,19 +27,32 @@
#ifndef _SPI_LLD_H_
#define _SPI_LLD_H_
+#undef FALSE
+#undef TRUE
+#include <stm32f10x.h>
+#define FALSE 0
+#define TRUE (!FALSE)
+
/*===========================================================================*/
/* Driver pre-compile time settings. */
/*===========================================================================*/
/**
- * @brief Enables the mutual exclusion APIs on the SPI bus.
+ * @brief SPI1 driver enable switch.
+ * @details If set to @p TRUE the support for SPI is included.
+ * @note The default is @p TRUE.
*/
-#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
-#define SPI_USE_MUTUAL_EXCLUSION TRUE
+#if !defined(USE_STM32_SPI1) || defined(__DOXYGEN__)
+#define USE_STM32_SPI1 TRUE
#endif
-#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
-#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
+/**
+ * @brief SPI1 driver enable switch.
+ * @details If set to @p TRUE the support for SPI is included.
+ * @note The default is @p TRUE.
+ */
+#if !defined(USE_STM32_SPI2) || defined(__DOXYGEN__)
+#define USE_STM32_SPI2 TRUE
#endif
/*===========================================================================*/
@@ -50,9 +63,9 @@
* @brief Driver state machine possible states.
*/
typedef enum {
- SPI_UNINIT = 0,//!< SPI_UNINIT
- SPI_IDLE = 1, //!< SPI_IDLE
- SPI_ACTIVE = 2 //!< SPI_ACTIVE
+ SPI_UNINIT = 0,
+ SPI_IDLE = 1,
+ SPI_ACTIVE = 2
} spistate_t;
/**
@@ -85,16 +98,28 @@ typedef struct {
#endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */
/**
- * Current configuration data.
+ * @brief Current configuration data.
*/
const SPIConfig *spd_config;
/* End of the mandatory fields.*/
+ SPI_TypeDef *spd_spi;
+ DMA_Channel_TypeDef *spd_dmarx;
+ DMA_Channel_TypeDef *spd_dmatx;
} SPIDriver;
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
+/** @cond never*/
+#if USE_STM32_SPI1
+extern SPIDriver SPID1;
+#endif
+
+#if USE_STM32_SPI2
+extern SPIDriver SPID2;
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -106,6 +131,7 @@ extern "C" {
#ifdef __cplusplus
}
#endif
+/** @endcond*/
#endif /* _SPI_LLD_H_ */
diff --git a/os/io/spi.h b/os/io/spi.h
index bb4244944..54409fe76 100644
--- a/os/io/spi.h
+++ b/os/io/spi.h
@@ -27,6 +27,17 @@
#ifndef _SPI_H_
#define _SPI_H_
+/**
+ * @brief Enables the mutual exclusion APIs on the SPI bus.
+ */
+#if !defined(SPI_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
+#define SPI_USE_MUTUAL_EXCLUSION TRUE
+#endif
+
+#if SPI_USE_MUTUAL_EXCLUSION && !CH_USE_MUTEXES && !CH_USE_SEMAPHORES
+#error "SPI_USE_MUTUAL_EXCLUSION requires CH_USE_MUTEXES and/or CH_USE_SEMAPHORES"
+#endif
+
#include "spi_lld.h"
#ifdef __cplusplus
diff --git a/os/io/templates/spi_lld.h b/os/io/templates/spi_lld.h
index 26a70d0a4..37f14781e 100644
--- a/os/io/templates/spi_lld.h
+++ b/os/io/templates/spi_lld.h
@@ -50,9 +50,9 @@
* @brief Driver state machine possible states.
*/
typedef enum {
- SPI_UNINIT = 0,//!< SPI_UNINIT
- SPI_IDLE = 1, //!< SPI_IDLE
- SPI_ACTIVE = 2 //!< SPI_ACTIVE
+ SPI_UNINIT = 0,
+ SPI_IDLE = 1,
+ SPI_ACTIVE = 2
} spistate_t;
/**
@@ -85,7 +85,7 @@ typedef struct {
#endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */
/**
- * Current configuration data.
+ * @brief Current configuration data.
*/
const SPIConfig *spd_config;
/* End of the mandatory fields.*/