theCore-embedded / theCore

theCore: C++ embedded framework
https://forgge.github.io/theCore
Mozilla Public License 2.0
81 stars 23 forks source link

Add error handling to i2c bus implementaion #19

Closed vadimol closed 6 years ago

vadimol commented 8 years ago

For now i2c bus implementation does not support error handling. Actually device can hang in case of en error or glitch on a bus. For polling we can use timeouts for operations. For irq - there is a separate handler for errors.

rasendubi commented 7 years ago

We should also switch to using I2C_GetLastEvent instead of I2C_GetFlagStatus because the former allows checking for errors.

forGGe commented 7 years ago

@rasendubi Makes sense.

forGGe commented 7 years ago

@Dubland : check https://github.com/forGGe/theCore/issues/19#issuecomment-300573650

forGGe commented 7 years ago

Function usage is described in stm32 i2c source.

Checks like these https://github.com/forGGe/theCore/blob/develop/platform/stm32/export/aux/i2c_bus.hpp#L586 must be re-implemented using I2C_GetFlagStatus.

Error can be reported using bus event: https://github.com/forGGe/theCore/blob/develop/platform/common/export/common/bus.hpp#L26

After that, soft_reset can try to repeat xfer if necessary: https://github.com/forGGe/theCore/blob/develop/dev/sensor/htu21d/export/dev/sensor/htu21d.hpp#L177

Talk to @vadimol for more details of how i2c driver works if something unclear.

rasendubi commented 7 years ago

A small correction: checks must be re-implemented using I2C_GetLastEvent.

I2C_GetFlagStatus resets some status flags so is not appropriate to call multiple times in a row.

forGGe commented 6 years ago

Implemented as a part of #279 Thanks to @Dubland !