📄 net_bsp.c
字号:
*********************************************************************************************************
* NETWORK MODULE FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetUtil_TS_Get()
*
* Description : Get current Internet Timestamp.
*
* (1) "The Timestamp is a right-justified, 32-bit timestamp in milliseconds since midnight
* UT [Universal Time]" (RFC #791, Section 3.1 'Options : Internet Timestamp').
*
* (2) The developer is responsible for providing a real-time clock with correct time-zone
* configuration to implement the Internet Timestamp.
*
*
* Argument(s) : none.
*
* Return(s) : Internet Timestamp.
*
* Caller(s) : various.
*
* Note(s) : none.
*********************************************************************************************************
*/
NET_TS NetUtil_TS_Get (void)
{
NET_TS ts;
/* $$$$ Insert code to return Internet Timestamp (see Notes #1 & #2). */
ts = NET_TS_NONE;
return (ts);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* TRANSMISSION CONTROL PROTOCOL LAYER FUNCTIONS
*********************************************************************************************************
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* NetTCP_InitTxSeqNbr()
*
* Description : Initialize the TCP Transmit Initial Sequence Counter, 'NetTCP_TxSeqNbrCtr'.
*
* (1) Possible initialization methods include :
*
* (a) Time-based initialization is one preferred method since it more appropriately
* provides a pseudo-random initial sequence number.
* (b) Hardware-generated random number initialization is NOT a preferred method since it
* tends to produce a discrete set of pseudo-random initial sequence numbers--often
* the same initial sequence number.
* (c) Hard-coded initial sequence number is NOT a preferred method since it is NOT random.
*
* See also 'net_tcp.h MACRO'S Note #2'.
*
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : NetTCP_Init().
*
* Note(s) : none.
*********************************************************************************************************
*/
#ifdef NET_TCP_MODULE_PRESENT
void NetTCP_InitTxSeqNbr (void)
{
NetTCP_TxSeqNbrCtr = 5000;
}
#endif
/*
*********************************************************************************************************
* NetTCP_TxRTT_GetTS()
*
* Description : Get a TCP Round-Trip Time (RTT) timestamp.
*
* (1) (a) (1) Although RFC #2988, Section 4 states that "there is no requirement for the
* clock granularity G used for computing RTT measurements ... experience has
* shown that finer clock granularities (<= 100 msec) perform somewhat better
* than more coarse granularities".
*
* (2) (A) RFC #2988, Section 2.4 states that "whenever RTO is computed, if it is
* less than 1 second then the RTO SHOULD be rounded up to 1 second".
*
* (B) RFC #1122, Section 4.2.3.1 states that "the recommended ... RTO ... upper
* bound should be 2*MSL" where RFC #793, Section 3.3 'Sequence Numbers :
* Knowing When to Keep Quiet' states that "the Maximum Segment Lifetime
* (MSL) is ... to be 2 minutes".
*
* Therefore, the required upper bound is :
*
* 2 * MSL = 2 * 2 minutes = 4 minutes = 240 seconds
*
* (b) Therefore, the developer is responsible for providing a timestamp clock with
* adequate resolution to satisfy the clock granularity (see Note #1a1) & adequate
* range to satisfy the minimum/maximum RTO values (see Note #1a2).
*
*
* Argument(s) : none.
*
* Return(s) : TCP RTT timestamp, in milliseconds.
*
* Caller(s) : NetTCP_RxPktValidate(),
* NetTCP_TxPktPrepareHdr().
*
* Note(s) : (2) (a) To avoid timestamp calculation overflow, a maximum clock tick threshold value
* MUST be configured to truncate all clock tick values.
*
* (b) Also, since the clock tick integer will periodically overflow; the maximum
* threshold MUST be a multiple of the clock tick to avoid a discontinuity in
* the timestamp calculation when the clock tick integer overflows.
*********************************************************************************************************
*/
#ifdef NET_TCP_MODULE_PRESENT
NET_TCP_TX_RTT_TS_MS NetTCP_TxRTT_GetTS (void)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
NET_TCP_TX_RTT_TS_MS rtt_ts_ms;
CPU_INT32U clk_tick;
CPU_INT32U clk_tick_th;
CPU_CRITICAL_ENTER();
clk_tick = (CPU_INT32U)OSTime;
CPU_CRITICAL_EXIT();
if (OS_TICKS_PER_SEC > 0) {
clk_tick_th = (NET_TCP_TX_RTT_TS_MAX /* MUST cfg clk tick th ... */
/ DEF_TIME_NBR_mS_PER_SEC); /* ... as multiple of max ts (see Note #2b). */
clk_tick %= clk_tick_th; /* Truncate clk ticks to avoid ovf (see Note #2a). */
rtt_ts_ms = (NET_TCP_TX_RTT_TS_MS)((clk_tick * DEF_TIME_NBR_mS_PER_SEC) / OS_TICKS_PER_SEC);
} else {
rtt_ts_ms = (NET_TCP_TX_RTT_TS_MS)clk_tick;
}
return (rtt_ts_ms);
}
#endif
/*
*********************************************************************************************************
* NetTCP_TxConnRTT_GetTS_ms()
*
* Description : Get a TCP Round-Trip Time (RTT) timestamp.
*
* (1) (a) (1) Although RFC #2988, Section 4 states that "there is no requirement for the
* clock granularity G used for computing RTT measurements ... experience has
* shown that finer clock granularities (<= 100 msec) perform somewhat better
* than more coarse granularities".
*
* (2) (A) RFC #2988, Section 2.4 states that "whenever RTO is computed, if it is
* less than 1 second then the RTO SHOULD be rounded up to 1 second".
*
* (B) RFC #1122, Section 4.2.3.1 states that "the recommended ... RTO ... upper
* bound should be 2*MSL" where RFC #793, Section 3.3 'Sequence Numbers :
* Knowing When to Keep Quiet' states that "the Maximum Segment Lifetime
* (MSL) is ... to be 2 minutes".
*
* Therefore, the required upper bound is :
*
* 2 * MSL = 2 * 2 minutes = 4 minutes = 240 seconds
*
* (b) Therefore, the developer is responsible for providing a timestamp clock with
* adequate resolution to satisfy the clock granularity (see Note #1a1) & adequate
* range to satisfy the minimum/maximum RTO values (see Note #1a2).
*
*
* Argument(s) : none.
*
* Return(s) : TCP RTT timestamp, in milliseconds.
*
* Caller(s) : NetTCP_RxPktValidate(),
* NetTCP_TxPktPrepareHdr().
*
* Note(s) : none.
*********************************************************************************************************
*/
#ifdef NET_TCP_MODULE_PRESENT
NET_TCP_TX_RTT_TS_MS NetTCP_TxConnRTT_GetTS_ms (void)
{
NET_TCP_TX_RTT_TS_MS rtt_ts_ms;
/* $$$$ Insert code to return TCP RTT timestamp (see Note #1). */
rtt_ts_ms = NET_TCP_TX_RTT_TS_NONE;
return (rtt_ts_ms);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -