rtos ameba

73
RTOS - AMEBA Neo Jou

Upload: jou-neo

Post on 15-Apr-2017

357 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: Rtos ameba

RTOS - AMEBA Neo Jou

Page 2: Rtos ameba

IOT 技術同好會

Search : Ameba / IoT

Page 3: Rtos ameba

AMEBA

Page 4: Rtos ameba

ARM ARCH

Page 5: Rtos ameba

ARM

Page 6: Rtos ameba

ARM CORTEX

Page 7: Rtos ameba

AMEBA CPU

CPU 處理速度

cortem-M3

1.25 DMIPS/MHz

Ameba - 166MHz

Page 8: Rtos ameba

DAP – DEBUG ACCESS PORT

Ameba firmware download

UART/Serial to USB

JTAG/SWD debug

Ameba

Page 9: Rtos ameba

CMSIS-DAP

USB mbed disk / USB-Serial / Debug

Page 10: Rtos ameba

CMSIS-DAP SETUP

Usb 轉 serial

Driver : ARM mbed serial driver :

https://developer.mbed.org/handbook/Windows-serial-configuration

Usb disk – firmware CMSIS-DAP

DAP Link : https://github.com/mbedmicro/DAPLink

OpenOCD + CMSIS-DAP

Page 11: Rtos ameba

AMEBA - PROS

相對於⼀般開發板

不⽤另外買 JTAG , 有 ARM CMSIS-DAP debug

有 wifi

Clock ⾼ , 速度快

省電

Page 12: Rtos ameba

空氣盒⼦

Page 13: Rtos ameba

AMEBA

Page 14: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – Arduino / Eclipse – open source

Micro Kernel

memory

schedule

IPC

Future

Page 15: Rtos ameba

WHY RTOS

Linux v.s. RTOS

Memory

Jitter / response time – audio

Real time

No-OS v.s. RTOS

擴充⽀援 / 多⼯

Page 16: Rtos ameba

即時 - REAL TIME

deadline : hard / soft

Linux : RTOS ?

kernel 非搶佔, user 權限⾼也無法搶佔

時間計算/限制機制

改良

重改 linux - PREEMPT_RT

dual kernel - 替換底層 - Xenomai ( 底層⽤ Nucleus )

Page 17: Rtos ameba

多⼯-1

真的需要多⼯?

* https://github.com/liuxuming/trochili

Page 18: Rtos ameba

ARDUINO

setup()

loop()

Page 19: Rtos ameba

多⼯-2

ISR

* https://github.com/liuxuming/trochili

Page 20: Rtos ameba

ARM MBED TICKER

https://developer.mbed.org/handbook/Ticker

Page 21: Rtos ameba

TIMER CONS

HW timer 有限

SW timer : 延遲

No Preemptive / context switch ?

starvation

Page 22: Rtos ameba

多⼯ - 3

multi-tasks

Page 23: Rtos ameba

多⼯ - 3

⼯作 Task 程式執⾏最⼩單位?

Process =>Thread

Unix -> Mach

第⼀代 micro kernel

Mac OSX

Page 24: Rtos ameba

THREAD

Page 25: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – arduino / eclipse

Micro Kernel

memory

schedule

IPC

Future

Page 26: Rtos ameba

WHY ARDUINO

• Prototype -> 量產 / ardupilot

Page 27: Rtos ameba

ARDUINO

http://njiot.blogspot.tw/2016/03/arduino-ameba-100-rtos-1-5100.html

板⼦管理員

Page 28: Rtos ameba

ARDUINO

http://njiot.blogspot.tw/2016/03/arduino-ameba-100-rtos-1-5100.html

板卡選擇

Page 29: Rtos ameba

ARDUINO 設定檔C:\Users\neo_jou\AppData\Local\Arduino15\packages\njiot\hardware\ameba\1.2.1

Platform.txt

Gcc

Compiler / link options

Page 30: Rtos ameba

ARDUINO

Page 31: Rtos ameba

ECLIPSE + QEMU

http://njiot.blogspot.tw/2016/07/qemu-arm-gnu-arm-eclipse.html

Page 32: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – arduino / eclipse

Micro Kernel

memory

schedule

IPC

Future

Page 33: Rtos ameba

微核⼼

Memory

Thread

IPC

Page 34: Rtos ameba

JIM HUANG / JSERV

Embedded system

Page 35: Rtos ameba

RTOS

https://github.com/neojou/mini-arm-os/tree/master/07-Threads/Threads

Page 36: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – arduino / eclipse

Micro Kernel

memory

schedule

IPC

Future

Page 37: Rtos ameba

TEXT / DATA

