Wiznet makers

ronpang

Published August 29, 2025 © Apache License 2.0 (Apache-2.0)

132 UCC

75 WCC

32 VAR

0 Contests

1 Followers

0 Following

Hardwired TCP/IP Chapter 27: W55MH32 Interrupt Example

Hardwired TCP/IP Chapter 27: W55MH32 Interrupt Example

COMPONENTS
PROJECT DESCRIPTION

Hardwired TCP/IP Chapter 27: W55MH32 Interrupt Example

In this article, we will provide a detailed explanation on how to utilize the TOE interrupt function on the W55MH32 chip. Through practical examples, we will also teach you how to conduct loopback data testing via interrupts.

For other network protocols used in this example, please refer to the relevant sections. Regarding the initialization process of the W55MH32, please refer to the "Network Installation" chapter. We will not elaborate on this here.

1 Introduction to TOE Interruption

In the TOE interrupt mode, multiple interrupt events can be configured, such as network connection establishment, data reception, and data transmission completion, etc. When a certain event occurs, it is notified to the processor through PD9, allowing the processing to immediately respond to the interrupt and perform the corresponding processing. This approach can enhance the response speed and efficiency of the system, and reduce the waste of resources in the processor's polling state.

2. Characteristics of Interruption

  • Real-time performance: After an interrupt event occurs, the processor will pause the current task being executed and immediately respond to the interrupt. When there are multiple interrupt handling processes, the processor will handle them based on priority.
  • Improving system efficiency: Without an interrupt mechanism, the processor needs to constantly poll the register status to check if processing is required. This will consume a lot of processor resources. However, the interrupt method allows the processor to focus on running the main program and handle the corresponding tasks when necessary, thereby increasing the utilization rate of system resources.
  • Event-driven: Interrupts are driven by events. These events can be external (such as the operation of external devices, signal changes, etc.) or internal (such as timer overflow, abnormal calculation results, etc.).
  • Interrupt service program: Each interrupt source usually has a corresponding interrupt service program. They are independent pieces of program code specifically written to handle the interrupt event.

3 TOE interruption application scenarios

  • Network Wakeup: After enabling the Magic Packet Interrupt, when the W55MH32 receives a Magic Packet, it will trigger an interrupt, thereby notifying the device to perform the wake-up operation.
  • Network Configuration: After enabling the Socket Reception Interrupt, the W55MH32 triggers an interrupt when receiving data. The system performs message reading configuration only after the interrupt is triggered, without the need for continuous polling, thus saving system resources.
  • Error Handling: When encountering errors (such as IP address conflicts, unreachable network), the W55MH32 can handle them immediately, improving the stability of the system.

4 TOE interrupt source

  • IP conflict: An interruption occurs when the received ARP request finds that the sender's IP is the same as the local IP.
  • Destination unreachable: An interruption is triggered after receiving an ICMP (Destination Port Unreachable) packet.
  • PPPoE connection closed: An interruption is triggered when the PPPoE connection is disconnected in the PPPoE mode.
  • Magic Packet: An interruption is triggered when the network wake-up mode is enabled and a Magic Packet for network wake-up is received via UDP.

The following are the interruptions in Socket:

  • Data sent complete: An interruption is triggered when data is successfully sent to the other party.
  • Timeout: An interruption is triggered when ARP times out or when TCP times out.
  • Received data: An interruption is triggered when data from the other party is received.
  • Connection closed: An interruption is triggered when the other party sends a FIN or FIN/ACK packet.
  • Connection established: An interruption is triggered when a connection with the other party is successfully established.

 

5 The process of receiving data using interrupt mode

1. Initialize the interrupt pin;

2. Enable the interrupt function for the corresponding Socket. The related registers and descriptions are as follows:

3.Enable the Socket RECV interrupt function. The related registers and descriptions are as follows:

4.Write the interrupt handling function, which will process the received data.

 

6 The implementation process

Next, let's take a look at how to implement the interrupt loopback data test on the W55MH32.

