📄 net_appl.c
字号:
* 'OK'(=0)
*
************************************************************************/
UINT32
TEST_ping( UINT32 ipadr, UINT32 data_size, UINT32 ping_ms_timeout)
{
UINT32 rcode, latest, previous, mstimout ;
/* check data_size */
if ( data_size > PING_MAX_DATAGRAM_SIZE )
{
data_size = PING_DEFAULT_DATAGRAM_SIZE ;
}
/* Set context before request is called */
appl_reply_received = FALSE ;
appl_sequence = data_size ;
appl_length = data_size ;
/* Request ICMP to 'send' */
NET_ICMP_ECHO_send( ipadr,
0,
appl_sequence,
appl_length );
/* Get millisecond count right now */
SYSCON_read( SYSCON_BOARD_GET_MILLISEC_ID,
&latest,
sizeof(latest) ) ;
mstimout = latest + ping_ms_timeout ; /* typically 1000 = one second */
do
{
/* Poll for any reply */
NET_poll() ;
if ( appl_reply_received )
{
if ( ( appl_sequence == appl_reply_sequence ) &&
( appl_length == appl_reply_length ) &&
( ipadr == appl_reply_ip ) )
{
rcode = OK ;
break ;
}
}
previous = latest;
/* get millisecond count right now */
rcode = SYSCON_read( SYSCON_BOARD_GET_MILLISEC_ID,
&latest,
sizeof(latest) ) ;
if ( latest < previous )
{
mstimout -= previous; /* may cause a few millisec extra delay */
}
if (latest > mstimout)
{
rcode = ERROR_NET_PING_TIME_OUT ;
}
} while (rcode == OK);
return( rcode ) ;
}
/************************************************************************
*
* NET_APPL_echo_reply
* Description :
* -------------
* Receive 'ECHO'-reply
*
*
* Parameters :
* ------------
* -
*
*
* Return values :
* ---------------
* 'OK'(=0)
*
************************************************************************/
static
UINT32 NET_APPL_echo_reply( UINT32 src_ip_adr, /* BE-format */
t_mac_addr *src_mac_adr,/* MAC */
UINT16 sequence, /* CPU-format */
UINT16 usr_length )
{
int i ;
UINT8 *p ;
#ifdef NET_DEBUG
printf("NET_APPL_echo_reply\n") ;
printf("src_ip_adr = %x\n", BE32_TO_CPU(src_ip_adr) ) ;
printf("sequence = %d\n", sequence ) ;
printf("usr_length = %d\n", usr_length ) ;
printf("src MAC = " ) ;
p = (UINT8*) src_mac_adr ;
for (i=0; i<6; i++)
{
printf(" %02x",*p++ ) ;
}
printf("\n" ) ;
#endif
/* save reply context */
if ( !appl_reply_received )
{
appl_reply_received = TRUE ;
appl_reply_sequence = sequence ;
appl_reply_length = usr_length ;
appl_reply_ip = src_ip_adr ;
memcpy( &appl_reply_mac_adr, src_mac_adr, SYS_MAC_ADDR_SIZE ) ;
}
return( OK ) ;
}
UINT32
net_open( UINT32 ipadr, char *filename )
{
UINT32 compl, state, cause, sp_hd ;
/* clear error context */
net_last_error = OK ;
net_diag_msg[0] = 0 ;
compl = NET_TFTPC_open( ipadr, filename, &sp_hd ) ;
if ( (compl != OK) &&
(compl != ERROR_NET_ARP_MAC_NOT_RESOLUTED) )
{
NET_TFTPC_close( 0 ) ;
return( compl ) ;
}
while (1)
{
/* Poll for any reply */
NET_poll() ;
if (GETCHAR_CTRLC( DEFAULT_PORT ))
{
NET_TFTPC_close( 0 ) ;
net_last_error = ERROR_NET_USER_BREAK ;
compl = net_last_error ;
break ;
}
NET_TFTPC_poll( &state, &compl, &cause ) ;
if (state != TFTPC_SAP_STATE_WAIT_FIRST_BLOCK)
{
if (state == TFTPC_SAP_STATE_ERROR)
{
net_last_error = cause ;
compl = net_last_error ;
NET_TFTPC_close( 0 ) ;
}
else
{
compl = OK ;
}
break ;
}
}
/* We need to reply OK, as loader will terminate by any error */
return( compl ) ;
}
char net_getchar( void )
{
char byte ;
UINT32 rcode, state, compl, cause, sp_hd ;
rcode = NET_TFTPC_readbyte( sp_hd,
&byte ) ;
if (!rcode)
{
return( byte ) ;
}
while (1)
{
/* Poll for any reply */
NET_poll() ;
if (GETCHAR_CTRLC( DEFAULT_PORT ))
{
NET_TFTPC_close( 0 ) ;
net_last_error = ERROR_NET_USER_BREAK ;
return( EOF_SREC ) ;
}
rcode = NET_TFTPC_readbyte( sp_hd,
&byte ) ;
if (!rcode)
{
return( byte ) ;
}
if (rcode == ERROR_NET_TFTPC_NO_DATA)
{
continue ;
}
if (rcode == ERROR_NET_TFTPC_EOF)
{
NET_TFTPC_close( 0 ) ;
return( EOF_SREC ) ;
}
if (rcode == ERROR_NET_TFTPC_SAP_ERROR_STATE)
{
NET_TFTPC_poll( &state, &compl, &cause ) ;
net_last_error = cause ;
NET_TFTPC_close( 0 ) ;
return( EOF_SREC ) ;
}
}
/* we should never arrive here */
return( EOF_SREC ) ;
}
UINT32
net_getbyte( UINT8 *byte )
{
UINT32 rcode, state, compl, cause, sp_hd ;
rcode = NET_TFTPC_readbyte( sp_hd,
byte ) ;
if (!rcode)
{
return( rcode ) ;
}
while (1)
{
/* Poll for any reply */
NET_poll() ;
if (GETCHAR_CTRLC( DEFAULT_PORT ))
{
NET_TFTPC_close( 0 ) ;
net_last_error = ERROR_NET_USER_BREAK ;
return( ERROR_NET_USER_BREAK ) ;
}
rcode = NET_TFTPC_readbyte( sp_hd,
byte ) ;
if (!rcode)
{
return( rcode ) ;
}
if (rcode == ERROR_NET_TFTPC_NO_DATA)
{
continue ;
}
if (rcode == ERROR_NET_TFTPC_EOF)
{
NET_TFTPC_close( 0 ) ;
return( rcode ) ;
}
if (rcode == ERROR_NET_TFTPC_SAP_ERROR_STATE)
{
NET_TFTPC_poll( &state, &compl, &cause ) ;
net_last_error = cause ;
NET_TFTPC_close( 0 ) ;
return( rcode ) ;
}
}
/* we should never arrive here */
return( ERROR_NET_TFTPC_SAP_ERROR_STATE ) ;
}
UINT32
NET_file_read( UINT32 ipadr,
char *filename,
UINT8 *buffer,
UINT32 *size )
{
return( NET_TFTPC_file_read( ipadr,
filename,
buffer,
size,
NET_poll ) ) ;
}
UINT32
NET_file_write( UINT32 ipadr,
char *filename,
UINT8 *buffer,
UINT32 *size )
{
return( NET_TFTPC_file_write( ipadr,
filename,
buffer,
size,
NET_poll ) ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -