| 424 | } |
| 425 | |
| 426 | struct rt_phy_device *rt_phy_find_by_mask(struct mii_bus *bus, unsigned int phy_mask) |
| 427 | { |
| 428 | struct rt_phy_device *phy; |
| 429 | unsigned int mask = phy_mask; |
| 430 | unsigned int addr; |
| 431 | if (bus->reset) |
| 432 | { |
| 433 | bus->reset(bus); |
| 434 | |
| 435 | rt_thread_mdelay(15); |
| 436 | } |
| 437 | |
| 438 | while (mask) |
| 439 | { |
| 440 | /* |
| 441 | *Whichever bit of the mask is the 1, |
| 442 | *which bit is the addr as the array subscript to search |
| 443 | *such as mask = 1110 ,this loop will search for subscript |
| 444 | *1,2,3,if the array subscript is not null then return it, |
| 445 | *if the array subscript is null then continue to search |
| 446 | */ |
| 447 | addr = __rt_ffs(mask) - 1; |
| 448 | |
| 449 | if (bus->phymap[addr]) |
| 450 | return bus->phymap[addr]; |
| 451 | |
| 452 | mask &= ~(1U << addr); |
| 453 | } |
| 454 | /*ifcan't find phy device, create a new phy device*/ |
| 455 | phy = rt_phydev_create_by_mask(bus, phy_mask); |
| 456 | |
| 457 | return phy; |
| 458 | |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * @brief get phy device by given mii bus, node and address |
no test coverage detected