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
This commit is contained in:
barthess 2012-01-02 19:25:44 +00:00
parent 68580cf650
commit e43bc0f967
2 changed files with 35 additions and 34 deletions

View File

@ -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;

View File

@ -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. */
/*===========================================================================*/