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/include/i2c.h | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'os/hal/include') diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h index 0a4ba8b53..774c0cf22 100644 --- a/os/hal/include/i2c.h +++ b/os/hal/include/i2c.h @@ -165,9 +165,9 @@ struct I2CSlaveConfig{ * @notapi */ #define _i2c_wait_s(i2cp) { \ - chDbgAssert((i2cp)->id_thread == NULL, \ + chDbgAssert((i2cp)->id_thread == NULL, \ "_i2c_wait(), #1", "already waiting"); \ - (i2cp)->id_thread = chThdSelf(); \ + (i2cp)->id_thread = chThdSelf(); \ chSchGoSleepS(THD_STATE_SUSPENDED); \ } @@ -179,9 +179,9 @@ struct I2CSlaveConfig{ * @notapi */ #define _i2c_wakeup_isr(i2cp) { \ - if ((i2cp)->id_thread != NULL) { \ - Thread *tp = (i2cp)->id_thread; \ - (i2cp)->id_thread = NULL; \ + if ((i2cp)->id_thread != NULL) { \ + Thread *tp = (i2cp)->id_thread; \ + (i2cp)->id_thread = NULL; \ chSysLockFromIsr(); \ chSchReadyI(tp); \ chSysUnlockFromIsr(); \ @@ -218,6 +218,31 @@ struct I2CSlaveConfig{ _i2c_wakeup_isr(i2cp); \ } +/** + * @brief Error ISR code. + * @details This code handles the portable part of the ISR code: + * - Error callback invocation. + * - Waiting thread wakeup, if any. + * - Driver state transitions. + * + * @note This macro is meant to be used in the low level drivers + * implementation only. + * + * @param[in] i2cp pointer to the @p I2CDriver object + * + * @notapi + */ +#define _i2c_isr_err_code(i2cp, i2cscfg) { \ + (i2cp)->id_state = I2C_COMPLETE; \ + if(((i2cp)->id_slave_config)->id_err_callback) { \ + ((i2cp)->id_slave_config)->id_err_callback(i2cp, i2cscfg); \ + if((i2cp)->id_state == I2C_COMPLETE) \ + (i2cp)->id_state = I2C_READY; \ + } \ + else \ + (i2cp)->id_state = I2C_READY; \ + _i2c_wakeup_isr(i2cp); \ +} /*===========================================================================*/ /* External declarations. */ -- cgit v1.2.3