* Waits until either timeout_us have passed or (iff for_scl is set) until SCL * goes high. Will report random line changes during the wait and return SCL. */
| 28 | * goes high. Will report random line changes during the wait and return SCL. |
| 29 | */ |
| 30 | static int __wait(unsigned int bus, int timeout_us, int for_scl) |
| 31 | { |
| 32 | int us; |
| 33 | int sda = software_i2c[bus]->get_sda(bus); |
| 34 | int scl = software_i2c[bus]->get_scl(bus); |
| 35 | struct stopwatch sw; |
| 36 | |
| 37 | stopwatch_init_usecs_expire(&sw, timeout_us); |
| 38 | |
| 39 | do { |
| 40 | int old_sda = sda; |
| 41 | int old_scl = scl; |
| 42 | |
| 43 | us = stopwatch_duration_usecs(&sw); |
| 44 | |
| 45 | if (old_sda != (sda = software_i2c[bus]->get_sda(bus))) |
| 46 | spew("[SDA transitioned to %d after %dus] ", sda, us); |
| 47 | if (old_scl != (scl = software_i2c[bus]->get_scl(bus))) |
| 48 | spew("[SCL transitioned to %d after %dus] ", scl, us); |
| 49 | } while (!stopwatch_expired(&sw) && (!for_scl || !scl)); |
| 50 | |
| 51 | return scl; |
| 52 | } |
| 53 | |
| 54 | /* Waits the default DELAY_US to allow line state to stabilize. */ |
| 55 | static void wait(unsigned int bus) |
no test coverage detected