void wizphy_setphyconf(wiz_PhyConf* phyconf) { uint8_t tmp = 0; if(phyconf->by == PHY_CONFBY_SW) tmp |= PHYCFGR_OPMD; else tmp &= ~PHYCFGR_OPMD; if(phyconf->mode == PHY_MODE_AUTONEGO) tmp |= PHYCFGR_OPMDC_ALLA; else { if(phyconf->duplex == PHY_DUPLEX_FULL) { if(phyconf->speed == PHY_SPEED_100) tmp |= PHYCFGR_OPMDC_100F; else tmp |= PHYCFGR_OPMDC_10F; } else { if(phyconf->speed == PHY_SPEED_100) tmp |= PHYCFGR_OPMDC_100H; else tmp |= PHYCFGR_OPMDC_10H; } } setPHYCFGR(tmp); wizphy_reset(); }
void ip_init(void){ wiz_NetInfo netInfo; uint8_t bufSize[] = {2, 2, 2, 2}; reg_wizchip_cs_cbfunc(cs_sel, cs_desel); reg_wizchip_spi_cbfunc(spi_rb, spi_wb); wizphy_reset(); wizchip_init(bufSize, bufSize); memcpy_P(&netInfo, &network_info, sizeof(wiz_NetInfo)); wizchip_setnetinfo(&netInfo); sock_state=IP_STATE_NO_SOCKET; }
int8_t wizphy_setphypmode(uint8_t pmode) { uint8_t tmp = 0; tmp = getPHYCFGR(); if((tmp & PHYCFGR_OPMD)== 0) return -1; tmp &= ~PHYCFGR_OPMDC_ALLA; if( pmode == PHY_POWER_DOWN) tmp |= PHYCFGR_OPMDC_PDOWN; else tmp |= PHYCFGR_OPMDC_ALLA; setPHYCFGR(tmp); wizphy_reset(); tmp = getPHYCFGR(); if( pmode == PHY_POWER_DOWN) { if(tmp & PHYCFGR_OPMDC_PDOWN) return 0; } else { if(tmp & PHYCFGR_OPMDC_ALLA) return 0; } return -1; }
int8_t ctlwizchip(ctlwizchip_type cwtype, void* arg) { uint8_t tmp = 0; uint8_t* ptmp[2] = {0,0}; switch(cwtype) { case CW_RESET_WIZCHIP: wizchip_sw_reset(); break; case CW_INIT_WIZCHIP: if(arg != 0) { ptmp[0] = (uint8_t*)arg; ptmp[1] = ptmp[0] + _WIZCHIP_SOCK_NUM_; } return wizchip_init(ptmp[0], ptmp[1]);; case CW_CLR_INTERRUPT: wizchip_clrinterrupt(*((intr_kind*)arg)); break; case CW_GET_INTERRUPT: *((intr_kind*)arg) = wizchip_getinterrupt(); break; case CW_SET_INTRMASK: wizchip_setinterruptmask(*((intr_kind*)arg)); break; case CW_GET_INTRMASK: *((intr_kind*)arg) = wizchip_getinterruptmask(); break; #if _WIZCHIP_ > 5100 case CW_SET_INTRTIME: setINTLEVEL(*(uint16_t*)arg); break; case CW_GET_INTRTIME: *(uint16_t*)arg = getINTLEVEL(); break; #endif case CW_GET_ID: ((uint8_t*)arg)[0] = WIZCHIP.id[0]; ((uint8_t*)arg)[1] = WIZCHIP.id[1]; ((uint8_t*)arg)[2] = WIZCHIP.id[2]; ((uint8_t*)arg)[3] = WIZCHIP.id[3]; ((uint8_t*)arg)[4] = WIZCHIP.id[4]; ((uint8_t*)arg)[5] = 0; break; #if _WIZCHIP_ == 5500 case CW_RESET_PHY: wizphy_reset(); break; case CW_SET_PHYCONF: wizphy_setphyconf((wiz_PhyConf*)arg); break; case CW_GET_PHYCONF: wizphy_getphyconf((wiz_PhyConf*)arg); break; case CW_GET_PHYSTATUS: break; case CW_SET_PHYPOWMODE: return wizphy_setphypmode(*(uint8_t*)arg); #endif case CW_GET_PHYPOWMODE: tmp = wizphy_getphypmode(); if((int8_t)tmp == -1) return -1; *(uint8_t*)arg = tmp; break; case CW_GET_PHYLINK: tmp = wizphy_getphylink(); if((int8_t)tmp == -1) return -1; *(uint8_t*)arg = tmp; break; default: return -1; } return 0; }