Specifications

SLAA137A
MSP430 Internet Connectivity 17
To prevent the receive buffer from corruption while receiving data, a handshake mechanism is
implemented. This mechanism uses the SOCK_DATA_AVAILABLE flag of the SocketStatus
register. The TCP stack only copies data to RxTCPBuffer if the SOCK_DATA_ AVAILABLE flag
is clear, and only in this case is an ACK-segment sent back to the other TCP. If the
RxTCPBuffer is empty and the stack has written new data to it, this is indicated to the application
by setting the SOCK_DATA_AVAILABLE flag. If the receive buffer is not empty, the incoming
data segment is discarded and not acknowledged. But due to the retransmission timeout of the
other TCP, no data is lost, because the other TCP retransmits its data until the local TCP
receive buffer is empty and can acknowledge the data. To avoid permanent retransmissions, the
local application should release the receive buffer frequently by calling the API-function
TCPReleaseRxBuffer() (see Section 4.3).
4.2.4 Opening a Connection
A connection can be opened in either passive or active mode by calling the proper API function
TCPPassiveOpen() or TCPActiveOpen(). The TCPPassiveOpen() function places the stack in a
mode in which it is attempting to detect an incoming connection. The TCPLocalPort variable
must have been set to indicate which port the stack must monitor.
Before performing an active open, the IP address of the remote TCP as well as the local and
remote port numbers must be set. After calling the TCPActiveOpen() function, the stack first tries
to determine the MAC address of the opponent by sending an ARP request. The stack checks
the destination IP to determine whether the other TCP is a member of the subnet (see symbols
SUBMASK_1…4), and if so, addresses that TCP directly. If the other TCP is not a member of
the subnet, the ARP request is performed for the default gateway (symbols GWIP_1…4) and
data transfer occurs over the gateway as a router. For further information about subnets and
gateways, see Reference [1].
After finding the MAC address to communicate with, the stack sends out a TCP segment
carrying a SYN flag and the TCP option maximum segment size (MSS). Along with this
segment, the initial sequence number required for opening a connection and also the size of the
receive buffer is sent. This ensures that no arriving segment exceeds the size of the receive
buffer. This frame is also prepared using the function PrepareTCPFrame().
4.2.5 Data Transfer
Once a connection is established (TCPStateMachine changes to ESTABLISHED), data transfer
can begin. The actual state of the connection can be read out by using the API flag register
SocketStatus (see Section 4.3). The receiving and transferring of data into the receive buffer is
done by the function ProcessTCPFrame(). The count of received bytes is stored in the global
variable TCPRxDataCount. New data can only be received when the receive buffer is released.
Use the function TCPReleaseRxBuffer() to do this.
To send data to the other TCP, the application has to write its data into the data area of
TxFrame1 buffer. For direct access to this area, the pointer TCP_TX_BUF should be used.
Sending is initiated by a user call of the function TCPTransmitTxBuffer(). This function checks
whether sending is allowed and then sets the flag SEND_FRAME1 in the TransmitControl
register. This flag leads during execution of DoNetWorkStuff() to sending of the frame. If an
acknowledge segment is received, the transmit buffer is released automatically. The application
then can fill the buffer with new data and send it out.