a survey of uc/os & lwip 蔡嘉泰 [email protected]
TRANSCRIPT
![Page 2: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/2.jpg)
NETLAB
MicroC/OS II
![Page 3: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/3.jpg)
NETLAB
Features
Source Code Open Source,程式碼簡潔易懂
Portable 程式碼大部分皆是利用 ANSI C所開發的 與 microprocessor行為有關的則利用組合語言來完成,使得 uC/OS-II能夠輕易的移植到其他 Processor
uC/OS-II可以在 8/16/32 bits 的 microprocessor上或是micro-controller上運作
![Page 4: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/4.jpg)
NETLAB
Features
ROMable 只要有適當的工具 (C compiler, assembler and
linker/locator)就可將 uC/OS-II嵌入成為產品一部分 Scalable
可以很簡單的選用程式 /產品所需要的特性 也就是說可以依照自己的需求減少程式的大小,以便可以放入 ROM/RAM中
![Page 5: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/5.jpg)
NETLAB
HIGH Priority Task
LOW Priority Task
ISR(1) (2)
(3)(4)
(5)
(6)
(7)
ISR makes the high priority task ready
Time
Features
Preemptive uC/OS-II 永遠會讓已經 Ready且優先權最高的工作行程先執行
![Page 6: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/6.jpg)
NETLAB
TASKWAITING
TASKDORMANT
TASKREADY
TASKRUNNING
ISRRUNNING
Features
![Page 7: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/7.jpg)
NETLAB
Features
Multi-tasking uC/OS-II最多可支援 64 個 task,其中會為系統保留8 個 task使用
每一個 task都有一個唯一的 priority,也就是說uC/OS-II無法實現 Round Robin排程
![Page 8: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/8.jpg)
NETLAB
Status
SP
Priority...
Task Control Block
TASK #1Stack
SP
.
.
.
Status
SP
Priority...
Task Control Block
TASK #2Stack
Status
SP
Priority...
Task Control Block
TASK #nStack
……
MEMORY
CPU
Features
![Page 9: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/9.jpg)
NETLAB
Features
Deterministic 在 uC/OS-II內的各項服務所需要的執行時間都是可明確預先得知的
Task Stacks uC/OS-II允許每一個 task擁有不一樣的 stack size 根據需要增減 task 的 stack size減少 RAM的使用
![Page 10: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/10.jpg)
NETLAB
Features
Services Mailbox, Queues, Semaphores, Fixed-sized
memory partitions, Time related function, etc. Interrupt Management
Interrupts can suspend the execution of a task 256 levels
Robust and Reliable
![Page 11: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/11.jpg)
NETLAB
uC/OS-II移植分析
只要有相對應的 C Compiler,即可將 uC/OS-II移植到特定的處理器上
大部分移植工作都在多任務的切換上 用來儲存以及恢復 register的值 利用組合語言完成
需修改的檔案 OS_CPU.H, OS_CPU_C.C, OS_CPU_A.S
![Page 12: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/12.jpg)
NETLAB
OS_CPU.H
定義DATA TYPE 與所使用的 Compiler相關 不同的 Compiler會使用不一樣的 byte來表示同一
DATA TYPE X86平台 , Integer:
• GNU (gcc): 4 bytes• MicroSoft (VC++): 2 bytes
![Page 13: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/13.jpg)
NETLAB
OS_CPU.H
Stack Entry 定義 TASK 的 Stack長度,必須要和 CPU 的
Register的長度一致堆疊增長方向
定義 Stack grows from HIGH to LOW or Low to HIGH Memory
![Page 14: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/14.jpg)
NETLAB
OS_CPU.H
![Page 15: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/15.jpg)
NETLAB
OS_CPU.H
中斷、 Content Switch
![Page 16: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/16.jpg)
NETLAB
OS_CPU_C.C
Initialize a Task‘s STACK 在堆疊增長的方向上定每一個需要保存的 Register位址
AX
CX
DX
BX
SP
BP
SI
DI
ES
DS
HIGH
LOW
![Page 17: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/17.jpg)
NETLAB
OS_CPU_C.C
![Page 18: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/18.jpg)
NETLAB
OS_CPU_A.S
OSStartHighRdy( ) 在 OSStart()啟動之後,負責從最高優先權任務的
TCB Control Block中獲得該任務的 Stack Point (SP)
OSCtxSw( ) 將前一 task 的 register保存到堆疊中,獲得最高優先
權 task 的 SP,將此 task 的 register恢復,使之繼續執行
OSIntCtxSw( ) 中斷級的 Content Switch
![Page 19: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/19.jpg)
NETLAB
Handbook
![Page 20: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/20.jpg)
NETLAB
Hardware Abstraction Layer (HAL) Real-time kernel Interrupt handling Exception handling Choice of schedulers Thread support Rich set of synchronization primitives Timers, counters and alarms Choice of memory allocators Debug and instrumentation support
μITRON 3.0 compatible API POSIX compatible API ISO C and math libraries Serial, ethernet, wallclock and watchdog device drivers USB slave support TCP/IP networking stacks GDB debug support
![Page 21: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/21.jpg)
NETLAB
light weight IP (lwIP)
![Page 22: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/22.jpg)
NETLAB
lwIP簡介
lwIP一套可用於 embedded system 的 TCP/IP protocol
lwIP可以移植到各OS上,在沒有OS情形下也可以獨立運作
lwIP主要是為了保持 TCP Protocol的主要功能並減少對 RAM的使用
只需要幾十 K 的 RAM和約 40K 的 ROM就可以運作,使得 lwIP很適合在嵌入式系統中運作
![Page 23: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/23.jpg)
NETLAB
lwIP簡介
嵌入式系統開發板
lwIP (TCP/IP Protocol)
uC-OS II
Upper Layer Protocol (ULP)
![Page 24: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/24.jpg)
NETLAB
lwIP特性
IP including packet forwarding over multiple network interfaces
ICMP for network maintenance and debugging
UDP for datagram data TCP with congestion control, RTT estimation
and fast recovery/fast retransmit Specialized no-copy API for enhanced
performance Optional Berkeley socket API
![Page 25: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/25.jpg)
NETLAB
lwIP特性
lwIP將所有與硬體、OS 、 Compiler相關的部分獨立出來放置在 /src/arch下
修改這一些相關檔案將 lwIP移植到 uC/OS-II上
![Page 26: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/26.jpg)
NETLAB
Application/ Management modelApplication/ Management model
Protocol Stack
RTP, RTCPRTP, RTCP
UDPUDP
IPIP
MACMAC
PhysicalPhysical
![Page 27: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/27.jpg)
NETLAB
TCP/IP與行程間的溝通
![Page 28: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/28.jpg)
NETLAB
SOCKET APIbindlistenconnectacceptrecvsendwriteclose
SOCKET APIbindlistenconnectacceptrecvsendwriteclose
lwip_APIlwip_bindlwip_listenlwip_connectlwip_acceptlwip_recvlwip_sendlwip_writelwip_close
lwip_APIlwip_bindlwip_listenlwip_connectlwip_acceptlwip_recvlwip_sendlwip_writelwip_close
netconn_APInetconn_bindnetconn_listennetconn_connectnetconn_acceptnetconn_recvnetconn_sendnetconn_writenetconn_close
netconn_APInetconn_bindnetconn_listennetconn_connectnetconn_acceptnetconn_recvnetconn_sendnetconn_writenetconn_close
![Page 29: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/29.jpg)
NETLAB
applicationapplication
socket APIsocket API
lwip_bind …lwip_bind …
netconn_bind …netconn_bind …
driverdriver
recv_buf_datarecv_buf_data
ethernetif_inputethernetif_input
low_level_inpitlow_level_inpit
ip_inputip_input
tcp_inputtcp_input
tcp_processtcp_process
tcpip_threadtcpip_thread
api_msg_input api_msg_input
do_bind …do_bind …
TASK 1 TASK 2 TASK 3
![Page 30: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/30.jpg)
NETLAB
TASK 1(application 1)
TASK 1(application 1) TASK 2
(data input)
TASK 2(data input)
TASK 3(tcpip_thread)
TASK 3(tcpip_thread)
mboxmboxrecvmbox acceptmbox
Single Application
![Page 31: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/31.jpg)
NETLAB
TASK 2(data input)
TASK 2(data input)
TASK 3(tcpip_thread)
TASK 3(tcpip_thread)
mboxmbox
TASK 1(application 1)
TASK 1(application 1)
recvmbox acceptmbox
TASK N(application N)
TASK N(application N)
recvmbox acceptmbox
Multi Application
![Page 32: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/32.jpg)
NETLAB
API types
TYPE 1 BIND, LISTEN, CLOSE
TYPE 2 CONNECT
TYPE 3 SEND. WRITE
TYPE 4 ACCEPT, RECV
![Page 33: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/33.jpg)
NETLAB
TASK 1TASK 1
TYPE 1
TASK 2TASK 2mboxmbox
1 2
34
msg->type• API_MSG_BIND• API_MSG_LISTEN
![Page 34: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/34.jpg)
NETLAB
netconn_bindnetconn_bind do_binddo_bind
API_MSG_BIND
netconn_bind
mboxmboxapi_msg_post sys_mbox_fetch
sys_mbox_postsys_mbox_fetch
tcp_bind
![Page 35: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/35.jpg)
NETLAB
netconn_listennetconn_listen do_listendo_listen
API_MSG_LISTEN
netconn_listen
mboxmboxapi_msg_post sys_mbox_fetch
sys_mbox_postsys_mbox_fetch
pcb->accpet = accept_function
![Page 36: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/36.jpg)
NETLAB
netconn_closenetconn_close do_closedo_close
API_MSG_CLOSE
netconn_close
mboxmboxapi_msg_post sys_mbox_fetch
sys_mbox_postsys_mbox_fetch
tcp_close
![Page 37: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/37.jpg)
NETLAB
TYPE 2
TASK 1TASK 1
TASK 2TASK 2
mboxmbox
1
2msg->type• API_MSG_CONNECT
TASK 3TASK 3
34
![Page 38: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/38.jpg)
NETLAB
netconn_connectnetconn_connect
do_connectdo_connect
pcb->connected = do_connectedpcb->state = SYN_SENTtcp_enqueue()tcp_output()
netconn_connect
tcp_input() , tcp_process()switch case: SYNSENTpcb->connected
do_connecteddo_connected
mboxmboxapi_msg_post
sys_mbox_fetch
sys_mbox_post
sys_mbox_fetch
![Page 39: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/39.jpg)
NETLAB
TYPE 3
TASK 1TASK 1 mboxmbox
1 2
34
msg->type• API_MSG_SEND• API_MSG_WRITE
TASK 2TASK 2
udp_outputor
tcp_write
![Page 40: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/40.jpg)
NETLAB
netconn_sendnetconn_send do_senddo_send
API_MSG_SEND
netconn_send
mboxmboxapi_msg_post sys_mbox_fetch
sys_mbox_postsys_mbox_fetch
udp_output
![Page 41: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/41.jpg)
NETLAB
netconn_writenetconn_write do_writedo_write
API_MSG_WRITE
netconn_write
mboxmboxapi_msg_post sys_mbox_fetch
sys_mbox_postsys_mbox_fetch
tcp_enqueuetcp_output
![Page 42: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/42.jpg)
NETLAB
TYPE 4
TASK 3TASK 3TASK 1TASK 112 acceptmbox
orrecvmbox
acceptmbox orrecvmbox
TASK 2TASK 2mboxmbox
3 4
56
msg->type• API_MSG_RECV
![Page 43: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/43.jpg)
NETLAB
netconn_accept
in tcp_processpcb->accept
accept_functionaccept_functionnetconn_acceptnetconn_accept acceptmboxsys_mbox_postsys_mbox_fetch
![Page 44: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/44.jpg)
NETLAB
netconn_recv
recv_tcprecv_tcpnetconn_recvnetconn_recv recvmbox
do_recvdo_recvmboxmbox
API_MSG_RECV
in tcp_input()pcb->recv
sys_mbox_postsys_mbox_fetch
api_msg_post sys_mbox_fetch
sys_mbox_postsys_mbox_fetch
Let the stack know that we have taken the data
![Page 45: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/45.jpg)
NETLAB
Server
netconn_new
netconn_bind
netconn_listen
netconn_accept
netconn_recv
netconn_write
netconn_close
do_bind
do_listen
accept_function
recv_tcp
do_write
do_recv
do_close
mbox
acceptmbox
recvmbox
mbox
mbox
mbox
mbox
TASK 1 TASK 2 TASK 3
![Page 46: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/46.jpg)
NETLAB
Client
netconn_new
netconn_bind
netconn_connect
netconn_recv
netconn_write
netconn_close
do_bind
do_connect
do_connected
recv_tcp
do_write
do_recv
do_close
mbox
recvmbox
mbox
mbox
mbox
mbox
TASK 1 TASK 2 TASK 3
![Page 47: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/47.jpg)
An Implementation of RDMA
Student: Chia-Tai TsaiAdviser: Prof. Rong-Hong Jan
![Page 48: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/48.jpg)
NETLAB
Introduction 1/3
Network bandwidth bottlenecks Network hardware Network Protocol Performance End station performance
• CPU• The I/O bottlenecks
– Interrupts– TCP/IP checksum– Copies
![Page 49: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/49.jpg)
NETLAB
DMA
![Page 50: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/50.jpg)
NETLAB
RDMA
![Page 51: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/51.jpg)
NETLAB
Protocol Stack
![Page 52: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/52.jpg)
NETLAB
Experimental Model
![Page 53: A survey of uC/OS & lwIP 蔡嘉泰 tai@cis.nctu.edu.tw](https://reader036.vdocuments.pub/reader036/viewer/2022081506/56649f4f5503460f94c70668/html5/thumbnails/53.jpg)
Click to edit company slogan .