Note: The test instance requires that the PC and the W55MH32 be on the same network segment.

Step 1: Initialize the interrupt pin

 1. void wizchip_int_init(void)
 2. {
 3.     GPIO_InitTypeDef GPIO_InitStructure;
 4.     NVIC_InitTypeDef NVIC_InitStructure;
 5.     EXTI_InitTypeDef EXTI_InitStructure;
 6.  
 7.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
 8.  
 9.     GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
10.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
11.     GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_IPU;
12.     GPIO_Init(GPIOD, &GPIO_InitStructure);
13.  
14.  
15.     GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource8);
16.  
17.     NVIC_InitStructure.NVIC_IRQChannel                   = EXTI9_5_IRQn;
18.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
19.     NVIC_InitStructure.NVIC_IRQChannelSubPriority        = 3;
20.     NVIC_InitStructure.NVIC_IRQChannelCmd                = ENABLE;
21.     NVIC_Init(&NVIC_InitStructure);
22.  
23.  
24.     EXTI_InitStructure.EXTI_Line    = EXTI_Line8;
25.     EXTI_InitStructure.EXTI_Mode    = EXTI_Mode_Interrupt;
26.     EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
27.     EXTI_InitStructure.EXTI_LineCmd = ENABLE;
28.     EXTI_Init(&EXTI_InitStructure);
29. }

Step 2: Interrupt Handling

 1. void EXTI9_5_IRQHandler(void)
 2. {
 3.     if (EXTI_GetITStatus(EXTI_Line8) == SET)
 4.     {
 5.         if (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_8) == RESET)
 6.         {
 7.             wizchip_ISR();
 8.         }
 9.     }
