📄 mac_low.c
字号:
#include "mac_low.h"void mac_low_init(void){ Uint8 x; Uint16 addr; BD_TYPE *bdptr; //Initializes the MAC module //Setup the mode register for Full duplex (bit 10); EMAC_MODE |= 0x00000400; //Setup the BD NUM EMAC_TXBDNUM = TXBDNUM; //Setup IPGT EMAC_IPGT = 0x15; //mac_clr_rxbd(); //Loop through and clear RX BD's //Evens start at low address and increment up for (x=0,addr=EMAC_RX_OFFSET;x<RXBDCOUNT;x++) { mac_clr_rxbd(x); mac_setbdaddr(x++,addr); addr += RXBDSIZE; } //Odds start high and decrement for (x=1,addr=EMAC_RAM_SIZE;x<RXBDCOUNT;x++) { addr -= RXBDSIZE; mac_clr_rxbd(x); mac_setbdaddr(x++,addr); } //Set the last BD to wrap mac_setwr(RXBDCOUNT-1); //mac_setwr(1);}//Sets length of TXBD//Length should be in 16-bit wordsvoid mac_set_len(Uint8 bdnum,Uint16 data_len){ BD_TYPE *bdptr; Uint32 word = 0; Uint8 *tmpptr; tmpptr = (Uint8 *) EMAC_TXBD_PTR; tmpptr += bdnum*BD_SIZE; //bdptr = (BD_TYPE *) EMAC_RXBD_PTR; //bdptr += (Uint8*) bdnum*BD_SIZE; bdptr = (BD_TYPE *) tmpptr; //Sets the length in the TX BD //bdptr = EMAC_TXBD_PTR; word = ((data_len*2) & 0xFFFF) << 16; //dbg_string((Uint16 *) &word,2); //Clear upper 2 bytes first bdptr->reg &= ~(0xFFFF0000); bdptr->reg |= word;}//Clears the RX BD and re-initializesvoid mac_clr_rxbd(Uint8 bdnum){ BD_TYPE *bdptr; Uint8 *tmpptr; //bdptr = (BD_TYPE *) (EMAC_RXBD_PTR+(bdnum*BD_SIZE)); tmpptr = (Uint8 *) EMAC_RXBD_PTR; tmpptr += bdnum*BD_SIZE; //bdptr = (BD_TYPE *) EMAC_RXBD_PTR; //bdptr += (Uint8*) bdnum*BD_SIZE; bdptr = (BD_TYPE *) tmpptr; //bdptr->reg = 0xE000; bdptr->reg &= ~(0x0fff); //bdptr->reg &= ~(0x1FF); //bdptr->reg = 0xC000; bdptr->reg |= 0xC000;}//Sets wrapping on the BDvoid mac_setwr(Uint8 bdnum){ BD_TYPE *bdptr; Uint8 *tmpptr; tmpptr = (Uint8 *) EMAC_RXBD_PTR; tmpptr += bdnum*BD_SIZE; //bdptr = (BD_TYPE *) EMAC_RXBD_PTR; //bdptr += (Uint8*) bdnum*BD_SIZE; bdptr = (BD_TYPE *) tmpptr; bdptr->reg |= 0x2000;}void mac_setbdaddr(Uint8 bdnum,Uint16 address){ BD_TYPE *bdptr; Uint8 *tmpptr; tmpptr = (Uint8 *) EMAC_RXBD_PTR; tmpptr += bdnum*BD_SIZE; //bdptr = (BD_TYPE *) EMAC_RXBD_PTR; //bdptr += (Uint8*) bdnum*BD_SIZE; bdptr = (BD_TYPE *) tmpptr; //Setup pointer to point to ram bdptr->buffer_address = address;}Uint32 mac_getbdaddr(Uint8 bdnum){ BD_TYPE *bdptr; Uint8 *tmpptr; Uint32 word; Uint16 tmpint; tmpptr = (Uint8 *) EMAC_RXBD_PTR; tmpptr += bdnum*BD_SIZE; //bdptr = (BD_TYPE *) EMAC_RXBD_PTR; //bdptr += (Uint8*) bdnum*BD_SIZE; bdptr = (BD_TYPE *) tmpptr; word = bdptr->buffer_address; word += EMAC_RAM_PTR; return word;}void mac_set_address(Uint8 *mac_address){ Uint32 tmpword = 0; tmpword = ((mac_address[0] & 0xff) << 8) | (mac_address[1] & 0xff); EMAC_MACADDR1 = tmpword; tmpword = ((mac_address[2] & 0xff) << 24) | ((mac_address[3] & 0xff) << 16) | ((mac_address[4] & 0xff) << 8) | ((mac_address[5] & 0xff)); EMAC_MACADDR0 = tmpword;}void mac_txen(void){ //Enable the transmitter by setting bit 1 EMAC_MODE |= 0x00000002;}void mac_rxen(void){ //Enable the receiver by setting bit 0 EMAC_MODE |= 0x00000001;}//Clears the RX interruptvoid mac_clr_rxint(void){ EMAC_INT_SRC |= 0x4;}//Unmasks the RX interruptvoid mac_rxint_en(void){ EMAC_INT_MASK |= 4;}//Masks the RX interruptvoid mac_rxint_dis(void){ EMAC_INT_MASK &= ~4;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -