Upload
jou-neo
View
559
Download
15
Embed Size (px)
Citation preview
RTOS - CM Neo Jou
IOT 技術同好會
Search : Ameba / IoT
AMEBA
CMSIS-DAP
USB mbed disk / USB-Serial / Debug
TOPICS
Cortex-M
RTOS
OS / Realtime
HW design for RTOS
Micro Kernel
memory
schedule
IPC
Future
ARM ARCH
ARM
ARM CORTEX
TOPICS
Cortex-M
RTOS
OS / Realtime
HW design for RTOS
Micro Kernel
memory
schedule
IPC
Future
OS -> OR
運籌學
資源 => 有效運⽤
兵⼒/糧草/時間...
空間
Memory
DOS - 640K
arduino : Atmega328 :
2K SRAM / 32K flash
Ameba : 512K internal
時間
CPU 處理速度
cortem-M3/M4
1.25 DMIPS/MHz
Ameba - 166MHz
時空轉換
compiler toolchain 參數選擇 -Osize / -Otime
空間換取時間
e.g. loop unroll, 查表 : switch , …
時間換取空間
e.g. loop without unroll, compression
資源
除了空間時間外, 還有什麼資源需要管理?
Power consumption -> Zephyr
容易 porting
CMSIS
middleware (USB / TCPIP / .. )
….
TRADE OFF
複雜的動態系統
external flash -> external RAM -> internal RAM -> cache ...
task priority / critical path
power consumption
…
TOPICS
Cortex-M
RTOS
OS / Realtime
HW design for RTOS
Micro Kernel
memory
schedule
IPC
即時 - REAL TIME
deadline => priority -> renice -> preemptive
Linux : RTOS ?
kernel 非搶佔, user 權限⾼也無法搶佔
時間計算/限制機制
改良
重改 linux - PREEMPT_RT
dual kernel - 替換底層 - Xenomai ( 底層⽤ Nucleus )
TOPICS
Cortex-M
RTOS
OS / Realtime
HW design for RTOS performance
Micro Kernel
memory
schedule
IPC
Future
HW FOR RTOS
MSP / PSP
LR - branch (bx lr), EXC_RETURN
auto push/pop stack
privileged / handler - thread
REGISTERS
AAPCS
Procedure Call Standard for ARM Architecture
HANDLER
privileged
thread / handler
handler only have privileged mode
EXC_RETURN
Exception : thread -> handler
LR : EXC_RETURN
TOPICS
Cortex-M
RTOS
OS / Realtime
HW design for RTOS performance
Micro Kernel
memory
schedule
IPC
Future
微核⼼
Memory
Thread
IPC
TEXT / DATA
* Howard - HyperC OS * Linker script - http://njiot.blogspot.tw/2016/03/arduino-ameba-100-textdatabssheapstack.html
動態管理
C: malloc / free
sbrk()
linker script
動態管理
Windows:
VirtualAlloc / HeapAlloc
非分⾴ / 分⾴
Linux:
vmalloc / kmalloc :
GFP_ATOMIC / GFP_KERNEL
動態管理
cortex-M : no MMU , no virtual address
經濟 <-> 技術, RAM 價格曲線
MMU overhead / die size cost
fragment / chunk / page / utilization
CACHE
Ameba : cortex-m3 , no cache
instruction / data
barrier : ISB , DSB, DMB
TOPICS
Cortex-M
RTOS
OS / Realtime
Micro Kernel
memory
schedule
IPC
ARDUINO
setup()
loop()
無線程排程-ISR
8-bit / 16-bit programming
x86
BIOS/DOS INT
VECTOR TABLE
線程排程 - TIMER - 1
One shot / period
latency : 8 cycles
auto push pop by HW
Pros : easy, quick, less overhead
TICKER SCHEDULER
ESP 8266 - yield() do back ground functions ; https://github.com/Toshik/TickerScheduler
void setup(void) { … if (ts.add(0, 5000, task0, true)) { Serial.println("Tick task - task0 ok"); } if (ts.add(1, 2000, task1, true)) { Serial.println("Tick task - task1 ok"); } …. }
void task0(void) { Serial.println("Task0"); } …
void loop(void) { ts.update(); }
TICKER SCHEDULER
TICKER SCHEDULER
ESP 8266 - yield() do back ground functions ; https://github.com/Toshik/TickerScheduler
ARM MBED TICKER
https://developer.mbed.org/handbook/Ticker
TIMER CONS
HW timer 有限
SW timer : 延遲
preemptive
no reentrant
context switch ?
function execution -> starvation
多⼯ - 2
multi-tasks
多⼯ - 3
⼯作 Task 程式執⾏最⼩單位?
Process =>Thread
Unix -> Mach
第⼀代 micro kernel
Mac OSX
THREAD
ARDUINO SCHEDULER
zero, MKR1000 - cortex-m0+ , Due - cortex-m3
https://www.arduino.cc/en/Reference/Scheduler
ARDUINO SCHEDULER
為何需要多⼯
ARDUINO SCHEDULR
NUM_REGS=10, https://github.com/arduino-libraries/Scheduler/blob/master/src/Scheduler.cpp
ARDUINO SCHEDULR
NUM_REGS=10, https://github.com/arduino-libraries/Scheduler/blob/master/src/Scheduler.cpp
ARDUINO SCHEDULR
NUM_REGS=10, https://github.com/arduino-libraries/Scheduler/blob/master/src/Scheduler.cpp
ARDUINO SCHEDULER
和 mini-arm-os / RTX 很像
比 timer 優點 :
TCB : Task control block
各⾃有 stack
RTX
何時切換:
systick interrupt
CMSIS API
IPC
SWITCH- SYSTICK
SWITCH - PENDSVC
CMSIS-RTOS
Cortex Microcontroller Software Interface Standard
IDLE TASK
busy waiting 耗電
WFI / WFE
中斷完成時直接休眠, 不回 Thread, 省下 stack push/pop
TOPICS
Cortex-M
RTOS
OS / Realtime
Micro Kernel
memory
schedule
IPC
IPC - 1
Inter Process Communication
L4 kernel - 第⼆代微核⼼重點
f9-kernel: http://wiki.csie.ncku.edu.tw/embedded/f9-kernel
SHARE MEMORY
No thread safe
flag
interrupt write status
thread polling
CRITICAL SECTION
atomic
spinlock / mutex / semaphore 差異?
IPC -⼩訊息傳遞
signal events
mutex
semaphore
IPC - ⼤訊息傳遞
message queue
mail queue
L4
http://www.slideshare.net/microkerneldude/from-l3-to-sel4-what-have-we-learnt-in-20-years-l4
https://www.youtube.com/watch?v=RdoaFc5-1Rk
優先權錯逆
priority inversion
realtime - deadline
優先權錯逆
⽕星探測計畫
http://wiki.csie.ncku.edu.tw/embedded/priority-inversion-on-Mars.pdf
複雜
drivers
wifi, usb, …
network protocol
TCP/IP
SSL / TLS
MQTT / HTTP
….
MBED OS
LoRa : https://docs.mbed.com/docs/lora-with-mbed/en/latest/intro-to-lora/
WIFI 驅動程式-1
http://www.slideshare.net/simenli/adv-embedded
WIN WDI DRIVER
安全
資料安全
資訊隱藏與封裝 (C++)
資訊最⼩化公開原則
各⾃ stack
系統安全 : security boot
網路安全 : SSL/TLS
安全- 硬體設計
Ameba Cortex-M3 :
MPU -> mbed uvisor
hardware crypto engine
加解密, 簽章 : AES / SHA-2
TrustZone : v8m : SAU
stack limit
FUTURE
Benchmark
ARM mbed / Arduino
CMSIS++ / mbed minar
NUTTX : ardupilot / cortex-m4
Zephyr : Linux ⼩弟
dynamic linking / module loading
hypervisor