aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/platforms
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-02 19:25:44 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2012-01-02 19:25:44 +0000
commite43bc0f96757b20d256d117e42289ffa92c2d296 (patch)
tree4292bed36e44c54a7e2ccdbb9181f6f86b0cc46b /os/hal/platforms
parent68580cf650b16b3b62116d71d94b3a7bb84ceec7 (diff)
downloadChibiOS-e43bc0f96757b20d256d117e42289ffa92c2d296.tar.gz
ChibiOS-e43bc0f96757b20d256d117e42289ffa92c2d296.tar.bz2
ChibiOS-e43bc0f96757b20d256d117e42289ffa92c2d296.zip
I2C. Clock checks moved to header file.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3713 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms')
-rw-r--r--os/hal/platforms/STM32/i2c_lld.c35
-rw-r--r--os/hal/platforms/STM32/i2c_lld.h34
2 files changed, 35 insertions, 34 deletions
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c
index 51e41d4fe..2641e54b9 100644
--- a/os/hal/platforms/STM32/i2c_lld.c
+++ b/os/hal/platforms/STM32/i2c_lld.c
@@ -95,9 +95,6 @@ restrictions.
/* Driver constants. */
/*===========================================================================*/
-/* Peripheral clock frequency */
-#define I2C_CLK_FREQ ((STM32_PCLK1) / 1000000)
-
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
@@ -144,40 +141,10 @@ static void i2c_lld_set_clock(I2CDriver *i2cp) {
chDbgCheck((i2cp != NULL) && (clock_speed > 0) && (clock_speed <= 4000000),
"i2c_lld_set_clock");
+
/**
* CR2 Configuration
*/
-#if defined(STM32F4XX)
- #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 42))
- #error "Peripheral clock freq. out of range."
- #endif
-
-#elif defined(STM32L1XX_MD)
- #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 32))
- #error "Peripheral clock freq. out of range."
- #endif
-
-#elif defined(STM32F2XX)
- #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 30))
- #error "Peripheral clock freq. out of range."
- #endif
-
-#elif defined(STM32F10X_LD_VL) || defined(STM32F10X_MD_VL) || \
- defined(STM32F10X_HD_VL)
- #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 24))
- #error "Peripheral clock freq. out of range."
- #endif
-
-#elif defined(STM32F10X_LD) || defined(STM32F10X_MD) || \
- defined(STM32F10X_HD) || defined(STM32F10X_XL) || \
- defined(STM32F10X_CL)
- #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 36))
- #error "Peripheral clock freq. out of range."
- #endif
-
-#else
-#error "unspecified, unsupported or invalid STM32 platform"
-#endif
i2cp->i2c->CR2 &= (uint16_t)~I2C_CR2_FREQ; /* Clear frequency FREQ[5:0] bits */
i2cp->i2c->CR2 |= (uint16_t)I2C_CLK_FREQ;
diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h
index f770be615..75c877a3a 100644
--- a/os/hal/platforms/STM32/i2c_lld.h
+++ b/os/hal/platforms/STM32/i2c_lld.h
@@ -163,6 +163,12 @@
#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#endif /* !STM32_ADVANCED_DMA*/
+
+/**
+ * @brief Peripheral clock frequency.
+ */
+#define I2C_CLK_FREQ ((STM32_PCLK1) / 1000000)
+
/** @} */
/*===========================================================================*/
@@ -234,6 +240,34 @@
#define STM32_DMA_REQUIRED
#endif
+/* Check clock range. */
+#if defined(STM32F4XX)
+ #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 42))
+ #error "Peripheral clock freq. out of range."
+ #endif
+#elif defined(STM32L1XX_MD)
+ #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 32))
+ #error "Peripheral clock freq. out of range."
+ #endif
+#elif defined(STM32F2XX)
+ #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 30))
+ #error "Peripheral clock freq. out of range."
+ #endif
+#elif defined(STM32F10X_LD_VL) || defined(STM32F10X_MD_VL) || \
+ defined(STM32F10X_HD_VL)
+ #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 24))
+ #error "Peripheral clock freq. out of range."
+ #endif
+#elif defined(STM32F10X_LD) || defined(STM32F10X_MD) || \
+ defined(STM32F10X_HD) || defined(STM32F10X_XL) || \
+ defined(STM32F10X_CL)
+ #if (!(I2C_CLK_FREQ >= 2) && (I2C_CLK_FREQ <= 36))
+ #error "Peripheral clock freq. out of range."
+ #endif
+#else
+#error "unspecified, unsupported or invalid STM32 platform"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/