/** \brief Check connection between chips * * \return true if the connection between chips is OK */ bool ksz8051_nandtree_check(void) { /* reset the controller and switch to nand tree mode */ io_output_low(MII_PIN_RST); io_output_low(MII_PIN_INTRP); // short delay io_high(MII_PIN_RST); // delay /* prepare all pins to NAND tree test */ for (uint32_t i = 0; i < N; i++) { io_output_high(nand_pins[i]); } io_input(MII_PIN_CRS); // delay /* process the NAND tree test on CRS (PA0) */ uint32_t nandtree = io_is_set(MII_PIN_CRS) ? 1 : 0; for (uint32_t i = 0; i < N; i++, nandtree <<= 1) { io_low(nand_pins[i]); nandtree |= io_is_set(MII_PIN_CRS) ? 1 : 0; // short delay } /* reset the controller and switch back to the normal mode */ io_low(MII_PIN_RST); io_high(MII_PIN_INTRP); io_af(MII_PIN_CRS, MII_AF); for (uint32_t i = 0; i < N; i++) { io_af(nand_pins[i], MII_AF); } // delay io_high(MII_PIN_RST); return (nandtree == 0b10101010101010101); }
int main(){ io_out(LED); i2c_init(); while(1){ io_high(LED); _delay_ms(1000); io_low(LED); _delay_ms(1000); } }