Yesterday I explained how to use asynchronous reception and transmission, watchdog timer & TCP/IP core. Today I will continue to introduce the content of TCP/IP core and its functional description.
8.3.2
Sn_MR (SOCKET n mode register) [R/W] [0xFE4000 + 0x100n] [0x0000]
This register configures the protocol or other options of SOCKET n.
Sn_CR (SOCKET n command register) [R/W] [0xFE4001 + 0x100n] [0x00]
This register is used to set the command of SOCKET n, such as: open, connect, listen, send, receive and other operations. When W7100A confirms the command, Sn_CR register is automatically cleared. Even if Sn_CR is cleared, the instruction is still being processed. To verify whether the command is executed, you can check the Sn_IR register or Sn_SR register.
The following command is only used for SOCKET 0 and S0_MR(P3:P0) = S0_MR_PPPoE.
For more information, please refer to the W5100 application note "How to use ADSL".
Sn_IR (SOCKET n interrupt register)[R/W][0xFE4002 + 0x100n][0x00]
The Sn_IR register provides the interrupt type information of SOCKET n (such as establishing a connection, disconnecting a connection, receiving data, timeout, etc.). When an interrupt is generated and the corresponding bit of the interrupt mask Sn_IMR is '1', the interrupt bit of Sn_IR will be set to '1'. In order to clear the Sn_IR bit, the host needs to write '1' to this bit. When all bits of Sn_IR are cleared, IR(n) will be automatically cleared. At this time, it will send the INT5 signal (nINT5: TCPIP core interrupt) to the MCU.
Sn_IMR (SOCKET n interrupt mask register) [R/W] [0xFE402C + 0x100n] [0xFF]
It configures the interrupt type of SOCKET n to indicate to the host. The interrupt mask register Sn_IMR of the port corresponds to Sn_IR. If the SOCKET generates an interrupt, the corresponding position of Sn_IR is set to '1'. If the corresponding bits of Sn_IMR and Sn_IR are both set to '1', IR(n) is set to '1'. At this time, if IMR(n) is also set to '1', an interrupt will be generated (the level of the '/INT' pin becomes low)
Sn_SR (SOCKET n status register)[R][0xFE4003 + 0x100n][0x00]
This register provides the status of SOCKET n. The status of SOCKET n will change during the operation of the Sn_CR register or the transmission and reception of data packets.
The following table describes the different states of SOCKET n
Below is the temporary status of Sn_SR during the change process.
Sn_PORT (SOCKET n source port number) [R/W] [(0xFE4004+0x100n)~(0xFE4005+0x100n)] [0x0000]
Set the source port number.
The port number is valid only when SOCKET n works in TCP and UDP mode, and is invalid in other modes.
The port number must be set before the OPEN command.
Example: To set the port number of SOCKET 0 to 5000 (0x1388), the configuration is as follows:
0xFE4004 | 0xFE4005 |
0x13 | 0x88 |
Sn_DHAR (SOCKET n destination physical address register) [R/W] [(0xFE4006 + 0x100n) – (0xFE400B + 0x100n)] [FF.FF.FF.FF.FF.FF]
It sets, or is set to, the destination physical address of SOCKET n. If SOCKET 0 is used in PPPoE mode, S0_DHAR is set to the physical address of the PPPoE server, which is already known.
When using the SEND_MAC command in UDP or IPRAW mode, it needs to be set to the destination physical address of SOCKET n. In TCP, UDP, IPRAW mode, when using the CONNECT command or SEND command, Sn_DHAR obtains the destination physical address through the ARP process. After successfully running the CONNECT or SEND command, the host can obtain the destination physical address through Sn_DHAR.
When using PPPoE with W7100A, there is no need to set the physical address of the PPPoE server.
However, even if you do not use the PPPoE processing of W7100A and use the MACRAW mode instead, in order to transmit and receive PPPoE packets, the physical address of the PPPoE server (obtained through the PPPoE process), the IP address of the PPPoE server, and the ID value of the PPP session need to be set, and MR (PPPoE) also needs to be set to '1'.
S0_DHAR is set to the physical address of the PPPoE server before the OPEN command. The physical address of the PPPoE server set by S0_DAHAR is applied to PDHAR after the OPEN command. The configuration information of PPPoE is internal information and remains valid even after the CLOSE command.
For example, the physical address of the destination of SOCKET 0 is: 00.08.DC.01.02.10, and the configuration is as follows:
0xFE4006 | 0xFE4007 | 0xFE4008 | 0xFE4009 | 0xFE400A | 0xFE400B |
0x00 | 0x08 | 0xDC | 0x01 | 0x02 | 0x10 |
Sn_DIPR (SOCKET n destination IP address register)[R/W][(0xFE400C + 0x100n) – (0xFE400F + 0x100n)][00.00.00.00]
It sets, or is set to, the destination IP address of SOCKET n. If SOCKET 0 is used in PPPoE mode, S0_DIPR0 will be set to the IP address of a known PPPoE server.
It is only valid in TCP, UDP, IPRAW or PPPoE mode, and invalid in MACRAW mode.
When the socket works as a TCP client, it must be set to the IP address of the TCP server before running the CONNECT command. When working in TCP server mode, after a successful connection is established, it is automatically set to the IP address of the TCP client.
In UDP or IPRAW mode, in order to transmit UDP or IPRAW data packets, the destination IP address must be set to Sn_DIPR before using the SEND or SEND_MAC command.
In PPPoE mode, S0_DIPR is set to the known IP address of the PPPoE server.
For example, the IP address of the destination of SOCKET 0 is 192.168.0.11, and the settings are as follows:
0xFE400C | 0xFE400D | 0xFE400E | 0xFE400F |
192 (0xC0) | 168 (0xA8) | 0 (0x00) | 11 (0x0B) |
Sn_DPORT (SOCKET n destination port number register) [R/W] [(0xFE4010 + 0x100n) – (0xFE4011 + 0x100n)] [0x0000]
The destination port number of SOCKET n is set by Sn_DPORT. If SOCKET 0 works in PPPoE mode, Sn_DPORT0 is set to a known session ID.
It is only valid in TCP, UDP and PPPoE modes, and invalid in other modes.
In TCP client mode, before running the CONNECT command, you must first set Sn_DPORT to the listening port of the TCP server.
In UDP mode, before the SEND command or SEND_MAC command, you need to set the destination port number Sn_DPORT of the UDP data packet.
In PPPoE mode, S0_DPORT is set to a known PPP session ID. The PPP session ID is applied to PSIDR after the OPEN command.
Example: To set the destination port number of SOCKET 0 to 5000 (0x1388), the configuration is as follows:
0xFE4010 | 0xFE4011 |
0x13 | 0x88 |
Sn_MSSR (SOCKET n maximum segment length register) [R/W] [(0xFE4012 + 0x100n) – (0xFE4013 + 0x100n)] [0x0000]
It sets the maximum transmission unit (MTU) of SOCKET n, or indicates that the MTU has been set. It supports TCP or UDP mode. When using PPPoE (MR(PPPoE)=1), the maximum transmission unit (MTU) of TCP or UDP is determined by the MTU range of PPPoE.
In IPRAW and MACRAW modes, MTU is not handled internally, but the default MTU is used. Therefore, when the transmitted data is larger than the default MTU, the host needs to manually segment it to make it within the default MTU range.
During SOCKET initialization, the reset value is 0, but MSSR becomes the smaller of the user-set value and the default value. If there is no user-set value, MSSR becomes the default value.
In TCP and UDP mode, if the number of bytes of data to be transmitted is larger than the MTU, W7100 will automatically segment the data within the MTU range.
In TCP mode, MTU is what we know as MSS. By choosing the value written by the host and the MSS of the other end, the MSS automatically chooses the smaller value during the TCP connection process.
In UDP mode, there is no TCP connection process, only the value written by the host is used. When communicating with a different MTU, W7100 can receive ICMP (fragmented MTU) packets. When IR (FMTU) = 1, UDP communication with the other end cannot be achieved. Therefore, the user must close SOCKET, set Sn_MSSR to FMTU, and then try to open the port with the OPEN command for communication.
Sn_PROTO (SOCKET n protocol number register) [R/W] [0xFE4014 + 0x100n] [0x00]
This is a 1-byte register used to set the protocol number field in the IP header of an IP layer data packet.
It is only valid in IPRAW mode and invalid in other modes. Sn_PROTO must be set before the OPEN command. When SOCKET n is opened in IPRAW mode, it sends and receives data with the protocol number set by Sn_PROTO. The value range of Sn_PROTO is between 0x00 ~ 0xFF. However, W7100 does not support the protocol numbers of TCP (0x06) and UDP (0x11). The protocol numbers are defined by IANA (Internet Assigned Numbers Authority). For details, please refer to the online information:
http://www.iana.org/assignments/protocol-numbers
For example: The protocol number of Internet Control Message Protocol (ICMP) is 0x01, and the protocol number of Internet Packet Management Protocol is 0x02.
Sn_TOS (SOCKET n Type of Service (TOS) Register) [R/W] [0xFE4015 + 0x100n] [0x00]
It sets the Type of Service (TOS), which is a field in the IP header of an IP layer packet. It must precede the OPEN command.
to set it up.
Please refer to: http://www.iana.org/assignments/ip-parameters .
Sn_TTL (SOCKET n Lifetime (TTL) register) [R/W] [0xFE4016 + 0x100n] [0x80]
It sets the Time To Live (TTL) field in the IP header of an IP layer packet. It must be set before the OPEN command.
Please refer to: http://www.iana.org/assignments/ip-parameters
Sn_RXMEM_SIZE (SOCKET n receive memory size register) [R/W][0xFE401E + 0x100n][0x02]
It is used to configure the size of the RX memory of each SOCKET. The RX memory size of each SOCKET can be configured to 1, 2, 4, 8, or 16K bytes. The default is 2K bytes after reset. The total of Sn_RXMEM_SIZE of 8 SOCKETs is 16K bytes. [page]
Example 1: SOCKET 0: 8KB, SOCKET 1: 2KB
0xFE401E | 0xFE411E |
0x08 | 0x02 |
Example 2: SOCKET 2: 1KB, SOCKET 3: 1KB
0xFE421E | 0xFE431E |
0x01 | 0x01 |
Example 3: SOCKET 4: 1KB, SOCKET 5: 1KB
0xFE441E | 0xFE451E |
0x01 | 0x01 |
Example 4: SOCKET 6: 1KB, SOCKET 7: 1KB
0xFE461E | 0xFE471E |
0x01 | 0x01 |
From the above examples 1 to 4, we can see that the sum of the RX memories of the eight SOCKETs is 16K bytes.
Sn_TXMEM_SIZE (SOCKET n transmit memory size register) [R/W] [0xFE401F + 0x100n] [0x02]
It configures the internal TX memory of the SOCKET. The TX memory size of each SOCKET can be configured to 1, 2, 4, 8, 16K bytes. The default after reset is 2K bytes. The total TX memory of 8 SOCKETs is 16K bytes.
Example 5: SOCKET 0: 4KB, SOCKET 1: 1KB
0xFE401F | 0xFE411F |
0x04 | 0x01 |
Example 6: SOCKET 2: 2KB, SOCKET 3: 1KB
0xFE421F | 0xFE431F |
0x02 | 0x01 |
Example 7: SOCKET 4: 2KB, SOCKET 5: 2KB
0xFE441F | 0xFE451F |
0x02 | 0x02 |
Example 8: SOCKET 6: 2KB, SOCKET 7: 2KB
0xFE461F | 0xFE471F |
0x02 | 0x02 |
As shown in Examples 5 to 8 above, the total TX memory of the eight SOCKETs is 16K bytes.
Sn_TX_FSR (SOCKET n transmit memory remaining space size register)[R][(0xFE4020 + 0x100n) – (0xFE4021 + 100n)][0x0000]
It indicates the available space size of the internal TX memory of SOCKET n (the number of bytes of transmission data that can be written). The host cannot write more data than Sn_TX_FSR to the TX memory. Therefore, check Sn_TX_FSR before writing the transmission data to the TX memory. If the number of data bytes to be written is less than or equal to Sn_TX_FSR, the data can be written to the TX memory and then sent using the SEND or SEND_MAC command.
In TCP mode, if the peer receives the data packet sent (if the DATA/ACK data packet is received from the peer), Sn_TX_FSR will automatically increase by the number of bytes sent. In other modes, as long as Sn_IR (SENDOK) = 1, Sn_TX_FSR will automatically increase by the length of the transmitted data.
For example: the value of S0_TX_FSR0 is 2048 (0x0800),
0xFE4020 | 0xFE4021 |
0x08 | 0x00 |
Sn_TX_RD (SOCKET n transmit memory read pointer register)[R][(0xFE4022 + 0x100n) – (0xFE4023 + 0x100n)][0x0000]
This register shows the address value where the TX memory ends the last transmission. Write the SEND command to the command control register of SOCKET n, and it will start transmitting data from the current Sn_TX_RD address until the Sn_WR_WR address. The value of this register changes automatically after the transmission is completed. Therefore, after the transmission is completed, the values of Sn_TX_RD and Sn_TX_WR are equal. When reading this register, first read its high byte (0xFE4022, 0xFE4122, 0xFE4222, 0xFE4322, 0xFE4422, 0xFE4522, 0xFE4622, 0xFE4722), and then read its low byte (0xFE4023, 0xFE4123, 0xFE4223, 0xFE4323, 0xFE4423, 0xFE4523, 0xFE4623, 0xFE4723), so that the data read is correct.
Sn_TX_WR (SOCKET n transmit memory write pointer register) [R/W] [(0xFE4024 + 0x100n) – (0xFE4025 + 0x100n)] [0x0000]
This register provides positioning information, indicating where the data should be written. When reading this register, first read the high byte (0xFE4024, 0xFE4124, 0xFE4224, 0xFE4324, 0xFE4424, 0xFE4524, 0xFE4624, 0xFE4724), and then read the low byte (0xFE4025, 0xFE4125, 0xFE4225, 0xFE4325, 0xFE4425, 0xFE4525, 0xFE4625, 0xFE4725), so that the data read is correct.
Example: The value of S0_TX_WR is 2048 (0x0800).
0xFE4024 | 0xFE4025 |
0x08 | 0x00 |
But this value itself is not a physical address that can be directly accessed. The actual physical address to be accessed is calculated as follows: (Please refer to the W7100A driver)
1. Calculate the port n TX memory base address (SBIUFBASEADDRES(n)) and mask address (SMASK(n)) from Sn_TXMEM_SIZE(n). See the provided source code for details.
2. Perform a bitwise AND operation on Sn_TX_WR0 and SMASK(n), the result of which is the offset address (dst_mask) within the TX memory range of port n.
3. Add dst_mask and SUBFBASEADDRESS(n) to get the physical address (dst_ptr) actually accessed. Now you can write the data to be transmitted to dst_ptr. (*There is one situation that needs attention. When writing data, it may exceed the upper boundary of the TX memory of port n. In this case, after writing the data to the upper boundary address, write the remaining data starting from SBUFBASEADDRESS(n), and repeat the writing operation in this way.)
After the operation is completed, the value of Sn_TX_WR must be added to the number of bytes of data currently written. Finally, a SEND command is issued to Sn_CR (command register of port n). For detailed information, refer to the source code for sending data in TCP server mode.
Figure 8.3 Calculating the physical address
Sn_RX_RSR (SOCKET n RX receive data length register)[R][(0xFE4026 + 0x100n) – (0xFE4027 + 0x100n)][0x0000]
It indicates the number of bytes of received data in the internal RX memory of SOCKET n. Since this value is calculated internally by Sn_Rx_RD and Sn_Rx_WR, it will automatically change when the RECV command is written to the command register (Sn_CR) of SOCKET n and the remote data is received. When reading this register, the user should first read the high byte (0xFE4026, 0xFE4126, 0xFE4226, 0xFE4326, 0xFE4426, 0xFE4526, 0xFE4626, 0xFE4726), and then read the low byte (0xFE4027, 0xFE4127, 0xFE4227, 0xFE4327, 0xFE4427, 0xFE4527, 0xFE4627, 0xFE4727) to get the correct value.
Example: The value of S0_RX_RSR0 is 2048 (0x0800)
0xFE4026 | 0xFE4027 |
0x08 | 0x00 |
The total length of this value is determined by the RX Memory Size register.
Sn_RX_RD (SOCKET n RX receive memory read pointer register) [R/W] [(0xFE4028 + 0x100n) – (0xFE4029 + 0x100n)] [0x0000]
This register determines the read address information of the received data. When reading this register, read the high byte first (0xFE4028, 0xFE4128, 0xFE4228, 0xFE4328, 0xFE4428, 0xFE4528, 0xFE4628, 0xFE4728), and then read the low byte (0xFE4029, 0xFE4129, 0xFE4229, 0xFE4329, 0xFE4429, 0xFE4529, 0xFE4629, 0xFE4729), so that the information read is correct.
Example: The value of S0_RX_RD02048 is (0x0800)
0x0428 | 0x0429 |
0x08 | 0x00 |
But this value is not the actual physical address to be read. The actual physical address needs to be calculated using the following relationship:
1. Obtain the base address of the RX memory of SOCKET n (RBUFBASEADDRESS(n)) and the RX mask address of SOCKET n (RMASK(n)) from Sn_RXMEM_SIZE(n).
2. Perform a bitwise AND operation on Sn_RX_RD0 and RMASK(n) to obtain the offset address (src_mask) within the address range of the SOCKET's RX memory.
3. Add src_mask and RBUFBASEADDRESS(n) to get the actual physical address to be accessed.
Now you can read the received data from the src_ptr address (there is a special case to note, the read address exceeds the upper boundary of the SOCKET's RX memory. At this time, after reading the data at the upper boundary address, return to the RBUFBASEADDRESS(n) address to read the remaining data, and so on for a loop access).
After the operation is completed, the value of Sn_RX_RD must be added to the number of bytes currently read (it must not exceed the number of bytes you read). Finally, write the RECV command to the Sn_CR command register to complete the operation.
For more details, please refer to the source code of receiving data in TCP server mode.
Sn_RX_WR (SOCKET n RX receive memory write pointer register) [R/W] [(0xFE402A + 0x100n) – (0xFE402B + 0x100n)] [0x0000]
It indicates the number of bytes of received data in the internal RX memory of port n. Since this value is calculated internally by Sn_Rx_RD and Sn_Rx_WR, it will automatically change when the RECV command is written to the command register (Sn_CR) of SOCKET n and remote data is received. When reading this register, the user should first read the high byte (0xFE4026, 0xFE4126, 0xFE4226, 0xFE4326, 0xFE4426, 0xFE4526, 0xFE4626, 0xFE4726), and then read the low byte (0xFE4027, 0xFE4127, 0xFE4227, 0xFE4327, 0xFE4427, 0xFE4527, 0xFE4627, 0xFE4727) to get the correct value.
Example: The value of S0_RX_WR0 is 2048 (0x0800)
0xFE402A | 0xFE402B |
0x08 | 0x00 |
Sn_FRAG (SOCKET n segment register) [R/W] [(0xFE402D + 0x100n) – (0xFE402E + 0x100n)] [0x4000]
This register sets the fragmentation field in the IP header of the IP layer. W7100 does not support fragmentation at the IP layer. Even if Sn_FRAG is configured, the IP packet cannot be fragmented. It is necessary to set this register before the OPEN command.
Example: Sn_FRAG0 = 0x4000 (no segmentation)
0xFE402D | 0xFE402E |
0x40 | 0x00 |
9. Functional Description
Because W7100A has an 8051 compatible CPU core and hardware TCP/IP core embedded inside, it can
In this section, we will explain the initialization of the 7100A and the communication methods of each protocol (TCP, UDP, IP raw, MACRAW) through some software source code.
9.1 Initialization
The initialization of W7100A is divided into three steps: setting up the 8051 microcontroller, network information and internal TX/RX memory.
Step
1. Interrupt settings
Enable or disable interrupts for the 8051. See Section 3, "Interrupts", for more information.
2. Memory access timing settings
The access timing of the memory is set through the CKCON (0x8E) and WTST (0x92) registers. CKCON (0x8E) controls the access timing of the data memory, while WTSR (0x92) controls the access timing of the program memory. The setting value is between 0 and 7. However, the CKCON value of W7100A can be set to 1 to 7, while the value of WTST (0x92) can only be 4 to 7. Other values are invalid. If the value set by the user is an invalid value, W7100 will not work properly. For more information, please refer to Section 2.4 "Definition of SFR".
Example: Disable interrupts, access data memory for 2 clock cycles, access program memory for 7 clock cycles, the settings are as follows:
3. Serial communication baud rate, register and interrupt settings
1) Set the relevant registers of W7100A serial communication.
The registers related to the serial port are: TMOD, PCON and SCON.
①
SM2:
REN: Receive Enable ('1' enables reception).
TB8: In Mode 2 and Mode 3, the 8th data bit sent.
RB8: In Mode 2 and Mode 3, the 8th data bit received.
TI:
RI:
2) The interrupt status must be set when initializing serial port communication.
Because serial communication uses interrupts, the user must disable other related interrupts when initializing serial communication.
3) Set the baud rate used by the user. Please refer to Section 6.6 'Baud rate setting example' to understand the timer used by W7100 to generate the baud rate. The baud rate of the timer is calculated as follows:
①
TH1 = 256 – ((K * 88.4736MHz) / (384 * baud rate))
K = '1' at SMOD = '0', K = '2' at SMOD = '1'
②
(RCAP2H, RCAP2L) = 65536 – (88.4736MHz / (32 * baud rate))
Example: Use Timer1 mode 2, SMOD = 1, clock frequency = 88.4736MHz, baud rate = 115200
- Step 2: Set up network information
1. Basic information of network communication
The basic network information that must be set is:
(1) SHAR (Source Hardware Address Register)
The source hardware address is set by SHAR. It must be noted that the physical address (MAC address) at the Ethernet MAC layer must be unique. IEEE manages the allocation of MAC addresses. The manufacturer of network equipment assigns MAC addresses to products. For detailed information on physical address allocation, please refer to the following website:
http://www.ieee.org/,http://standards.ieee.org/regauth/oui/index.shtml
(2) GAR (Gateway Address Register)
(3) SUBR (Subnet Mask Register)
(4) SIPR (Source IP Address Register)
2. When the data packet fails to be sent, set the resend time and number of times
To set the retransmission time, the registers need to be set as follows:
(1) RTR (Retransmission Time Register), '1' in RTR represents '100us'.
(2) RCR (Retransmission Count Register)
- Step 3: Allocate internal TX/RX memory of SOCKET n
The maximum length of each configurable TX/RX memory is 16K bytes. Within the range of 16K bytes, users can arbitrarily allocate the memory to 8 SOCKETs as 1K, 2K, 4K, 8K, or 16K bytes. However, the total of the TX and RX memory settings cannot exceed 16K bytes. (TXMAX=16KB,RXMAX=16KB)
Figure 9.1 SOCKET n internal TX/RX memory allocation
After completing these three steps of initialization of W7100A, W7100A can transmit data via Ethernet. At this time, W7100A can respond to Ping requests from the network.
9.2 Data Communication
After the initialization process is completed, W7100A can open the socket in TCP, UDP, IPRAW or MACRAW mode and send and receive data. W7100A supports 8 ports working simultaneously in different modes. This section will introduce the communication method of each mode.
9.2.1
TCP is a connection-oriented protocol. TCP uses the local IP address/port number and the destination IP address/port number to create a connection. Data is sent and received through the end SOCKET of this connection.
The methods of establishing a connection to a SOCKET are TCP server and TCP client. The difference between them is who actively sends a connection request (SYN packet).
The TCP server listens for connection requests from TCP clients, receives the sent connection requests (passive open), and establishes connections.
The TCP client sends a connection request to the TCP server (actively open) and a connection is established.
Figure 9.2 TCP server and TCP client
9.2.1.1
Figure 9.3 “TCP Server” operation process
- Socket Initialization
TCP data communication requires initialization of the SOCKET. The initialization process first selects a SOCKET of W7100A (from the 8 SOCKETs of W7100A), sets the protocol mode (Sn_MR (P3:P0)) and sets the source port number Sn_PORT0 (the listening port number of the TCP server). Then run the OPEN instruction. After executing the OPEN command, if the port status Sn_SR changes to SOCK_INIT, the port initialization is completed.
The port initialization of TCP server and TCP client is exactly the same. The operation of port initialization in TCP mode is as follows:
- establish connection
When the state of SOCKET Sn_SR is SOCK_LISTEN, if it receives a SYN packet, the state of Sn_SR will change to SOCK_SYNRECV, and a SYN/ACK packet will be sent, and then SOCKET n will establish a connection. Data communication is allowed only after SOCKET n establishes a connection. There are two ways to verify whether SOCKET n has established a connection.
The first method: When receiving a data packet, Sn_IR(RECV) is set to 1. If the host does not set the previous Sn_IR(RECV) to '1' before receiving the next data packet, then W7100 will not be able to identify the Sn_I(RECV) of the next data packet. This is due to the overlap between the previous Sn_IR(RECV) and the following Sn_IR(RECV). Therefore, if the host cannot fully process each Sn_IR(RECV) data packet, this method is not recommended. [page]
- Establishing a connection: Receiving process
During this process, it processes the received data in the internal RX memory. In TCP mode, if the byte length of the received data exceeds the remaining space of the current RX memory of the port, the W7100A cannot receive the data. If this happens, the W7100A will maintain the connection (pause) and wait until the remaining space of the RX is greater than the byte length of the data to be received.
The wizmemecpy function defined in the wiznetmemcpy.c file in the W7100A driver uses the Receive/Send procedure to quickly copy memory data. For more details, please refer to Chapter 13, refer to 'W7100A Performance Improvement' to understand its performance, and refer to 'W7100A Driver Guide' to understand its usage. If the user does not want to use the wizmemcpy function, then use the normal memory copy function.
Since W7100A has both data memory and TCPIP core internal memory, users should classify them according to the address. So users must add '0xFE' before the highest level address of TCPIP core internal memory, or set DPX0 register to '0xFE' when copying from TCPIP core memory to data memory. For more details about wizmemcpy, please refer to 'W7100A Driver Guide'.
- Establish connection: Check sending data/sending process
The byte length of the transmitted data cannot exceed the size of the SOCKET n TX memory. If the length of the data to be transmitted is greater than the set MSS, it will be transmitted in segments according to the MSS.
For the next data transmission, the user must check whether the last SEND command has been executed. If the last SEND command has not been executed and the next SEND command is started, an error will occur. The more data, the longer it takes to execute the SEND command. Therefore, the user can send the data in segments appropriately.
During the transmission process, the user must add '0xFE' to the highest address to point to the memory of the TCPIP core.
- Establishing connection: Timeout
Timeouts may occur during the transmission of connection requests (SYN packets) or their responses (SYN/ACK packets), data communications or their responses (DATA/ACK packets), disconnection requests (FIN packets) or their responses (FIN/ACK packets), and all other TCP packets. If the transmission of the above packets cannot be completed within the time defined by RTR and the number of retransmissions defined by RCR, TCP timeout will occur and the state of Sn_SR will change to SOCK_CLOSED. The method for determining TCP timeout is as follows:
9.2.1.2
Except for the "CONNECT" state, it is exactly the same as the TCP server. Users can refer to 9.2.1.1 "TCP Server".
Figure 9.4 “TCP Client” operation process
- connect
Send a connection request (SYN packet) to the "TCP server". When making a "connection port" to the server, timeouts such as ARPTO and TCPTO may occur.
9.2.2
UDP is a connectionless protocol, and its communication does not require SOCKET to establish a connection. TCP is a connection-oriented communication protocol that can guarantee reliability, but UDP uses datagram communication, and the reliability of data transmission is not guaranteed. However, because UDP does not use connected SOCKETs, it can exchange data with multiple ports of multiple known IP addresses. This is its advantage. Using one port to communicate with other ports can also bring many problems, such as losing transmitted data or receiving unnecessary data from other ports. In UDP mode, in order to avoid these problems and ensure the reliability of data communication, the host needs to resend damaged data or discard unnecessary data. The UDP protocol supports communication methods such as unicast, broadcast, and multicast. It follows the following communication process.
Binary
11011110.01100010.10101101.01111011
00000000.00000000.00000000.11111111
-
11011110.01100010.10101101.11111111
Figure 9.5 UDP operation process
9.2.2.1
Unicast is a communication method of UDP. It can only transmit data to one destination at a time. Broadcast communication uses the broadcast address (255.255.255.255) to send data to all receivable destinations. For example, suppose a user transmits data to destinations A, B, and C. Unicast is to transmit data to A, B, or C separately each time. In this case, ARP timeout may occur when obtaining the physical address of destination A, B, or C. When ARP timeout occurs, data cannot be transmitted to the destination.
Broadcast uses the broadcast address (255.255.255.255) to send data to destination sites A, B, and C at the same time. At this time, there is no need to obtain the physical address of the destination site A, B, or C, so no ARP timeout will occur.
- How to create a broadcast IP?
The broadcast IP address can be obtained by performing a bitwise logical OR operation on the subnet mask and the host IP address.
For example: local IP: 222.98.173.123, subnet mask: 255.255.255.0, then the broadcast IP address is: 222.98.173.255
- Socket Initialization
To realize UDP communication, the SOCKET must be initialized. The operation process of opening the SOCKET is as follows: First, select one SOCKET from the 8 SOCKETs of W7100A to work with UDP and set it to UDP mode (Sn_MR (P3:P0)), then set the local port number (Sn_PORT0), and finally run the OPEN command. After executing the OPEN command, if the Sn_SR state changes to SOCK_UDP, the initialization setting of the port is completed.
Figure 9.6 Format of receiving UDP data
The received UDP data contains 8 bytes of data packet information and valid data. The data packet information consists of two parts: the sender's information (IP address and port number) and the length of the data packet. UDP can receive many other UDP data, and users can distinguish the source of UDP data by the sender's information. It also receives information sent with the broadcast address of "255.255.255.255". Therefore, the host can discard unnecessary data by analyzing the sender's information.
If the length of the data to be received is greater than the remaining space of the SOCKET's RX memory, the user will not be able to receive the data, nor will they be able to receive segmented data.
- Check the sending data/sending process
The size of the data that the user wants to send cannot exceed the range that the internal TX buffer can accommodate. If it is larger than the MTU, it will be automatically divided into MTU units and then sent. When the user wants to use the broadcast method, Sn_DIPR0 should be set to "255.255.255.255"
- Checking for send completion/timeout
Before continuing to send data, the user must check whether the previous SEND command has been completed. The more data is sent, the longer it takes to send. Therefore, the user must divide the data to be sent reasonably. ARP timeout may occur when the user sends UDP data. If ARP timeout occurs, the transmission of UDP data fails.
9.2.2.2
Broadcast is communication with all, undefined destinations. But multicast is communication with multiple destinations registered in a multicast group. Suppose A, B, and C are sites registered in a specific multicast group. If the user transmits data to the multicast group (including site A), sites B and C can also get data from site A. In order to use multicast communication, the IGMP protocol is used to register the destination site list to the multicast group. The multicast group includes: group hardware address, group IP address, and group port number. Users cannot change the "group hardware address" and "group IP address". But users can change the "group port number".
The selection range of the packet hardware address is between "01:00:5e:00:00:00" and "01:00:5e:7f:ff:ff", while the packet IP address uses the Class D address, ranging from "224.0.0.0" to "239.255.255.255". For more details, please refer to the official website:
http://www.iana.org/assignments/multicast-addresses .
When selecting, the high 23 bits of the 6-byte "packet hardware address" and the 4-byte "packet IP address" must be the same. For example, if the user selects the packet IP address "244.1.1.11", then the packet hardware address is "01:00:5e:01:01:0b". For more information, please refer to RFC1112: http://www.ietf.org/rfc.html
In W7100A, IGMP processing of multicast registration is done internally (automatically). When the user opens the port in multicast mode, the "Join" message will be automatically sent internally. If the user closes the port, the "Leave" message will be automatically sent internally. After the port is opened, the "Report" message will be sent at regular intervals during data transmission.
W7100A supports IGMP v1 and v2. If the user wants to use an upgraded version, the host can use IPRAW mode to process IGMP directly.
- Socket Initialization
Select one of the 8 ports of W7100A for multicast. Set the "Multicast Group MAC Address" to Sn_DHAR0 and the "Multicast Group IP Address" to Sn_DIPR0. Then set the "Multicast Group Port Number" to Sn_PORT0 and Sn_DPORT0. Set Sn_MR(P3:P0) to UDP mode and set Sn_MR(MULT1) to 1. Finally, execute the OPEN command. If the state of Sn_SR is changed to SOCK_UDP after the OPEN command, the port initialization is completed.
- Check the received data
Please refer to 9.2.2.1 "Unicast mode and broadcast mode"
- Receiving process
Please refer to 9.2.2.1 "Unicast mode and broadcast mode"
- Check the sending data/sending process
Because the user has set the multicast grouping information in the port initialization, the user does not need to set the IP address and port number of the destination device. Therefore, just copy the data to be transmitted to the internal TX buffer and execute the SEND command.
lCheck
Refer to 9.2.2.1 "Unicast & Broadcast"
Previous article:Single chip Ethernet control chip W7100A data sheet (Part 3)
Next article:W5200 driver for MSP430
Recommended ReadingLatest update time:2024-11-16 07:22
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications