Proper PLIB Ethernet MIIM driver example in hamony
I'm using Harmony 2.06 and I've created MIIM read/write functions using PLIB library. Just to get started I've been using blocking functionality just to prove the concept and test out the library. It's seems to be working but I'd like to refactor the code to something usable and I'm limited on time, I'm wondering if there is a Harmony example I can possible lift and use?
Any help is greatly appreciated and the two test functions I have are below.
uint16_t mdio_read(uint8_t port_offset, uint8_t PhyReg)
{
ETH_MODULE_ID ethphyId = DRV_MIIM_ETH_MODULE_ID;
while ( PLIB_ETH_MIIMIsBusy(ethphyId));
PLIB_ETH_PHYAddressSet(ethphyId, port_offset);
PLIB_ETH_RegisterAddressSet(ethphyId,PhyReg);
PLIB_ETH_MIIMReadStart(ethphyId);
while ( PLIB_ETH_MIIMIsBusy(ethphyId));
PLIB_ETH_MIIMWriteStart(ethphyId); // Stop read cycle.
return PLIB_ETH_MIIMReadDataGet(ethphyId); // get the read register
}
void mdio_write(uint8_t port_offset, uint8_t PhyReg, uint16_t Value)
{
ETH_MODULE_ID ethphyId = DRV_MIIM_ETH_MODULE_ID;
while ( PLIB_ETH_MIIMIsBusy(ethphyId));
PLIB_ETH_PHYAddressSet(ethphyId, port_offset);
PLIB_ETH_RegisterAddressSet(ethphyId,PhyReg);
PLIB_ETH_MIIMWriteDataSet(ethphyId,Value);
while ( PLIB_ETH_MIIMIsBusy(ethphyId));
}