Raw TCP/IP interface for lwIP
Authors: Adam Dunkels, Leon Woestenberg, Christiaan Simons
lwIP provides three Application Program's Interfaces (APIs) for programs
to use for communication with the TCP/IP code:
* low-level "core" / "callback" or "raw" API.
* higher-level "sequential" API.
* BSD-style socket API.
The raw API (sometimes called native API) is an event-driven API designed
to be used without an operating system that implements zero-copy send and
receive. This API is also used by the core stack for interaction between
the various protocols. It is the only API available when running lwIP
without an operating system.
The sequential API provides a way for ordinary, sequential, programs
to use the lwIP stack. It is quite similar to the BSD socket API. The
model of execution is based on the blocking open-read-write-close
paradigm. Since the TCP/IP stack is event based by nature, the TCP/IP
code and the application program must reside in different execution
contexts (threads).
The socket API is a compatibility API for existing applications,
currently it is built on top of the sequential API. It is meant to
provide all functions needed to run socket API applications running
on other platforms (e.g. unix / windows etc.). However, due to limitations
in the specification of this API, there might be incompatibilities
that require small modifications of existing programs.
** Multithreading
lwIP started targeting single-threaded environments. When adding multi-
threading support, instead of making the core thread-safe, another
approach was chosen: there is one main thread running the lwIP core
(also known as the "tcpip_thread"). When running in a multithreaded
environment, raw API functions MUST only be called from the core thread
since raw API functions are not protected from concurrent access (aside
from pbuf- and memory management functions). Application threads using
the sequential- or socket API communicate with this main thread through
message passing.
As such, the list of functions that may be called from
other threads or an ISR is very limited! Only functions
from these API header files are thread-safe:
- api.h
- netbuf.h
- netdb.h
- netifapi.h
- pppapi.h
- sockets.h
- sys.h
Additionaly, memory (de-)allocation functions may be
called from multiple threads (not ISR!) with NO_SYS=0
since they are protected by SYS_LIGHTWEIGHT_PROT and/or
semaphores.
Netconn or Socket API functions are thread safe against the
core thread but they are not reentrant at the control block
granularity level. That is, a UDP or TCP control block must
not be shared among multiple threads without proper locking.
If SYS_LIGHTWEIGHT_PROT is set to 1 and
LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT is set to 1,
pbuf_free() may also be called from another thread or
an ISR (since only then, mem_free - for PBUF_RAM - may
be called from an ISR: otherwise, the HEAP is only
protected by semaphores).
** The remainder of this document discusses the "raw" API. **
The raw TCP/IP interface allows the application program to integrate
better with the TCP/IP code. Program execution is event based by
having callback functions being called from within the TCP/IP
code. The TCP/IP code and the application program both run in the same
thread. The sequential API has a much higher overhead and is not very
well suited for small systems since it forces a multithreaded paradigm
on the application.
The raw TCP/IP interface is not only faster in terms of code execution
time but is also less memory intensive. The drawback is that program
development is somewhat harder and application programs written for
the raw TCP/IP interface are more difficult to understand. Still, this
is the preferred way of writing applications that should be small in
code size and memory usage.
All APIs can be used simultaneously by different application
programs. In fact, the sequential API is implemented as an application
program using the raw TCP/IP interface.
Do not confuse the lwIP raw API with raw Ethernet or IP sockets.
The former is a way of interfacing the lwIP network stack (including
TCP and UDP), the later refers to processing raw Ethernet or IP data
instead of TCP connections or UDP packets.
Raw API applications may never block since all packet processing
(input and output) as well as timer processing (TCP mainly) is done
in a single execution context.
--- Callbacks
Program execution is driven by callbacks functions, which are then
invoked by the lwIP core when activity related to that application
occurs. A particular application may register to be notified via a
callback function for events such as incoming data available, outgoing
data sent, error notifications, poll timer expiration, connection
closed, etc. An application can provide a callback function to perform
processing for any or all of these events. Each callback is an ordinary
C function that is called from within the TCP/IP code. Every callback
function is passed the current TCP or UDP connection state as an
argument. Also, in order to be able to keep program specific state,
the callback functions are called with a program specified argument
that is independent of the TCP/IP state.
The function for setting the application connection state is:
- void tcp_arg(struct tcp_pcb *pcb, void *arg)
Specifies the program specific state that should be passed to all
other callback functions. The "pcb" argument is the current TCP
connection control block, and the "arg" argument is the argument
that will be passed to the callbacks.
--- TCP connection setup
The functions used for setting up connections is similar to that of
the sequential API and of the BSD socket API. A new TCP connection
identifier (i.e., a protocol control block - PCB) is created with the
tcp_new() function. This PCB can then be either set to listen for new
incoming connections or be explicitly connected to another host.
- struct tcp_pcb *tcp_new(void)
Creates a new connection identifier (PCB). If memory is not
available for creating the new pcb, NULL is returned.
- err_t tcp_bind(struct tcp_pcb *pcb, ip_addr_t *ipaddr,
u16_t port)
Binds the pcb to a local IP address and port number. The IP address
can be specified as IP_ADDR_ANY in order to bind the connection to
all local IP addresses.
If another connection is bound to the same port, the function will
return ERR_USE, otherwise ERR_OK is returned.
- struct tcp_pcb *tcp_listen(struct tcp_pcb *pcb)
Commands a pcb to start listening for incoming connections. When an
incoming connection is accepted, the function specified with the
tcp_accept() function will be called. The pcb will have to be bound
to a local port with the tcp_bind() function.
The tcp_listen() function returns a new connection identifier, and
the one passed as an argument to the function will be
deallocated. The reason for this behavior is that less memory is
needed for a connection that is listening, so tcp_listen() will
reclaim the memory needed for the original connection and allocate a
new smaller memory block for the listening connection.
tcp_listen() may return NULL if no memory was available for the
listening connection. If so, the memory associated with the pcb
passed as an argument to tcp_listen() will not be deallocated.
- struct tcp_pcb *tcp_listen_with_backlog(struct tcp_pcb *pcb, u8_t backlog)
Same as tcp_listen, but limits the number of outstanding connections
in the listen queue to the value specified by the backlog argument.
To use it, your need to set TCP_LISTEN_BACKLOG=1 in your lwipopts.h.
- void tcp_accept(struct tcp_pcb *pcb,
err_t (*
没有合适的资源?快使用搜索试试~ 我知道了~
NXP i.MX RT1021驱动以太网
共632个文件
h:313个
c:249个
txt:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 88 浏览量
2022-12-01
15:51:17
上传
评论
收藏 3.01MB ZIP 举报
温馨提示
NXP i.MX RT1021驱动程序。 资源代码可直接编译、运行。
资源推荐
资源详情
资源评论
收起资源包目录
NXP i.MX RT1021驱动以太网 (632个子文件)
generate.bat 23B
router_adv.bin 118B
icmp_ping.bin 98B
neighbor_solicitation.bin 86B
tcp_syn.bin 74B
udp_port_5000.bin 50B
arp_req.bin 42B
httpsrv_fs_data.c 141KB
fsl_enet.c 110KB
fsl_lpuart_cmsis.c 106KB
sockets.c 93KB
httpd.c 88KB
fsl_sai.c 78KB
fsl_edma.c 75KB
lcp.c 74KB
dhcp.c 72KB
fsl_trng.c 72KB
fsl_flexcan.c 71KB
fsl_lpi2c_cmsis.c 70KB
fsl_lpspi_cmsis.c 70KB
tcp_in.c 69KB
nd6.c 69KB
tcp.c 68KB
snmp_msg.c 67KB
auth.c 66KB
mdns.c 65KB
ipcp.c 64KB
eap.c 63KB
fsl_usdhc.c 63KB
api_msg.c 62KB
fsl_lpi2c.c 61KB
fsl_lpspi.c 61KB
fsl_lpuart.c 60KB
tcp_out.c 58KB
httpsrv_supp.c 52KB
dns.c 52KB
ppp.c 49KB
ccp.c 49KB
smtp.c 48KB
pbuf.c 47KB
etharp.c 46KB
mqtt.c 44KB
fsl_str.c 43KB
ipv6cp.c 42KB
ethernetif.c 42KB
snmp_core.c 42KB
lowpan6.c 41KB
usb_device_ch9.c 41KB
ip6.c 39KB
test_dhcp.c 39KB
ip4.c 39KB
pppol2tp.c 39KB
udp.c 39KB
netif.c 38KB
pppoe.c 38KB
httpsrv_ws.c 37KB
fsl_semc.c 36KB
fsl_lpspi_edma.c 36KB
test_tcp_oos.c 36KB
fsl_dcp.c 36KB
makefsdata.c 35KB
shell.c 35KB
fsl_flexio_spi.c 35KB
chap_ms.c 33KB
api_lib.c 32KB
fsl_flexspi.c 30KB
fsl_flexio_i2c_master.c 30KB
pppos.c 29KB
ip4_frag.c 29KB
test_mdns.c 29KB
snmp_mib2_ip.c 28KB
igmp.c 28KB
httpsrv_task.c 27KB
fsl_io.c 27KB
mem.c 27KB
ip6_frag.c 27KB
fsl_flexio_uart.c 26KB
fsl_pwm.c 26KB
lwiperf.c 26KB
virtual_com.c 25KB
fsl_flexio_i2s.c 25KB
sys_arch.c 25KB
test_tcp.c 24KB
sntp.c 23KB
fsl_clock.c 23KB
snmp_mib2_tcp.c 23KB
fsl_spdif.c 22KB
utils.c 21KB
fsl_snvs_lp.c 21KB
fsl_shell.c 21KB
usb_device_descriptor.c 21KB
snmp_asn1.c 20KB
fsl_spdif_edma.c 20KB
fsm.c 20KB
vj.c 20KB
chap-new.c 19KB
inet_chksum.c 19KB
fsdata.c 19KB
fsl_lpi2c_edma.c 18KB
autoip.c 18KB
共 632 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7
资源评论
不脱发的程序猿
- 粉丝: 24w+
- 资源: 5837
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Java实现的pagerank算法.zip
- 基于C++实现的pagerank算法.zip
- 基于Python实现的pagerank算法.zip
- java面试题-leetcode题解之第14题最长公共前缀.zip
- java面试题-leetcode题解之第28题找出字符串中第一个匹配项的下标.zip
- java面试题-leetcode题解之第31题下一个排列.zip
- java面试题-leetcode题解之第6题Z字形变换.zip
- java面试题-leetcode题解之第8题字符串转换整数atoi.zip
- java面试题-leetcode题解之第13题罗马数字转整数.zip
- 夏总-2405232148.awb
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功