/*----------------------------------------------------------------------------- * I2C_Recovery: Recovery procedure for I2C lines when irregular * communication interrupt occures. * * Return: 0 on success, nonzero on error *----------------------------------------------------------------------------*/ uint32_t I2C_Recovery (uint32_t err) { uint32_t i; #if 1 GPIOB->AFR[1] &= ~0x000000FF; /* Set SDA and SCL as GPIO */ I2C1->CR1 |= I2C_CR1_SWRST; /* Put I2C peripheral in reset mode */ io_dir (IO_SDA | IO_SCL, IO_OUT); /* SDA and SCL pins are outputs */ io_pin (IO_SDA | IO_SCL, IO_HI); /* Pull both lines high */ Wait(); io_pin (IO_SCL, IO_LOW); /* Generate start ccondition */ io_pin (IO_SDA, IO_HI); /* Pull SDA high */ for (i = 0; i < 9; i++) { if (io_state (IO_SDA) == IO_HI) break; /* Break if SDA released by slave */ io_pin (IO_SCL, IO_HI); /* Clock high */ Wait(); io_pin (IO_SCL, IO_LOW); /* Clock low */ Wait(); } /* Send stop */ io_pin (IO_SDA, IO_LOW); /* Pull SDA low */ io_pin (IO_SCL, IO_HI); /* Pull SCL high */ Wait(); io_pin (IO_SDA, IO_HI); /* Pull SDA high == stop condition */ I2C1->CR1 &= ~I2C_CR1_SWRST; /* Dereset I2C peripheral */ return (I2C_Init()); /* Reinit I2C peripheral */ #else return (1); #endif }
static int tcp_server_client_state(object_t parent) { return io_state(parent); }