From 8b45c58317683148179c9964e67c8f7d0683257b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 17 Aug 2010 08:50:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2132 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 222 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c new file mode 100644 index 000000000..03d882446 --- /dev/null +++ b/os/hal/src/i2c.c @@ -0,0 +1,222 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file i2c.c + * @brief I2C Driver code. + * + * @addtogroup I2C + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if CH_HAL_USE_I2C || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief I2C Driver initialization. + */ +void i2cInit(void) { + + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cObjectInit(I2CDriver *i2cp) { + + i2cp->i2c_state = I2C_STOP; + i2cp->i2c_config = NULL; +} + +/** + * @brief Configures and activates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] config pointer to the @p I2CConfig object + */ +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + "i2cStart(), #1", + "invalid state"); + i2cp->i2c_config = config; + i2c_lld_start(i2cp); + i2cp->i2c_state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + "i2cStop(), #1", + "invalid state"); + i2c_lld_stop(i2cp); + i2cp->i2c_state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Initiates a master bus transaction. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] callback operation complete callback + */ +void i2cMasterStartI(I2CDriver *i2cp, i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); + chDbgAssert((i2cp->i2c_state == I2C_READY) || (i2cp->i2c_state == I2C_MREADY), + "i2cMasterStartI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_start(i2cp); +} + +/** + * @brief Terminates a master bus transaction. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] callback operation complete callback + */ +void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterStopI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_stop(i2cp); +} + +/** + * @brief Master transmission. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] n number of bytes to be transmitted + * @param[in] txbuf transmit data buffer pointer + * @param[in] callback operation complete callback + */ +void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, + i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (n > 0) && + (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterTransmitI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_transmit(i2cp, n, txbuf); +} + +/** + * @brief Master receive. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] n number of bytes to be transmitted + * @param[in] rxbuf receive data buffer pointer + * @param[in] callback operation complete callback + */ +void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, + i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (n > 0) && + (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterReceiveI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_receive(i2cp, n, rxbuf); +} + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->id_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->id_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->id_semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_I2C */ + +/** @} */ -- cgit v1.2.3 From 4e26a3b42cb49974f63d1b8727d7b1d1830c9c81 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 17 Aug 2010 13:23:41 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2133 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 03d882446..cc48c4147 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -104,19 +104,24 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Initiates a master bus transaction. + * @brief Initiates a master bus transaction. + * @details This function sends a start bit followed by an one or two bytes + * header. * * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] header transaction header * @param[in] callback operation complete callback */ -void i2cMasterStartI(I2CDriver *i2cp, i2ccallback_t callback) { +void i2cMasterStartI(I2CDriver *i2cp, + uint16_t header, + i2ccallback_t callback) { chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); - chDbgAssert((i2cp->i2c_state == I2C_READY) || (i2cp->i2c_state == I2C_MREADY), + chDbgAssert(i2cp->i2c_state == I2C_READY, "i2cMasterStartI(), #1", "invalid state"); i2cp->id_callback = callback; - i2c_lld_master_start(i2cp); + i2c_lld_master_start(i2cp, header); } /** @@ -135,6 +140,24 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { i2c_lld_master_stop(i2cp); } + +/** + * @brief Sends a restart bit. + * @details Restart bits are required by some types of I2C transactions. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] callback operation complete callback + */ +void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { + + chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); + chDbgAssert(i2cp->i2c_state == I2C_MREADY, + "i2cMasterRestartI(), #1", "invalid state"); + + i2cp->id_callback = callback; + i2c_lld_master_restart(i2cp); +} + /** * @brief Master transmission. * -- cgit v1.2.3 From 2891f7d645c4be187ac96ee4011207531d25c34a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 4 Oct 2010 17:16:18 +0000 Subject: Documentation improvements, fixed a small error in the STM32 serial driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2234 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index cc48c4147..1a55f53cd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -48,6 +48,8 @@ /** * @brief I2C Driver initialization. + * + * @init */ void i2cInit(void) { @@ -58,6 +60,8 @@ void i2cInit(void) { * @brief Initializes the standard part of a @p I2CDriver structure. * * @param[in] i2cp pointer to the @p I2CDriver object + * + * @init */ void i2cObjectInit(I2CDriver *i2cp) { @@ -70,6 +74,8 @@ void i2cObjectInit(I2CDriver *i2cp) { * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] config pointer to the @p I2CConfig object + * + * @api */ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { @@ -89,6 +95,8 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { * @brief Deactivates the I2C peripheral. * * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api */ void i2cStop(I2CDriver *i2cp) { @@ -111,6 +119,8 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] header transaction header * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterStartI(I2CDriver *i2cp, uint16_t header, @@ -129,6 +139,8 @@ void i2cMasterStartI(I2CDriver *i2cp, * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { @@ -147,6 +159,8 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { @@ -165,6 +179,8 @@ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { * @param[in] n number of bytes to be transmitted * @param[in] txbuf transmit data buffer pointer * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, i2ccallback_t callback) { @@ -185,6 +201,8 @@ void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, * @param[in] n number of bytes to be transmitted * @param[in] rxbuf receive data buffer pointer * @param[in] callback operation complete callback + * + * @iclass */ void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, i2ccallback_t callback) { @@ -203,11 +221,13 @@ void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, * @brief Gains exclusive access to the I2C bus. * @details This function tries to gain ownership to the I2C bus, if the bus * is already being used then the invoking thread is queued. - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * + * @api + * */ void i2cAcquireBus(I2CDriver *i2cp) { @@ -222,10 +242,12 @@ void i2cAcquireBus(I2CDriver *i2cp) { /** * @brief Releases exclusive access to the I2C bus. - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api */ void i2cReleaseBus(I2CDriver *i2cp) { -- cgit v1.2.3 From 7c2a8e13d969029fb675e67c57349c1deaa09284 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 11 Oct 2010 11:48:03 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2246 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 1a55f53cd..7558d6741 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -65,8 +65,11 @@ void i2cInit(void) { */ void i2cObjectInit(I2CDriver *i2cp) { - i2cp->i2c_state = I2C_STOP; - i2cp->i2c_config = NULL; + i2cp->i2c_state = I2C_STOP; + i2cp->i2c_config = NULL; +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif } /** -- cgit v1.2.3 From d8be44136c1e6d02ee105ac0791f9e6732551fec Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 1 Nov 2010 17:29:56 +0000 Subject: Fixed bug 3100946, renamed HAL switches removing the CH_ part. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2326 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 7558d6741..b432fa89f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -28,7 +28,7 @@ #include "ch.h" #include "hal.h" -#if CH_HAL_USE_I2C || defined(__DOXYGEN__) +#if HAL_USE_I2C || defined(__DOXYGEN__) /*===========================================================================*/ /* Driver exported variables. */ @@ -265,6 +265,6 @@ void i2cReleaseBus(I2CDriver *i2cp) { } #endif /* I2C_USE_MUTUAL_EXCLUSION */ -#endif /* CH_HAL_USE_I2C */ +#endif /* HAL_USE_I2C */ /** @} */ -- cgit v1.2.3 From 7aa43aee7029b232c558174bcbdf90e8fbebd57b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Dec 2010 08:31:56 +0000 Subject: Documentation improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2490 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b432fa89f..429d4b521 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -48,6 +48,8 @@ /** * @brief I2C Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. * * @init */ -- cgit v1.2.3 From 24cb881726f09c6bccba471b40bde76dc27036c7 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 4 Jan 2011 15:08:29 +0000 Subject: Documentation related fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2580 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 429d4b521..2b5971b6f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -61,7 +61,7 @@ void i2cInit(void) { /** * @brief Initializes the standard part of a @p I2CDriver structure. * - * @param[in] i2cp pointer to the @p I2CDriver object + * @param[out] i2cp pointer to the @p I2CDriver object * * @init */ -- cgit v1.2.3 From 063c6e138d59529b911235fe537bdefe60e0cfb8 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 25 Jan 2011 18:59:18 +0000 Subject: Initial commit of I2C driver code git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2684 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 163 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 103 insertions(+), 60 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 2b5971b6f..273bb5933 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -54,7 +54,6 @@ * @init */ void i2cInit(void) { - i2c_lld_init(); } @@ -67,8 +66,9 @@ void i2cInit(void) { */ void i2cObjectInit(I2CDriver *i2cp) { - i2cp->i2c_state = I2C_STOP; - i2cp->i2c_config = NULL; + i2cp->id_state = I2C_STOP; + i2cp->id_config = NULL; + i2cp->id_slave_config = NULL; #if defined(I2C_DRIVER_EXT_INIT_HOOK) I2C_DRIVER_EXT_INIT_HOOK(i2cp); #endif @@ -82,17 +82,17 @@ void i2cObjectInit(I2CDriver *i2cp) { * * @api */ -void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { +void i2cStart(I2CDriver *i2cp, I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); chSysLock(); - chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), "i2cStart(), #1", "invalid state"); - i2cp->i2c_config = config; + i2cp->id_config = config; i2c_lld_start(i2cp); - i2cp->i2c_state = I2C_READY; + i2cp->id_state = I2C_READY; chSysUnlock(); } @@ -108,13 +108,56 @@ void i2cStop(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cStop"); chSysLock(); - chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY), + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), "i2cStop(), #1", "invalid state"); i2c_lld_stop(i2cp); - i2cp->i2c_state = I2C_STOP; + i2cp->id_state = I2C_STOP; 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 + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, const void *txbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), + "i2cSend"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cSend(), #1", + "not active"); + + //i2c_lld_master_transmit(i2cp, slave_addr1, slave_addr2, n, txbuf); + +} + +/** + * @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 + * + */ +void i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, void *rxbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cReceive"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cReceive(), #1", + "not active"); + + //i2c_lld_master_receive(i2cp, slave_addr1, slave_addr2, n, rxbuf); + +} /** * @brief Initiates a master bus transaction. @@ -127,17 +170,17 @@ void i2cStop(I2CDriver *i2cp) { * * @iclass */ -void i2cMasterStartI(I2CDriver *i2cp, - uint16_t header, - i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); - chDbgAssert(i2cp->i2c_state == I2C_READY, - "i2cMasterStartI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_start(i2cp, header); -} +//void i2cMasterStartI(I2CDriver *i2cp, +// uint16_t header, +// i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); +// chDbgAssert(i2cp->id_state == I2C_READY, +// "i2cMasterStartI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_start(i2cp, header); +//} /** * @brief Terminates a master bus transaction. @@ -147,15 +190,15 @@ void i2cMasterStartI(I2CDriver *i2cp, * * @iclass */ -void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterStopI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_stop(i2cp); -} +//void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterStopI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_stop(i2cp); +//} /** @@ -167,15 +210,15 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { * * @iclass */ -void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterRestartI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_restart(i2cp); -} +//void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterRestartI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_restart(i2cp); +//} /** * @brief Master transmission. @@ -187,17 +230,17 @@ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { * * @iclass */ -void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, - i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (n > 0) && - (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterTransmitI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_transmit(i2cp, n, txbuf); -} +//void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, +// i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (n > 0) && +// (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterTransmitI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_transmit(i2cp, n, txbuf); +//} /** * @brief Master receive. @@ -209,17 +252,17 @@ void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, * * @iclass */ -void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, - i2ccallback_t callback) { - - chDbgCheck((i2cp != NULL) && (n > 0) && - (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); - chDbgAssert(i2cp->i2c_state == I2C_MREADY, - "i2cMasterReceiveI(), #1", "invalid state"); - - i2cp->id_callback = callback; - i2c_lld_master_receive(i2cp, n, rxbuf); -} +//void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, +// i2ccallback_t callback) { +// +// chDbgCheck((i2cp != NULL) && (n > 0) && +// (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); +// chDbgAssert(i2cp->id_state == I2C_MREADY, +// "i2cMasterReceiveI(), #1", "invalid state"); +// +// i2cp->id_callback = callback; +// i2c_lld_master_receive(i2cp, n, rxbuf); +//} #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** -- cgit v1.2.3 From 9c45802837b9053bbe32a8c8d5688cbf8c5d2706 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 25 Jan 2011 21:25:10 +0000 Subject: I2C. Some hy level functions created and tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2686 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 124 ++++++------------------------------------------------- 1 file changed, 12 insertions(+), 112 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 273bb5933..e621c652d 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -115,6 +115,7 @@ void i2cStop(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; chSysUnlock(); } + /** * @brief Sends data ever the I2C bus. * @@ -125,18 +126,18 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] txbuf the pointer to the transmit buffer * */ -void i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, const void *txbuf) { +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart) { - chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), - "i2cSend"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterTransmit"); chDbgAssert(i2cp->id_state == I2C_READY, - "i2cSend(), #1", + "i2cMasterTransmit(), #1", "not active"); - //i2c_lld_master_transmit(i2cp, slave_addr1, slave_addr2, n, txbuf); - + i2c_lld_master_transmit(i2cp, i2cscfg, restart); } + /** * @brief Receives data from the I2C bus. * @@ -147,122 +148,21 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2 * @param[out] rxbuf the pointer to the receive buffer * */ -void i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr1, uint8_t slave_addr2, size_t n, void *rxbuf) { +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), - "i2cReceive"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterReceive"); chDbgAssert(i2cp->id_state == I2C_READY, - "i2cReceive(), #1", + "i2cMasterReceive(), #1", "not active"); - //i2c_lld_master_receive(i2cp, slave_addr1, slave_addr2, n, rxbuf); - + i2c_lld_master_receive(i2cp, i2cscfg); } -/** - * @brief Initiates a master bus transaction. - * @details This function sends a start bit followed by an one or two bytes - * header. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] header transaction header - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterStartI(I2CDriver *i2cp, -// uint16_t header, -// i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI"); -// chDbgAssert(i2cp->id_state == I2C_READY, -// "i2cMasterStartI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_start(i2cp, header); -//} - -/** - * @brief Terminates a master bus transaction. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterStopI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_stop(i2cp); -//} -/** - * @brief Sends a restart bit. - * @details Restart bits are required by some types of I2C transactions. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterRestartI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_restart(i2cp); -//} -/** - * @brief Master transmission. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] n number of bytes to be transmitted - * @param[in] txbuf transmit data buffer pointer - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf, -// i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (n > 0) && -// (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterTransmitI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_transmit(i2cp, n, txbuf); -//} -/** - * @brief Master receive. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] n number of bytes to be transmitted - * @param[in] rxbuf receive data buffer pointer - * @param[in] callback operation complete callback - * - * @iclass - */ -//void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf, -// i2ccallback_t callback) { -// -// chDbgCheck((i2cp != NULL) && (n > 0) && -// (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI"); -// chDbgAssert(i2cp->id_state == I2C_MREADY, -// "i2cMasterReceiveI(), #1", "invalid state"); -// -// i2cp->id_callback = callback; -// i2c_lld_master_receive(i2cp, n, rxbuf); -//} #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** -- cgit v1.2.3 From f4bdefbd11466c09dbf47f3eb680c33987a12172 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 30 Jan 2011 21:19:51 +0000 Subject: I2C. Async transmit done. Need much of testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2697 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index e621c652d..5a0471e0f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -126,7 +126,7 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] txbuf the pointer to the transmit buffer * */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart) { +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), "i2cMasterTransmit"); @@ -134,7 +134,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart) "i2cMasterTransmit(), #1", "not active"); - i2c_lld_master_transmit(i2cp, i2cscfg, restart); + i2c_lld_master_transmitI(i2cp, i2cscfg); } @@ -156,7 +156,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); - i2c_lld_master_receive(i2cp, i2cscfg); + i2c_lld_master_receiveI(i2cp, i2cscfg); } -- cgit v1.2.3 From 34f9fdfb6260e91ae827a4b6edd49631c116576a Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 14:53:42 +0000 Subject: I2C. Move barthess driver to backup files. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2709 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 215 ------------------------------------------------------- 1 file changed, 215 deletions(-) delete mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c deleted file mode 100644 index 5a0471e0f..000000000 --- a/os/hal/src/i2c.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file i2c.c - * @brief I2C Driver code. - * - * @addtogroup I2C - * @{ - */ - -#include "ch.h" -#include "hal.h" - -#if HAL_USE_I2C || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Driver exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver exported functions. */ -/*===========================================================================*/ - -/** - * @brief I2C Driver initialization. - * @note This function is implicitly invoked by @p halInit(), there is - * no need to explicitly initialize the driver. - * - * @init - */ -void i2cInit(void) { - i2c_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p I2CDriver structure. - * - * @param[out] i2cp pointer to the @p I2CDriver object - * - * @init - */ -void i2cObjectInit(I2CDriver *i2cp) { - - i2cp->id_state = I2C_STOP; - i2cp->id_config = NULL; - i2cp->id_slave_config = NULL; -#if defined(I2C_DRIVER_EXT_INIT_HOOK) - I2C_DRIVER_EXT_INIT_HOOK(i2cp); -#endif -} - -/** - * @brief Configures and activates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] config pointer to the @p I2CConfig object - * - * @api - */ -void i2cStart(I2CDriver *i2cp, I2CConfig *config) { - - chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - - chSysLock(); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), - "i2cStart(), #1", - "invalid state"); - i2cp->id_config = config; - i2c_lld_start(i2cp); - i2cp->id_state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - */ -void i2cStop(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cStop"); - - chSysLock(); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), - "i2cStop(), #1", - "invalid state"); - i2c_lld_stop(i2cp); - i2cp->id_state = I2C_STOP; - 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 - * - */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterTransmit"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", - "not active"); - - i2c_lld_master_transmitI(i2cp, i2cscfg); -} - - -/** - * @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 - * - */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterReceive"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterReceive(), #1", - "not active"); - - i2c_lld_master_receiveI(i2cp, i2cscfg); -} - - - - - - -#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus - * is already being used then the invoking thread is queued. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - * - */ -void i2cAcquireBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&i2cp->id_semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the I2C bus. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @api - */ -void i2cReleaseBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cReleaseBus"); - -#if CH_USE_MUTEXES - (void)i2cp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->id_semaphore); -#endif -} -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#endif /* HAL_USE_I2C */ - -/** @} */ -- cgit v1.2.3 From aad95ce0637a96ee81e60c5251a1a5851b6dfb7d Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 14:55:56 +0000 Subject: I2C. Added driver from albi. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2710 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 268 insertions(+) create mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c new file mode 100644 index 000000000..64bed78eb --- /dev/null +++ b/os/hal/src/i2c.c @@ -0,0 +1,268 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2C || defined(__DOXYGEN__) + +/** + * @brief I2C Driver initialization. + */ +void i2cInit(void) { + + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cObjectInit(I2CDriver *i2cp) { + chEvtInit(&i2cp->sevent); + i2cp->errors = I2CD_NO_ERROR; + i2cp->state = I2C_STOP; +// i2cp->i2cd_config = NULL; +#if I2C_USE_WAIT + i2cp->thread = NULL; +#endif /* I2C_USE_WAIT */ +#if I2C_USE_MUTUAL_EXCLUSION +#if CH_USE_MUTEXES + chMtxInit(&i2cp->mutex); +#elif CH_USE_SEMAPHORES + chSemInit(&i2cp->semaphore, 1); +#endif +#endif /* I2C_USE_MUTUAL_EXCLUSION */ +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif +} + +/** + * @brief Configures and activates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] config pointer to the @p I2CConfig object + */ +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->state == I2C_STOP)||(i2cp->state == I2C_READY), + "i2cStart(), #1", "invalid state"); + + i2cp->nbit_address = config->nBitAddress; + i2c_lld_start(i2cp); + i2c_lld_set_clock(i2cp, config->ClockSpeed, config->FastModeDutyCycle); + i2c_lld_set_opmode(i2cp, config->opMode); + i2c_lld_set_own_address(i2cp, config->OwnAddress1, config->nBitAddress); + i2cp->state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + "i2cStop(), #1", "invalid state"); + i2c_lld_stop(i2cp); + i2cp->state = I2C_STOP; + chSysUnlock(); +} + +/** + * @brief Sends data ever the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr 7-bit or 10-bit address of the slave + * @param[in] n number of words to send + * @param[in] txbuf the pointer to the transmit buffer + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *txbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), + "i2cMasterTransmit"); + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif + + chSysLock(); + chDbgAssert(i2cp->state == I2C_READY, + "i2cMasterTransmit(), #1", "not ready"); + + i2cp->state = I2C_ACTIVE; + i2c_lld_master_transmit(i2cp, slave_addr, n, txbuf); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->state == I2C_COMPLETE) + i2cp->state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Receives data from the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] slave_addr 7-bit or 10-bit address of the slave + * @param[in] n number of bytes to receive + * @param[out] rxbuf the pointer to the receive buffer + * + */ +void i2cMasterReceive(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *rxbuf) { + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cMasterReceive"); + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif + + chSysLock(); + chDbgAssert(i2cp->state == I2C_READY, + "i2cMasterReceive(), #1", "not ready"); + + i2cp->state = I2C_ACTIVE; + i2c_lld_master_receive(i2cp, slave_addr, n, rxbuf); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->state == I2C_COMPLETE) + i2cp->state = I2C_READY; + chSysUnlock(); +} + +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp) { + uint16_t slv_addr; + + i2cMasterReceive(i2cp, 0x0C, 2, &slv_addr); + return slv_addr; +} + + +/** + * @brief Handles communication events/errors. + * @details Must be called from the I/O interrupt service routine in order to + * notify I/O conditions as errors, signals change etc. + * + * @param[in] i2cp pointer to a @p I2CDriver structure + * @param[in] mask condition flags to be added to the mask + * + * @iclass + */ +void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { + + chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); + + i2cp->errors |= mask; + chEvtBroadcastI(&i2cp->sevent); +} + +/** + * @brief Returns and clears the errors mask associated to the driver. + * + * @param[in] i2cp pointer to a @p I2CDriver structure + * @return The condition flags modified since last time this + * function was invoked. + * + * @api + */ +i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { + i2cflags_t mask; + + chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); + + chSysLock(); + mask = i2cp->errors; + i2cp->errors = I2CD_NO_ERROR; + chSysUnlock(); + return mask; +} + + + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* CH_HAL_USE_I2C */ -- cgit v1.2.3 From a74dd37c2cad661eee2070888a55a99e49745b6b Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 18:10:23 +0000 Subject: I2C. Moved Alberto drivers to backup. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2711 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 268 ------------------------------------------------------- 1 file changed, 268 deletions(-) delete mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c deleted file mode 100644 index 64bed78eb..000000000 --- a/os/hal/src/i2c.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/RT is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -#include "ch.h" -#include "hal.h" - -#if HAL_USE_I2C || defined(__DOXYGEN__) - -/** - * @brief I2C Driver initialization. - */ -void i2cInit(void) { - - i2c_lld_init(); -} - -/** - * @brief Initializes the standard part of a @p I2CDriver structure. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cObjectInit(I2CDriver *i2cp) { - chEvtInit(&i2cp->sevent); - i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_STOP; -// i2cp->i2cd_config = NULL; -#if I2C_USE_WAIT - i2cp->thread = NULL; -#endif /* I2C_USE_WAIT */ -#if I2C_USE_MUTUAL_EXCLUSION -#if CH_USE_MUTEXES - chMtxInit(&i2cp->mutex); -#elif CH_USE_SEMAPHORES - chSemInit(&i2cp->semaphore, 1); -#endif -#endif /* I2C_USE_MUTUAL_EXCLUSION */ -#if defined(I2C_DRIVER_EXT_INIT_HOOK) - I2C_DRIVER_EXT_INIT_HOOK(i2cp); -#endif -} - -/** - * @brief Configures and activates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] config pointer to the @p I2CConfig object - */ -void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { - - chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - - chSysLock(); - chDbgAssert((i2cp->state == I2C_STOP)||(i2cp->state == I2C_READY), - "i2cStart(), #1", "invalid state"); - - i2cp->nbit_address = config->nBitAddress; - i2c_lld_start(i2cp); - i2c_lld_set_clock(i2cp, config->ClockSpeed, config->FastModeDutyCycle); - i2c_lld_set_opmode(i2cp, config->opMode); - i2c_lld_set_own_address(i2cp, config->OwnAddress1, config->nBitAddress); - i2cp->state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Deactivates the I2C peripheral. - * - * @param[in] i2cp pointer to the @p I2CDriver object - */ -void i2cStop(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cStop"); - - chSysLock(); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), - "i2cStop(), #1", "invalid state"); - i2c_lld_stop(i2cp); - i2cp->state = I2C_STOP; - chSysUnlock(); -} - -/** - * @brief Sends data ever the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr 7-bit or 10-bit address of the slave - * @param[in] n number of words to send - * @param[in] txbuf the pointer to the transmit buffer - * - */ -void i2cMasterTransmit(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *txbuf) { - - chDbgCheck((i2cp != NULL) && (n > 0) && (txbuf != NULL), - "i2cMasterTransmit"); - -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif - - chSysLock(); - chDbgAssert(i2cp->state == I2C_READY, - "i2cMasterTransmit(), #1", "not ready"); - - i2cp->state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, slave_addr, n, txbuf); - _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->state == I2C_COMPLETE) - i2cp->state = I2C_READY; - chSysUnlock(); -} - -/** - * @brief Receives data from the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr 7-bit or 10-bit address of the slave - * @param[in] n number of bytes to receive - * @param[out] rxbuf the pointer to the receive buffer - * - */ -void i2cMasterReceive(I2CDriver *i2cp, uint16_t slave_addr, size_t n, void *rxbuf) { - - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), - "i2cMasterReceive"); - -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif - - chSysLock(); - chDbgAssert(i2cp->state == I2C_READY, - "i2cMasterReceive(), #1", "not ready"); - - i2cp->state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, slave_addr, n, rxbuf); - _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->state == I2C_COMPLETE) - i2cp->state = I2C_READY; - chSysUnlock(); -} - -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp) { - uint16_t slv_addr; - - i2cMasterReceive(i2cp, 0x0C, 2, &slv_addr); - return slv_addr; -} - - -/** - * @brief Handles communication events/errors. - * @details Must be called from the I/O interrupt service routine in order to - * notify I/O conditions as errors, signals change etc. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @param[in] mask condition flags to be added to the mask - * - * @iclass - */ -void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { - - chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - - i2cp->errors |= mask; - chEvtBroadcastI(&i2cp->sevent); -} - -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @return The condition flags modified since last time this - * function was invoked. - * - * @api - */ -i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { - i2cflags_t mask; - - chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); - - chSysLock(); - mask = i2cp->errors; - i2cp->errors = I2CD_NO_ERROR; - chSysUnlock(); - return mask; -} - - - -#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -/** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus - * is already being used then the invoking thread is queued. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void i2cAcquireBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cAcquireBus"); - -#if CH_USE_MUTEXES - chMtxLock(&i2cp->mutex); -#elif CH_USE_SEMAPHORES - chSemWait(&i2cp->semaphore); -#endif -} - -/** - * @brief Releases exclusive access to the I2C bus. - * - * @param[in] i2cp pointer to the @p I2CDriver object - * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. - */ -void i2cReleaseBus(I2CDriver *i2cp) { - - chDbgCheck(i2cp != NULL, "i2cReleaseBus"); - -#if CH_USE_MUTEXES - (void)i2cp; - chMtxUnlock(); -#elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->semaphore); -#endif -} -#endif /* I2C_USE_MUTUAL_EXCLUSION */ - -#endif /* CH_HAL_USE_I2C */ -- cgit v1.2.3 From d6f77c1ef14cc6b4636fde34d2025e5f23bc9e36 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 5 Feb 2011 18:22:45 +0000 Subject: I2C. After comparing of two drivers decided to start of importing features from Alberto driver to mine. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2712 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 os/hal/src/i2c.c (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c new file mode 100644 index 000000000..5a0471e0f --- /dev/null +++ b/os/hal/src/i2c.c @@ -0,0 +1,215 @@ +/* + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + + This file is part of ChibiOS/RT. + + ChibiOS/RT is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/RT is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file i2c.c + * @brief I2C Driver code. + * + * @addtogroup I2C + * @{ + */ + +#include "ch.h" +#include "hal.h" + +#if HAL_USE_I2C || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Driver exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver exported functions. */ +/*===========================================================================*/ + +/** + * @brief I2C Driver initialization. + * @note This function is implicitly invoked by @p halInit(), there is + * no need to explicitly initialize the driver. + * + * @init + */ +void i2cInit(void) { + i2c_lld_init(); +} + +/** + * @brief Initializes the standard part of a @p I2CDriver structure. + * + * @param[out] i2cp pointer to the @p I2CDriver object + * + * @init + */ +void i2cObjectInit(I2CDriver *i2cp) { + + i2cp->id_state = I2C_STOP; + i2cp->id_config = NULL; + i2cp->id_slave_config = NULL; +#if defined(I2C_DRIVER_EXT_INIT_HOOK) + I2C_DRIVER_EXT_INIT_HOOK(i2cp); +#endif +} + +/** + * @brief Configures and activates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] config pointer to the @p I2CConfig object + * + * @api + */ +void i2cStart(I2CDriver *i2cp, I2CConfig *config) { + + chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); + + chSysLock(); + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + "i2cStart(), #1", + "invalid state"); + i2cp->id_config = config; + i2c_lld_start(i2cp); + i2cp->id_state = I2C_READY; + chSysUnlock(); +} + +/** + * @brief Deactivates the I2C peripheral. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + */ +void i2cStop(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cStop"); + + chSysLock(); + chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + "i2cStop(), #1", + "invalid state"); + i2c_lld_stop(i2cp); + i2cp->id_state = I2C_STOP; + 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 + * + */ +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterTransmit"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterTransmit(), #1", + "not active"); + + i2c_lld_master_transmitI(i2cp, i2cscfg); +} + + +/** + * @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 + * + */ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), + "i2cMasterReceive"); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterReceive(), #1", + "not active"); + + i2c_lld_master_receiveI(i2cp, i2cscfg); +} + + + + + + +#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) +/** + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the I2C bus, if the bus + * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + * + */ +void i2cAcquireBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cAcquireBus"); + +#if CH_USE_MUTEXES + chMtxLock(&i2cp->id_mutex); +#elif CH_USE_SEMAPHORES + chSemWait(&i2cp->id_semaphore); +#endif +} + +/** + * @brief Releases exclusive access to the I2C bus. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @api + */ +void i2cReleaseBus(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cReleaseBus"); + +#if CH_USE_MUTEXES + (void)i2cp; + chMtxUnlock(); +#elif CH_USE_SEMAPHORES + chSemSignal(&i2cp->id_semaphore); +#endif +} +#endif /* I2C_USE_MUTUAL_EXCLUSION */ + +#endif /* HAL_USE_I2C */ + +/** @} */ -- cgit v1.2.3 From 76bac6bb8704e039a7f9e4b34da7af3bd909c2bd Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 9 Feb 2011 19:33:19 +0000 Subject: I2C. Added own slave address handling and error callback. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2723 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 5a0471e0f..04af9a6c2 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -161,9 +161,6 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the I2C bus. -- cgit v1.2.3 From 4f827c235aa25d0c0b45eca7ccd06ce2c1740a24 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 27 Feb 2011 15:22:18 +0000 Subject: I2C. Code cleanups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2776 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 04af9a6c2..7dede9f86 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -116,14 +116,35 @@ void i2cStop(I2CDriver *i2cp) { chSysUnlock(); } +/** + * @brief Generate (re)start on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStart(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + + i2c_lld_master_start(i2cp); +} + +/** + * @brief Generate stop on the bus. + * + * @param[in] i2cp pointer to the @p I2CDriver object + */ +void i2cMasterStop(I2CDriver *i2cp){ + + chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + + i2c_lld_master_stop(i2cp); +} + /** * @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 +155,15 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not active"); - i2c_lld_master_transmitI(i2cp, i2cscfg); + i2c_lld_master_transmit(i2cp, i2cscfg); } /** * @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,7 +173,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); - i2c_lld_master_receiveI(i2cp, i2cscfg); + i2c_lld_master_receive(i2cp, i2cscfg); } -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 2b5971b6f..86bfc16f6 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 7a694b4402e8d47ef0fdc651492ee09084ebcad0 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 27 Mar 2011 21:12:43 +0000 Subject: I2C. Mutual exclusion support added. Need testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2847 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 7dede9f86..11d4fccfa 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.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 -- cgit v1.2.3 From 57fb5e703ba8ab824d1849d7436abd64684caf20 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 2 Apr 2011 09:33:46 +0000 Subject: I2C. Additional locks added to avoiding system hangups. Some mistypes in comments fixed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2865 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 11d4fccfa..ad9a5d0ac 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -138,7 +138,9 @@ void i2cMasterStart(I2CDriver *i2cp){ chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + chSysLock(); i2c_lld_master_start(i2cp); + chSysUnlock(); } /** @@ -149,8 +151,9 @@ void i2cMasterStart(I2CDriver *i2cp){ void i2cMasterStop(I2CDriver *i2cp){ chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); - + chSysLock(); i2c_lld_master_stop(i2cp); + chSysUnlock(); } /** @@ -168,7 +171,9 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not active"); + chSysLock(); i2c_lld_master_transmit(i2cp, i2cscfg); + chSysUnlock(); } @@ -186,7 +191,9 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1", "not active"); + chSysLock(); i2c_lld_master_receive(i2cp, i2cscfg); + chSysUnlock(); } -- cgit v1.2.3 From 4fda4dc84fcfcfa483f10a8b5043d124ad551ba0 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 5 May 2011 17:43:54 +0000 Subject: I2C. Code compiles successfully, but totally not tested. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2921 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 150 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 109 insertions(+), 41 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index ad9a5d0ac..50767b3a9 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -130,106 +130,174 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Generate (re)start on the bus. + * @brief Sends data ever the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * */ -void i2cMasterStart(I2CDriver *i2cp){ +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + size_t n; + i2cblock_t *txbuf; + + txbuf = i2cscfg->txbuf; + n = i2cscfg->tx_remaining_bytes; + + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && (txbuf != NULL), + "i2cMasterTransmit"); - chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); + // init slave config field in driver + i2cp->id_slave_config = i2cscfg; + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif chSysLock(); - i2c_lld_master_start(i2cp); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterTransmit(), #1", "not ready"); + + i2cp->id_state = I2C_ACTIVE; + i2c_lld_master_transmit(i2cp); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->id_state == I2C_COMPLETE) + i2cp->id_state = I2C_READY; chSysUnlock(); } /** - * @brief Generate stop on the bus. + * @brief Receives data from the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * */ -void i2cMasterStop(I2CDriver *i2cp){ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ + + size_t n; + i2cblock_t *rxbuf; + + rxbuf = i2cscfg->rxbuf; + n = i2cscfg->rx_remaining_bytes; + + chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + "i2cMasterReceive"); + + // init slave config field in driver + i2cp->id_slave_config = i2cscfg; + +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); +#endif + return; + }; +#endif - chDbgCheck((i2cp != NULL), "i2cMasterTransmit"); chSysLock(); - i2c_lld_master_stop(i2cp); + chDbgAssert(i2cp->id_state == I2C_READY, + "i2cMasterReceive(), #1", "not ready"); + + i2cp->id_state = I2C_ACTIVE; + i2c_lld_master_receive(i2cp); + _i2c_wait_s(i2cp); +#if !I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); +#endif + if (i2cp->id_state == I2C_COMPLETE) + i2cp->id_state = I2C_READY; chSysUnlock(); } +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + + i2cMasterReceive(i2cp, i2cscfg); + return i2cp->id_slave_config->slave_addr; +} + + /** - * @brief Sends data ever the I2C bus. + * @brief Handles communication events/errors. + * @details Must be called from the I/O interrupt service routine in order to + * notify I/O conditions as errors, signals change etc. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object + * @param[in] i2cp pointer to a @p I2CDriver structure + * @param[in] mask condition flags to be added to the mask * + * @iclass */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterTransmit"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", - "not active"); + chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - chSysLock(); - i2c_lld_master_transmit(i2cp, i2cscfg); - chSysUnlock(); + i2cp->id_slave_config->errors |= mask; + chEvtBroadcastI(&i2cp->id_slave_config->sevent); } - /** - * @brief Receives data from the I2C bus. + * @brief Returns and clears the errors mask associated to the driver. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object + * @param[in] i2cp pointer to a @p I2CDriver structure + * @return The condition flags modified since last time this + * function was invoked. + * + * @api */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { + i2cflags_t mask; - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL), - "i2cMasterReceive"); - chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterReceive(), #1", - "not active"); + chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); chSysLock(); - i2c_lld_master_receive(i2cp, i2cscfg); + mask = i2cp->id_slave_config->errors; + i2cp->id_slave_config->errors = I2CD_NO_ERROR; chSysUnlock(); + return mask; } #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** - * @brief Gains exclusive access to the I2C bus. + * @brief Gains exclusive access to the I2C bus. * @details This function tries to gain ownership to the I2C bus, if the bus * is already being used then the invoking thread is queued. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @api - * + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. */ void i2cAcquireBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); + chMtxLock(&i2cp->mutex); #elif CH_USE_SEMAPHORES chSemWait(&i2cp->id_semaphore); #endif } /** - * @brief Releases exclusive access to the I2C bus. - * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION - * must be enabled. + * @brief Releases exclusive access to the I2C bus. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @api + * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION + * option is set to @p TRUE. */ void i2cReleaseBus(I2CDriver *i2cp) { -- cgit v1.2.3 From 60975ca7fed0e2960bced2fe72239422f8376068 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 6 May 2011 15:16:15 +0000 Subject: I2C. Some fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2922 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 50767b3a9..1a2873a29 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -140,11 +140,14 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { size_t n; i2cblock_t *txbuf; + uint8_t nbit_addr; txbuf = i2cscfg->txbuf; + nbit_addr = i2cscfg->nbit_address; n = i2cscfg->tx_remaining_bytes; - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && (txbuf != NULL), + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ + ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), "i2cMasterTransmit"); // init slave config field in driver @@ -186,11 +189,14 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ size_t n; i2cblock_t *rxbuf; + uint8_t nbit_addr; rxbuf = i2cscfg->rxbuf; n = i2cscfg->rx_remaining_bytes; + nbit_addr = i2cscfg->nbit_address; - chDbgCheck((i2cp != NULL) && (n > 0) && (rxbuf != NULL), + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ + ((nbit_addr == 7) || (nbit_addr == 10)) && (rxbuf != NULL), "i2cMasterReceive"); // init slave config field in driver @@ -221,6 +227,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ chSysUnlock(); } + uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { i2cMasterReceive(i2cp, i2cscfg); -- cgit v1.2.3 From 732eaa72c18b9bc6ddb9b6c5ac2294420d14552e Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 8 May 2011 13:20:10 +0000 Subject: I2C. Code cleanups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2937 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 1a2873a29..18d1d78c0 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -144,7 +144,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { txbuf = i2cscfg->txbuf; nbit_addr = i2cscfg->nbit_address; - n = i2cscfg->tx_remaining_bytes; + n = i2cscfg->tx_bytes; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), @@ -192,7 +192,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ uint8_t nbit_addr; rxbuf = i2cscfg->rxbuf; - n = i2cscfg->rx_remaining_bytes; + n = i2cscfg->rx_bytes; nbit_addr = i2cscfg->nbit_address; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ -- cgit v1.2.3 From 152f34a80c6ffe5fd17809732272823091b854e8 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 28 May 2011 12:31:47 +0000 Subject: I2C. Some refactorings. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3000 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 18d1d78c0..84dfcf958 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -144,7 +144,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { txbuf = i2cscfg->txbuf; nbit_addr = i2cscfg->nbit_address; - n = i2cscfg->tx_bytes; + n = i2cscfg->txbytes; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), @@ -192,7 +192,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ uint8_t nbit_addr; rxbuf = i2cscfg->rxbuf; - n = i2cscfg->rx_bytes; + n = i2cscfg->rxbytes; nbit_addr = i2cscfg->nbit_address; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ -- cgit v1.2.3 From 350ae0a1a9721b8889b038cf2fce6a88f1c288e3 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 11:12:33 +0000 Subject: I2C. API BROKEN! Structure fields renamed in underscore naming style. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3055 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 6f99a1afb..b43be0261 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -144,7 +144,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { uint8_t nbit_addr; txbuf = i2cscfg->txbuf; - nbit_addr = i2cscfg->nbit_address; + nbit_addr = i2cscfg->nbit_addr; n = i2cscfg->txbytes; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ @@ -194,7 +194,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ rxbuf = i2cscfg->rxbuf; n = i2cscfg->rxbytes; - nbit_addr = i2cscfg->nbit_address; + nbit_addr = i2cscfg->nbit_addr; chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ ((nbit_addr == 7) || (nbit_addr == 10)) && (rxbuf != NULL), -- cgit v1.2.3 From f3e571839bd7649073664d1c2c4ea3842695b6d5 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 13:35:26 +0000 Subject: I2C. Code cleanups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3056 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b43be0261..cd1a238ba 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -96,7 +96,7 @@ void i2cObjectInit(I2CDriver *i2cp) { * * @api */ -void i2cStart(I2CDriver *i2cp, I2CConfig *config) { +void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); -- cgit v1.2.3 From 79f477ba95384ef082a7f2ec71e228e02e62e864 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 18 Jun 2011 14:31:27 +0000 Subject: I2C. "Slave_addr" and "nbit_addr" fields from I2CSlaveConfig structure merged together. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3057 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index cd1a238ba..f31dcb7ba 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -139,17 +139,10 @@ void i2cStop(I2CDriver *i2cp) { */ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - size_t n; - i2cblock_t *txbuf; - uint8_t nbit_addr; - - txbuf = i2cscfg->txbuf; - nbit_addr = i2cscfg->nbit_addr; - n = i2cscfg->txbytes; - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && \ - ((nbit_addr == 7) || (nbit_addr == 10)) && (n > 0) && (txbuf != NULL), - "i2cMasterTransmit"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (i2cscfg->txbytes > 0) &&\ + (i2cscfg->txbuf != NULL), + "i2cMasterTransmit"); // init slave config field in driver i2cp->id_slave_config = i2cscfg; @@ -188,17 +181,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { */ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ - size_t n; - i2cblock_t *rxbuf; - uint8_t nbit_addr; - - rxbuf = i2cscfg->rxbuf; - n = i2cscfg->rxbytes; - nbit_addr = i2cscfg->nbit_addr; - - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) && (n > 0) && \ - ((nbit_addr == 7) || (nbit_addr == 10)) && (rxbuf != NULL), - "i2cMasterReceive"); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (i2cscfg->rxbytes > 0) && \ + (i2cscfg->rxbuf != NULL), + "i2cMasterReceive"); // init slave config field in driver i2cp->id_slave_config = i2cscfg; -- cgit v1.2.3 From b54133ab1beba9d2923450d1d5f1b2c73dc2afa3 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 21 Jun 2011 18:30:50 +0000 Subject: I2C. Some fields from I2CSlaveConfig moved to driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3066 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f31dcb7ba..dc48b9478 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -137,10 +137,10 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] i2cscfg pointer to the @p I2C slave config * */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ - (i2cscfg->txbytes > 0) &&\ + (txbytes > 0) &&\ (i2cscfg->txbuf != NULL), "i2cMasterTransmit"); @@ -162,7 +162,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp); + i2c_lld_master_transmit(i2cp, txbytes, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -179,10 +179,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { * @param[in] i2cscfg pointer to the @p I2C slave config * */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ +void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ - (i2cscfg->rxbytes > 0) && \ + (rxbytes > 0) && \ (i2cscfg->rxbuf != NULL), "i2cMasterReceive"); @@ -204,7 +204,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp); + i2c_lld_master_receive(i2cp, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -215,11 +215,11 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ } -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - - i2cMasterReceive(i2cp, i2cscfg); - return i2cp->id_slave_config->slave_addr; -} +//uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { +// +// i2cMasterReceive(i2cp, i2cscfg); +// return i2cp->id_slave_config->slave_addr; +//} /** @@ -236,7 +236,7 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - i2cp->id_slave_config->errors |= mask; + i2cp->errors |= mask; chEvtBroadcastI(&i2cp->id_slave_config->sevent); } @@ -255,8 +255,8 @@ i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); chSysLock(); - mask = i2cp->id_slave_config->errors; - i2cp->id_slave_config->errors = I2CD_NO_ERROR; + mask = i2cp->errors; + i2cp->errors = I2CD_NO_ERROR; chSysUnlock(); return mask; } @@ -279,7 +279,7 @@ void i2cAcquireBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&i2cp->mutex); + chMtxLock(&i2cp->id_mutex); #elif CH_USE_SEMAPHORES chSemWait(&i2cp->id_semaphore); #endif -- cgit v1.2.3 From 70179f12dd387a82493d13fd51d5aab7e4e55674 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 21 Jun 2011 20:17:14 +0000 Subject: I2C. Slave config structure now have const qualifier. Moset of fields moved to the driver structure. May be broken events subsystem in driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3067 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index dc48b9478..4e3f5e5b9 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,11 +135,17 @@ void i2cStop(I2CDriver *i2cp) { * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received */ -void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, size_t rxbytes) { +void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (slave_addr != 0) &&\ (txbytes > 0) &&\ (i2cscfg->txbuf != NULL), "i2cMasterTransmit"); @@ -162,7 +168,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, txbytes, rxbytes); + i2c_lld_master_transmit(i2cp, slave_addr, txbytes, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -177,11 +183,16 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t txbytes, * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited */ -void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ +void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + (slave_addr != 0) &&\ (rxbytes > 0) && \ (i2cscfg->rxbuf != NULL), "i2cMasterReceive"); @@ -204,7 +215,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, rxbytes); + i2c_lld_master_receive(i2cp, slave_addr, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -215,6 +226,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, size_t rxbytes){ } +// FIXME: I do not know what this function must do. And can not test it //uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { // // i2cMasterReceive(i2cp, i2cscfg); -- cgit v1.2.3 From fbeff97d9230af12326c94e3875adf9438f16ed4 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 18:05:20 +0000 Subject: I2C. Variables shared among I2C1 and I2C2 interrupt handlers moved to driver structure. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3070 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4e3f5e5b9..56e2f4484 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -69,6 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; + i2cp->rxBuffp = NULL; + i2cp->txBuffp = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT -- cgit v1.2.3 From 10153a4f3062c85b4595558df5df41f8962c6aae Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 18:29:22 +0000 Subject: I2C. Fixed indent style. All tabs changed to 2 spaces. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3071 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 56e2f4484..75541494f 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,14 +135,14 @@ void i2cStop(I2CDriver *i2cp) { /** * @brief Sends data ever the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited - * @param[in] rxbytes number of bytes to be received + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { @@ -183,13 +183,13 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. - * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] i2cscfg pointer to the @p I2C slave config + * @param[in] slave_addr Slave device address. Bits 0-9 contain slave + * device address. Bit 15 must be set to 1 if 10-bit + * addressing modes used. Otherwise keep it cleared. + * Bits 10-14 unused. + * @param[in] txbytes number of bytes to be transmited */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ @@ -251,7 +251,7 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); i2cp->errors |= mask; - chEvtBroadcastI(&i2cp->id_slave_config->sevent); + chEvtBroadcastI(&i2cp->sevent); } /** -- cgit v1.2.3 From 97e643a2a2086bf8d52c77d599748849ff6a8148 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 18:50:13 +0000 Subject: I2C. Commetns style changed to /**/. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3073 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 75541494f..377b27ecf 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -152,7 +152,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t (i2cscfg->txbuf != NULL), "i2cMasterTransmit"); - // init slave config field in driver + /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; #if I2C_USE_WAIT @@ -199,7 +199,7 @@ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t s (i2cscfg->rxbuf != NULL), "i2cMasterReceive"); - // init slave config field in driver + /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; #if I2C_USE_WAIT @@ -228,13 +228,12 @@ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t s } -// FIXME: I do not know what this function must do. And can not test it -//uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { -// -// i2cMasterReceive(i2cp, i2cscfg); -// return i2cp->id_slave_config->slave_addr; -//} - +/* FIXME: I do not know what this function must do. And can not test it +uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { + i2cMasterReceive(i2cp, i2cscfg); + return i2cp->id_slave_config->slave_addr; +} +*/ /** * @brief Handles communication events/errors. -- cgit v1.2.3 From b1d043cede9e37dccff9731978887f51a514c387 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 23 Jun 2011 19:06:33 +0000 Subject: I2C. Some coding style improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3074 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 377b27ecf..490ecf656 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -69,8 +69,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; - i2cp->rxBuffp = NULL; - i2cp->txBuffp = NULL; + i2cp->rxbuff_p = NULL; + i2cp->txbuff_p = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT @@ -144,7 +144,11 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] txbytes number of bytes to be transmited * @param[in] rxbytes number of bytes to be received */ -void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t txbytes, size_t rxbytes) { +void i2cMasterTransmit(I2CDriver *i2cp, + const I2CSlaveConfig *i2cscfg, + uint16_t slave_addr, + size_t txbytes, + size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ @@ -191,7 +195,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t * Bits 10-14 unused. * @param[in] txbytes number of bytes to be transmited */ -void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, size_t rxbytes){ +void i2cMasterReceive(I2CDriver *i2cp, + const I2CSlaveConfig *i2cscfg, + uint16_t slave_addr, + size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ -- cgit v1.2.3 From f73960c8dcbcc2f4f4b4aba8599a45485038ec82 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 30 Jun 2011 13:43:42 +0000 Subject: I2C. API changed. Transmit and receive buffers removed from I2CSlaveConfig. Now pointers to that buffers pass in functions arguments. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3099 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 490ecf656..dca7c6125 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -141,19 +141,23 @@ void i2cStop(I2CDriver *i2cp) { * device address. Bit 15 must be set to 1 if 10-bit * addressing modes used. Otherwise keep it cleared. * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] txbytes number of bytes to be transmitted + * @param[in] txbuf pointer to transmit buffer * @param[in] rxbytes number of bytes to be received + * @param[in] rxbuf pointer to receive buffer */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, + uint8_t *txbuf, size_t txbytes, + uint8_t *rxbuf, size_t rxbytes) { chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ - (i2cscfg->txbuf != NULL), + (txbuf != NULL), "i2cMasterTransmit"); /* init slave config field in driver */ @@ -174,7 +178,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_transmit(i2cp, slave_addr, txbytes, rxbytes); + i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); @@ -198,12 +202,13 @@ void i2cMasterTransmit(I2CDriver *i2cp, void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, uint16_t slave_addr, + uint8_t *rxbuf, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ - (i2cscfg->rxbuf != NULL), + (rxbuf != NULL), "i2cMasterReceive"); /* init slave config field in driver */ @@ -224,7 +229,7 @@ void i2cMasterReceive(I2CDriver *i2cp, "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - i2c_lld_master_receive(i2cp, slave_addr, rxbytes); + i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); #if !I2C_USE_WAIT i2c_lld_wait_bus_free(i2cp); -- cgit v1.2.3 From 551a1c1f22fb53085ab9485115fc3d27af92083c Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 30 Jun 2011 21:37:34 +0000 Subject: I2C. Added dirty hack to realize thread safe dirver. Needs to be rewrited. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3100 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index dca7c6125..725e92d65 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -71,6 +71,8 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_config = NULL; i2cp->rxbuff_p = NULL; i2cp->txbuff_p = NULL; + i2cp->rxbuf = NULL; + i2cp->txbuf = NULL; i2cp->id_slave_config = NULL; #if I2C_USE_WAIT @@ -154,6 +156,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes) { + i2cAcquireBus(i2cp); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ @@ -180,11 +184,6 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->id_state == I2C_COMPLETE) - i2cp->id_state = I2C_READY; chSysUnlock(); } @@ -205,6 +204,8 @@ void i2cMasterReceive(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes){ + i2cAcquireBus(i2cp); + chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ @@ -231,11 +232,6 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); -#if !I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); -#endif - if (i2cp->id_state == I2C_COMPLETE) - i2cp->id_state = I2C_READY; chSysUnlock(); } -- cgit v1.2.3 From af0e40079ded13b8842e8d129fa6ed2f37fdf678 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 1 Jul 2011 13:36:59 +0000 Subject: I2C. Trying to add optional WAIT support. Driver broken. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3101 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 725e92d65..3f4095aa3 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -156,8 +156,6 @@ void i2cMasterTransmit(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes) { - i2cAcquireBus(i2cp); - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ @@ -167,15 +165,15 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif +//#if I2C_USE_WAIT +// i2c_lld_wait_bus_free(i2cp); +// if(i2c_lld_bus_is_busy(i2cp)) { +//#ifdef PRINTTRACE +// print("I2C Bus busy!\n"); +//#endif +// return; +// }; +//#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, @@ -204,8 +202,6 @@ void i2cMasterReceive(I2CDriver *i2cp, uint8_t *rxbuf, size_t rxbytes){ - i2cAcquireBus(i2cp); - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 0) && \ @@ -215,15 +211,15 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT - i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); -#endif - return; - }; -#endif +//#if I2C_USE_WAIT +// i2c_lld_wait_bus_free(i2cp); +// if(i2c_lld_bus_is_busy(i2cp)) { +//#ifdef PRINTTRACE +// print("I2C Bus busy!\n"); +//#endif +// return; +// }; +//#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, -- cgit v1.2.3 From ccb28114da9485c5e3f950fd31dfb67be1b8a173 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 3 Jul 2011 18:02:55 +0000 Subject: I2C. Driver looks working, but sometimes hangs up. I don't know, my big project cause troubles in it, or driver cause troubles in my project. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3116 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 3f4095aa3..93d00bcae 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -165,15 +165,18 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -//#if I2C_USE_WAIT -// i2c_lld_wait_bus_free(i2cp); -// if(i2c_lld_bus_is_busy(i2cp)) { -//#ifdef PRINTTRACE -// print("I2C Bus busy!\n"); -//#endif -// return; -// }; -//#endif +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); + return; +#else + /* the time is out */ + chDbgAssert(FALSE, "i2cMasterTransmit(), #1", "time is out"); +#endif + }; +#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, @@ -211,15 +214,18 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -//#if I2C_USE_WAIT -// i2c_lld_wait_bus_free(i2cp); -// if(i2c_lld_bus_is_busy(i2cp)) { -//#ifdef PRINTTRACE -// print("I2C Bus busy!\n"); -//#endif -// return; -// }; -//#endif +#if I2C_USE_WAIT + i2c_lld_wait_bus_free(i2cp); + if(i2c_lld_bus_is_busy(i2cp)) { +#ifdef PRINTTRACE + print("I2C Bus busy!\n"); + return; +#else + /* the time is out */ + chDbgAssert(FALSE, "i2cMasterReceive(), #1", "time is out"); +#endif + }; +#endif chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, -- cgit v1.2.3 From 03acd18161901b17be78e280ebbebbc0bbd47c8f Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 4 Jul 2011 14:27:00 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3117 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 93d00bcae..4aade6fe9 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -165,18 +165,18 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT +#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { + if(i2c_lld_bus_is_busy(i2cp)) { /* Probably slave locks up and need reset. */ #ifdef PRINTTRACE print("I2C Bus busy!\n"); return; #else - /* the time is out */ + /* the time is out. Probably slave locks up. */ chDbgAssert(FALSE, "i2cMasterTransmit(), #1", "time is out"); -#endif +#endif /* PRINTTRACE */ }; -#endif +#endif /* CH_DBG_ENABLE_ASSERTS */ chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, @@ -214,18 +214,17 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if I2C_USE_WAIT +#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); if(i2c_lld_bus_is_busy(i2cp)) { #ifdef PRINTTRACE print("I2C Bus busy!\n"); return; #else - /* the time is out */ chDbgAssert(FALSE, "i2cMasterReceive(), #1", "time is out"); -#endif +#endif /* PRINTTRACE */ }; -#endif +#endif /* CH_DBG_ENABLE_ASSERTS */ chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, -- cgit v1.2.3 From 6eca6554847f7a824fbbafd892c4b3797e74983d Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 7 Jul 2011 21:53:01 +0000 Subject: I2C. Driver still cause stack overflows. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3134 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4aade6fe9..4882330bd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -178,11 +178,11 @@ void i2cMasterTransmit(I2CDriver *i2cp, }; #endif /* CH_DBG_ENABLE_ASSERTS */ - chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; + chSysLock(); i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); chSysUnlock(); @@ -226,14 +226,12 @@ void i2cMasterReceive(I2CDriver *i2cp, }; #endif /* CH_DBG_ENABLE_ASSERTS */ - chSysLock(); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); - chSysUnlock(); } -- cgit v1.2.3 From b064c25e390f880570f119f5533e431aaae55721 Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 9 Jul 2011 22:25:31 +0000 Subject: I2C. Main problem fixed, but some minor problems must to be fixed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3142 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4882330bd..4c9a46e5e 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -182,10 +182,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE; - chSysLock(); i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); - chSysUnlock(); } /** -- cgit v1.2.3 From 0ada09b54288d8d632dad6cb4149234ccea34c43 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 11 Jul 2011 19:49:14 +0000 Subject: I2C. Code clean ups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3151 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4c9a46e5e..cd12d42eb 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -165,18 +165,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { /* Probably slave locks up and need reset. */ -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); - return; -#else - /* the time is out. Probably slave locks up. */ - chDbgAssert(FALSE, "i2cMasterTransmit(), #1", "time is out"); -#endif /* PRINTTRACE */ - }; -#endif /* CH_DBG_ENABLE_ASSERTS */ + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); @@ -212,17 +202,8 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; -#if CH_DBG_ENABLE_ASSERTS i2c_lld_wait_bus_free(i2cp); - if(i2c_lld_bus_is_busy(i2cp)) { -#ifdef PRINTTRACE - print("I2C Bus busy!\n"); - return; -#else - chDbgAssert(FALSE, "i2cMasterReceive(), #1", "time is out"); -#endif /* PRINTTRACE */ - }; -#endif /* CH_DBG_ENABLE_ASSERTS */ + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); -- cgit v1.2.3 From 621d794bf0d2a6456221f1e478de66e48c293063 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 12 Jul 2011 18:26:39 +0000 Subject: I2C. Documentation improvements. Dead code clenups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3153 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index cd12d42eb..b169fb70d 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -135,18 +135,23 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Sends data ever the I2C bus. + * @brief Sends data via the I2C bus. + * + * @details Function designed to realize "read-through-write" transfer + * paradigm. If you want transmit data without any further read, + * than set @b rxbuf field to 0. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr Slave device address. Bits 0-9 contain slave * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. + * addressing mode used. Otherwise keep it cleared. * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmitted * @param[in] txbuf pointer to transmit buffer - * @param[in] rxbytes number of bytes to be received + * @param[in] txbytes number of bytes to be transmitted * @param[in] rxbuf pointer to receive buffer + * @param[in] rxbytes number of bytes to be received, set it to 0 if + * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, @@ -183,9 +188,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr Slave device address. Bits 0-9 contain slave * device address. Bit 15 must be set to 1 if 10-bit - * addressing modes used. Otherwise keep it cleared. + * addressing mode used. Otherwise keep it cleared. * Bits 10-14 unused. - * @param[in] txbytes number of bytes to be transmited + * @param[in] rxbytes number of bytes to be received + * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, -- cgit v1.2.3 From b569145b24a59d0741a26885767efa04146f78a5 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 19 Jul 2011 20:45:57 +0000 Subject: I2C. STOP waitings was replaced by GPT callback functions. Need much of testing. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3166 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b169fb70d..b233764f5 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -176,7 +176,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); - i2cp->id_state = I2C_ACTIVE; + i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); } @@ -214,7 +214,7 @@ void i2cMasterReceive(I2CDriver *i2cp, chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); - i2cp->id_state = I2C_ACTIVE; + i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); } -- cgit v1.2.3 From 6ee04cf23282fff92b088ac6f408e5233eb3aa75 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 5 Aug 2011 17:24:23 +0000 Subject: I2C. Added template of synchronouse deriver. It does not work for a moment. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3190 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index b233764f5..9676a3250 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -178,7 +178,11 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); +#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); +#else + i2cp->id_state = I2C_READY; +#endif /* I2C_SUPPORTS_CALLBACKS */ } /** @@ -216,7 +220,11 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); +#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); +#else + i2cp->id_state = I2C_READY; +#endif /* I2C_SUPPORTS_CALLBACKS */ } -- cgit v1.2.3 From da23780899ae4b9ce1bbe0cb9109da1c87fe0fa1 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 23 Aug 2011 08:38:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3250 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 974f65a08..8508bc682 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -147,7 +147,7 @@ void i2cStop(I2CDriver *i2cp) { * * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, - * than set @b rxbuf field to 0. + * than set @b rxbytes field to 0. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config -- cgit v1.2.3 From fe0093f795b6c88db8f12e2f7e45e11355fc3340 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 26 Aug 2011 13:47:22 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3254 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 86bfc16f6..260dcbb17 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -31,6 +31,10 @@ #if HAL_USE_I2C || defined(__DOXYGEN__) +/*===========================================================================*/ +/* Driver local definitions. */ +/*===========================================================================*/ + /*===========================================================================*/ /* Driver exported variables. */ /*===========================================================================*/ -- cgit v1.2.3 From 2ad41625e0dc9ee78dadba2f2527857f9476e40d Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Dec 2011 14:32:59 +0000 Subject: I2C. Nop. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3545 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9ce2cc76f..abd3252cf 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -182,6 +182,7 @@ void i2cMasterTransmit(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; + // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); @@ -224,6 +225,7 @@ void i2cMasterReceive(I2CDriver *i2cp, /* init slave config field in driver */ i2cp->id_slave_config = i2cscfg; + // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); -- cgit v1.2.3 From 62608271adb730505a4a3d0a9ef49ef2efe91552 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 1 Dec 2011 20:17:58 +0000 Subject: I2C. Code compiles but does not work. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3548 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index abd3252cf..0f46e4e64 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -111,10 +111,6 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { "i2cStart(), #1", "invalid state"); -#if (!(STM32_I2C_I2C2_USE_POLLING_WAIT) && I2C_SUPPORTS_CALLBACKS) - gptStart(i2cp->timer, i2cp->timer_cfg); -#endif /* !(STM32_I2C_I2C2_USE_POLLING_WAIT) */ - chSysLock(); i2cp->id_config = config; i2c_lld_start(i2cp); @@ -136,10 +132,6 @@ void i2cStop(I2CDriver *i2cp) { "i2cStop(), #1", "invalid state"); -#if (!(STM32_I2C_I2C2_USE_POLLING_WAIT) && I2C_SUPPORTS_CALLBACKS) - gptStop(i2cp->timer); -#endif /* !(STM32_I2C_I2C2_USE_POLLING_WAIT) */ - chSysLock(); i2c_lld_stop(i2cp); i2cp->id_state = I2C_STOP; -- cgit v1.2.3 From dbac0ef26b2977c9862ec6ddc22f10dac76b3239 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 2 Dec 2011 15:01:31 +0000 Subject: I2C. DMA works. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3550 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 0f46e4e64..3add2af98 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -210,7 +210,7 @@ void i2cMasterReceive(I2CDriver *i2cp, chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ - (rxbytes > 0) && \ + (rxbytes > 1) && \ (rxbuf != NULL), "i2cMasterReceive"); -- cgit v1.2.3 From 59014aa2be0488eba89c6ec0fb1934aa43aeb224 Mon Sep 17 00:00:00 2001 From: barthess Date: Sun, 4 Dec 2011 17:46:19 +0000 Subject: I2C. Tested on tmp75, mma8451, max1236. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3553 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 3add2af98..9f443be6c 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -73,8 +73,6 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; - i2cp->rxbuff_p = NULL; - i2cp->txbuff_p = NULL; i2cp->rxbuf = NULL; i2cp->txbuf = NULL; i2cp->id_slave_config = NULL; @@ -145,12 +143,12 @@ void i2cStop(I2CDriver *i2cp) { * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. * + * @details Number of receiving byts must be 0 or more than 1 because of stm32 + * hardware restrictions. + * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing mode used. Otherwise keep it cleared. - * Bits 10-14 unused. + * @param[in] slave_addr Slave device address (7 bits) without R/W bit * @param[in] txbuf pointer to transmit buffer * @param[in] txbytes number of bytes to be transmitted * @param[in] rxbuf pointer to receive buffer @@ -159,7 +157,7 @@ void i2cStop(I2CDriver *i2cp) { */ void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, - uint16_t slave_addr, + uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, @@ -168,7 +166,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ - (txbuf != NULL), + (txbuf != NULL) &&\ + ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), "i2cMasterTransmit"); /* init slave config field in driver */ @@ -183,28 +182,23 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); -#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); -#else - i2cp->id_state = I2C_READY; -#endif /* I2C_SUPPORTS_CALLBACKS */ } /** * @brief Receives data from the I2C bus. + * @details Number of receiving byts must be more than 1 because of stm32 + * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] i2cscfg pointer to the @p I2C slave config - * @param[in] slave_addr Slave device address. Bits 0-9 contain slave - * device address. Bit 15 must be set to 1 if 10-bit - * addressing mode used. Otherwise keep it cleared. - * Bits 10-14 unused. + * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg, - uint16_t slave_addr, + uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ @@ -226,21 +220,9 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); -#if I2C_SUPPORTS_CALLBACKS _i2c_wait_s(i2cp); -#else - i2cp->id_state = I2C_READY; -#endif /* I2C_SUPPORTS_CALLBACKS */ } - -/* FIXME: I do not know what this function must do. And can not test it -uint16_t i2cSMBusAlertResponse(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { - i2cMasterReceive(i2cp, i2cscfg); - return i2cp->id_slave_config->slave_addr; -} -*/ - /** * @brief Handles communication events/errors. * @details Must be called from the I/O interrupt service routine in order to -- cgit v1.2.3 From 2db3c769f1abba36a1e7a843d83e5006de58cbd5 Mon Sep 17 00:00:00 2001 From: barthess Date: Tue, 6 Dec 2011 18:09:34 +0000 Subject: I2C. Bug fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3562 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9f443be6c..4b9160a68 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -238,7 +238,6 @@ void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); i2cp->errors |= mask; - chEvtBroadcastI(&i2cp->sevent); } /** -- cgit v1.2.3 From 0738591b023a4e2c6cacebadebfef08aafea4d6e Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 17:57:42 +0000 Subject: I2C. Switch to synchronous model. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3570 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 4b9160a68..996343104 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -75,11 +75,7 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_config = NULL; i2cp->rxbuf = NULL; i2cp->txbuf = 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 @@ -147,7 +143,6 @@ void i2cStop(I2CDriver *i2cp) { * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr Slave device address (7 bits) without R/W bit * @param[in] txbuf pointer to transmit buffer * @param[in] txbytes number of bytes to be transmitted @@ -156,24 +151,19 @@ void i2cStop(I2CDriver *i2cp) { * you want transmit only */ void i2cMasterTransmit(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes) { - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + chDbgCheck((i2cp != NULL) &&\ (slave_addr != 0) &&\ (txbytes > 0) &&\ (txbuf != NULL) &&\ ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), "i2cMasterTransmit"); - /* init slave config field in driver */ - i2cp->id_slave_config = i2cscfg; - - // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); @@ -191,27 +181,21 @@ void i2cMasterTransmit(I2CDriver *i2cp, * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] i2cscfg pointer to the @p I2C slave config * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer */ void i2cMasterReceive(I2CDriver *i2cp, - const I2CSlaveConfig *i2cscfg, uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ - chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\ + chDbgCheck((i2cp != NULL) &&\ (slave_addr != 0) &&\ (rxbytes > 1) && \ (rxbuf != NULL), "i2cMasterReceive"); - /* init slave config field in driver */ - i2cp->id_slave_config = i2cscfg; - - // TODO: remove this loop. Do only 1 check because mutual exclusion resolve collisions i2c_lld_wait_bus_free(i2cp); chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); @@ -298,7 +282,6 @@ void i2cReleaseBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cReleaseBus"); #if CH_USE_MUTEXES - (void)i2cp; chMtxUnlock(); #elif CH_USE_SEMAPHORES chSemSignal(&i2cp->id_semaphore); -- cgit v1.2.3 From 3799bf56f52f7a5be9eeda6757c6642105c4ed66 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 7 Dec 2011 19:23:09 +0000 Subject: I2C. Error handling from userland code added. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3572 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 996343104..f20932ef3 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -149,8 +149,10 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received, set it to 0 if * you want transmit only + * + * @return Zero if no errors, otherwise return error code. */ -void i2cMasterTransmit(I2CDriver *i2cp, +i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, @@ -173,6 +175,8 @@ void i2cMasterTransmit(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); _i2c_wait_s(i2cp); + + return i2cGetAndClearFlags(i2cp); } /** @@ -184,8 +188,10 @@ void i2cMasterTransmit(I2CDriver *i2cp, * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer + * + * @return Zero if no errors, otherwise return error code. */ -void i2cMasterReceive(I2CDriver *i2cp, +i2cflags_t i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes){ @@ -205,6 +211,8 @@ void i2cMasterReceive(I2CDriver *i2cp, i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); _i2c_wait_s(i2cp); + + return i2cGetAndClearFlags(i2cp); } /** -- cgit v1.2.3 From c7c5942ac386fcfddcb77cb3c0e525d0e85063c4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 8 Dec 2011 08:36:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3578 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 54 ++++++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f20932ef3..ae5f9f7a8 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -133,13 +133,11 @@ void i2cStop(I2CDriver *i2cp) { } /** - * @brief Sends data via the I2C bus. - * + * @brief Sends data via the I2C bus. * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. - * - * @details Number of receiving byts must be 0 or more than 1 because of stm32 + * Number of receiving byts must be 0 or more than 1 because of stm32 * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object @@ -153,22 +151,21 @@ void i2cStop(I2CDriver *i2cp) { * @return Zero if no errors, otherwise return error code. */ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *txbuf, - size_t txbytes, - uint8_t *rxbuf, - size_t rxbytes) { - - chDbgCheck((i2cp != NULL) &&\ - (slave_addr != 0) &&\ - (txbytes > 0) &&\ - (txbuf != NULL) &&\ - ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), - "i2cMasterTransmit"); + uint8_t slave_addr, + uint8_t *txbuf, + size_t txbytes, + uint8_t *rxbuf, + size_t rxbytes) { + + chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + (txbytes > 0) && (txbuf != NULL) && + ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), + "i2cMasterTransmit"); i2c_lld_wait_bus_free(i2cp); - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), + "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); @@ -180,8 +177,8 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, } /** - * @brief Receives data from the I2C bus. - * @details Number of receiving byts must be more than 1 because of stm32 + * @brief Receives data from the I2C bus. + * Number of receiving byts must be more than 1 because of stm32 * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object @@ -192,19 +189,18 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, * @return Zero if no errors, otherwise return error code. */ i2cflags_t i2cMasterReceive(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *rxbuf, - size_t rxbytes){ + uint8_t slave_addr, + uint8_t *rxbuf, + size_t rxbytes){ - chDbgCheck((i2cp != NULL) &&\ - (slave_addr != 0) &&\ - (rxbytes > 1) && \ - (rxbuf != NULL), - "i2cMasterReceive"); + chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + (rxbytes > 1) && (rxbuf != NULL), + "i2cMasterReceive"); i2c_lld_wait_bus_free(i2cp); - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), "i2cMasterReceive(), #1", "time is out"); + chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), + "i2cMasterReceive(), #1", "time is out"); chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); @@ -253,8 +249,6 @@ i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { return mask; } - - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** * @brief Gains exclusive access to the I2C bus. -- cgit v1.2.3 From a524ec87f1fffcfea724d8485911fe94a503265f Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 8 Dec 2011 14:34:44 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3581 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index ae5f9f7a8..63c03565a 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -137,8 +137,6 @@ void i2cStop(I2CDriver *i2cp) { * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. - * Number of receiving byts must be 0 or more than 1 because of stm32 - * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] slave_addr Slave device address (7 bits) without R/W bit @@ -159,7 +157,7 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, chDbgCheck((i2cp != NULL) && (slave_addr != 0) && (txbytes > 0) && (txbuf != NULL) && - ((rxbytes == 0) || ((rxbytes > 1) && (rxbuf != NULL))), + ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))), "i2cMasterTransmit"); i2c_lld_wait_bus_free(i2cp); @@ -178,8 +176,6 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, /** * @brief Receives data from the I2C bus. - * Number of receiving byts must be more than 1 because of stm32 - * hardware restrictions. * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] slave_addr slave device address (7 bits) without R/W bit @@ -194,7 +190,7 @@ i2cflags_t i2cMasterReceive(I2CDriver *i2cp, size_t rxbytes){ chDbgCheck((i2cp != NULL) && (slave_addr != 0) && - (rxbytes > 1) && (rxbuf != NULL), + (rxbytes > 0) && (rxbuf != NULL), "i2cMasterReceive"); i2c_lld_wait_bus_free(i2cp); -- cgit v1.2.3 From edfa9d2fae1d667b3f71a8e61aa954ac2233e493 Mon Sep 17 00:00:00 2001 From: barthess Date: Thu, 8 Dec 2011 19:24:21 +0000 Subject: I2C. Added timeout in functions. Code clean ups. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3583 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 94 ++++++++++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 58 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 63c03565a..f7f7c335e 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -145,33 +145,40 @@ void i2cStop(I2CDriver *i2cp) { * @param[in] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received, set it to 0 if * you want transmit only + * @param[in] errors pointer to variable to store error code, zero means + * no error. + * @param[in] timeout operation timeout * - * @return Zero if no errors, otherwise return error code. + * @return timeout status + * @retval RDY_OK if timeout not reached + * @retval RDY_TIMEOUT if a timeout occurs */ -i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, +msg_t i2cMasterTransmit(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, - size_t rxbytes) { + size_t rxbytes, + i2cflags_t *errors, + systime_t timeout) { + msg_t rdymsg; chDbgCheck((i2cp != NULL) && (slave_addr != 0) && (txbytes > 0) && (txbuf != NULL) && - ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))), + ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))) && + (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterTransmit"); - - i2c_lld_wait_bus_free(i2cp); - - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), - "i2cMasterReceive(), #1", "time is out"); + i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); - _i2c_wait_s(i2cp); + _i2c_wait_s(i2cp, timeout, rdymsg); + + *errors = i2cp->errors; - return i2cGetAndClearFlags(i2cp); + return rdymsg; } /** @@ -181,69 +188,40 @@ i2cflags_t i2cMasterTransmit(I2CDriver *i2cp, * @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] rxbytes number of bytes to be received * @param[in] rxbuf pointer to receive buffer + * @param[in] errors pointer to variable to store error code, zero means + * no error. + * @param[in] timeout operation timeout * - * @return Zero if no errors, otherwise return error code. + * @return timeout status + * @retval RDY_OK if timeout not reached + * @retval RDY_TIMEOUT if a timeout occurs */ -i2cflags_t i2cMasterReceive(I2CDriver *i2cp, +msg_t i2cMasterReceive(I2CDriver *i2cp, uint8_t slave_addr, uint8_t *rxbuf, - size_t rxbytes){ + size_t rxbytes, + i2cflags_t *errors, + systime_t timeout){ + + msg_t rdymsg; chDbgCheck((i2cp != NULL) && (slave_addr != 0) && - (rxbytes > 0) && (rxbuf != NULL), + (rxbytes > 0) && (rxbuf != NULL) && + (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterReceive"); - - i2c_lld_wait_bus_free(i2cp); - - chDbgAssert(!(i2c_lld_bus_is_busy(i2cp)), - "i2cMasterReceive(), #1", "time is out"); + i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); i2cp->id_state = I2C_ACTIVE_RECEIVE; i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); - _i2c_wait_s(i2cp); + _i2c_wait_s(i2cp, timeout, rdymsg); - return i2cGetAndClearFlags(i2cp); -} - -/** - * @brief Handles communication events/errors. - * @details Must be called from the I/O interrupt service routine in order to - * notify I/O conditions as errors, signals change etc. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @param[in] mask condition flags to be added to the mask - * - * @iclass - */ -void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask) { + *errors = i2cp->errors; - chDbgCheck(i2cp != NULL, "i2cAddFlagsI"); - - i2cp->errors |= mask; + return rdymsg; } -/** - * @brief Returns and clears the errors mask associated to the driver. - * - * @param[in] i2cp pointer to a @p I2CDriver structure - * @return The condition flags modified since last time this - * function was invoked. - * - * @api - */ -i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp) { - i2cflags_t mask; - - chDbgCheck(i2cp != NULL, "i2cGetAndClearFlags"); - - chSysLock(); - mask = i2cp->errors; - i2cp->errors = I2CD_NO_ERROR; - chSysUnlock(); - return mask; -} #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** -- cgit v1.2.3 From 28cb4b4849c6e124baed09bdb4753d7b87a47483 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 9 Dec 2011 10:22:41 +0000 Subject: I2C. Added forgotten check of BUSY flag. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3587 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f7f7c335e..c67f3a8c6 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -168,6 +168,8 @@ msg_t i2cMasterTransmit(I2CDriver *i2cp, ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))) && (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterTransmit"); + + i2c_lld_wait_bus_free(i2cp); i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterTransmit(), #1", "not ready"); @@ -209,6 +211,8 @@ msg_t i2cMasterReceive(I2CDriver *i2cp, (rxbytes > 0) && (rxbuf != NULL) && (timeout > TIME_IMMEDIATE) && (errors != NULL), "i2cMasterReceive"); + + i2c_lld_wait_bus_free(i2cp); i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); -- cgit v1.2.3 From b30ba31603e2e1f130e9af44f1f140390fff65fe Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 29 Dec 2011 18:03:49 +0000 Subject: I2C API proposal. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3684 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 154 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 88 insertions(+), 66 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index c67f3a8c6..28dd99762 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -132,111 +132,132 @@ void i2cStop(I2CDriver *i2cp) { chSysUnlock(); } +/** + * @brief Returns the errors mask associated to the previous operation. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * @return The errors mask. + * + * @api + */ +i2cflags_t i2cGetErrors(I2CDriver *i2cp) { + + chDbgCheck(i2cp != NULL, "i2cGetErrors"); + + return i2c_lld_get_errors(i2cp); +} + /** * @brief Sends data via the I2C bus. * @details Function designed to realize "read-through-write" transfer * paradigm. If you want transmit data without any further read, * than set @b rxbytes field to 0. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr Slave device address (7 bits) without R/W bit - * @param[in] txbuf pointer to transmit buffer - * @param[in] txbytes number of bytes to be transmitted - * @param[in] rxbuf pointer to receive buffer - * @param[in] rxbytes number of bytes to be received, set it to 0 if - * you want transmit only - * @param[in] errors pointer to variable to store error code, zero means - * no error. - * @param[in] timeout operation timeout + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] addr slave device address (7 bits) without R/W bit + * @param[in] txbuf pointer to transmit buffer + * @param[in] txbytes number of bytes to be transmitted + * @param[in] rxbuf pointer to receive buffer + * @param[in] rxbytes number of bytes to be received, set it to 0 if + * you want transmit only + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_INFINITE no timeout. + * . + * + * @return The number of received bytes or an exit code. + * @retval RDY_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval RDY_TIMEOUT if a timeout occurred before operation end. * - * @return timeout status - * @retval RDY_OK if timeout not reached - * @retval RDY_TIMEOUT if a timeout occurs + * @api */ -msg_t i2cMasterTransmit(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *txbuf, - size_t txbytes, - uint8_t *rxbuf, - size_t rxbytes, - i2cflags_t *errors, - systime_t timeout) { +msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, + i2caddr_t addr, + const uint8_t *txbuf, + size_t txbytes, + uint8_t *rxbuf, + size_t rxbytes, + systime_t timeout) { msg_t rdymsg; - chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + chDbgCheck((i2cp != NULL) && (addr != 0) && (txbytes > 0) && (txbuf != NULL) && ((rxbytes == 0) || ((rxbytes > 0) && (rxbuf != NULL))) && - (timeout > TIME_IMMEDIATE) && (errors != NULL), - "i2cMasterTransmit"); + (timeout != TIME_IMMEDIATE), + "i2cMasterTransmitTimeout"); - i2c_lld_wait_bus_free(i2cp); - i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, - "i2cMasterTransmit(), #1", "not ready"); + "i2cMasterTransmitTimeout(), #1", "not ready"); + chSysLock(); + i2cp->errors = I2CD_NO_ERROR; i2cp->id_state = I2C_ACTIVE_TRANSMIT; - i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); - _i2c_wait_s(i2cp, timeout, rdymsg); - - *errors = i2cp->errors; - + rdymsg = i2c_lld_master_transmit_timeout(i2cp, addr, txbuf, txbytes, + rxbuf, rxbytes, timeout); + i2cp->id_state = I2C_READY; + chSysUnlock(); return rdymsg; } /** * @brief Receives data from the I2C bus. * - * @param[in] i2cp pointer to the @p I2CDriver object - * @param[in] slave_addr slave device address (7 bits) without R/W bit - * @param[in] rxbytes number of bytes to be received - * @param[in] rxbuf pointer to receive buffer - * @param[in] errors pointer to variable to store error code, zero means - * no error. - * @param[in] timeout operation timeout + * @param[in] i2cp pointer to the @p I2CDriver object + * @param[in] addr slave device address (7 bits) without R/W bit + * @param[in] rxbytes number of bytes to be received + * @param[in] rxbuf pointer to receive buffer + * @param[in] errors pointer to variable to store error code, zero means + * no error. + * @param[in] timeout the number of ticks before the operation timeouts, + * the following special values are allowed: + * - @a TIME_INFINITE no timeout. + * . * - * @return timeout status - * @retval RDY_OK if timeout not reached - * @retval RDY_TIMEOUT if a timeout occurs + * @return The number of received bytes or an exit code. + * @retval RDY_OK if the function succeeded. + * @retval RDY_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval RDY_TIMEOUT if a timeout occurred before operation end. + * + * @api */ -msg_t i2cMasterReceive(I2CDriver *i2cp, - uint8_t slave_addr, - uint8_t *rxbuf, - size_t rxbytes, - i2cflags_t *errors, - systime_t timeout){ +msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, + i2caddr_t slave_addr, + uint8_t *rxbuf, + size_t rxbytes, + systime_t timeout){ msg_t rdymsg; - chDbgCheck((i2cp != NULL) && (slave_addr != 0) && + chDbgCheck((i2cp != NULL) && (addr != 0) && (rxbytes > 0) && (rxbuf != NULL) && - (timeout > TIME_IMMEDIATE) && (errors != NULL), - "i2cMasterReceive"); + (timeout != TIME_IMMEDIATE), + "i2cMasterReceiveTimeout"); - i2c_lld_wait_bus_free(i2cp); - i2cp->errors = I2CD_NO_ERROR; /* clear error flags from previous run */ chDbgAssert(i2cp->id_state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); + chSysLock(); + i2cp->errors = I2CD_NO_ERROR; i2cp->id_state = I2C_ACTIVE_RECEIVE; - i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); - _i2c_wait_s(i2cp, timeout, rdymsg); - - *errors = i2cp->errors; - + rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); + i2cp->id_state = I2C_READY; + chSysUnlock(); return rdymsg; } - #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) /** - * @brief Gains exclusive access to the I2C bus. - * @details This function tries to gain ownership to the I2C bus, if the bus + * @brief Gains exclusive access to the I2C bus. + * @details This function tries to gain ownership to the SPI bus, if the bus * is already being used then the invoking thread is queued. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @api */ void i2cAcquireBus(I2CDriver *i2cp) { @@ -250,12 +271,13 @@ void i2cAcquireBus(I2CDriver *i2cp) { } /** - * @brief Releases exclusive access to the I2C bus. + * @brief Releases exclusive access to the I2C bus. + * @pre In order to use this function the option @p I2C_USE_MUTUAL_EXCLUSION + * must be enabled. * * @param[in] i2cp pointer to the @p I2CDriver object * - * @note This function is only available when the @p I2C_USE_MUTUAL_EXCLUSION - * option is set to @p TRUE. + * @api */ void i2cReleaseBus(I2CDriver *i2cp) { -- cgit v1.2.3 From 411418930f549e656dde9067446cfd52317fe33d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 29 Dec 2011 18:07:02 +0000 Subject: Updated credits. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3685 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 28dd99762..5cf5cb4f7 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -17,6 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +/* + Concepts and parts of this file have been contributed by Uladzimir Pylinsky + aka barthess. + */ /** * @file i2c.c -- cgit v1.2.3 From 08feb80580ca82cfebd77a43d14d1197ec7c4f99 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 29 Dec 2011 22:18:25 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3686 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 5cf5cb4f7..598719d24 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -169,7 +169,8 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { * - @a TIME_INFINITE no timeout. * . * - * @return The number of received bytes or an exit code. + * @return The operation status. + * @retval RDY_OK if the function succeeded. * @retval RDY_RESET if one or more I2C errors occurred, the errors can * be retrieved using @p i2cGetErrors(). * @retval RDY_TIMEOUT if a timeout occurred before operation end. @@ -218,7 +219,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, * - @a TIME_INFINITE no timeout. * . * - * @return The number of received bytes or an exit code. + * @return The operation status. * @retval RDY_OK if the function succeeded. * @retval RDY_RESET if one or more I2C errors occurred, the errors can * be retrieved using @p i2cGetErrors(). -- cgit v1.2.3 From 2234fd3e31d4ce6e2b3990340b52719951e65731 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 30 Dec 2011 20:45:56 +0000 Subject: I2C. API changes mostly done. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3692 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 598719d24..f48ca9e7e 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -179,7 +179,7 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { */ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, - const uint8_t *txbuf, + uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, @@ -202,7 +202,10 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - return rdymsg; + if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) + return RDY_RESET; + else + return rdymsg; } /** @@ -228,7 +231,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, * @api */ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, - i2caddr_t slave_addr, + i2caddr_t addr, uint8_t *rxbuf, size_t rxbytes, systime_t timeout){ @@ -249,7 +252,10 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - return rdymsg; + if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) + return RDY_RESET; + else + return rdymsg; } #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From 72266f8b591c6e7857f4578ba753eeea7222ac6b Mon Sep 17 00:00:00 2001 From: barthess Date: Sat, 31 Dec 2011 09:40:52 +0000 Subject: I2C. Fixes. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3694 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index f48ca9e7e..841349be4 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -78,7 +78,6 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->id_state = I2C_STOP; i2cp->id_config = NULL; i2cp->rxbuf = NULL; - i2cp->txbuf = NULL; i2cp->id_thread = NULL; #if I2C_USE_MUTUAL_EXCLUSION @@ -179,7 +178,7 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { */ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, - uint8_t *txbuf, + const uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, @@ -202,10 +201,7 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) - return RDY_RESET; - else - return rdymsg; + return rdymsg; } /** @@ -252,10 +248,7 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); i2cp->id_state = I2C_READY; chSysUnlock(); - if (i2cGetErrors(i2cp) != I2CD_NO_ERROR) - return RDY_RESET; - else - return rdymsg; + return rdymsg; } #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__) -- cgit v1.2.3 From f76898bb0f7e6c894a1e5fb5d55f3e81a4f28fa6 Mon Sep 17 00:00:00 2001 From: barthess Date: Mon, 2 Jan 2012 17:53:20 +0000 Subject: I2C. Rest of "id_" prefixes deleted from driver. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3708 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 841349be4..fb45ce6a5 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -75,16 +75,16 @@ void i2cInit(void) { */ void i2cObjectInit(I2CDriver *i2cp) { - i2cp->id_state = I2C_STOP; - i2cp->id_config = NULL; + i2cp->state = I2C_STOP; + i2cp->config = NULL; i2cp->rxbuf = NULL; - i2cp->id_thread = NULL; + i2cp->thread = NULL; #if I2C_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES - chMtxInit(&i2cp->id_mutex); + chMtxInit(&i2cp->mutex); #else - chSemInit(&i2cp->id_semaphore, 1); + chSemInit(&i2cp->semaphore, 1); #endif /* CH_USE_MUTEXES */ #endif /* I2C_USE_MUTUAL_EXCLUSION */ @@ -104,14 +104,14 @@ void i2cObjectInit(I2CDriver *i2cp) { void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), "i2cStart(), #1", "invalid state"); chSysLock(); - i2cp->id_config = config; + i2cp->config = config; i2c_lld_start(i2cp); - i2cp->id_state = I2C_READY; + i2cp->state = I2C_READY; chSysUnlock(); } @@ -125,13 +125,13 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { void i2cStop(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cStop"); - chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), "i2cStop(), #1", "invalid state"); chSysLock(); i2c_lld_stop(i2cp); - i2cp->id_state = I2C_STOP; + i2cp->state = I2C_STOP; chSysUnlock(); } @@ -191,15 +191,15 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, (timeout != TIME_IMMEDIATE), "i2cMasterTransmitTimeout"); - chDbgAssert(i2cp->id_state == I2C_READY, + chDbgAssert(i2cp->state == I2C_READY, "i2cMasterTransmitTimeout(), #1", "not ready"); chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->id_state = I2C_ACTIVE_TRANSMIT; + i2cp->state = I2C_ACTIVE_TRANSMIT; rdymsg = i2c_lld_master_transmit_timeout(i2cp, addr, txbuf, txbytes, rxbuf, rxbytes, timeout); - i2cp->id_state = I2C_READY; + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } @@ -239,14 +239,14 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, (timeout != TIME_IMMEDIATE), "i2cMasterReceiveTimeout"); - chDbgAssert(i2cp->id_state == I2C_READY, + chDbgAssert(i2cp->state == I2C_READY, "i2cMasterReceive(), #1", "not ready"); chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->id_state = I2C_ACTIVE_RECEIVE; + i2cp->state = I2C_ACTIVE_RECEIVE; rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); - i2cp->id_state = I2C_READY; + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } @@ -268,9 +268,9 @@ void i2cAcquireBus(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cAcquireBus"); #if CH_USE_MUTEXES - chMtxLock(&i2cp->id_mutex); + chMtxLock(&i2cp->mutex); #elif CH_USE_SEMAPHORES - chSemWait(&i2cp->id_semaphore); + chSemWait(&i2cp->semaphore); #endif } @@ -290,7 +290,7 @@ void i2cReleaseBus(I2CDriver *i2cp) { #if CH_USE_MUTEXES chMtxUnlock(); #elif CH_USE_SEMAPHORES - chSemSignal(&i2cp->id_semaphore); + chSemSignal(&i2cp->semaphore); #endif } #endif /* I2C_USE_MUTUAL_EXCLUSION */ -- cgit v1.2.3 From 354a341507f6b174a576a8023f3f4bb2715b5b16 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 4 Jan 2012 10:36:13 +0000 Subject: Fixed some documentation errors. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3725 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index fb45ce6a5..42481a2fd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -160,7 +160,7 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) { * @param[in] addr slave device address (7 bits) without R/W bit * @param[in] txbuf pointer to transmit buffer * @param[in] txbytes number of bytes to be transmitted - * @param[in] rxbuf pointer to receive buffer + * @param[out] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received, set it to 0 if * you want transmit only * @param[in] timeout the number of ticks before the operation timeouts, @@ -209,10 +209,8 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, * * @param[in] i2cp pointer to the @p I2CDriver object * @param[in] addr slave device address (7 bits) without R/W bit + * @param[out] rxbuf pointer to receive buffer * @param[in] rxbytes number of bytes to be received - * @param[in] rxbuf pointer to receive buffer - * @param[in] errors pointer to variable to store error code, zero means - * no error. * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_INFINITE no timeout. -- cgit v1.2.3 From 8bd4ec7b8474fcfce5c4441131f841175d62e0b0 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 4 Jan 2012 11:19:31 +0000 Subject: Removed two initializations that should go in the low level. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3727 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 42481a2fd..66b01e0f3 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -77,8 +77,6 @@ void i2cObjectInit(I2CDriver *i2cp) { i2cp->state = I2C_STOP; i2cp->config = NULL; - i2cp->rxbuf = NULL; - i2cp->thread = NULL; #if I2C_USE_MUTUAL_EXCLUSION #if CH_USE_MUTEXES -- cgit v1.2.3 From 3f685aa996b5fd8af4ea87b67c32fa2ce311c273 Mon Sep 17 00:00:00 2001 From: barthess Date: Wed, 4 Jan 2012 14:36:51 +0000 Subject: I2C. Merged changes from i2c_lld_2.zip git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3729 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 1 - 1 file changed, 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 66b01e0f3..ea0df6589 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -29,7 +29,6 @@ * @addtogroup I2C * @{ */ - #include "ch.h" #include "hal.h" -- cgit v1.2.3 From 54c975bed0b0fbfbf6fdd1a5024c258150c4c5dc Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 6 Jan 2012 19:05:13 +0000 Subject: I2C driver state diagram modified, documentation improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3751 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index ea0df6589..fcccd6a87 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -101,7 +101,8 @@ void i2cObjectInit(I2CDriver *i2cp) { void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart"); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) || + (i2cp->state == I2C_LOCKED), "i2cStart(), #1", "invalid state"); @@ -122,7 +123,8 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) { void i2cStop(I2CDriver *i2cp) { chDbgCheck(i2cp != NULL, "i2cStop"); - chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY), + chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) || + (i2cp->state == I2C_LOCKED), "i2cStop(), #1", "invalid state"); @@ -193,10 +195,13 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_ACTIVE_TRANSMIT; + i2cp->state = I2C_ACTIVE_TX; rdymsg = i2c_lld_master_transmit_timeout(i2cp, addr, txbuf, txbytes, rxbuf, rxbytes, timeout); - i2cp->state = I2C_READY; + if (rdymsg == RDY_TIMEOUT) + i2cp->state = I2C_LOCKED; + else + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } @@ -239,9 +244,12 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp, chSysLock(); i2cp->errors = I2CD_NO_ERROR; - i2cp->state = I2C_ACTIVE_RECEIVE; + i2cp->state = I2C_ACTIVE_RX; rdymsg = i2c_lld_master_receive_timeout(i2cp, addr, rxbuf, rxbytes, timeout); - i2cp->state = I2C_READY; + if (rdymsg == RDY_TIMEOUT) + i2cp->state = I2C_LOCKED; + else + i2cp->state = I2C_READY; chSysUnlock(); return rdymsg; } -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index fcccd6a87..152a77840 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 152a77840..9e2438ecd 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 01f971ba1d63d8568789adf51cde22fb35f69e73 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Thu, 28 Feb 2013 16:23:19 +0000 Subject: Adjusted C file templates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5339 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/hal/src/i2c.c') diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 9e2438ecd..78519cc35 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -43,7 +43,7 @@ /*===========================================================================*/ /*===========================================================================*/ -/* Driver local variables. */ +/* Driver local variables and types. */ /*===========================================================================*/ /*===========================================================================*/ -- cgit v1.2.3