| Description | The poll_ethernet function polls the ethernet status register for any received ethernet packets. If there is a new packet, it allocates a block of memory. It then reads and copies the packet from the ethernet controller into the allocated memory. The function puts the pointer to the memory block into the received frames queue by calling the put_in_queue function. The poll_ethernet function is part of RL-TCPnet. The prototype is defined in net_config.h. note - You must provide the poll_ethernet function if the ethernet controller you use is different from the ones provided in the TCPnet source.
- You must provide the poll_ethernet function only if you want to use the ethernet driver in poll mode.
- The TcpNet system frequently calls poll_ethernet to poll for any received ethernet packet.
|
| Example |
void poll_ethernet (void) {
/* Poll the Ethernet controller for received frames. If the Ethernet */
/* controller runs in interrupt mode, this function must be empty. */
OS_FRAME *frame;
U32 State, RxLen;
U32 val, *dp;
LREG (U16, BSR) = 2;
val = LREG (U8, B2_IST);
if (!(val & (IST_RCV | IST_RX_OVRN))) {
/* Nothing received yet. */
return;
}
if (val & IST_RX_OVRN) {
/* Clear the RX overrun bit. */
LREG (U8, B2_ACK) = ACK_RX_OVRN;
return;
}
State = LREG (U16, B2_FIFO);
if (State & FIFO_REMPTY) {
/* Check if empty packet. */
return;
}
/* Read status and packet length */
LREG (U16, B2_PTR) = PTR_RCV | PTR_AUTO_INCR | PTR_READ;
val = LREG (U32, B2_DATA);
State = val & 0xFFFF;
RxLen = (val >> 16) - 6;
if (State & RFS_ODDFRM) {
/* Odd number of bytes in a frame. */
RxLen++;
}
if (RxLen > ETH_MTU) {
/* Packet too big, ignore it and free MMU. */
LREG (U16, BSR) = 2;
LREG (U16, B2_MMUCR) = MMU_REMV_REL_RX;
return;
}
frame = alloc_mem (RxLen);
/* Make sure that block is 4-byte aligned */
RxLen = (RxLen + 3) >> 2;
dp = (U32 *)&frame->data[0];
for ( ; RxLen; RxLen--) {
*dp++ = LREG (U32, B2_DATA);
}
/* MMU free packet. */
LREG (U16, BSR) = 2;
LREG (U16, B2_MMUCR) = MMU_REMV_REL_RX;
put_in_queue (frame);
}
|