예제 #1
0
파일: emac.c 프로젝트: running1919/qianlab
/**
 * Execute PHY maintanance command
 */
void EMAC_PHYMaintain(Emac      *pEmac,
                      uint8_t   bPhyAddr,
                      uint8_t   bRegAddr,
                      uint8_t   bRW,
                      uint16_t  wData)
{
    /* Wait until bus idle */
    while((pEmac->EMAC_NSR & EMAC_NSR_IDLE) == 0);
    /* Write maintain register */
    pEmac->EMAC_MAN = EMAC_MAN_CODE(10) | EMAC_MAN_SOF(0x1)
                    | EMAC_MAN_PHYA(bPhyAddr)
                    | EMAC_MAN_REGA(bRegAddr)
                    | EMAC_MAN_RW((bRW ? 0x2 : 0x1))
                    | EMAC_MAN_DATA(wData)
                    ;
}
예제 #2
0
void sam3xEthWritePhyReg(uint8_t phyAddr, uint8_t regAddr, uint16_t data)
{
   //Set up a write operation
   uint32_t value = EMAC_MAN_SOF(1) | EMAC_MAN_RW(1) | EMAC_MAN_CODE(2);
   //PHY address
   value |= EMAC_MAN_PHYA(phyAddr);
   //Register address
   value |= EMAC_MAN_REGA(regAddr);
   //Register value
   value |= EMAC_MAN_DATA(data);

   //Start a write operation
   EMAC->EMAC_MAN = value;
   //Wait for the write to complete
   while(!(EMAC->EMAC_NSR & EMAC_NSR_IDLE));
}