Lifelog/RC

Moka - 시스템 아키텍처

sunshout1 2026. 6. 14. 17:11
반응형

레이어 다이어그램

┌─────────────────────────────────────────────────────────┐
│  Application / RC services (rc/)                      │
│  - Input decode (RC UART / WiFi UDP)                    │
│  - Control (PID, mix, slew limit)                     │
│  - Safety supervisor (timeout, estop)                 │
├─────────────────────────────────────────────────────────┤
│  Kernel (kernel/)                                       │
│  - Scheduler (cooperative → preemptive)               │
│  - Syscall-less API: direct driver calls initially    │
│  - Timer, IRQ, MMU, memory allocator (simple bump)    │
├─────────────────────────────────────────────────────────┤
│  Drivers (drivers/)                                     │
│  - GPIO, mailbox (GPU), UART, Timer, PWM, I2C         │
│  - (v2) SDIO WiFi                                       │
├─────────────────────────────────────────────────────────┤
│  Bootloader (boot/)                                     │
│  - Stage 1: load kernel @ 0x8000, optional DTB         │
│  - Early UART, SD (EMMC/SDHOST) minimal read            │
├─────────────────────────────────────────────────────────┤
│  GPU firmware (binary on SD, not in repo initially)     │
│  bootcode.bin → start.elf → config.txt → kernel.img     │
└─────────────────────────────────────────────────────────┘

부팅 시퀀스 (목표)

sequenceDiagram
    participant SD as SD card
    participant GPU as VideoCore
    participant S1 as Moka Stage1
    participant K as Kernel
    participant RC as RC stack

    SD->>GPU: bootcode.bin / start.elf
    GPU->>SD: reads config.txt, kernel.img
    GPU->>S1: jumps to ARM (0x8000 typical)
    S1->>S1: UART init, parse image header
    S1->>K: load segments, zero BSS, setup stacks
    K->>K: MMU on, IRQ, timers
    K->>RC: rc_init(), main loop tasks

v1 현실적 접근: GPU chain은 유지하고 kernel.img 자리에 Moka Stage1+Kernel 패키지를 두거나, config.txt의 kernel= 항목으로 Moka 이미지 지정.

메모리 맵 (초안, ARM Linux 관례 참고)

영역물리 주소 (예)용도

GPU reserved 0x00000000– Framebuffer/mailbox (v1 미사용 가능)
ARM RAM 0x00008000– Stage1 / 커널 로드 (전통적 0x8000)
Kernel text/data 0x00100000– 링커 스크립트로 확정
Kernel heap growth simple allocator
Stack(s) high RAM IRQ/FIQ/ABT/UND/SVC + per-task

config.txt 예시 방향:

arm_freq=1000
kernel=kernel.img
disable_commandline_tags=0

정확한 주소는 Stage1 링커 스크립트와 GPU config.txt (kernel_old, arm_mem) 조합으로 확정.

실행 모델

Phase A — 슈퍼루프 (M0)

  • kernel_main() → rc_tick() 폴링, 타이머 IRQ에서 플래그만 설정.
  • 구현 빠름, 디버그 쉬움.

Phase B — 협력式 스케줄러 (M1)

  • 타이머 슬라이스로 rc_task, telemetry_task, idle 교대.
  • 스택 per-task, yield() 명시.

Phase C — 선점 (M2, 선택)

  • RC 제어는 최고 우선순위; WiFi 스택은 낮은 우선순위.
  • ARM1176에 짧은 크리티컬 섹션만.

모듈 경계

모듈 입력 출력 의존
boot/stage1 SD 블록, partition RAM에 kernel UART, SD driver stub
kernel/platform Device tree or hardcoded tables IRQ, clocks mailbox
drivers/pwm duty, freq GPIO ALT clock, GPIO
rc/controller setpoint, feedback throttle, steer pwm, time
rc/input bytes (UART/WiFi) normalized channels parser

통신 아키텍처 (v1 vs v2)

경로 v1 v2
디버그 UART0 115200 동일
조종 USB-UART CP2102 또는 PWM RC 수신기 → GPIO WiFi UDP (port fixed)
텔레메트리 UART printf CSV BLE notify (선택)

신뢰성

  • Watchdog: BCM2835 PM watchdog 또는 외부 IC; RC 슈퍼바이저가 주기적 킥.
  • Failsafe: 입력 500 ms 미수신 → throttle=0, steer=center, MOTOR_EN deassert.
  • Brownout: 소프트웨어 ADC 없으면 BEC UVLO 하드웨어에 의존.

보안 (간략)

  • v1: 네트워크 스택 없거나 UDP 고정 키 없음 → 실험실 전용
  • v2: 페어링, HMAC, rate limit
728x90
반응형