10.     EXTI_ClearITPendingBit(EXTI_Line8);
11. }
12.  
13.  
14. /**
15.  * @brief   Determine the interrupt type and store the value in I STATUS
16.  * @param   none
17.  * @return  none
18.  */
19. void wizchip_ISR(void)
20. {
21.     uint8_t SIR_val = 0;
22.     uint8_t tmp, sn;
23.     SIR_val = getSIR();
24.     if (SIR_val != 0xff)
25.     {
26.         setSIMR(0x00);
27.         for (sn = 0; sn < _WIZCHIP_SOCK_NUM_; sn++)
28.         {
29.             tmp = 0;
30.             if (SIR_val & IR_SOCK(sn))
31.             {
32.                 tmp           = getSn_IR(sn);
33.                 I_STATUS[sn] |= tmp;
34.                 tmp          &= 0x0f;
35.                 setSn_IR(sn, tmp);
36.             }
37.         }
38.         setSIMR(0xff);
39.     }
40. }  
After the TOE successfully triggers the interrupt, the wizchip_ISR() function will be called. Here, the interrupt flag will be recorded and the interrupt flag will be cleared.
Step 3: Enable the interrupt function
1.     setSIMR(0x01); // enable socket0 interrupt
2.     setSn_IMR(SOCKET_ID, 0x0f);//enable all interrupt functions of socket 0.
Step 4: Run the TCP loopback server within the main loop
1. void loopback_tcps_interrupt(uint8_t sn, uint8_t *buf, uint16_t port)
 2. {
 3.     uint16_t len = 0;
 4.     uint8_t  destip[4];
 5.     uint16_t destport;
 6.  
 7.     if (I_STATUS[sn] == SOCK_CLOSED)
 8.     {
 9.         if (!ch_status[sn])
10.         {
11. #ifdef INTERRUPT_DEBUG
12.             printf("%d:TCP server start\r\n", sn);
13. #endif
14.             ch_status[sn] = ready_status;
15.  
16.             if (socket(sn, Sn_MR_TCP, port, 0x00) != sn)
17.             {
18.                 ch_status[sn] = closed_status;
19.             }
20.             else
21.             {
22. #ifdef INTERRUPT_DEBUG
23.                 printf("%d:Socket opened\r\n", sn);
24. #endif
25.                 listen(sn);
26. #ifdef INTERRUPT_DEBUG
27.                 printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
28. #endif
29.             }
30.         }
31.     }
32.     if (I_STATUS[sn] & Sn_IR_CON)
33.     {
34.         getSn_DIPR(sn, destip);
35.         destport = getSn_DPORT(sn);
36. #ifdef INTERRUPT_DEBUG
37.         printf("%d:Connected - %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
38.  
39. #endif
40.         ch_status[sn]  = connected_status;
41.         I_STATUS[sn]  &= ~(Sn_IR_CON);
42.     }
43.  
44.     if (I_STATUS[sn] & Sn_IR_DISCON)
45.     {
46.         printf("%d:Socket disconnected\r\n", sn);
47.         if ((getSn_RX_RSR(sn)) > 0)
48.         {
49.             if (len > ETHERNET_BUF_MAX_SIZE)
50.             {
51.                 len = ETHERNET_BUF_MAX_SIZE;
52.             }
53.             recv(sn, buf, len);
54.             buf[len] = 0x00;
55.             printf("%d:recv data:%s\r\n", sn, buf);
56.             I_STATUS[sn] &= ~(Sn_IR_RECV);
57.             send(sn, buf, len);
58.         }
59.         disconnect(sn);
60.         ch_status[sn]  = closed_status;
61.         I_STATUS[sn]  &= ~(Sn_IR_DISCON);
62.     }
63.  
64.     if (I_STATUS[sn] & Sn_IR_RECV)
65.     {
66.         setIMR(0x00);
67.         I_STATUS[sn] &= ~(Sn_IR_RECV);
68.         setIMR(0xff);
69.         if ((len = getSn_RX_RSR(sn)) > 0)
70.         {
71.             if (len > ETHERNET_BUF_MAX_SIZE)
72.             {
73.                 len = ETHERNET_BUF_MAX_SIZE;
74.             }
75.             len      = recv(sn, buf, len);
76.             buf[len] = 0x00;
77.             printf("%d:recv data:%s\r\n", sn, buf);
78.             send(sn, buf, len);
79.         }
80.     }
82.     if (I_STATUS[sn] & Sn_IR_SENDOK)
83.     {
84.         I_STATUS[sn] &= ~(Sn_IR_SENDOK);
85.     }
86. }

After entering the function, the first step is to check the status of the Socket. If the Socket is in a closed state, a TCP server is started. Then, based on the recorded interrupt flag, it is determined whether an interrupt has occurred, and corresponding processing is carried out according to the interrupt type.

7 Run results

After the burning routine is executed, the following can be observed: Firstly, a PHY link detection is performed. Then, the set network address information is printed. Next, a TCP loopback test is conducted. After W55MH32 receives the Socket data, it triggers an interrupt and transmits it back. As shown in the figure below:

8 Summary

This article explains how to utilize the TOE interrupt function on the W55MH32 chip and conduct loopback data testing. Through practical examples, it demonstrates the entire process from initializing the interrupt pins, handling interrupts, enabling the interrupt function, to running the TCP loopback server in the main loop. The article details the concept, characteristics, application scenarios, interrupt sources, and the process of using interrupt to receive data of the TOE interrupt, helping readers understand its practical application value in improving system response speed and resource utilization.

The next article will explain how to implement the Ethernet speed measurement function on the W55MH32 chip, analyze its core principle and application in network performance evaluation, and also explain how to use the Jperf tool for speed measurement through practical examples. Please stay tuned!

 

 

WIZnet is a non-chipfoundry semiconductor company founded in 1998. Its products include the Internet processor iMCU™, which adopts TOE (TCP/IP Offloading Engine) technology and is based on a unique patented fully hardwired TCP/IP. iMCU™ is designed for embedded Internet devices in various applications.

WIZnet has over 70 distributors worldwide, with offices in Hong Kong, South Korea, and the United States, providing technical support and product marketing.

The region managed by the Hong Kong office includes: Australia, India, Turkey, and Asia (excluding South Korea and Japan).

Documents
Comments Write