aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms/AT91SAM7/spi_lld.h
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-10-17 19:40:36 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-10-17 19:40:36 +0000
commitb7e7258008897b11c6c8bbdc3220a49f3eaed949 (patch)
tree5d88028354554d0fb2823a7837d1f94c1d5794b0 /os/hal/platforms/AT91SAM7/spi_lld.h
parentbef0924474a4180b737e20fac0f27bcd468d1a2f (diff)
downloadChibiOS-b7e7258008897b11c6c8bbdc3220a49f3eaed949.tar.gz
ChibiOS-b7e7258008897b11c6c8bbdc3220a49f3eaed949.tar.bz2
ChibiOS-b7e7258008897b11c6c8bbdc3220a49f3eaed949.zip
Unfinished AT91SAM7 SPI driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2266 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms/AT91SAM7/spi_lld.h')
-rw-r--r--os/hal/platforms/AT91SAM7/spi_lld.h110
1 files changed, 92 insertions, 18 deletions
diff --git a/os/hal/platforms/AT91SAM7/spi_lld.h b/os/hal/platforms/AT91SAM7/spi_lld.h
index 4c5ed4388..db896fe18 100644
--- a/os/hal/platforms/AT91SAM7/spi_lld.h
+++ b/os/hal/platforms/AT91SAM7/spi_lld.h
@@ -31,11 +31,24 @@
#if CH_HAL_USE_SPI || defined(__DOXYGEN__)
/*===========================================================================*/
-/* Device compatibility. SAM7X have 2 SPIs. */
+/* Device compatibility.. */
/*===========================================================================*/
-#if defined (AT91SAM7X256_H)
-#define AT91C_BASE_SPI AT91C_BASE_SPI0
-#define AT91C_ID_SPI AT91C_ID_SPI0
+
+#if defined (AT91C_BASE_SPI)
+#define AT91C_BASE_SPI0 AT91C_BASE_SPI
+#define AT91C_ID_SPI0 AT91C_ID_SPI
+
+#define SPI0_MISO (1 << 12)
+#define SPI0_MOSI (1 << 13)
+#define SPI0_SCK (1 << 14)
+#else
+#define SPI0_MISO (1 << 16)
+#define SPI0_MOSI (1 << 17)
+#define SPI0_SCK (1 << 18)
+
+#define SPI1_MISO (1 << 24)
+#define SPI1_MOSI (1 << 23)
+#define SPI1_SCK (1 << 22)
#endif
/*===========================================================================*/
@@ -47,27 +60,75 @@
/*===========================================================================*/
/**
- * @brief SPI driver enable switch.
+ * @brief SPID1 enable switch (SPI0 device).
* @details If set to @p TRUE the support for SPI0 is included.
* @note The default is @p TRUE.
*/
-#if !defined(USE_AT91SAM7_SPI) || defined(__DOXYGEN__)
-#define USE_AT91SAM7_SPI TRUE
+#if !defined(AT91SAM7_SPI_USE_SPI0) || defined(__DOXYGEN__)
+#define AT91SAM7_SPI_USE_SPI0 TRUE
+#endif
+
+/**
+ * @brief SPID2 enable switch (SPI1 device).
+ * @details If set to @p TRUE the support for SPI1 is included.
+ * @note The default is @p TRUE.
+ */
+#if !defined(AT91SAM7_SPI_USE_SPI1) || defined(__DOXYGEN__)
+#define AT91SAM7_SPI_USE_SPI1 TRUE
+#endif
+
+/**
+ * @brief SPI0 device interrupt priority level setting.
+ */
+#if !defined(AT91SAM7_SPI0_PRIORITY) || defined(__DOXYGEN__)
+#define AT91SAM7_SPI0_PRIORITY (AT91C_AIC_PRIOR_HIGHEST - 1)
+#endif
+
+/**
+ * @brief SPI1 device interrupt priority level setting.
+ */
+#if !defined(AT91SAM7_SPI1_PRIORITY) || defined(__DOXYGEN__)
+#define AT91SAM7_SPI1_PRIORITY (AT91C_AIC_PRIOR_HIGHEST - 1)
#endif
/*===========================================================================*/
/* Derived constants and error checks. */
/*===========================================================================*/
+#if !AT91SAM7_SPI_USE_SPI0 && !AT91SAM7_SPI_USE_SPI1
+#error "SPI driver activated but no SPI peripheral assigned"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
/**
+ * @brief Type of a structure representing an SPI driver.
+ */
+typedef struct SPIDriver SPIDriver;
+
+/**
+ * @brief SPI notification callback type.
+ *
+ * @param[in] spip pointer to the @p SPIDriver object triggering the
+ * callback
+ */
+typedef void (*spicallback_t)(SPIDriver *spip);
+
+/**
* @brief Driver configuration structure.
*/
typedef struct {
/**
+ * @brief Operation complete callback or @p NULL.
+ * @note In order to use synchronous functions this field must be set to
+ * @p NULL, callbacks and synchronous operations are mutually
+ * exclusive.
+ */
+ spicallback_t spc_endcb;
+ /* End of the mandatory fields.*/
+ /**
* @brief The chip select line port.
*/
ioportid_t spc_ssport;
@@ -76,10 +137,6 @@ typedef struct {
*/
uint16_t spc_sspad;
/**
- * @brief SPI Mode Register initialization data.
- */
- uint32_t spc_mr;
- /**
* @brief SPI Chip Select Register initialization data.
*/
uint32_t spc_csr;
@@ -88,11 +145,21 @@ typedef struct {
/**
* @brief Structure representing a SPI driver.
*/
-typedef struct {
+struct SPIDriver {
/**
* @brief Driver state.
*/
spistate_t spd_state;
+ /**
+ * @brief Current configuration data.
+ */
+ const SPIConfig *spd_config;
+#if SPI_USE_WAIT || defined(__DOXYGEN__)
+ /**
+ * @brief Waiting thread.
+ */
+ Thread *spd_thread;
+#endif /* SPI_USE_WAIT */
#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
#if CH_USE_MUTEXES || defined(__DOXYGEN__)
/**
@@ -103,12 +170,15 @@ typedef struct {
Semaphore spd_semaphore;
#endif
#endif /* SPI_USE_MUTUAL_EXCLUSION */
+#if defined(SPI_DRIVER_EXT_FIELDS)
+ SPI_DRIVER_EXT_FIELDS
+#endif
+ /* End of the mandatory fields.*/
/**
- * @brief Current configuration data.
+ * @brief Pointer to the SPIx registers block.
*/
- const SPIConfig *spd_config;
- /* End of the mandatory fields.*/
-} SPIDriver;
+ AT91PS_SPI spd_spi;
+};
/*===========================================================================*/
/* Driver macros. */
@@ -118,8 +188,12 @@ typedef struct {
/* External declarations. */
/*===========================================================================*/
-#if USE_AT91SAM7_SPI && !defined(__DOXYGEN__)
-extern SPIDriver SPID;
+#if AT91SAM7_SPI_USE_SPI0 && !defined(__DOXYGEN__)
+extern SPIDriver SPID1;
+#endif
+
+#if AT91SAM7_SPI_USE_SPI1 && !defined(__DOXYGEN__)
+extern SPIDriver SPID2;
#endif
#ifdef __cplusplus