📄 custom_ethernet.c
字号:
retval = ETHER_SEND_ERROR;
break;
}
else if (1)
{
// If the transmission was successful, break.
break;
}
}
}
// Clear the transmit busy signal
MN_XMIT_BUSY_CLEAR;
return (retval);
}
/************************************************************/
/* */
/* ether_poll_recv */
/* */
/* This function is called periodically by the TCP/IP */
/* stack. It polls the Ethernet controller to determine if */
/* it has received a packet. */
/* */
/* It places the received packet (excluding the FCS) into */
/* recv_buff, the receive queue of the TCP/IP stack. */
/* */
/* Returns the number of bytes received if successful or a */
/* negative number on error. */
/* */
/************************************************************/
int ether_poll_recv(void)
{
word16 recv_len, i;
TIMER_INFO_T wait_timer;
int retval;
byte oddLength;
retval = 0;
/* Check to see if a packet has been received.
If a packet has not been received, start a timer to
run ether_wait_ticks and poll the Ethernet controller
to see if a packet has arrived.
*/
/******************************************************/
/* */
/* Replace PACKET_RECEIVED with code which determines */
/* if the Ethernet controller has received a packet. */
/* */
/******************************************************/
if (1)
{
mn_reset_timer(&wait_timer,(ether_wait_ticks));
while (!mn_timer_expired(&wait_timer))
{
// Make a call to callback_app_recv_idle().
// If callback_app_recv_idle() returns NEED_TO_EXIT, exit immediately.
if(callback_app_recv_idle() == NEED_TO_EXIT)
return (NEED_TO_EXIT);
/******************************************************/
/* */
/* Replace PACKET_RECEIVED with code which determines */
/* if the Ethernet controller has received a packet. */
/* */
/******************************************************/
if (1)
{
retval = 1;
break;
}
}
if (!retval)
return (SOCKET_TIMED_OUT);
}
/******************************************************/
/* */
/* Modify this code to read the RX status register of */
/* the Ethernet controller and determine if the */
/* packet was received properly. */
/* */
/******************************************************/
// if(!(ETHER_RDWR[RX_RESULT] & RX_OK)) // Check that packet was received properly.
// {
/******************************************************/
/* */
/* Replace SKIPFRAME with code which flushes the */
/* packet from the Ethernet controller. */
/* */
/******************************************************/
// SKIPFRAME;
// return(ETHER_RECV_ERROR);
// }
recv_len = 0x0000;
/*********************************************************/
/* */
/* Modify this code to read the length of the */
/* received packet from the Ethernet controller. */
/* The length is put into the 16-bit variable recv_len. */
/* */
/* NOTE: The FCS should not be copied into recv_buff. */
/* If the packet length includes the 4 bytes of FCS, */
/* subtract four from recv_len. */
/* */
/**********************************************************/
// recv_len = (ETHER_RDWR[RX_LENGTH] << 8); // Get length of received packet
// recv_len |= ETHER_RDWR[RX_LENGTH];
oddLength = recv_len & 0x01; // Determine whether recv_len is odd or even
if ( (recv_buff_size - recv_count) > recv_len) // Check to see if there is room in the receive
{ // buffer for the packet
retval = recv_len; // The packet length will be returned.
/* put recv_len into buffer so all packets start with the length.
Do NOT remove the next two lines.
*/
mn_put_recv_byte(HIGHBYTE(recv_len));
mn_put_recv_byte(LOWBYTE(recv_len));
if (oddLength)
recv_len--; // need even count for the loop
// If the FCS is included with the received packet,
// DO NOT copy the FCS into recv_buff.
for ( i = 0; i < recv_len; i += 2)
{
/******************************************************/
/* */
/* Modify this code to read a byte from the RX buffer */
/* on the Ethernet controller and place it in the */
/* location pointed to by recv_in_ptr. */
/* */
/******************************************************/
// *recv_in_ptr = ETHER_RDWR[RX_PORT]; // Place one byte of the packet in the receive buffer
++recv_in_ptr; // Increment recv_in_ptr
if (recv_in_ptr >= &recv_buff[recv_buff_size]) // If necessary, loop
recv_in_ptr = &recv_buff[0]; // recv_in_ptr around.
/******************************************************/
/* */
/* Modify this code to read a byte from the RX buffer */
/* on the Ethernet controller and place it in the */
/* location pointed to by recv_in_ptr. */
/* */
/******************************************************/
//*recv_in_ptr = ETHER_RDWR[RX_PORT]; // Place one byte of the packet in the receive buffer
++recv_in_ptr; // Increment recv_in_ptr
if (recv_in_ptr >= &recv_buff[recv_buff_size]) // If necessary, loop
recv_in_ptr = &recv_buff[0]; // recv_in_ptr around.
recv_count += 2;
}
if (oddLength) // get the last byte if there were an odd number of bytes in the packet
{
/******************************************************/
/* */
/* Modify this code to read a byte from the RX buffer */
/* on the Ethernet controller and place it in the */
/* location pointed to by recv_in_ptr. */
/* */
/******************************************************/
// *recv_in_ptr = ETHER_RDWR[RX_PORT]; // Place one byte of the packet in the receive buffer
++recv_in_ptr; // Increment recv_in_ptr
if (recv_in_ptr >= &recv_buff[recv_buff_size]) // If necessary, loop
recv_in_ptr = &recv_buff[0]; // recv_in_ptr around.
++recv_count; // Add one to recv_count
}
/******************************************************/
/* */
/* NOTE: If the FCS is included in the RX buffer of */
/* the Ethernet controller, add code here to read out */
/* the four bytes of FCS and throw the data away. */
/* */
/******************************************************/
}
else // Not enough room to hold this packet so get rid of it
{
/******************************************************/
/* */
/* Replace SKIPFRAME with code which flushes the */
/* packet from the Ethernet controller. */
/* */
/******************************************************/
// SKIPFRAME; // Flush current packet
retval = ETHER_RECV_ERROR; // Return an error
}
return (retval); // Returns the number of bytes received or an error condition
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -