Analysis of DM9000 Drive in U-boot
1. CSRS and PHY Reg Read and write.
1 StaticU162Phy_read (intreg)3 {4 U16 Val;5 6 /*Fill the Phyxcer register into reg_0c*/7Dm9000_iow (Dm9000_epar, dm9000_phy |reg);8Dm9000_iow (DM9000_EPCR,0xc);/*Issue phyxcer Read command*/9Udelay ( -);/*Wait Read complete*/TenDm9000_iow (DM9000_EPCR,0x0);/*Clear phyxcer Read command*/ Oneval = (Dm9000_ior (DM9000_EPDRH) <<8) |Dm9000_ior (DM9000_EPDRL); A - /*The read data keeps on reg_0d & reg_0e*/ -DM9000_DBG ("Phy_read (%d):%d\n", Reg, Val); the returnVal; -}Phy_read
1 Static void2Phy_write (intReg, U16 value)3 {4 5 /*Fill the Phyxcer register into reg_0c*/6Dm9000_iow (Dm9000_epar, dm9000_phy |reg);7 8 /*Fill the written data into reg_0d & reg_0e*/9Dm9000_iow (DM9000_EPDRL, (Value &0xFF));TenDm9000_iow (DM9000_EPDRH, (Value >>8) &0xFF)); OneDm9000_iow (DM9000_EPCR,0xa);/*Issue phyxcer Write command*/ AUdelay ( -);/*Wait Write complete*/ -Dm9000_iow (DM9000_EPCR,0x0);/*Clear phyxcer Write command*/ -DM9000_DBG ("Phy_write (reg:%d, value:%d) \ n", Reg, value); the}Phy_write
1 StaticU82Dm9000_ior (intreg)3 {4 u32 Val;5 6 Validate_addr_port (REG)7 8val = * (u16*) Dm9000_data;9 TenVal &=0xFFFF; One A return(U8) Val; -}Dm9000_ior
1 Static void 2 dm9000_iow (int reg, U8 value)3{4 validate_addr_ PORT (REG)56 * (u16*) (dm9000_data) = (u16) value; 7 }
Dm9000_iow
1 #define 2 if (m_ulastaddressport!=3 4 * (u16*) (dm9000_io) =(U16) (p) ; 5 M_ulastaddressport = (p); 6 }
Validate_addr_port
2. Network Port Transceiver
1 int2ETH_RX (void)3 {4U8 Rxbyte, *rdptr = (U8 *) netrxpackets[0];5 interrors=0;6 U16 Rxlen;7 8 u32 desc;9 pdm9000_rx_descriptor Pdesc;Ten One Dm9000_ior (DM9000_RSR); A Dm9000_ior (DM9000_ROCR); - - for(Pdesc= (Pdm9000_rx_descriptor) &desc;;) the { - //probe first byte -desc =devicereaddatawithoutincrement (); -DM9000_DBG ("1:\tdesc is 0x%x\n", desc); + - //Check if packet available, 01h means available, 00h means no data + if(Pdesc->bstate! =0x01) A { atRxlen =0; - Break; - } - - //get the data descriptor again -desc =Devicereaddata (); inDM9000_DBG ("2:\tdesc is 0x%x\n", DESC); - toDM9000_DBG ("Len is 0x%x\n",pdesc->nlength); + -Devicereadstring (rdptr,pdesc->nlength); the * //check status, as specified in DM9000_RXSR, $ //The following bits is errorPanax Notoginseng //<3> PLE - //<2> AE the //<1> CE + //<0> FOE A if(Pdesc->bstatus & Make_mask4 (3,2,1,0)) the { +errors++; - Continue; $}//of error happens $ -Rxlen =pdesc->nlength; - the Break; -}//of forever Read LoopWuyi the /*Pass to upper layer*/ -DM9000_DBG ("passing packet to upper layer\n"); WuNetreceive (netrxpackets[0], rxlen); - returnRxlen; About}Eth_rx
1 int2Eth_send (volatile void*packet,intlength)3 {4UnsignedintLoop;5 #if06 for(Loop =0; loop<length;loop++)7 {8printf"%02x",*((Char*) packet+loop)); 9 }Tenprintf"\ n"); One #endif ADevicewritestring ((u8*) packet,length); - - Dm9000_iow (dm9000_txplh,high_byte (length)); the Dm9000_iow (dm9000_txpll,low_byte (length)); - - //Txcr<0>, issue TX request -Dm9000_iow (DM9000_TCR, Make_mask (0)); + - +DM9000_DBG ("Transmit done\n\n"); A return 0; at}Eth_send
Data is received first 4 bytes above the header, the first byte must be 0x01, the 3rd, 4 bytes is the length of the data (minus 4 bytes from the beginning).
When the data is received, it is compared to the second byte (DM9000 RSR) to confirm whether the error occurred again.
The programming technique used is to read the header 4 bytes directly assigned to a u32, the lowest byte is 01, the height two bits is the packet length.
U-boot--The software part of the network port processing