diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-05-04 13:12:34 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-05-04 13:12:34 +0000 |
commit | 2459b2beb0af669675d93c57fc132c734981667c (patch) | |
tree | fd276316ef2370891af913a810ce0d7db0512220 /os/hal/src | |
parent | 57fb5e703ba8ab824d1849d7436abd64684caf20 (diff) | |
download | ChibiOS-2459b2beb0af669675d93c57fc132c734981667c.tar.gz ChibiOS-2459b2beb0af669675d93c57fc132c734981667c.tar.bz2 ChibiOS-2459b2beb0af669675d93c57fc132c734981667c.zip |
I2C. My driver really sucks. I'll try to use alberto driver with my improvements
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2918 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/src')
-rw-r--r-- | os/hal/src/i2c_brts.c | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/os/hal/src/i2c_brts.c b/os/hal/src/i2c_brts.c index 5a0471e0f..ad9a5d0ac 100644 --- a/os/hal/src/i2c_brts.c +++ b/os/hal/src/i2c_brts.c @@ -69,6 +69,19 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP;
i2cp->id_config = NULL;
i2cp->id_slave_config = NULL;
+
+#if I2C_USE_WAIT
+ i2cp->id_thread = NULL;
+#endif /* I2C_USE_WAIT */
+
+#if I2C_USE_MUTUAL_EXCLUSION
+#if CH_USE_MUTEXES
+ chMtxInit(&i2cp->id_mutex);
+#else
+ chSemInit(&i2cp->id_semaphore, 1);
+#endif /* CH_USE_MUTEXES */
+#endif /* I2C_USE_MUTUAL_EXCLUSION */
+
#if defined(I2C_DRIVER_EXT_INIT_HOOK)
I2C_DRIVER_EXT_INIT_HOOK(i2cp);
#endif
@@ -117,13 +130,37 @@ void i2cStop(I2CDriver *i2cp) { }
/**
+ * @brief Generate (re)start on the bus.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ */
+void i2cMasterStart(I2CDriver *i2cp){
+
+ chDbgCheck((i2cp != NULL), "i2cMasterTransmit");
+
+ chSysLock();
+ i2c_lld_master_start(i2cp);
+ chSysUnlock();
+}
+
+/**
+ * @brief Generate stop on the bus.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ */
+void i2cMasterStop(I2CDriver *i2cp){
+
+ chDbgCheck((i2cp != NULL), "i2cMasterTransmit");
+ chSysLock();
+ i2c_lld_master_stop(i2cp);
+ chSysUnlock();
+}
+
+/**
* @brief Sends data ever the I2C bus.
*
* @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] slave_addr1 7-bit address of the slave
- * @param[in] slave_addr1 used in 10-bit address mode
- * @param[in] n number of words to send
- * @param[in] txbuf the pointer to the transmit buffer
+ * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object
*
*/
void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) {
@@ -134,19 +171,17 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1",
"not active");
- i2c_lld_master_transmitI(i2cp, i2cscfg);
+ chSysLock();
+ i2c_lld_master_transmit(i2cp, i2cscfg);
+ chSysUnlock();
}
/**
* @brief Receives data from the I2C bus.
*
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] slave_addr1 7-bit address of the slave
- * @param[in] slave_addr1 used in 10-bit address mode
- * @param[in] n number of words to receive
- * @param[out] rxbuf the pointer to the receive buffer
- *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object
*/
void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) {
@@ -156,14 +191,13 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1",
"not active");
- i2c_lld_master_receiveI(i2cp, i2cscfg);
+ chSysLock();
+ i2c_lld_master_receive(i2cp, i2cscfg);
+ chSysUnlock();
}
-
-
-
#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
/**
* @brief Gains exclusive access to the I2C bus.
|