* Howard - HyperC OS * Linker script - http://njiot.blogspot.tw/2016/03/arduino-ameba-100-textdatabssheapstack.html

Page 38: Rtos ameba

MEMORY

C: malloc / free

sbrk()

linker script

Page 39: Rtos ameba

MALLOC

Page 40: Rtos ameba

RLX8195A

C:\Users\neo_jou\AppData\Local\Arduino15\packages\njiot\hardware\ameba\1.2.1\variants\arduino_ameba\linker_scripts\gcc

Page 41: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – arduino / eclipse

Micro Kernel

memory

schedule

IPC

Future

Page 42: Rtos ameba

REGISTERS

Page 43: Rtos ameba

AAPCS

Procedure Call Standard for ARM Architecture

Page 44: Rtos ameba

VECTOR TABLE

Page 45: Rtos ameba

HANDLER

privileged

thread / handler

handler only have privileged mode

Page 46: Rtos ameba

AUTO PUSH / POP

Thread mode -> Handler mode

Page 47: Rtos ameba

EXC_RETURN

Exception : thread -> handler

LR : EXC_RETURN

Page 48: Rtos ameba

ARDUINO SCHEDULER

和 mini-arm-os / RTX 很像

 比 timer 優點 :

TCB : Task control block

各⾃有 stack

Page 49: Rtos ameba

ARDUINO SCHEDULR

NUM_REGS=10, https://github.com/arduino-libraries/Scheduler/blob/master/src/Scheduler.cpp

Page 50: Rtos ameba

SWITCH- SYSTICK

Page 51: Rtos ameba

SWITCH - PENDSVC

Page 52: Rtos ameba

TODO

Thread Priority

Scheduling

Round robin

Page 53: Rtos ameba

優先權錯逆

priority inversion

realtime - deadline

Page 54: Rtos ameba

優先權錯逆

⽕星探測計畫

http://wiki.csie.ncku.edu.tw/embedded/priority-inversion-on-Mars.pdf

Page 55: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – arduino / eclipse

Micro Kernel

memory

schedule

IPC

Future

Page 56: Rtos ameba

IPC

Inter Process Communication

L4 kernel - 第⼆代微核⼼重點

f9-kernel: http://wiki.csie.ncku.edu.tw/embedded/f9-kernel

Page 57: Rtos ameba

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

Page 58: Rtos ameba

RTX ON AMEBA

Page 59: Rtos ameba

RTX

Keil ARM

CMSIS API

IPC

Page 60: Rtos ameba

CMSIS-RTOS

Cortex Microcontroller Software Interface Standard

Page 61: Rtos ameba

SHARE MEMORY

No thread safe

flag

interrupt write status

thread polling

Page 62: Rtos ameba

CRITICAL SECTION

atomic

spinlock / mutex / semaphore 差異?

Page 63: Rtos ameba

IPC -⼩訊息傳遞

signal events

mutex

semaphore

Page 64: Rtos ameba

IPC - ⼤訊息傳遞

message queue

mail queue

Page 65: Rtos ameba

TOPICS

⼯商時間

RTOS

Why RTOS

Environment – arduino / eclipse

Micro Kernel

memory

schedule

IPC

Future

Page 66: Rtos ameba

複雜

drivers

wifi, usb, …

network protocol

TCP/IP

SSL / TLS

MQTT / HTTP

….

Page 67: Rtos ameba

MBED OS

LoRa : https://docs.mbed.com/docs/lora-with-mbed/en/latest/intro-to-lora/

Page 68: Rtos ameba

POWER

Tickless kernel

Busy waiting 耗電

WFI / WFE

中斷完成時直接休眠, 不回 Thread, 省下 stack push/pop

Systick or external sleep clock (32K)

Page 69: Rtos ameba

ZEPHYR 和風

https://www.zephyrproject.org/doc/subsystems/power_management.html

Page 70: Rtos ameba

安全

資料安全

資訊隱藏與封裝 (C++)

資訊最⼩化公開原則

各⾃ stack

系統安全 : security boot

網路安全 : SSL/TLS

Page 71: Rtos ameba

安全- 硬體設計

Ameba Cortex-M3 :

MPU -> mbed uvisor

hardware crypto engine

加解密, 簽章 : AES / SHA-2

TrustZone : v8m : SAU

stack limit

Page 72: Rtos ameba

FUTURE

Benchmark

ARM mbed / Arduino

CMSIS++ / mbed minar

NUTTX : ardupilot / cortex-m4

Zephyr : Linux ⼩弟

dynamic linking / module loading

hypervisor

Page 73: Rtos ameba

THANK YOU

Q & A