Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

RTOS on ARM cortex-M platform -draft

997 visualizaciones

Publicado el

Introduce how to make a RTOS by yourself on ARM cortex-M platform.

Publicado en: Ingeniería
  • Inicia sesión para ver los comentarios

RTOS on ARM cortex-M platform -draft

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

×