IPC Fundamentals

Lab 1: IPC Fundamentals (Ping, Logging, Sensor Data)

Part 4 - IPC & Event Bus


1. ภาพรวมของ Lab

Why? - ทำไมต้องเรียนรู้เรื่องนี้

  • Multi-Core Communication: ระบบ Embedded สมัยใหม่ใช้หลาย Core ทำงานร่วมกัน ต้องมีกลไกสื่อสารระหว่าง Core ที่เชื่อถือได้

  • IPC (Inter-Processor Communication): เทคนิคพื้นฐานที่ใช้ในระบบ Industrial, Automotive, IoT ทุกประเภท

  • Remote Logging: ไม่ใช่ทุก Core จะมี UART console ต้องส่ง log ผ่าน IPC เพื่อ debug และ diagnostics

  • Distributed Sensing: ในระบบ Multi-Core sensor อยู่คนละ Core กับ UI ต้องส่งข้อมูลผ่าน IPC

  • Thread Safety: เรียนรู้ pattern ที่ถูกต้องสำหรับการอัปเดต UI จาก IPC callback

What? - จะได้เรียนรู้อะไร

  1. IPC Pipe Architecture: โครงสร้างการสื่อสารระหว่าง CM33-NS กับ CM55

  2. Ping-Pong Protocol: ส่ง PING → รับ PONG วัดเวลา Round-Trip

  3. Remote Logging: CM55 ส่ง log ผ่าน IPC → CM33 พิมพ์ออก UART พร้อมระบบ Log Levels

  4. Sensor Request-Response: CM55 ร้องขอ → CM33 อ่าน sensor → ส่งกลับผ่าน IPC

  5. Flag-Based Pattern: วิธีอัปเดต LVGL UI อย่างปลอดภัยจาก IPC callback

How? - จะทำอย่างไร

Lab นี้แบ่งเป็น 3 ส่วน:

  • Part A: สร้าง Ping-Pong ทดสอบ IPC พื้นฐาน วัด Round-Trip Time

  • Part B: สร้างระบบ Logging ส่ง log จาก CM55 ไป CM33 console

  • Part C: ส่งข้อมูล Sensor (IMU/ADC) ผ่าน IPC แสดงผลบน Chart


2. หลักการทางเทคนิค

2.1 สถาปัตยกรรม Multi-Core ของ PSoC Edge E84

2.2 ทำไม CM55 ถึง printf() ไม่ได้?

2.3 IPC Message Structure

2.4 Flag-Based Pattern (Thread Safety) - CRITICAL

ตัวอย่าง Pattern:

2.5 Sensor Data Flow Architecture


Part A: IPC Ping-Pong (Ex1)

IPC Commands ที่ใช้

Command
Value
ทิศทาง
คำอธิบาย

IPC_CMD_PING

0x42

CM55 → CM33

ส่งสัญญาณ Ping

IPC_CMD_PONG

0x43

CM33 → CM55

CM33 ตอบกลับอัตโนมัติ

Ping-Pong Flow

Step-by-Step Implementation

Step 1: ตั้งค่า Example Selector

Step 2: Include Headers

Step 3: ประกาศ Global Variables

Step 4: IPC Callback Function

Step 5: LVGL Timer Callback (UI Update)

Step 6: Button Event Callback

Step 7: สร้าง UI Layout (Main Entry Point)


Part B: IPC Logging System (Ex2)

Log Level System

IPC Log Command Reference

Command
Value
ทิศทาง
คำอธิบาย

IPC_CMD_LOG

0x90

CM55 → CM33

Log ทั่วไป (ไม่ระบุ level)

IPC_CMD_LOG_LEVEL

0x91

CM55 → CM33

ตั้ง log level filter

IPC_CMD_LOG_ERROR

0x92

CM55 → CM33

Error level log

IPC_CMD_LOG_WARN

0x93

CM55 → CM33

Warning level log

IPC_CMD_LOG_INFO

0x94

CM55 → CM33

Info level log

IPC_CMD_LOG_DEBUG

0x95

CM55 → CM33

Debug level log

Log Macros (จาก cm55_ipc_pipe.h)

Step-by-Step Implementation

Step 1: ประกาศ Constants และ Variables

Step 2: Log Management Functions

Step 3: Send Log via IPC + Update Local Display

Step 4: Event Handlers

