void NICPut(int8 reg, int8 val) { WRITE_NIC_ADDR(reg); NIC_DATA_LAT = val; SET_NIC_WRITE(); NIC_IOW_LAT = 0; NIC_IOW_LAT = 1; SET_NIC_READ(); }
int8 NICGet(int8 reg) { int8 val; SET_NIC_READ(); WRITE_NIC_ADDR(reg); NIC_IOR_LAT = 0; val = NIC_DATA_IO; NIC_IOR_LAT = 1; return val; }
/** * Write a byte to the I/O Port */ void NICPut(BYTE reg, BYTE val) { WRITE_NIC_ADDR(reg); NIC_DATA_IO = val; TRISD = 0x00; //Output BEGIN_IO_CYCLE(); NIC_IOW_IO = 0; WAIT_FOR_IOCHRDY(); NIC_IOW_IO = 1; LEAVE_IO_CYCLE(); }
/** * Read a byte from the I/O Port */ BYTE NICGet(BYTE reg) { BYTE val; TRISD = 0xff; //Input WRITE_NIC_ADDR(reg); BEGIN_IO_CYCLE(); NIC_IOR_IO = 0; WAIT_FOR_IOCHRDY(); val = NIC_DATA_IO; NIC_IOR_IO = 1; LEAVE_IO_CYCLE(); return val; }
/** * Reads a single byte via Remote DMA from the current MAC Receive buffer. * If the last byte of the RX Buffer was read, this function automatically * updates the Remote DMA read address to the first page of the RX Buffer. * See PreConditions for more info. * * @preCondition: Remote DMA address has to be set up prior to calling this function. * The Remote DMA registers are NOT configured by this function, * and simply continue reading from the current "Remote DMA Address". A function * like MACRxbufGetHdr() can be called prior to this function to configure Remote * DMA to read the next packet in RX Buffer (situated in Remote DMA RAM) * * @return Read byte */ BYTE MACRxbufGet(void) { #if defined(__18CXX) overlay #endif BYTE b; //Configure RBCR (Remote Byte Count Register) for bytes to be read via DMA FirstFastNICPut(RBCR0, 1); FastNICPut(RBCR1, 0); //Last byte of MAC RX Buffer is read wronge by RTL8019AS - Address has to be set again! if ((DMAAddr.v[0] == 0xff) && (DMAAddr.v[1] == (RXSTOP-1))) { //Set NIC Remote DMA read again - this fixes the RTL8019AS bug!!!! NICSetAddr((RXSTOP << 8) - 1); //Remote DMA Read command. This causes given (RBCR0 & 1) number of bytes, starting at given //address (RSAR0 & 1) set by NICSetAddr() to be read with each I/O read cycle. FastNICPut(CMDR, 0x0a); b = NICGet(NIC_DATAPORT); //Read I/O port //Reset to first byte of MAC RX Buffer - this function also updates DMAAddr //This fixes the RTL8019AS bug where the address point is not updated to first byte of Receive Buffer NICSetAddr(RXSTART << 8); } else { //Remote DMA Read command. This causes given (RBCR0 & 1) number of bytes, starting at given //address (RSAR0 & 1) set by NICSetAddr() to be read with each I/O read cycle. FastNICPut(CMDR, 0x0a); //Read a byte from the I/O port TRISD = 0xff; //Input WRITE_NIC_ADDR(NIC_DATAPORT); BEGIN_IO_CYCLE(); NIC_IOR_IO = 0; WAIT_FOR_IOCHRDY(); b = NIC_DATA_IO; NIC_IOR_IO = 1; LEAVE_IO_CYCLE(); //The above I/O port operation updated the Remote DMA address DMAAddr.Val++; } return (b); }
/** * Reads the given amount of bytes via Remote DMA from the current MAC Receive buffer. * If the end of the RX Buffer is reached, this function automatically rolls over to * the first page of the RX Ring Buffer. See PreConditions above for more info. * * @preCondition Remote DMA address has to be set up prior to calling this function. * The Remote DMA registers are NOT configured by this function, * and simply continue reading from the current "Remote DMA Address". A function * like MACRxbufGetHdr() can be called prior to this function to configure Remote * DMA to read the next packet in RX Buffer (situated in Remote DMA RAM) * * @param len Length of array to be read * @param val Buffer to read packet into * * @return Number of bytes read * */ WORD MACRxbufGetArray(BYTE *val, WORD len) { #if defined(__18CXX) overlay #endif WORD_VAL t; t.Val = len; //Configure RBCR (Remote Byte Count Register) for bytes to be read via DMA FirstFastNICPut(RBCR0, t.byte.LSB); FastNICPut(RBCR1, t.byte.MSB); //Remote DMA Read command. This causes given (RBCR0 & 1) number of bytes, starting at given //address (RSAR0 & 1) set by NICSetAddr() to be read with each I/O read cycle. FastNICPut(CMDR, 0x0a); //Update DMAAddr for what it will be after all requested bytes are read DMAAddr.Val += len; if (DMAAddr.v[1] >= RXSTOP) { //If end of MAC Receive buffer is reached, roll over to beginning of buffer DMAAddr.Val -= (RXPAGES << 8); } //Read requested number of bytes from I/O port TRISD = 0xff; //Input WRITE_NIC_ADDR(NIC_DATAPORT); while( len-- > 0 ) { BEGIN_IO_CYCLE(); NIC_IOR_IO = 0; WAIT_FOR_IOCHRDY(); *val++ = NIC_DATA_IO; NIC_IOR_IO = 1; LEAVE_IO_CYCLE(); } #if (DEBUG_MAC >= LOG_ERROR) if (DMAAddr.Val != MACGetNICAddr()) { debugPutMsg(2); } #endif return t.Val; }
void NICReset(void) { SET_NIC_READ(); WRITE_NIC_ADDR(0); NIC_IOW_LAT = 1; NIC_IOR_LAT = 1; NIC_RESET_LAT = 1; NIC_RESET_TRIS=0; NIC_IOW_TRIS=0; NIC_IOR_TRIS=0; // Reset pulse must be at least 800 ns. delay_us(10); NIC_RESET_LAT = 0; }
/** * Reset the NIC */ void NICReset(void) { #if (DEBUG_MAC >= LOG_INFO) debugPutMsg(5); //@mxd:5:Reset MAC #endif TRISD = 0xff; //Input WRITE_NIC_ADDR(0); NIC_IOW_IO = 1; NIC_IOR_IO = 1; NIC_RESET_IO = 1; NIC_CTRL_TRIS = 0x00; // Reset pulse must be at least 800 ns. Delay10us(1); DelayMs(5); NIC_RESET_IO = 0; }