https://www.nongnu.org/lwip/2_1_x/index.html (https://www.nongnu.org/lwip/2_1_x/index.html)
Overview
INTRODUCTION
lwIP เป็น a small independent implementation ของ the TCP/IP protocol suite.
จุดเน้นอง the lwIP TCP/IP implementation คือลด the RAM usageในขณะที่ยังคงมี a full scale TCP. นี้ทำให้ lwIP เหมาะสมสำหรับใช้ใน embedded systems ที่มี tens of kilobytes of free RAM และที่ว่างสำหรับประมาณ 40 kilobytes of code ROM.
lwIP ถูกพัฒนาเริ่มแรกโดย Adam Dunkels ที่ the Computer and Networks Architectures (CNA) lab ที่ the Swedish Institute of Computer Science (SICS) และขณะนี้ถูกพัฒนาและดูแลโดย a worldwide network of developers.
FEATURES
* IP (Internet Protocol, IPv4 and IPv6) including packet forwarding over
multiple network interfaces
* ICMP (Internet Control Message Protocol) for network maintenance and debugging
* IGMP (Internet Group Management Protocol) for multicast traffic management
* MLD (Multicast listener discovery for IPv6). Aims to be compliant with
RFC 2710. No support for MLDv2
* ND (Neighbor discovery and stateless address autoconfiguration for IPv6).
Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862
(Address autoconfiguration)
* DHCP, AutoIP/APIPA (Zeroconf) and (stateless) DHCPv6
* UDP (User Datagram Protocol) including experimental UDP-lite extensions
* TCP (Transmission Control Protocol) with congestion control, RTT estimation
fast recovery/fast retransmit and sending SACKs
* raw/native API for enhanced performance
* Optional Berkeley-like socket API
* TLS: optional layered TCP ("altcp") for nearly transparent TLS for any
TCP-based protocol (ported to mbedTLS) (see changelog for more info)
* PPPoS and PPPoE (Point-to-point protocol over Serial/Ethernet)
* DNS (Domain name resolver incl. mDNS)
* 6LoWPAN (via IEEE 802.15.4, BLE or ZEP)
APPLICATIONS
* HTTP server with SSI and CGI (HTTPS via altcp)
* SNMPv2c agent with MIB compiler (Simple Network Management Protocol), v3 via altcp
* SNTP (Simple network time protocol)
* NetBIOS name service responder
* MDNS (Multicast DNS) responder
* iPerf server implementation
* MQTT client (TLS support via altcp)
LICENSE
lwIP มีให้ใช้เป็นประโยชน์ได้ฟรีภายใต้ a BSD license.
DEVELOPMENT
lwIP ได้เติบโตขึ้นเป็น an excellent TCP/IP stack สำหรับ embedded devices,
และ developers ที่ใช้ the stack มักจะส่ง bug fixes, improvements,
and additions ไปยัง the stack เพื่อเพิ่มการใช้ประโยชน์ของมันต่อไป.
Development of lwIP ถูกเป็นเจ้าภาพบน Savannah, a central point สำหรับ
software development, maintenance and distribution. ทุกๆคนสามารถ
ช่วยปรับปรุง lwIP โดยใช้ Savannah's interface, Git and the
mailing list. A core team of developers จะผูกมัดการเปลี่ยนแปลงไปยัง the
Git source tree.
The lwIP TCP/IP stack ถูกดูแลใน the 'lwip' Git module และ
การสนับสนุน (อย่างเช่น platform ports) อยู่ใน the 'contrib' Git module.
ดู doc/savannah.txt สำหรับรายละเอียดเกี่ยวกับ Git server เข้าถึงได้สำหรับ users และ
developers.
The current Git trees เป็น web-browsable:
http://git.savannah.gnu.org/cgit/lwip.git (http://git.savannah.gnu.org/cgit/lwip.git)
http://git.savannah.gnu.org/cgit/lwip/lwip-contrib.git (http://git.savannah.gnu.org/cgit/lwip/lwip-contrib.git)
ส่ง patches และ bugs โดยทาง the lwIP project page:
http://savannah.nongnu.org/projects/lwip/ (http://savannah.nongnu.org/projects/lwip/)
Continuous integration builds (GCC, clang):
https://travis-ci.org/yarrick/lwip-merged (https://travis-ci.org/yarrick/lwip-merged)
DOCUMENTATION
Self documentation ของ the source code ถูกดึงออกเป็นประจำจาก the current
Git sources และมีให้ใช้เป็นประโยชน์จาก web page นี้:
http://www.nongnu.org/lwip/ (http://www.nongnu.org/lwip/)
ขณะนี้มีการเติบโตอย่างต่อเนื่อง wiki เกี่ยวกับ lwIP ที่
http://lwip.wikia.com/wiki/LwIP_Wiki (http://lwip.wikia.com/wiki/LwIP_Wiki)
นอกจากนี้, มี mailing lists คุณสามารถสมัครได้ที่
http://savannah.nongnu.org/mail/?group=lwip (http://savannah.nongnu.org/mail/?group=lwip)
บวก searchable archives:
http://lists.nongnu.org/archive/html/lwip-users/ (http://lists.nongnu.org/archive/html/lwip-users/)
http://lists.nongnu.org/archive/html/lwip-devel/ (http://lists.nongnu.org/archive/html/lwip-devel/)
lwIP เริ่มแรดถูกเขียนโดย Adam Dunkels:
http://dunkels.com/adam/ (http://dunkels.com/adam/)
การอ่าน Adam's papers, the files ใน docs/, เรียกดู the source code
documentation และเรียกดู the mailing list archives เป็นวิธีที่ดีเพื่อ
กลายมาเป็นความคุ้นเคยกับ the design of lwIP.
Adam Dunkels <adam@sics.se>
Leon Woestenberg <leon.woestenberg@gmx.net>
ข้าม Upgrading กับ Changelog ไปก่อนนะ ยังไม่รู้เรื่องเลย ยาก ยังไม่ได้ใช้ด้วย เอาเรื่องอื่นก่อน
https://www.nongnu.org/lwip/2_1_x/contrib.html (https://www.nongnu.org/lwip/2_1_x/contrib.html)
How to contribute to lwIP
1 Introduction
เอกสารนี้อธิบายแนวทางบางประการสำหรับผู้ที่เข้าร่วม
ใน lwIP development.
2 How to contribute to lwIP
นี่คือรายการคำแนะนำสั้น ๆ สำหรับทุกคนที่ทำงานกับ lwIP และ
พยายามมีส่วนร่วมใน bug reports, fixes, enhancements, platform ports etc.
ก่อนอื่นอย่างที่คุณรู้อยู่แล้วว่า lwIP เป็น a volunteer project ดังนั้นข้อเสนอแนะ
การแก้ไขหรือคำถามมักจะมาช้า. หวังว่า the bug and patch tracking
features ของ Savannah ช่วยให้เราไม่สูญเสีย users' input.
2.1 Source code style:
1. ห้ามใช้ tabs.
2. การเยื้องคือสองช่องว่างต่อระดับ (เช่นต่อ tab).
3. สิ้นสุด debug messages ด้วย a trailing newline (\n).
4. หนึ่งช่องว่างระหว่างคำหลักและวงเล็บเปิด
5. ไม่มีช่องว่างระหว่างฟังก์ชันและวงเล็บเปิด
6. หนึ่งช่องว่างและไม่มีการขึ้นบรรทัดใหม่ก่อนเปิดวงเล็บปีกกาของบล็อก
7. ปิดเครื่องหมายปีกกาโค้งบนเส้นเดียว
8. ช่องว่างโดยรอบการมอบหมายและการเปรียบเทียบ
9. อย่าเริ่มต้น static และ/หรือ global variables เป็นศูนย์, the compiler จะดูแลสิ่งนั้น.
10. ใช้ current source code style เป็นตัวอ้างอิงต่อไป.
2.2 Source code documentation style:
1. สอดคล้องกับ JavaDoc และเข้ากันได้กับ Doxygen
2. Function documentation อยู่บน functions ใน .c files, ไม่ใช่ .h files.
(สิ่งนี้บังคับให้คุณซิงโครไนซ์ documentation และ implementation.)
3. ใช้ current documentation style เป็นตัวอ้างอิงต่อไป.
2.3 Bug reports and patches:
1. ทำให้แน่ใจว่าคุณกำลังรายงาน bugs หรือส่ง patches ตรงกับ the latest
sources. (จาก the latest release และ/หรือ the current Git sources.)
2. หากคุณคิดว่าคุณพบ a bug ทำให้แน่ใจว่ามันยังไม่ได้ใส่ไฟล์แล้วใน the
bugtracker ที่ Savannah.
3. ถ้าคุณมีการโปรแกรมแก้ไขให้ใส่ the patch บน Savannah. ถ้ามันเป็น a patch ที่ส่งผลกระทบ
ทั้ง core และ arch ระบุ stuff โปรดแยกพวกมันเพื่อว่า the core สามารถ
ถูกใช้งานแยกได้ในขณะที่ปล่อยให้ the other patch 'open'. วิธีที่ต้องการ
คือ NOT แตะต้อง archs คุณไม่สามารถตรวจสอบและปล่อยให้ maintainers ดูแลรับผิดชอบพวกมัน.
นี้เป็นวิธีที่ดีเพื่อดูถ้าพวกมันถูกใช้หรือไม่ - เช่นเดียวกันกับสำหรับ unix
netifs ยกเว้น tapif.
4. อย่าส่ง a bug และโพสต์ a fix ถึงมันไปยัง the patch area. อย่างใดอย่างหนึ่ง a bug report
หรือ a patch จะเพียงพอ.
ถ้าคุณทำให้ถูกต้อง an existing bug ให้แนบ the patch ไปยัง the bug แทนที่จะสร้าง a new entry ใน the patch area.
5. Patches ควรถูกระบุเป็น a single change หรือเป็น related changes. อย่าผสม bugfixes ด้วย spelling และ
trivial fixes อื่นๆยกเว้น the bugfix เล็กน้อยเช่นกัน. อย่าจัดระเบียบใหม่ code และเปลี่ยนชื่อ identifiers ใน the same patch ที่คุณ
เปลี่ยนพฤติกรรมถ้าไม่จำเป็น. A patch ง่ายต่อการอ่านและเข้าใจกว่าถ้ามันตรงประเด็นและส้นกว่า
ถ้ามันไม่ตรงประเด็นและยาว :) ดังนั้นโอกาศสำหรับมันถูกนำไปใช้จึงมีมากขึ้น.
2.4 Platform porters:
1. ถ้าคุณพอร์ต lwIP ไปยัง a platform (an OS, a uC/processor หรือการรวมกันของพวกมัน) และ
คุณคิดว่ามันเป็นประโยชน์ต่อคนอื่น[1] คุณอาจต้องการพูดคุยเรื่องนี้บน the mailing list. คุณ
ยังสามารถขอสำหรับ Git access เพื่อส่งและดูแลพอร์ตของคุณใน the contrib Git module.
https://www.nongnu.org/lwip/2_1_x/pitfalls.html (https://www.nongnu.org/lwip/2_1_x/pitfalls.html)
Common pitfalls
Multiple Execution Contexts in lwIP code
The most common source of lwIP problems คือมี multiple execution contexts ภายใน the lwIP code.
lwIP สามารถถูกใช้ใน two basic modes: Mainloop mode ("NO_SYS") (ไม่มี OS/RTOS รันบน target system) หรือ OS mode (TCPIP thread) (มี an OS รันบน the target system).
ดูเพิ่มเติมที่: Multithreading (โดยเฉพาะส่วนที่เกี่ยวกับ LWIP_ASSERT_CORE_LOCKED()!)
Mainloop Mode
ใน mainloop mode, มีเพียง "raw" APIs สามารถถูกใช้. ผู้ใช้มีความเป็นไปได้สองทางเพื่อให้แน่ใจว่ามีเพียง one exection context ในแต่ละครั้งเท่านั้นใน lwIP:
1) ส่ง RX ethernet packets โดยตรงใน interrupt context ไปยัง lwIP โดยการเรียก netif->input โดยตรงใน interrupt. นี้หมายความว่าทุก lwIP callback functions ถูกเรียกใช้ใน IRQ context, ซึ่งอาจเป็นเหตุให้เกิดปัญหาเพิ่มเติมใน application code: IRQ ถูกบล็อกเป็นเวลานาน, multiple execution contexts ใน application code ฯลฯ. เมื่อ the application ต้องการเรียกใช้ lwIP, มันเพียงต้องการปิดการใช้งาน interrupts ในระหว่างการเรียกใช้. ถ้า timers ถูกเกี่ยวข้อง, มากไปกว่านั้น locking code ถูกจำเป็นเพื่อล็อค timer IRQ และ ethernet IRQ ออกจากกัน, ทึกทักเอาว่าสิ่งเหล่านี้อาจถูกวงซ้อนกัน.
2) รัน lwIP ใน a mainloop. มี example code ที่นี่: Mainloop mode ("NO_SYS"). lwIP เพียงถูกเรียกใช้จาก mainloop callstacks ที่นี่. The ethernet IRQ ต้องใส่ received telegrams ลงใน a queue ซึ่งถูกวนตรวจจับใน the mainloop. ทำให้แน่ใจว่า lwIP ไม่เคยถูกเรียกใช้จาก an interrupt, ตัวอย่างเช่นบาง SPI IRQ ต้องการส่ง data ไปยัง udp_send() หรือ tcp_write()!
OS Mode
ใน OS mode, "raw" APIs และ Sequential-style APIs สามารถถูกใช้. Sequential-style APIs ถูกออกแบบเพื่อถูกเรียกใช้จาก threads นอกเหนือจาก the TCPIP thread, ดังนั้นจึงไม่มีอะไรต้องพิจารณาที่นี่. แต่ "raw" APIs functions ต้องถูกเรียกจาก TCPIP thread เท่านั้น. มันเป็น a common error ที่เรียกเหล่านี้จาก threads อื่นหรือจาก IRQ contexts. Ethernet RX จำเป็นต้องส่ง incoming packets ใน the correct way โดยการส่ง a message ไปยัง TCPIP thread, นี้จัดให้มีใช้งานใน tcpip_input(). อีกครั้ง, ทำให้แน่ใจว่า lwIP ไม่เคยถูกเรียกใช้จาก an interrupt, ตัวอย่างเช่นบาง SPI IRQ ต้องการส่ง data ไปยัง udp_send() หรือ tcp_write()!
1) tcpip_callback() สามารถถูกใช้ได้ called back จาก TCPIP thread, มันเป็นความปลอดภัยที่เรียกใช้ "raw" APIs ใดๆจากที่นี่.
2) ใช้ LWIP_TCPIP_CORE_LOCKING. ทุก "raw" APIs functions สามารถถูกเรียกใช้เมื่อ lwIP core lock ถูกได้รับ, ดู LOCK_TCPIP_CORE() และ UNLOCK_TCPIP_CORE(). macros เหล่านี้ไม่สามารถถูกใช้ใน an interrupt context! บันทึกไว้ว่า the OS ต้องจัดการอย่างถูกต้อง priority inversion สำหรับการนี้.
Cache / DMA issues
DMA-capable ethernet hardware and zero-copy RX
lwIP เปลี่ยนสิ่งที่บรรจุอยู่ภายในของ RECEIVED pbufs ใน the TCP code path. นี้หมายความว่าหนึ่งหรือมากกว่า cacheline(s) ของ the RX pbuf กลายมาเป็นสกปรกและจำเป็นต้องถูกล้างก่อน the memory จะถูกส่งมอบไปยัง the DMA ethernet hardware สำหรับ the next telegram ที่จะถูกรับ. ดู http://lists.nongnu.org/archive/html/lwip-devel/2017-12/msg00070.html สำหรับการอธิบายรายละเอียดเพิ่มเติม. พึงระลึกไว้เสมอว่า the user application อาจเขียนลงใน pbufs อีกด้วย, ดังนั้นโดยทั่วไปมันเป็น a bug ไม่ได้ล้าง the data cache ก่อนส่งมอบ a buffer ไปยัง DMA hardware.
DMA-capable ethernet hardware and cacheline alignment
คำอธิบายที่ดีเกี่ยวกับ DMA capable hardware และ buffer handling: http://www.pebblebay.com/a-guide-to-using-direct-memory-access-in-embedded-systems-part-two/ อ่านโดยเฉพาะส่วน "Cache coherency" and "Buffer alignment".
https://www.nongnu.org/lwip/2_1_x/bugs.html (https://www.nongnu.org/lwip/2_1_x/bugs.html)
Reporting bugs
โปรดรายงาน bugs ใน the lwIP bug tracker ที่ savannah.
ก่อนยื่นเสนอ, โปรดตรวจสอบถ้า the bug ถูกรายงานแล้ว!
https://savannah.nongnu.org/bugs/?group=lwip (https://savannah.nongnu.org/bugs/?group=lwip)
https://www.nongnu.org/lwip/2_1_x/zerocopyrx.html (https://www.nongnu.org/lwip/2_1_x/zerocopyrx.html)
Zero-copy RX
โค๊ดต่อไปนี้เป็นตัวอย่างสำหรับ zero-copy RX ethernet driver:
(ตัวอย่างโค๊ดดูที่ลิ้งค์เอานะครับ)
https://www.nongnu.org/lwip/2_1_x/sys_init.html (https://www.nongnu.org/lwip/2_1_x/sys_init.html)
System initalization
ความสมบูรณ์อย่างแท้จริงและลำดับโดยทั่วไปสำหรับการเริ่มต้น the lwIP stack ไม่สามารถถูกให้ได้เพราะว่ามันขึ้นอยู่กับการเริ่มต้นเพิ่มเติมสำหรับ runtime environment ของคุณ (เช่น timers).
เราสามารถให้คุณบางแนวคิดเกี่ยวกับวิธีการดำเนินการเมื่อใช้ the raw API. เราทึกทักเอาว่า a configuration โดยใช้ a single Ethernet netif และ the UDP and TCP transport layers, IPv4 and the DHCP client.
เรียกฟังก์ชันเหล่านี้ในลำดับของลักษณะที่ปรากฏ:
• lwip_init(): เริ่มต้น the lwIP stack และทั้งหมดของ subsystems ของมัน.
• netif_add(struct netif *netif, ...): เพิ่ม network interface ของคุณไปยัง the netif_list. จัดสรร a struct netif และส่ง
ผ่าน a pointer ไปส่ง structure นี้เป็น the first argument. ให้ pointers เพื่อเคลียร์ ip_addr structures เมื่อใช้ DHCP,
หรือเติมพวกมันด้วย sane numbers มิฉะนั้น. The state pointer อาจเป็น NULL.
The init function pointer ต้องชี้ไปยัง a initialization function สำหรับ Ethernet netif interface ของคุณ. โค้ดต่อไปนี้
แสดงการใช้งานของมัน.
(https://i.imgur.com/1VCLT1k.png)
สำหรับ Ethernet drivers, the input function pointer ต้องชี้ไปยัง the lwIP function ethernet_input() ที่ประกาศใน "netif/etharp.h". drivers อื่นๆต้องใช้ ip_input() ที่ประกาศใน "lwip/ip.h".
• netif_set_default(struct netif *netif) ลงทะเบียน the default network interface.
• netif_set_link_up(struct netif *netif) นี้คือ the hardware link state; เช่นว่า cable ถูกเสียบปลั๊กสำหรับ wired
Ethernet interface. ฟังชั่นนี้ต้องถูกเรียกใช้ถึงแม้ว่าคุณไมรู้สถานะปัจจุบัน. มี link up และ link down events เป็นทางเลือกแต่
DHCP and IPv6 ค้นพบว่ามีประโยชน์จาก events เหล่านี้.
• netif_set_up(struct netif *netif) นี้คือ the administrative (= software) state ของ the netif, เมื่อ the netif ถูก
กำหนดค่าอย่างสมบูรณ์ฟังชั่นนี้ต้องถูกเรียกใช้.
• dhcp_start(struct netif *netif) สร้าง a new DHCP client สำหรับ interface นี้บน the first call. คุณสามารถดูใน the
netif->dhcp struct สำหรับ the actual DHCP status.
• sys_check_timeouts() เมื่อ the system กำลังรันอยู่, คูณต้องเรียกใช้ sys_check_timeouts() เป็นระยะๆซึ่งจะจัดการ
timers ทั้งหมดสำหรับ protocols ทั้งหมดใน the stack; เพิ่มสิ่งนี้ไปยัง main loop ของคุณหรือ equivalent.
https://www.nongnu.org/lwip/2_1_x/multithreading.html (https://www.nongnu.org/lwip/2_1_x/multithreading.html)
Multithreading
lwIP สตาร์ท targeting single-threaded environments. เมื่อเพิ่ม multi- threading support, แทนที่จะทำ the core thread-safe, วิธีเข้าใกล้หนึ่งเคยถูกเลือก: มี one main thread รัน the lwIP core (เรียกอีกอย่างว่า the "tcpip_thread"). เมื่อรันใน a multithreaded environment, raw API functions ต้องถูกเรียกเฉพาะจาก the core thread เท่านั้นเนื่องจาก raw API functions ไม่ได้ถูกป้องกันจากการเข้าถึงพร้อมกัน (นอกเหนือจาก pbuf- และ memory management functions). Application threads ใช้ the sequential- หรือ socket API สื่อสารกับ main thread นี้ผ่านทาง message passing.
ด้วยเหตุนี้, รายการของฟังชั่นที่อาจถูกเรียกจาก threads อื่นหรือ an ISR ถูกจำกัดมาก! เฉพาะฟังชั่นจาก API header files เหล่านี้เป็น thread-safe:
• api.h
• netbuf.h
• netdb.h
• netifapi.h
• pppapi.h
• sockets.h
• sys.h
นอกจากนี้, memory (de-)allocation functions อาจถูกเรียกจากหลาย threads (ไม่ใช่ ISR!) ด้วย NO_SYS=0 เนื่องจากพวกมันถูกป้องกันโดย SYS_LIGHTWEIGHT_PROT และ/หรือ semaphores.
Netconn หรือ Socket API functions เป็น thread safe ขัดต่อ the core thread แต่พวกมันไม่กลับเข้ามาใหม่ที่ the control block granularity level. นั่นคือ, a UDP or TCP control block ต้องไม่ถูกแชร์ในหมู่ threads ทั้งหลายโดยไม่มีการล็อคที่เหมาะสม.
ถ้า SYS_LIGHTWEIGHT_PROT ถูกเซ็ตเป็น 1 และ LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT ถูกเซ็ตเป็น 1, pbuf_free() อาจถูกเรียกใช้จาก thread อื่นหรือ an ISR อีกด้วย (ตั้งแต่นั้นมา, mem_free - สำหรับ PBUF_RAM - อาจถูกเรียกใช้จาก an ISR: มิฉะนั้น, the HEAP ถูกป้องกันโดย semaphores เท่านั้น).
How to get threading done right
ขอแนะนำอย่างยิ่งให้ใช้ the LWIP_ASSERT_CORE_LOCKED() macro ใน an application ที่ใช้ multithreading. lwIP code มีหลายตำแหน่งที่ตรวจสอบสำหรับ a correct thread context ถูกจัดให้มีใช้ซึ่งช่วยอย่างมากให้ผู้ใช้ได้รับการ threading อย่างถูกต้อง. ดูตัวอย่าง sys_arch.c files ใน unix และ Win32 พอร์ตใน the contrib repository.
กล่าวโดยย่อ: คัดลอก the functions sys_mark_tcpip_thread() และ sys_check_core_locking() ไปยังพอร์ตของคุณและแก้ไขพวกมันให้ทำงานกับ OS ของคุณ. จากนั้นให้ LWIP_ASSERT_CORE_LOCKED() and LWIP_MARK_TCPIP_THREAD() ชี้ไปยังฟังชั่นเหล่านี้.
ถ้าคุณใช้ LWIP_TCPIP_CORE_LOCKING, คุณจำเป็นต้องคัดลอกและปรับเปลี่ยน the functions sys_lock_tcpip_core() and sys_unlock_tcpip_core(). ให้ LOCK_TCPIP_CORE() and UNLOCK_TCPIP_CORE() ชี้ไปยังฟังชั่นเหล่านี้.
https://www.nongnu.org/lwip/2_1_x/optimization.html (https://www.nongnu.org/lwip/2_1_x/optimization.html)
Optimization hints
สิ่งแรกที่คุณต้องการเพิ่มประสิทธิภาพคือ the lwip_standard_checksum() routine จาก src/core/inet.c. คุณสามารถข้ามผ่าน standard function นี้ด้วย the #define LWIP_CHKSUM your_checksum_routine().
มี C examples ที่ให้ไว้ใน inet.c หรือคุณอาจต้องการงานฝีมือ an assembly function สำหรับสิ่งนี้. RFC1071 เป็น a good introduction ในเรื่องนี้.
การปรับปรุงที่สำคัญอื่นๆ สามารถทำได้โดย supplying assembly หรือ inline replacements สำหรับ htons() and htonl() ถ้าคุณกำลังใช้ a little-endian architecture. #define lwip_htons(x) your_htons() #define lwip_htonl(x) your_htonl() ถ้าคุณ #define พวกมันไปยัง htons() and htonl(), คุณควร #define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS เพื่อป้องกัน lwIP จากการกำหนด htonx / ntohx ความเข้ากันได้ของมาโคร.
ตรวจสอบ network interface driver ของคุณถ้ามันอ่านที่ความเร็วสูงกว่า the maximum wire-speed. ถ้า the hardware ไม่ได้รับการบริการบ่อยครั้งหรือเร็วเพียงพอ buffer overflows มีแนวโน้มที่จะเกิดขึ้น.
ตัวอย่างเช่น เมื่อใช้ the cs8900 driver, เรียก cs8900if_service(ethif) ให้บ่อยที่สุดเท่าที่เป็นได้. เมื่อใช้ an RTOS ให้ the cs8900 interrupt ปลุก a high priority task ที่บริการ driver ของคุณโดยใช้ a binary semaphore หรือ event flag. บาง drivers อาจยอมให้มีการปรับแต่งเพิ่มเติมเพื่อให้ตรงกับ application and network ของคุณ.
สำหรับรุ่นที่ใช้งานจริง ขอแนะนำให้ตั้งค่า LWIP_STATS เป็น 0. โปรดทราบว่า speed performance ไม่ได้มีผลมากนักจากการตั้งค่าสูงให้กับ the memory options.
https://www.nongnu.org/lwip/2_1_x/deprecated.html (https://www.nongnu.org/lwip/2_1_x/deprecated.html)
(https://i.imgur.com/BxZfYca.png)
https://www.nongnu.org/lwip/2_1_x/group__lwip__nosys.html (https://www.nongnu.org/lwip/2_1_x/group__lwip__nosys.html)
(https://i.imgur.com/WkPAo4c.png)
Detailed Description
ใช้โหมดนี้ถ้าคุณไม่รัน an OS บนระบบของคุณ. #define NO_SYS เป็น 1. ป้อน incoming packets ไปยัง netif->input(pbuf, netif) function จาก mainloop, ไม่จาก interrupt context. คุณสามารถจัดสรร a Packet buffers (PBUF) ใน interrupt context และใส่พวกมันลงใน a queue ซึ่งถูกประมวลผลจาก mainloop.
เรียก sys_check_timeouts() เป็นระยะๆใน the mainloop.
Porting: จัดให้มีใช้งาน functions ทั้งหมดใน Time, Critical sections และ Compiler/platform abstraction.
คุณสามารถใช้เฉพาะ "raw" APIs ในโหมดนี้.
Sample code:
(ตัวอย่างโปรแกรมดูในเว็บเอานะครับ)
(https://i.imgur.com/SR0t1XL.png)
ประมวลผล received ethernet frames. โดยใช้ฟังชั่นนี้แทนที่จะใช้การเรียก ip_input โดยตรงและส่งผ่าน ARP frames ผ่านทาง etharp ใน ethernetif_input, the ARP cache ถูกป้องกันจากการเข้าถึงพร้อมกัน.
ไม่เรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input().
Parameters
p the received packet, p->payload ชี้ไปยัง the ethernet header
netif the network interface ที่ the packet ถูกรับแล้ว
See also
LWIP_HOOK_UNKNOWN_ETH_PROTOCOL
ETHARP_SUPPORT_VLAN
LWIP_HOOK_VLAN_CHECK
(https://i.imgur.com/0z6m0SM.png)
ถ้าทั้งสอง IP versions ถูกเปิดการใช้งาน, ฟังชั่นนี้สามารถส่ง packets ไปยังตัวที่ถูกต้อง. ไม่เรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input().
(https://i.imgur.com/wpJWHM0.png)
เริ่มต้น modules ทั้งหมด. ใช้สิ่งนี้ใน NO_SYS mode. ใช้ tcpip_init() ถ้าเป็นอย่างอื่น.
(https://i.imgur.com/DjglAdu.png)
ส่งต่อ a received packet สำหรับ input processing ด้วย ethernet_input() หรือ ip_input() ขึ้นอยู่กับ netif flags. ไม่เรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input(). จะทำงานเฉพาะถ้า the netif driver เซ็ต NETIF_FLAG_ETHARP และ/หรือ NETIF_FLAG_ETHERNET flag! อย่างถูกต้อง
(https://i.imgur.com/cNWymU6.png)
จัดการ timeouts สำหรับ NO_SYS==1 (ตัวอย่างเช่นไมมีการใช้ tcpip_thread/sys_timeouts_mbox_fetch(). ใช้ sys_now() เพื่อเรียก timeout handler functions เมื่อ timeouts หมดเวลาลง.
ต้องถูกเรียกเป็นระยะๆจาก main loop ของคุณ.
https://www.nongnu.org/lwip/2_1_x/group__lwip__os.html (https://www.nongnu.org/lwip/2_1_x/group__lwip__os.html)
(https://i.imgur.com/InubWyw.png)
Detailed Description
ใช้โหมดนี้ถ้าคุณรัน an OS บนระบบของคุณ. ขอแนะนำให้ใช้ an RTOS ที่จัดการ priority inversion อย่างถูกต้องและใช้ LWIP_TCPIP_CORE_LOCKING.
Porting: จัดให้มีใช้ทุกฟังชั่นใน Porting (system abstraction layer).
คุณสามารถใช้ "raw" APIs ร่วมกันกับ tcpip_callback, และทุก Sequential-style APIs.
(https://i.imgur.com/qZwxItp.png)
(https://i.imgur.com/Wugp3Rb.png)
เรียก a specific function ใน the thread context ของ tcpip_thread เพื่อเข้าถึง synchronization ได้ง่าย. A function ที่เรียกในวิธีนั้นอาจเข้าถึง lwIP core code โดยไม่มีการกลัวการเข้าถึงที่พร้อมกัน. บล็อกจนกระทั่ง the request ถูกโพสต์. ต้องไม่ถูกเรียกจาก interrupt context!
Parameters
function the function ที่เรียก
ctx parameter ที่ส่งผ่านไปยัง f
Returns
ERR_OK ถ้า the function ถูกเรียกแล้ว, เป็น err_t อย่างอื่นถ้าไม่ใช่
See also
tcpip_try_callback
(https://i.imgur.com/GGg5LNL.png)
(https://i.imgur.com/atvYlt6.png)
จัดสรร a structure สำหรับ a static callback message และเริ่มต้นมัน. The message มี a special type ดังนั้น lwIP ไม่เคยปล่อยฟรีมัน. นี้ถูกมุ่งหมายเพื่อถูกใช้ส่ง "static" messages จาก interrupt context, ตัวอย่างเช่น the message ถูกจัดสรรครั้งเดียวและถูกโพสต์หลายครั้งจาก an IRQ โดยใช้ tcpip_callbackmsg_trycallback(). ตัวอย่างการใช้งาน: Trigger execution ของ an ethernet IRQ DPC routine ใน lwIP thread context.
Parameters
function the function ที่เรียก
ctx parameter ที่ส่งผ่านไปยัง function
Returns
a struct pointer ที่ส่งผ่านไปยัง tcpip_callbackmsg_trycallback().
See also
tcpip_callbackmsg_trycallback()
tcpip_callbackmsg_delete()
(https://i.imgur.com/mCsVsBg.png)
(https://i.imgur.com/gFLMWlx.png)
ลองโพสต์ a callback-message ไปยัง the tcpip_thread mbox. เหมือนกับ tcpip_callbackmsg_trycallback แต่เรียก sys_mbox_trypost_fromisr(), โดยหลักเพื่อช่วย FreeRTOS, ที่เรียกต่างที่กันระหว่าง task level และ ISR level.
Parameters
msg pointer ไปยัง the message เพื่อโพสต์
Returns
sys_mbox_trypost_fromisr() return code (โดยไม่มีการเปลี่ยนแปลง, ดังนั้นความรู้นี้สามารถถูกใช้เพื่อตัวอย่างเช่น เผยแพร่
"bool needs_scheduling")
See also
tcpip_callbackmsg_new()
(https://i.imgur.com/HlSg1FY.png)
เริ่มต้น module นี้:
• เริ่มต้น modules ย่อยทั้งหมด
• สตาร์ท the tcpip_thread
Parameters
initfunc a function ที่เรียกเมื่อ tcpip_thread กำลังรันและสำเร็จการเริ่มต้น
arg argument ที่ส่งผ่านไปยัง initfunc
(https://i.imgur.com/Ox1wlrT.png)
ส่งผ่าน a received packet ไปยัง tcpip_thread สำหรับ input processing ด้วย ethernet_input หรือ ip_input. อย่าเรียกโดยตรง, ส่งผ่านไปยัง netif_add() และเรียก netif->input().
Parameters
p the received packet, p->payload ที่ชี้ไปยัง the Ethernet header หรือไปยัง an IP header (ถ้า inp ไม่มี
NETIF_FLAG_ETHARP หรือ NETIF_FLAG_ETHERNET flags)
inp the network interface ที่ซึ่ง the packet ถูกรับแล้ว
(https://i.imgur.com/Ru6S7u7.png)
เรียก a specific function ใน the thread context ของ tcpip_thread เพื่อเข้าถึง synchronization ได้ง่าย. A function ที่เรียกในวิธีนั้นอาจเข้าถึง lwIP core code โดยไม่มีการกลัวการเข้าถึงที่พร้อมกัน. อย่าบล็อกเมื่อ the request ไม่สามารถถูกโพสต์เพราะว่า the tcpip_mbox เต็ม, แต่รีเทิร์น ERR_MEM แทน . สามารถถูกเรียกจาก interrupt context!
Parameters
function the function ที่เรียก
ctx parameter ที่ส่งผ่านไปยัง f
Returns
ERR_OK ถ้า the function ถูกเรียกแล้ว, เป็น err_t อย่างอื่นถ้าไม่ใช่
See also
tcpip_callback
https://www.nongnu.org/lwip/2_1_x/group__sys__layer.html (https://www.nongnu.org/lwip/2_1_x/group__sys__layer.html)
(https://i.imgur.com/57Mt4dV.png)
https://www.nongnu.org/lwip/2_1_x/group__sys__nonstandard.html (https://www.nongnu.org/lwip/2_1_x/group__sys__nonstandard.html)
(https://i.imgur.com/UtfN0xX.png)
Detailed Description
lwIP จัดให้มี default implementations สำหรับ non-standard functions. เหล่านี้สามารถถูกแม็ปเข้ากับ OS functions เพื่อลด code footprint ถ้าต้องการ. defines ทั้งหมดที่เกี่ยวกับ section นี้ต้องไม่ถูกวางใน lwipopts.h, แต่ใน arch/cc.h! ทางเลือกเหล่านี้ไม่สามารถถูก #defined ใน lwipopts.h เนื่องจากไม่ใช่ทางเลือกของ lwIP เอง, แต่เป็นทางเลือกของ the lwIP port ไปยังระบบของคุณ.
(https://i.imgur.com/Vp4uiBW.png)
การจัดให้มีใช้งานเริ่มต้น lwIP สำหรับ itoa() non-standard function. นี้สามารถถูก #defined ไปยัง itoa() หรือ snprintf(result, bufsize, "%d", number) ขึ้นอยู่กับ your platform port.
(https://i.imgur.com/FzyqVyX.png)
lwIP default implementation สำหรับ stricmp() non-standard function. นี้สามารถถูก #defined ไปยัง stricmp() ขึ้นอยู่กับ your platform port.
(https://i.imgur.com/2ZIxi05.png)
lwIP default implementation สำหรับ strnicmp() non-standard function. นี้สามารถถูก #defined ไปยัง strnicmp() ขึ้นอยู่กับ your platform port.
(https://i.imgur.com/YozMZUX.png)
lwIP default implementation สำหรับ strnstr() non-standard function. นี้สามารถถูก #defined ไปยัง strnstr() ขึ้นอยู่กับ your platform port.
https://www.nongnu.org/lwip/2_1_x/group__sys__os.html (https://www.nongnu.org/lwip/2_1_x/group__sys__os.html)
(https://i.imgur.com/CTa5qoI.png)
Detailed Description
ไม่จำเป็นต้องจัดให้มีใช้ functions ใน section นี้ใน NO_SYS mode. The OS-specific code ควรถูกจัดให้มีใช้ใน arch/sys_arch.h และ sys_arch.c ของ your port.
The operating system emulation layer จัดให้มี a common interface ระหว่าง the lwIP code และ the underlying operating system kernel. The general idea คือการย้าย lwIP ไปยัง new architectures ที่ต้องการเพียงการเปลี่ยนแปลงเล็กน้อยใน a few header files และ a new sys_arch implementation. มันสามารถเป็นได้อีกด้วยที่จะทำ a sys_arch implementation ที่จะไม่พึ่งพา any underlying operating system.
The sys_arch จัดให้มี semaphores, mailboxes and mutexes ไปยัง lwIP. สำหรับ the full lwIP functionality, multiple threads support สามารถถูกจัดให้มีใช้ใน the sys_arch, แต่สิ่งนี้ไม่ถูกต้องการสำหรับ the basic lwIP functionality. Timer scheduling ถูกจัดให้มีใช้ใน lwIP, แต่สามารถถูกจัดให้มีใช้โดย the sys_arch port (LWIP_TIMERS_CUSTOM==1).
นอกจาก the source file จัดให้มี the functionality of sys_arch, the OS emulation layer ต้องจัดให้มี several header files กำหนด macros ที่ใช้ตลอดทั้ง lwip. The files ที่ต้องการและ the macros พวกมันต้อง define ถูกลิสท์รายการข้างล่าง the sys_arch description.
ตั้งแต่ lwIP 1.4.0, semaphore, mutexes and mailbox functions ถูกสร้างต้นแบบในลักษณะที่ยอมให้ทั้งใช้ pointers หรือ actual OS structures ถูกใช้. วิธีนี้, memory ที่ต้องการสำหรับชนิดดังกล่าวสามารถถูกอย่างใดอย่างหนึ่ง ถูกจัดสรรใน place (globally หรือบน the stack) หรือบน the heap (จัดสรรภายในใน the "*_new()" functions).
Note:
โปรดใช้ความระมัดระวังในการใช้ mem_malloc() ใน sys_arch. เมื่อ malloc() อ้างอิงถึง mem_malloc() คุณสามารถพบปัญหาการเรียก a circular function. ใน mem.c mem_init() พยายามจัดสรร a semaphore โดยใช้ mem_malloc, ซึ่งแน่นอนว่าไม่สามารถทำได้เมื่อ sys_arch ใช้ mem_malloc.
https://www.nongnu.org/lwip/2_1_x/group__sys__sem.html (https://www.nongnu.org/lwip/2_1_x/group__sys__sem.html)
(https://i.imgur.com/v6ycXZU.png)
Detailed Description
Semaphores สามารถเป็นอย่างใดอย่างหนึ่ง counting หรือ binary - lwIP ทำงานกับทั้งสองชนิด. Semaphores ถูกแสดงโดย the type "sys_sem_t" ซึ่งเป็น typedef'd ใน the sys_arch.h file. Mailboxes ถูกแสดงเทียบเท่ากันโดย the type "sys_mbox_t". Mutexes ถูกแสดงโดย the type "sys_mutex_t". lwIP ไม่ได้วางข้อจำกัดใดๆว่าชนิดเหล่านี้ถูกแสดงภายในอย่างไร.
(https://i.imgur.com/k6C9pkT.png)
บล็อก the thread ขณะการรอสำหรับ the semaphore ถูกให้สัญญาน. ถ้า the "timeout" argument เป็น non-zero, the thread จะถูกบล็อกเพียงเป็นเวลาเวลาที่ระบุ (วัดใน milliseconds). ถ้า the "timeout" argument เป็น zero, the thread จะถูกบล็อกจนกรทั่ง the semaphore ถูกให้สัญญาน.
The return value เป็น SYS_ARCH_TIMEOUT ถ้า the semaphore ไม่ถูกให้สัญญานภายในเวลาที่ระบุหรือค่าอื่นใดๆถ้ามันถูกให้สัญญานแล้ว (มีหรือไม่มีการรอ). ขอให้สังเกตว่า lwIP จัดให้มีใช้ a function ที่มีชื่อคล้ายกัน, sys_sem_wait(), ที่ใช้ the sys_arch_sem_wait() function.
Parameters
sem the semaphore ที่รอ for
timeout timeout ใน milliseconds ที่รอ (0 = รอตลอดไป)
Returns
SYS_ARCH_TIMEOUT เมื่อ timeout, ค่าอื่นใดๆหากสำเร็จ
(https://i.imgur.com/oZp90OJ.png)
(https://i.imgur.com/02xCXlJ.png)
สร้าง a new semaphore สร้าง a new semaphore. The semaphore ถูกจัดสรรไปยัง the memory ที่ 'sem' ชี้ไปยัง (ซึ่งสามารถเป็นได้ทั้ง a pointer หรือ the actual OS structure). The "count" argument ระบุสถานะเริ่มต้นของ the semaphore (ซึ่งเป็นอย่างใดอย่างหนึ่ง 0 หรือ 1). ถ้า the semaphore ถูกสร้างแล้ว, ERR_OK ควรถูกรีเทิร์น. การรีเทิร์น error อื่นใดๆจะเป็นการบอกใบ้ถึงสิ่งที่ผิดพลาด, แต่ยกเว้นสำหรับการถือสิทธิ์, ไม่มี real error handling ถูกจัดให้มีใช้.
Parameters
sem ชี้ไปยัง the semaphore ที่สร้าง
count initial count of the semaphore
Returns
ERR_OK ถ้าสำเร็จ, err_t อื่นถ้าเป็นอย่างอื่น
(https://i.imgur.com/8Ee1AE8.png)
ทำให้ a semaphore เป็นโมฆะดังนั้น sys_sem_valid() จะส่งคืนค่า 0. ข้อควรระวัง: นี่ไม่ได้หมายความว่า the semaphore จะถูกคืนการจัดสรร: sys_sem_free() ถูกเรียกเสมอก่อนการเรียกฟังชั่นนี้! นี้อาจเป็น a define อีกด้วย, ซึ่งในกรณีนี้ ฟังก์ชันจะไม่ถูกสร้างเป็นต้นแบบ.
(https://i.imgur.com/WXq8Uf3.png)
(https://i.imgur.com/MlnMmq1.png)
คืนค่า 1 ถ้า the semaphore ใช้ได้, 0 ถ้ามันใช้ไม่ได้. เมื่อใช้ pointers, วิธีง่ายๆคือตรวจสอบ the pointer สำหรับ != NULL. เมื่อใช้ OS structures โดยตรง, การจัดให้มีใช้นี้อาจซับซ้อนมากขึ้น. นี้อาจเป็น a define อีกด้วย, ซึ่งในกรณีนี้ the function จะไม่ถูกสร้างเป็นต้นแบบ.
https://www.nongnu.org/lwip/2_1_x/group__sys__mutex.html (https://www.nongnu.org/lwip/2_1_x/group__sys__mutex.html)
(https://i.imgur.com/me3i8ZY.png)
Detailed Description
Mutexes ถูกแนะนำเพื่อจัดการ priority inversion อย่างถูกต้อง, โดยเฉพาะอย่างยิ่งถ้าคุณใช้ LWIP_CORE_LOCKING .
(https://i.imgur.com/05AtZ7w.png)
(https://i.imgur.com/To3R8rd.png)
สร้าง a new mutex. บันทึกไว้ว่า mutexes ถูกคาดว่าไม่ถูกเรียกซ้ำโดย the lwIP code, ดังนั้นทั้งสอง implementation types (recursive หรือ non-recursive) ควรทำงาน. The mutex ถูกจัดสรรไปยัง the memory ที่ 'mutex' ชี้ไปยัง (ซึ่งสามารถเป็นทั้ง a pointer หรือ the actual OS structure). ถ้า the mutex ถูกสร้างแล้ว, ERR_OK ควรถูกรีเทิร์น. การรีเทิร์น error อื่นใดๆจะเป็นการบอกใบ้ถึงสิ่งที่ผิดพลาด, แต่ยกเว้นสำหรับการถือสิทธิ์, ไม่มี real error handling ถูกจัดให้มีใช้.
Parameters
mutex ชี้ไปยัง the mutex ที่สร้าง
Returns
ERR_OK ถ้าสำเร็จ, err_t อื่นถ้าเป็นอย่างอื่น
(https://i.imgur.com/QZMOUHO.png)
ทำให้ a mutex เป็นโมฆะดังนั้น sys_mutex_valid() ส่งคืนค่า 0. ข้อควรระวัง: นี่ไม่ได้หมายความว่า the mutex จะถูกคืนการจัดสรร: sys_mutex_free() ถูกเรียกเสมอก่อนการเรียกฟังชั่นนี้! นี้อาจเป็น a define อีกด้วย, ซึ่งในกรณีนี้ ฟังก์ชันจะไม่ถูกสร้างเป็นต้นแบบ.
(https://i.imgur.com/uSHQPM0.png)
(https://i.imgur.com/rdA5kkk.png)
คืนค่า 1 ถ้า the mutex ใช้ได้, 0 ถ้ามันใช้ไม่ได้. เมื่อใช้ pointers, วิธีง่ายๆคือตรวจสอบ the pointer สำหรับ != NULL. เมื่อใช้ OS structures โดยตรง, การจัดให้มีใช้นี้อาจซับซ้อนมากขึ้น. นี้อาจเป็น a define อีกด้วย, ซึ่งในกรณีนี้ the function จะไม่ถูกสร้างเป็นต้นแบบ.
https://www.nongnu.org/lwip/2_1_x/group__sys__mbox.html (https://www.nongnu.org/lwip/2_1_x/group__sys__mbox.html)
(https://i.imgur.com/qISxnxI.png)
Detailed Description
Mailboxes ควรถูกจัดให้มีใช้เป็น a queue ซึ่งยอมให้หลาย messages ถูกโพสต์ (การจัดให้มีใช้เป็น a rendez-vous point ที่เพียงหนึ่ง message สามารถถูกโพสต์ในแต่ละครั้งเท่านั้นสามารถส่งผลเสียอย่างมากต่อประสิทธิภาพการทำงาน). A message ใน a mailbox เป็นเพียง a pointer, ไม่มีอะไรมากไปกว่านี้.
(https://i.imgur.com/7FCkYPa.png)
บล็อก the thread จนกระทั่ง a message มาถึงใน the mailbox, แต่ไม่บล็อก the thread นานไปกว่า "timeout" milliseconds (คล้ายกันกับ the sys_arch_sem_wait() function). ถ้า "timeout" เป็น 0, the thread จะถูกบล็อกจนกว่า a message มาถึง. The "msg" argument เป็น a result parameter ที่ถูกเซ็ตโดย the function (ตัวอย่างเช่น, โดยการทำ "*msg = ptr"). The "msg" parameter อาจเป็น NULL เพื่อแสดงให้เห็นว่า the message ควรถูกดร็อป. The return values เป็นเหมือนกับสำหรับ the sys_arch_sem_wait() function: SYS_ARCH_TIMEOUT ถ้ามี a timeout แล้ว, เป็นค่าอื่นใดๆถ้า a messages ถูกรับ.
บันทึกไว้ว่า a function ที่มีชื่อคล้ายกัน, sys_mbox_fetch(), ถูกจัดให้มีใช้โดย lwIP.
Parameters
mbox mbox ที่ได้รับ a message จาก
msg ชี้ไปยังที่ๆ the message ถูกเก็บ
timeout maximum time (in milliseconds) ที่รอสำหรับ a message (0 = รอตลอดไป)
Returns
SYS_ARCH_TIMEOUT เมื่อ timeout, ค่าอื่นใดๆถ้า a message ถูกรับแล้ว
(https://i.imgur.com/1XqZeWT.png)
สิ่งนี้คล้ายกับ sys_arch_mbox_fetch, อย่างไรก็ตามถ้า a message ไม่ปรากฎใน the mailbox, มันจะรีเทิร์นทันทีด้วย the code SYS_MBOX_EMPTY. เมื่อสำเร็จ 0 ถูกรีเทิร์น. เพื่อยอมให้สำหรับ efficient implementations, นี้สามารถถูกกำหนดเป็น a function-like macro ใน sys_arch.h แทนที่จะเป็น a normal function. ตัวอย่างเช่น, a naive implementation อาจเป็น: #define sys_arch_mbox_tryfetch(mbox,msg) sys_arch_mbox_fetch(mbox,msg,1) แม้ว่าสิ่งนี้จะทำให้เกิดความล่าช้าโดยไม่จำเป็น.
Parameters
mbox mbox ที่ได้รับ a message จาก
msg ชี้ไปยังที่ๆ the message ถูกเก็บ
Returns
0 (milliseconds) ถ้า a message ถูกรับแล้วหรือ SYS_MBOX_EMPTY ถ้า the mailbox ว่างเปล่า
(https://i.imgur.com/ZVgfxJw.png)
คืนการจัดสรร a mailbox. ถ้ามี messages ยังคงปรากฎใน the mailbox เมื่อ the mailbox ถูกคืนการจัดสรร, มันเป็นการแสดงให้เห็นของ a programming error ใน lwIP และ the developer ควรถูกแจ้งให้ทราบ.
Parameters
mbox mbox ที่ลบ
(https://i.imgur.com/QuW2hrX.png)
สร้าง an empty mailbox สำหรับ maximum "size" elements. Elements ที่เก็บใน mailboxes เป็น pointers. คุณต้องกำหนด macros "_MBOX_SIZE" ใน your lwipopts.h, หรือเพิกเฉย parameter นี้ใน your implementation และใช้ a default size. ถ้า the mailbox ถูกสร้างแล้ว, ERR_OK ควรถูกรีเทิร์น. การรีเทิร์น error อื่นใดๆจะเป็นการบอกใบ้ถึงสิ่งที่ผิดพลาด, แต่ยกเว้นสำหรับการถือสิทธิ์, ไม่มี real error handling ถูกจัดให้มีใช้.
Parameters
mbox ชี้ไปยัง the mbox ที่สร้าง
size (minimum) จำนวนของ messages ใน this mbox
Returns
ERR_OK ถ้าสำเร็จ, err_t อื่นถ้าเป็นอย่างอื่น
(https://i.imgur.com/LqKFJWP.png)
โพสต์ a message ไปยัง an mbox - อาจไม่ล้มเหลว -> บล็อกถ้าเต็ม, ถูกใช้เฉพาจาก tasks เท่านั้นไม่จาก ISR!
Parameters
mbox mbox ที่โพสต์ the message
msg message ที่โพสต์ (ข้อควรระวัง : สามารถเป็น NULL)
(https://i.imgur.com/1vvWu4K.png)
ทำให้ a mailbox เป็นโมฆะดังนั้น sys_mbox_valid() ส่งคืนค่า 0. ข้อควรระวัง: นี่ไม่ได้หมายความว่า the mailbox จะถูกคืนการจัดสรร: sys_mbox_free() ถูกเรียกก่อนการเรียกฟังชั่นนี้เสมอ! นี้อาจเป็น a define อีกด้วย, ซึ่งในกรณีนี้ ฟังก์ชันจะไม่ถูกสร้างเป็นต้นแบบ.
(https://i.imgur.com/3ky9nKL.png)
พยายามโพสต์ a message ไปยัง an mbox - อาจล้มเหลวถ้าเต็ม. สามารถถูกใช้จาก ISR (ถ้า the sys arch layer ยอมให้การนี้). รีเทิร์น ERR_MEM ถ้ามันเต็ม, เป็นอย่างอื่น, ERR_OK ถ้า the "msg" ถูกโพสต์.
Parameters
mbox mbox ที่โพสต์ the message
msg message ที่โพสต์ (ข้อควรระวัง : สามารถเป็น NULL)
(https://i.imgur.com/tsHDkTs.png)
พยายามโพสต์ a message ไปยัง an mbox - อาจล้มเหลวถ้าเต็ม. ถูกใช้ได้จาก ISR. รีเทิร์น ERR_MEM ถ้ามันเต็ม, เป็นอย่างอื่น, ERR_OK ถ้า the "msg" ถูกโพสต์.
Parameters
mbox mbox ที่โพสต์ the message
msg message ที่โพสต์ (ข้อควรระวัง : สามารถเป็น NULL)
(https://i.imgur.com/dsRM8wy.png)
คืนค่า 1 ถ้า the mailbox ใช้ได้, 0 ถ้ามันใช้ไม่ได้. เมื่อใช้ pointers, วิธีง่ายๆคือตรวจสอบ the pointer เพื่อ != NULL. เมื่อใช้ OS structures โดยตรง, การจัดให้มีใช้นี้อาจซับซ้อนมากขึ้น. นี้อาจเป็น a define อีกด้วย, ซึ่งในกรณีนี้ the function จะไม่ถูกสร้างเป็นต้นแบบ.
https://www.nongnu.org/lwip/2_1_x/group__sys__misc.html (https://www.nongnu.org/lwip/2_1_x/group__sys__misc.html)
(https://i.imgur.com/eWOiW32.png)
(https://i.imgur.com/GxrN96e.png)
sys_init() ต้องถูกเรียกก่อนสิ่งอื่น. เริ่มต้น the sys_arch layer.
(https://i.imgur.com/ggrnJKl.png)
Sleep เป็นเวลาจำนวนที่ระบุของ ms
Sleep เป็นเวลาบาง ms. Timeouts จะไม่ถูกประมวลผลในขณะ sleeping.
Parameters
ms จำนวนของ milliseconds ที่ sleep
(https://i.imgur.com/sU4uEk7.png)
The only thread function: สตาร์ท a new thread ที่ชื่อ "name" ที่มี priority "prio" ที่จะเริ่มการปฏิบัติงานของมันใน the function "thread()". The "arg" argument จะถูกส่งผ่านเป็น an argument ไปยัง the thread() function. The stack size ที่ใช้สำหรับ thread นี้คือ the "stacksize" parameter. The id ของ the new thread ถูกรีเทิร์น. ทั้งคู่ the id และ the priority เป็น system dependent. ข้อควรระวัง: แม้ว่าฟังชั่นนี้ส่งคืนค่า, มันต้องไม่ล้มเหลว (พอร์ตต้องถือสิทธิ์สิ่งนี้!)
Parameters
name human-readable name สำหรับ the thread (ที่ใช้สำหรับ debugging purposes)
thread thread-function
arg parameter ที่ส่งผ่านไปยัง 'thread'
stacksize stack size in bytes สำหรับ the new thread (อาจถูกละเลยโดย ports)
prio priority of the new thread (อาจถูกละเลยโดย ports)
https://www.nongnu.org/lwip/2_1_x/group__sys__time.html (https://www.nongnu.org/lwip/2_1_x/group__sys__time.html)
(https://i.imgur.com/PP1yWWi.png)
ส่งคืนเวลาปัจจุบันในหน่วย milliseconds, อาจเป็นเหมือนกับ sys_jiffies หรืออย่างน้อยขึ้นอยู่กับมัน. ไม่ต้องสนใจสำหรับการพันรอบ, สิ่งนี้ถูกใช้เฉพาะสำหรับความแตกต่างของเวลา. การไม่จัดให้มีใช้ฟังชั่นนี้หมายความว่าคุณไม่สามารถใช้บาง modules (ตัวอย่างเช่น. TCP timestamps, internal timeouts for NO_SYS==1).
https://www.nongnu.org/lwip/2_1_x/group__sys__prot.html (https://www.nongnu.org/lwip/2_1_x/group__sys__prot.html)
(https://i.imgur.com/XB9J1hr.png)
Detailed Description
ใช้เพื่อป้องกันเขตแดนที่สั้นของ code จากการเข้าถึงพร้อมกัน.
• Your system เป็น a bare-metal system (บางทีพร้อมกับ an RTOS) และ interrupts อยู่ภายใต้ your control: จัดให้มีใช้
สิ่งนี้เป็น LockInterrupts() / UnlockInterrupts()
• Your system ใช้ an RTOS ที่มีการจัดการอินเตอร์รัปต์ที่เลื่อนออกไปจาก a worker thread: จัดให้มีใช้เป็น a global mutex
หรือ lock/unlock scheduler
• Your system ใช้ a high-level OS ที่มีตัวอย่างเช่น POSIX signals: จัดให้มีใช้เป็น a global mutex
(https://i.imgur.com/7ciy1f2.png)
SYS_LIGHTWEIGHT_PROT define SYS_LIGHTWEIGHT_PROT ใน lwipopts.h ถ้าคุณต้องการ inter-task protection สำหรับบริเวณส่วนสำคัญ(วิกฤต)ที่แน่นอนในระหว่าง buffer allocation, deallocation and memory allocation and deallocation.
SYS_ARCH_DECL_PROTECT ประกาศ a protection variable. macro นี้จะมีค่าเริ่มต้นเพื่อกำหนดตัวแปรของ type sys_prot_t. ถ้าพอร์ตใดพอร์ตหนึ่งต้องการการจัดให้มีใช้งานที่แตกต่างกัน, ดังนั้นมาโครนี้อาจถูกกำหนดใน sys_arch.h.
(https://i.imgur.com/1hxH42k.png)
SYS_ARCH_PROTECT กระทำการ a "fast" protect. นี้สามารถถูกจัดให้มีใช้โดยการปิดการใช้งาน interrupts สำหรับ an embedded system หรือโดยการใช้ a semaphore หรือ mutex. The implementation ควรยอมให้มีการเรียก SYS_ARCH_PROTECT เมื่อถูกป้องกันแล้ว. The old protection level ถูกรีเทิร์นใน the variable "lev". มาโครนี้จะมีค่าเริ่มต้นเพื่อเรียก the sys_arch_protect() function ซึ่งควรถูกจัดให้มีใช้ใน sys_arch.c. ถ้าพอร์ตใดพอร์ตหนึ่งต้องการการจัดให้มีใช้งานที่แตกต่างกัน, ดังนั้นมาโครนี้อาจถูกกำหนดใน sys_arch.h.
(https://i.imgur.com/iaJbgz1.png)
SYS_ARCH_UNPROTECT กระทำการ a "fast" การตั้งค่าของ the protection level ไปยัง "lev". นี้สามารถถูกจัดให้มีใช้โดยการตั้งค่า the interrupt level ไปยัง "lev" ภายใน the MACRO หรือโดยการใช้ a semaphore หรือ mutex. มาโครนี้จะมีค่าเริ่มต้นเพื่อเรียก the sys_arch_unprotect() function ซึ่งควรถูกจัดให้มีใช้ใน sys_arch.c. ถ้าพอร์ตใดพอร์ตหนึ่งต้องการการจัดให้มีใช้งานที่แตกต่างกัน, ดังนั้นมาโครนี้อาจถูกกำหนดใน sys_arch.h.
https://www.nongnu.org/lwip/2_1_x/group__compiler__abstraction.html (https://www.nongnu.org/lwip/2_1_x/group__compiler__abstraction.html)
(https://i.imgur.com/nlKfZgn.png)
(https://i.imgur.com/cw9YfV1.png)
Detailed Description
การ defines ทั้งหมดที่เกี่ยวข้องกับ section นี้ต้องไม่ถูกวางใน lwipopts.h, แต่ใน arch/cc.h! ถ้า the compiler ไม่จัดให้มี memset() ไฟล์นี้ต้องรวม a definition ของมัน, หรือ include ไฟล์ซึ่ง defines มัน. ทางเลือกเหล่านี้ไม่สามารถถูก #defined ใน lwipopts.h เนื่องจากพวกมันไม่เป็นทางเลือกของ lwIP มันเอง, แต่เป็นทางเลือกของ the lwIP ที่พอร์ตไปยังระบบของคุณ.
(https://i.imgur.com/8DQQiUL.png)
กำหนด the byte order ของ the system. ที่จำเป็นสำหรับการแปลงของ network data ไปเป็น host byte order. ค่าที่ยอมให้: LITTLE_ENDIAN และ BIG_ENDIAN
(https://i.imgur.com/ZxLsdSZ.png)
กำจัด alignment cast warnings (GCC -Wcast-align)
(https://i.imgur.com/scSzdYS.png)
C++ const_cast<target_type>(val) เทียบเท่ากับการลบค่า constness ออกจาก a value (GCC -Wcast-qual)
(https://i.imgur.com/eHxnS0F.png)
จัดสรร a memory buffer ของขนาดที่ระบุทซึ่งเป็นขนาดที่พอเพียงเพื่อจัดวางตำแหน่ง start address ของมันโดยใช้ LWIP_MEM_ALIGN. คุณสามารถประกาศ version ของคุณเองได้ที่นี่ ตัวอย่างเช่นเพื่อบังคับ alignment โดยไม่มีการเพิ่ม trailing padding bytes (ดู LWIP_MEM_ALIGN_BUFFER) หรือ section placement requirements ของคุณเอง.
ตัวอย่างเช่น ถ้าคุณใช้ gcc และต้องการ 32 bit alignment:
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] __attribute__((aligned(4))) หรือพกพาได้สะดวกกว่า:
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)]
(https://i.imgur.com/F4lr8H2.png)
จัดวางตำแหน่ง a memory pointer ไปยัง the alignment ที่กำหนดโดย MEM_ALIGNMENT ดังนั้น ADDR % MEM_ALIGNMENT == 0
(https://i.imgur.com/Ct4gdKf.png)
คำนวณ safe memory size สำหรับ an aligned buffer เมื่อใช้ an unaligned type เป็นที่เก็บข้อมูล. นี้จะรวม a safety-margin บน (MEM_ALIGNMENT - 1) ที่จุดเริ่มต้น (ตัวอย่างเช่น ถ้า buffer เป็น u8_t[] และ actual data จะเป็น u32_t*)
(https://i.imgur.com/HQXVVIp.png)
คำนวณ memory size สำหรับ an aligned buffer - ส่งคืนกลับค่าผลคูณสูงสุดถัดไปของ MEM_ALIGNMENT (ตัวอย่างเช่น LWIP_MEM_ALIGN_SIZE(3) และ LWIP_MEM_ALIGN_SIZE(4) ทั้งคู่จะให้ผล 4 สำหรับ MEM_ALIGNMENT == 4).
(https://i.imgur.com/eXIXSUY.png)
กำหนดสิ่งนี้เป็น 1 ใน arch/cc.h ของ port ของคุณถ้า your compiler ไม่จัดให้มี the ctype.h header. ถ้า ctype.h มีให้ใช้งาน, a few character functions จะถูกแม็ปไปยัง the appropriate functions (lwip_islower, lwip_isdigit...), ถ้าไม่มี, a private implementation ถูกจัดให้มี.
(https://i.imgur.com/EACK5eR.png)
กำหนดสิ่งนี้เป็น 1 ใน arch/cc.h ของ port ของคุณถ้า your compiler ไม่จัดให้มี the inttypes.h header. คุณจำเป็นต้อง define the format strings ที่แสดงรายการใน lwip/arch.h ด้วยตัวคุณเองในกรณีนี้ (X8_F, U16_F...).
(https://i.imgur.com/N23vyOH.png)
กำหนดสิ่งนี้เป็น 1 ใน arch/cc.h ของ your port ถ้า your compiler ไม่จัดให้มี the limits.h header. คุณจำเป็นต้อง define the type limits ด้วยตัวคุณเองในกรณีนี้ (ตัวอย่างเช่่น INT_MAX, SSIZE_MAX).
(https://i.imgur.com/pGQhH6k.png)
กำหนดสิ่งนี้เป็น 1 ใน arch/cc.h ของ your port ถ้าคุณไม่ต้องการ include stddef.h header เพื่อรับ size_t. คุณจำเป็นต้อง typedef size_t ด้วยตัวคุณเองในกรณีนี้.
(https://i.imgur.com/SKHniR8.png)
กำหนดสิ่งนี้เป็น 1 ใน arch/cc.h ของ your port ถ้า your compiler ไม่จัดให้มี the stdint.h header. คุณจำเป็นต้อง typedef the generic types ที่แสดงรายการใน lwip/arch.h ด้วยตัวคุณเองในกรณีนี้ (u8_t, u16_t...).
(https://i.imgur.com/Y1m3g3a.png)
หลีกเลี่ยง warnings/errors ที่เกี่ยวกับ implicitly casting ไกลออกไปจากการแพ็ค attributes โดยการทำ a explicit cast
(https://i.imgur.com/N4osvWH.png)
Platform specific assertion handling.
โปรดทราบว่า the default implementation จะดึงใน printf, fflush และ abort, ซึ่งอาจดึงเป็นลำดับใน standard libary code จำนวนมาก. ใน resource-constrained systems, สิ่งนี้ควรจะถูกกำหนดเป็นสิ่งที่ใช้ทรัพยากรที่น้อยกว่า.
(https://i.imgur.com/mxUWDpn.png)
Platform specific diagnostic output.
โปรดทราบว่า the default implementation จะดึงใน printf, ซึ่งอาจดึงเป็นลำดับใน standard libary code จำนวนมาก. ใน resource-constrained systems, สิ่งนี้ควรจะถูกกำหนดเป็นสิ่งที่ใช้ทรัพยากรที่น้อยกว่า.
(https://i.imgur.com/deW6YeU.png)
LWIP_PROVIDE_ERRNO==1: ให้ lwIP จัดให้มี ERRNO values และ the 'errno' variable. ถ้าสิ่งนี้ถูกปิดการใช้งาน, cc.h ต้องอย่างใดอย่างหนึ่ง define 'errno', include <errno.h>, define LWIP_ERRNO_STDINCLUDE เพื่อรับ <errno.h> included หรือ define LWIP_ERRNO_INCLUDE ไปยัง <errno.h> หรือเทียบเท่า.
(https://i.imgur.com/UfTuipG.png)
กำจัด warnings ที่เกี่ยวกับ pointer-to-numeric และ vice-versa casts, ตัวอย่างเช่น "การแปลงจาก 'u8_t' ไปเป็น 'void *' ของขนาดที่ใหญ่กว่า"
(https://i.imgur.com/UfTuipG.png)
กำจัด warnings ที่เกี่ยวกับ pointer-to-numeric และ vice-versa casts, ตัวอย่างเช่น "การแปลงจาก 'u8_t' ไปเป็น 'void *' ของขนาดที่ใหญ่กว่า"
(https://i.imgur.com/VNNghgb.png)
(https://i.imgur.com/AGRYQVt.png)
(https://i.imgur.com/GTqPKAw.png)
รองรับ packed structs. วางก่อนการประกาศ a packed struct.
สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่.
(https://i.imgur.com/5TglCFy.png)
รองรับ packed structs. วางหลังการประกาศ a packed struct.
สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่.
(https://i.imgur.com/gIokCvO.png)
รองรับ packed structs. ห่อหุ้ม u32_t and u16_t members..
สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่
(https://i.imgur.com/04b3lAx.png)
รองรับ packed structs. ห่อหุ้ม u8_t members, โดยที่บาง compilers เตือนว่าการแพ็คไม่จำเป็น.
สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่
(https://i.imgur.com/qBCDGG9.png)
รองรับ packed structs. ห่อหุ้ม members ที่เป็น packed structs ตัวเอง,โดยที่บาง compilers เตือนว่าการแพ็คไม่จำเป็น.
สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่
(https://i.imgur.com/NG25Gzh.png)
รองรับ packed structs. วางไว้ระหว่างจุดสิ้นสุดของ declaration of a packed struct และเซมิโคลอนต่อท้าย
สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่
(https://i.imgur.com/21xHqqC.png)
PACK_STRUCT_USE_INCLUDES==1: Packed structs support โดยใช้ #include files ก่อนและหลัง struct ถูกแพ็ค.
The file included BEFORE the struct คือ "arch/bpstruct.h".
The file included AFTER the struct คือ "arch/epstruct.h".
นี้สามารถถูกใช้เพื่อจัดให้มีใช้ struct packing บน MS Visual C compilers, ดู the Win32 port ใน the lwIP contrib repository สำหรับการอ้างอิง. สำหรับตัวอย่างของ packed struct declarations, ดู include/lwip/prot/ subfolder.
พอร์ตไปยัง GCC/clang ถูก included ใน lwIP, ถ้าคุณใช้ these compilers ก็ไม่มีอะไรต้องทำที่นี่
https://www.nongnu.org/lwip/2_1_x/autoip_8h.html (https://www.nongnu.org/lwip/2_1_x/autoip_8h.html)
(https://i.imgur.com/1tHxItx.png)
(https://i.imgur.com/o0QdoJV.png)
(https://i.imgur.com/MwFR9fc.png)
เอาออก a struct autoip ที่เซ็ตก่อนหน้านี้ถึง the netif โดยใช้ autoip_set_struct()
(https://i.imgur.com/uP5K0eb.png)
(https://i.imgur.com/FNICwYR.png)
จัดการทุก incoming ARP Packet, ที่เรียกโดย etharp_input().
Parameters
netif network interface ที่ใช้สำหรับ autoip processing
hdr Incoming ARP packet
(https://i.imgur.com/t3eJYpD.png)
จัดการกับการเปลี่ยนแปลงที่เป็นไปได้ใน the network configuration.
ถ้ามี an AutoIP address ถูกกำหนด, ให้เอา the interface ออกและเริ่มการตรวจสอบด้วย the same address.
(https://i.imgur.com/8hWts3n.png)
ตรวจสอบว่า AutoIP จัดให้ netif->ip_addr . หรือไม่
Parameters
netif the netif ที่ตรวจสอบ
Returns
1 ถ้า AutoIP จัดให้ netif->ip_addr (สถานะ BOUND หรือ ANNOUNCING), 0 ถ้าเป็นอย่างอื่น
(https://i.imgur.com/gntRP7e.png)
ต้องถูกเรียกใน loop ทุกๆ AUTOIP_TMR_INTERVAL milliseconds
https://www.nongnu.org/lwip/2_1_x/debug_8h.html (https://www.nongnu.org/lwip/2_1_x/debug_8h.html)
(https://i.imgur.com/EPmhDwk.png)
(https://i.imgur.com/5FgOcfn.png)
(https://i.imgur.com/R7U8Y6s.png)
เปิดการใช้งาน debug message printing, แต่เฉพาะถ้า debug message type ถูกเปิดการใช้งาน AND(และ) เป็นชนิดที่ถูกต้อง AND(และ) อย่างน้อย LWIP_DBG_LEVEL.
https://www.nongnu.org/lwip/2_1_x/def_8h.html (https://www.nongnu.org/lwip/2_1_x/def_8h.html)
(https://i.imgur.com/Q4MogxS.png)
(https://i.imgur.com/fhoTQ0b.png)
(https://i.imgur.com/w860M3g.png)
(https://i.imgur.com/N9BDNdM.png)
(https://i.imgur.com/hCAAAZR.png)