GD32 GD32F30x_Firmware_Library V3.0.3 ENET 以太网 Telnet 示例教学
ENET — 以太网 Telnet
固件库: GD32F30x_Firmware_Library V3.0.3
芯片: GD32
源文件: GD32F30x_Firmware_Library_V3.0.3/Examples/ENET/Telnet/src/main.c
功能简介
本示例演示 ENET 的基本用法。
完整代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#include "gd32f30x.h"
#include "netconf.h"
#include "main.h"
#include "lwip/tcp.h"
#include "lwip/timeouts.h"
#include "gd32f307c_eval.h"
#include "hello_gigadevice.h"
#define SYSTEMTICK_PERIOD_MS 10
__IO uint32_t g_localtime = 0; /* for creating a time reference incremented by 10ms */
int main(void)
{
gd_eval_com_init(EVAL_COM0);
/* setup ethernet system(GPIOs, clocks, MAC, DMA, systick) */
enet_system_setup();
/* initilaize the LwIP stack */
lwip_stack_init();
while(1) {
#ifndef USE_ENET_INTERRUPT
/* check if any packet received */
if(enet_rxframe_size_get()) {
/* process received ethernet packet */
lwip_frame_recv();
}
#endif /* USE_ENET_INTERRUPT */
/* handle periodic timers for LwIP */
#ifdef TIMEOUT_CHECK_USE_LWIP
sys_check_timeouts();
#ifdef USE_DHCP
lwip_dhcp_address_get();
#endif /* USE_DHCP */
#else
lwip_timeouts_check(g_localtime);
#endif /* TIMEOUT_CHECK_USE_LWIP */
}
}
|
代码讲解
代码结构清晰,主要包含外设初始化配置和主循环中的功能逻辑。请结合注释理解每一步的含义。