Step 5: สร้าง UI Layout (Main Entry Point)


Part C: IPC Sensor Data (Ex3)

IPC Sensor Data Structures

IMU Data (จาก ipc_shared.h)

ADC Data (จาก ipc_shared.h)

การ Pack ข้อมูลใน IPC Message

IPC Sensor Commands

Command
Value
ทิศทาง
คำอธิบาย

IPC_CMD_SENSOR_REQ

0xA0

CM55 → CM33

ร้องขอข้อมูล sensor

IPC_CMD_SENSOR_DATA

0xA1

CM33 → CM55

ส่งข้อมูล sensor กลับ

IPC_CMD_IMU_DATA

0xA2

CM33 → CM55

ข้อมูล IMU โดยเฉพาะ

IPC_CMD_ADC_DATA

0xA3

CM33 → CM55

ข้อมูล ADC โดยเฉพาะ

Request-Response Sequence

IPC Buffer Warning (CRITICAL)

PSoC Edge IPC Pipe ใช้ rx_buffer เดียว ถ้าส่ง request ติดกันเร็วเกินไป ข้อมูลจะถูก overwrite วิธีแก้: 1) ใช้ timer คนละตัวที่ offset กัน (ใช้ใน Lab นี้) 2) ให้ CM33 ส่ง IMU+ADC รวมกัน 3) ใช้ FreeRTOS Queue

Step-by-Step Implementation

Step 1: ประกาศ Variables และ Structures

Step 2: IPC Callback (รับข้อมูล Sensor)

Step 3: Sensor Request Timers

Step 4: UI Update Timer (อ่าน flag + อัปเดต Chart)

Step 5: สร้าง UI Layout (Main Entry Point)


3. แบบฝึกหัด

Exercise 1: Ping Statistics (Min/Max/Avg RTT)

เพิ่มการวิเคราะห์สถิติ Ping-Pong:

  • RTT: min / max / average

  • Packet loss rate (%)

  • แสดงผลบน Label เพิ่มเติม

Hints:

Exercise 2: Data Rate Monitor (Sensor)

เพิ่มการวัดอัตราข้อมูล sensor:

  • แยก IMU sps กับ ADC sps

  • เปรียบเทียบ actual rate กับ target rate (10 Hz)

  • แสดงเป็น % ของ target

  • เปลี่ยนสีเตือนเมื่อ rate ต่ำกว่า 80%

Hints:

Exercise 3: Color-Coded Log Viewer

สร้าง log viewer ที่แสดงแต่ละ level ด้วยสีต่างกัน:

  • ERROR: สีแดง, WARN: สีเหลือง, INFO: สีเขียว, DEBUG: สีเทา

  • ปุ่ม "Clear" ล้าง log ทั้งหมด

  • จำนวน log แต่ละ level (E:3 W:5 I:10 D:2)

Hints:

LVGL TextArea ไม่รองรับหลายสี ต้องใช้ approach อื่น:


4. Quick Reference / Cheat Sheet

Application ในงาน Industrial

Use Case
คำอธิบาย

System Health Monitor

วัด latency ระหว่าง Core ตรวจจับ hang

Watchdog Ping

Core A ping Core B ทุก 1 วินาที ถ้าไม่ตอบ → reset

Production Diagnostics

บันทึก error log สำหรับวิเคราะห์ปัญหาในโรงงาน

Field Service

ช่างซ่อมอ่าน log จากหน้าจอเครื่องโดยไม่ต้องต่อ PC

Condition Monitoring

วัดการสั่นสะเทือนของเครื่องจักรเพื่อพยากรณ์การบำรุงรักษา

Process Control

แสดงค่า sensor ของกระบวนการผลิตแบบ real-time

Remote Monitoring

ส่ง log ผ่าน WiFi/BLE ไปยัง cloud dashboard

Quality Inspection

ตรวจจับค่าผิดปกติในสายการผลิต


5. References

  • LVGL Docs: https://docs.lvgl.io/master/

  • PSoC Edge E84: Infineon documentation

  • ModusToolbox: https://www.infineon.com/modustoolbox

  • LVGL Chart Widget: https://docs.lvgl.io/master/widgets/chart.html

  • LVGL TextArea Widget: https://docs.lvgl.io/master/widgets/textarea.html

Last updated

Was this helpful?