3e5cb5ce1294e50e5a0be0ca22d79b6244134a0f
Network-dat/Bluetooth-dat/BLE-dat/BLE-dat.md
| ... | ... | @@ -3,6 +3,9 @@ |
| 3 | 3 | |
| 4 | 4 | - [[data-storage-dat]] |
| 5 | 5 | |
| 6 | +- [[nimBLE-dat]] |
|
| 7 | + |
|
| 8 | + |
|
| 6 | 9 | |
| 7 | 10 | |
| 8 | 11 | ### Mobile Apps for BLE Debugging |
Network-dat/Bluetooth-dat/BLE-dat/nimBLE-dat/nimBLE-dat.md
| ... | ... | @@ -0,0 +1,34 @@ |
| 1 | + |
|
| 2 | +# nimBLE-dat |
|
| 3 | + |
|
| 4 | +NimBLE (often written as NimBLE, sometimes people shorten it to "NIM BLE") is an open-source Bluetooth Low Energy (BLE) stack originally developed by Apache Mynewt project. |
|
| 5 | + |
|
| 6 | +On ESP32, it’s provided as an alternative BLE library to the default bluedroid stack from Espressif. |
|
| 7 | + |
|
| 8 | +## Why NimBLE is used on ESP32 |
|
| 9 | + |
|
| 10 | +- Lower RAM & flash usage than Bluedroid (important if you’re doing Wi-Fi + BLE + other heavy tasks). |
|
| 11 | +- More stable and lightweight for applications that only need BLE (not full Bluetooth Classic). |
|
| 12 | +- Provides GATT server/client, advertising, scanning with a smaller footprint. |
|
| 13 | +- Integrated in ESP-IDF as NimBLE host, so you can choose either Bluedroid or NimBLE. |
|
| 14 | +- In Arduino-ESP32, there’s a library called NimBLE-Arduino (a wrapper around ESP-IDF NimBLE). |
|
| 15 | + |
|
| 16 | +## Example differences |
|
| 17 | + |
|
| 18 | +Bluedroid stack (default ESP32 BLE): |
|
| 19 | + |
|
| 20 | +- Feature-rich, supports more profiles. |
|
| 21 | +- Uses more memory (often ~100kB+ RAM). |
|
| 22 | +- Heavier API. |
|
| 23 | + |
|
| 24 | +NimBLE stack: |
|
| 25 | + |
|
| 26 | +- Lightweight (~50% less RAM/flash). |
|
| 27 | +- Faster connection / lower latency. |
|
| 28 | +- Still supports most BLE use cases (advertising, GATT server/client). |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + |
|
| 32 | +## ref |
|
| 33 | + |
|
| 34 | +- [[BLE-dat]] |
|
| ... | ... | \ No newline at end of file |
SDK-dat/ESP-SDK-dat/ESP32-SDK-dat/ESP32-SDK-dat.md
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | |
| 15 | 15 | - [[BLE-dat]] |
| 16 | 16 | |
| 17 | -- [[LVGL-dat]] |
|
| 17 | +- [[LVGL-dat]] - [[RTOS-dat]] |
|
| 18 | 18 | |
| 19 | 19 | - [[ESP-IDF-dat]] |
| 20 | 20 |
Tech-dat/RTOS-dat/2024-08-28-15-15-47.png
| ... | ... | Binary files /dev/null and b/Tech-dat/RTOS-dat/2024-08-28-15-15-47.png differ |
Tech-dat/RTOS-dat/RT-Thread-dat/2025-08-28-18-00-45.png
| ... | ... | Binary files /dev/null and b/Tech-dat/RTOS-dat/RT-Thread-dat/2025-08-28-18-00-45.png differ |
Tech-dat/RTOS-dat/RT-Thread-dat/RT-Thread-dat.md
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | + |
|
| 2 | +# RT-Thread-dat |
|
| 3 | + |
|
| 4 | +- [[allwinner-dat]] |
|
| 5 | + |
|
| 6 | +https://github.com/RT-Thread/rt-thread |
|
| 7 | + |
|
| 8 | +Nano 也得到了优秀国产物联网操作系统 RT-Thread 的官方支持,有rtt相关知识或经验,我们就可以对 Nano 进行快速高效的开发; |
|
| 9 | + |
|
| 10 | +RTT官方已经给出由 uestczyh222 所维护的 Nano固件详细的编译、烧录过程,搬运至此: |
|
| 11 | + |
|
| 12 | +https://github.com/RT-Thread/rt-thread/blob/master/bsp/allwinner_tina/README.md |
|
| 13 | + |
|
| 14 | +git clone https://github.com/RT-Thread/rt-thread.git |
|
| 15 | + |
|
| 16 | + |
|
| 17 | +project - [[wch-fly-dat]] |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + |
|
| 24 | +## ref |
|
| 25 | + |
|
| 26 | +- [[system-dat]] |
|
| ... | ... | \ No newline at end of file |
Tech-dat/RTOS-dat/RTOS-dat.md
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | + |
|
| 2 | +# RTOS-dat |
|
| 3 | + |
|
| 4 | +- [[peripherals-dat]] |
|
| 5 | + |
|
| 6 | +## realtime system |
|
| 7 | + |
|
| 8 | +- [[FreeRTOS-dat]] - [[Zephyr-dat]] - [[MongooseOS-dat]] |
|
| 9 | + |
|
| 10 | +- [[openthread-dat]] - [[micropython-dat]] |
|
| 11 | + |
|
| 12 | +- [[RT-Thread-dat]] |
|
| 13 | + |
|
| 14 | + |
|
| 15 | + |
|
| 16 | +## intelligent-system |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + |
|
| 20 | +## AC-DC |
|
| 21 | + |
|
| 22 | + |
|
| 23 | + |
|
| 24 | + |
|
| 25 | +## ref |
|
| 26 | + |
|
| 27 | +- [[tech-dat]] |
|
| ... | ... | \ No newline at end of file |
Tech-dat/RTOS-dat/cooperative-loop-dat/cooperative-loop-dat.md
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | + |
|
| 2 | +# cooperative-loop-dat |
|
| 3 | + |
|
| 4 | +``` |
|
| 5 | +void loop() { |
|
| 6 | + readELRS(); // non-blocking UART read |
|
| 7 | + updateMotors(); // update PWM |
|
| 8 | + if (millis() - lastAdc >= 1000) { |
|
| 9 | + readBattery(); |
|
| 10 | + lastAdc = millis(); |
|
| 11 | + } |
|
| 12 | + if (millis() - lastBle >= 2000) { |
|
| 13 | + updateBleAdvert(control.battery_mv); |
|
| 14 | + lastBle = millis(); |
|
| 15 | + } |
|
| 16 | +} |
|
| 17 | +``` |
|
| ... | ... | \ No newline at end of file |
Tech-dat/RTOS-dat/freertos-dat/freertos-dat.md
| ... | ... | @@ -0,0 +1,376 @@ |
| 1 | + |
|
| 2 | +# freertos-dat |
|
| 3 | + |
|
| 4 | + |
|
| 5 | +## freeRTOS debug |
|
| 6 | + |
|
| 7 | +Your sketch is written for ESP32 but you’re compiling it for ESP8266, and that’s why it’s failing. |
|
| 8 | + |
|
| 9 | +Why |
|
| 10 | + |
|
| 11 | +SemaphoreHandle_t, xSemaphoreCreateBinary(), xSemaphoreGive(), xSemaphoreTake(), and portMAX_DELAY are FreeRTOS API calls. |
|
| 12 | + |
|
| 13 | +ESP32 Arduino comes with FreeRTOS by default. |
|
| 14 | + |
|
| 15 | +ESP8266 Arduino does not use FreeRTOS — so those types and functions don’t exist unless you add a separate RTOS layer. |
|
| 16 | + |
|
| 17 | + |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + |
|
| 22 | +## ✅ When is it a Good Time to Use FreeRTOS? |
|
| 23 | + |
|
| 24 | +**FreeRTOS** is a real-time operating system designed for microcontrollers. It lets you split your application into multiple tasks that run seemingly in parallel. |
|
| 25 | + |
|
| 26 | +--- |
|
| 27 | + |
|
| 28 | +### 🧠 Use FreeRTOS When: |
|
| 29 | + |
|
| 30 | +#### 1. 🧵 **You Need to Run Multiple Tasks Concurrently** |
|
| 31 | +- Example: Reading sensor data, updating a display, and handling WiFi at the same time. |
|
| 32 | +- Each task can run independently using `xTaskCreate()`. |
|
| 33 | + |
|
| 34 | +#### 2. ⏱️ **You Require Real-Time Responsiveness** |
|
| 35 | +- Critical tasks (e.g., handling motor feedback or interrupts) can be given **higher priority**. |
|
| 36 | +- Guarantees **predictable response time**. |
|
| 37 | + |
|
| 38 | +#### 3. 🕓 **You Need Precise Timing or Scheduling** |
|
| 39 | +- Use `vTaskDelay()`, `xTimerCreate()`, etc., to run tasks at specific intervals. |
|
| 40 | +- Better than using `delay()` or busy-wait loops. |
|
| 41 | + |
|
| 42 | +#### 4. 📶 **You Have Asynchronous Events to Handle** |
|
| 43 | +- Great for UART, I2C, network communication, button presses, etc. |
|
| 44 | +- Use **queues**, **semaphores**, and **event groups** for clean async handling. |
|
| 45 | + |
|
| 46 | +#### 5. 🔄 **You Want to Structure a Large Project Cleanly** |
|
| 47 | +- Modular task-based design. |
|
| 48 | +- Easier to manage and debug than a giant `loop()` function. |
|
| 49 | + |
|
| 50 | +#### 6. 📦 **You're Using ESP32 or STM32 with Multiple Cores or Peripherals** |
|
| 51 | +- ESP32 has dual-core (PRO & APP cores). |
|
| 52 | +- FreeRTOS lets you **pin tasks to cores**, assign priority, and manage memory better. |
|
| 53 | + |
|
| 54 | +--- |
|
| 55 | + |
|
| 56 | +### 🧊 Not Always Necessary If: |
|
| 57 | +| Situation | Recommendation | |
|
| 58 | +|----------------------------------|---------------------------| |
|
| 59 | +| Simple blink or sensor reading | No need for FreeRTOS | |
|
| 60 | +| Single function, low resource | Use `loop()` and interrupts | |
|
| 61 | +| Ultra-low-power apps | May be better without RTOS | |
|
| 62 | + |
|
| 63 | +--- |
|
| 64 | + |
|
| 65 | +### ✅ Example: Good Use Case (ESP32 with Camera, Webserver, Sensors) |
|
| 66 | + |
|
| 67 | +- 📷 Task 1: Camera image capture |
|
| 68 | +- 🌐 Task 2: Web server and WiFi communication |
|
| 69 | +- 🌡️ Task 3: Sensor data read and logging |
|
| 70 | +- 🎯 Task 4: OTA update check |
|
| 71 | + |
|
| 72 | +All these tasks can run smoothly in parallel using FreeRTOS, each with its own stack and priority. |
|
| 73 | + |
|
| 74 | +--- |
|
| 75 | + |
|
| 76 | +### 🚀 Summary |
|
| 77 | + |
|
| 78 | +| Feature | Why FreeRTOS Helps | |
|
| 79 | +|--------------------------|-----------------------------------------| |
|
| 80 | +| Multitasking | Run multiple functions in parallel | |
|
| 81 | +| Real-time priority | Critical tasks get CPU first | |
|
| 82 | +| Precise scheduling | Timers, delays, and periodic execution | |
|
| 83 | +| Clean architecture | Organized, modular task-based design | |
|
| 84 | +| Event handling | Easy async using semaphores & queues | |
|
| 85 | + |
|
| 86 | +--- |
|
| 87 | + |
|
| 88 | +Let me know if you'd like a simple FreeRTOS project example! |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + |
|
| 93 | +## Use FreeRTOS primitives: |
|
| 94 | + |
|
| 95 | +Queue: for passing sensor/audio/display data between tasks |
|
| 96 | + |
|
| 97 | +Semaphore: to lock I2C bus or protect shared resources |
|
| 98 | + |
|
| 99 | +Timer: for periodic updates (e.g., sensor every 1s) |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + |
|
| 103 | +## 🧩 Inter-Task Communication |
|
| 104 | + |
|
| 105 | +✅ 1. SSD1306 (I2C) |
|
| 106 | + |
|
| 107 | +Use Adafruit SSD1306 or u8g2 with I2C. |
|
| 108 | + |
|
| 109 | +Share I2C bus with BMP280. |
|
| 110 | + |
|
| 111 | +Protect with mutex semaphore. |
|
| 112 | + |
|
| 113 | +xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
| 114 | +// update display |
|
| 115 | +xSemaphoreGive(i2c_mutex); |
|
| 116 | + |
|
| 117 | + |
|
| 118 | +✅ 2. BMP280 Sensor (I2C) |
|
| 119 | + |
|
| 120 | +Read temperature & pressure every 1–2 seconds. |
|
| 121 | + |
|
| 122 | +Send data to DisplayTask via queue. |
|
| 123 | + |
|
| 124 | +### Example Queues and Semaphores: |
|
| 125 | + |
|
| 126 | + QueueHandle_t sensor_data_queue; |
|
| 127 | + QueueHandle_t display_msg_queue; |
|
| 128 | + SemaphoreHandle_t i2c_mutex; |
|
| 129 | + |
|
| 130 | +### Sensor to Display Queue Message: |
|
| 131 | + |
|
| 132 | + typedef struct { |
|
| 133 | + float temperature; |
|
| 134 | + float pressure; |
|
| 135 | + } sensor_data_t |
|
| 136 | + |
|
| 137 | + |
|
| 138 | +## Pseudocode Overview |
|
| 139 | + |
|
| 140 | + void SensorTask(void *pvParams) { |
|
| 141 | + sensor_data_t data; |
|
| 142 | + while (1) { |
|
| 143 | + xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
| 144 | + data = read_bmp280(); |
|
| 145 | + xSemaphoreGive(i2c_mutex); |
|
| 146 | + |
|
| 147 | + xQueueSend(sensor_data_queue, &data, 0); |
|
| 148 | + vTaskDelay(pdMS_TO_TICKS(1000)); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + void DisplayTask(void *pvParams) { |
|
| 153 | + sensor_data_t data; |
|
| 154 | + while (1) { |
|
| 155 | + if (xQueueReceive(sensor_data_queue, &data, portMAX_DELAY)) { |
|
| 156 | + xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
| 157 | + update_display(data.temperature, data.pressure); |
|
| 158 | + xSemaphoreGive(i2c_mutex); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | +## cores |
|
| 166 | + |
|
| 167 | + xTaskCreatePinnedToCore(task1, "Task1", 2048, NULL, 1, NULL, 0); // Run on Core 0 |
|
| 168 | + xTaskCreatePinnedToCore(task2, "Task2", 2048, NULL, 1, NULL, 1); // Run on Core 1 |
|
| 169 | + |
|
| 170 | +Core 0: PRO_CPU (usually handles Wi-Fi, BT stack) |
|
| 171 | + |
|
| 172 | +Core 1: APP_CPU (often used for your application) |
|
| 173 | + |
|
| 174 | +## compare |
|
| 175 | + |
|
| 176 | +| Feature / RTOS | FreeRTOS | Zephyr RTOS | ThreadX (Azure RTOS) | Bare-Metal (No RTOS) | |
|
| 177 | +| ----------------------- | --------------------------------- | ---------------------------------------- | ---------------------------------- | ------------------------------ | |
|
| 178 | +| **License** | MIT (Permissive, Free) | Apache 2.0 (Permissive, Free) | Microsoft EULA (Free, but limited) | None | |
|
| 179 | +| **Footprint** | Very Small (<10 KB) | Medium (~50–100 KB) | Small (~10–20 KB) | Very Small | |
|
| 180 | +| **Real-Time** | Yes (preemptive, deterministic) | Yes (configurable RT, preemptive) | Yes (deterministic RTOS) | Depends on implementation | |
|
| 181 | +| **Ease of Use** | Simple API, easy learning curve | More complex, powerful config system | Easy API, good documentation | Full control but more effort | |
|
| 182 | +| **Hardware Support** | Very wide (ARM, RISC-V, etc.) | Very wide + device trees | Good (mainly ARM, RISC-V, x86) | Manual per-device work | |
|
| 183 | +| **Task Management** | Yes (tasks, priorities) | Yes (threads, priorities, SMP) | Yes (threads, priorities) | Manual state machine | |
|
| 184 | +| **Synchronization** | Semaphores, mutexes, queues | Semaphores, FIFOs, message queues | Semaphores, mutexes, event flags | Manual implementation | |
|
| 185 | +| **File System Support** | External (e.g., FatFs) | Native FS (e.g., LittleFS, FatFS) | With Azure FileX | Manual or third-party | |
|
| 186 | +| **Networking** | External (e.g., lwIP) | Native (TCP/IP stack, 6LoWPAN) | Azure NetX Duo (IPv4/IPv6) | External, complex to integrate | |
|
| 187 | +| **Power Management** | Basic, user-implemented | Advanced (built-in PM framework) | Good (some MCU-specific features) | Manual | |
|
| 188 | +| **Security/IoT** | AWS IoT support (via Amazon RTOS) | Secure boot, crypto, OTA, TLS | Azure IoT support, TLS, OTA | Manual, very limited | |
|
| 189 | +| **Trace & Debug** | Tools: SystemView, Tracealyzer | Zephyr logging & tracing | NetX, ThreadX tracing tools | Manual logging | |
|
| 190 | +| **Community Support** | Huge, mature ecosystem | Growing fast, backed by Linux Foundation | Good, backed by Microsoft | None (solo dev) | |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + |
|
| 195 | +## example 3 |
|
| 196 | + |
|
| 197 | +FreeRTOS Example Explanations |
|
| 198 | + |
|
| 199 | +✅ In short: |
|
| 200 | + |
|
| 201 | +- `Queue examples` → show how to pass data safely. |
|
| 202 | +- `Mutex/Notifications` → show synchronization methods. |
|
| 203 | +- `AnalogRead/Blink` → show multitasking with hardware. |
|
| 204 | +- `TaskStatus/Utilities` → show debugging and monitoring. |
|
| 205 | +- `Interrupts` → show ISR to task communication. |
|
| 206 | + |
|
| 207 | + |
|
| 208 | +### 1. AnalogRead_DigitalRead |
|
| 209 | +- Shows how to create tasks that perform **analog input** and **digital output**. |
|
| 210 | +- One task periodically reads an analog pin (ADC). |
|
| 211 | +- Another task toggles a digital pin (e.g., LED). |
|
| 212 | +- Demonstrates how multiple tasks run independently without blocking. |
|
| 213 | + |
|
| 214 | +--- |
|
| 215 | + |
|
| 216 | +### 2. ArrayQueue |
|
| 217 | +- Demonstrates using a **FreeRTOS queue** to pass an **array of data** between tasks. |
|
| 218 | +- For example: Task A fills an array → sends via queue → Task B receives and processes. |
|
| 219 | +- Useful for handling data buffers (sensor readings, UART packets). |
|
| 220 | + |
|
| 221 | +--- |
|
| 222 | + |
|
| 223 | +### 3. Assert |
|
| 224 | +- Shows how **configASSERT()** works in FreeRTOS. |
|
| 225 | +- Asserts help catch programming errors (e.g., stack overflow, bad API usage). |
|
| 226 | +- Example demonstrates failing conditions to show how assert is triggered. |
|
| 227 | + |
|
| 228 | +--- |
|
| 229 | + |
|
| 230 | +### 4. Blink_AnalogRead |
|
| 231 | +- Combines two common Arduino tasks: |
|
| 232 | + - One task **blinks an LED**. |
|
| 233 | + - Another task **reads analog input**. |
|
| 234 | +- Demonstrates that FreeRTOS allows both to run concurrently without delay() blocking. |
|
| 235 | + |
|
| 236 | +--- |
|
| 237 | + |
|
| 238 | +### 5. GoldilocksAnalogueTestSuite |
|
| 239 | +- Specific test suite for the **Goldilocks Analogue board** (Arduino-compatible with audio-grade ADC/DAC). |
|
| 240 | +- Shows how to use FreeRTOS tasks with more advanced ADC/DAC hardware. |
|
| 241 | +- Mostly relevant if you use that hardware. |
|
| 242 | + |
|
| 243 | +--- |
|
| 244 | + |
|
| 245 | +### 6. IntegerQueue |
|
| 246 | +- Demonstrates using a **queue of integers** between producer/consumer tasks. |
|
| 247 | +- Example: one task generates numbers, another task prints them. |
|
| 248 | +- Basic introduction to queues in FreeRTOS. |
|
| 249 | + |
|
| 250 | +--- |
|
| 251 | + |
|
| 252 | +### 7. Interrupts |
|
| 253 | +- Shows how FreeRTOS interacts with **hardware interrupts**. |
|
| 254 | +- Example: An ISR (interrupt service routine) gives a semaphore or sends data to a queue. |
|
| 255 | +- Demonstrates safe communication between interrupts and tasks. |
|
| 256 | + |
|
| 257 | +--- |
|
| 258 | + |
|
| 259 | +### 8. Mutex |
|
| 260 | +- Demonstrates a **mutex (mutual exclusion lock)**. |
|
| 261 | +- Ensures only one task at a time accesses a shared resource (like Serial or an I²C bus). |
|
| 262 | +- Prevents data corruption when multiple tasks try to use the same peripheral. |
|
| 263 | + |
|
| 264 | +--- |
|
| 265 | + |
|
| 266 | +### 9. Notifications |
|
| 267 | +- Shows how to use **task notifications** instead of semaphores/queues. |
|
| 268 | +- Lightweight way to signal a task from another task or from an ISR. |
|
| 269 | +- Example: ISR notifies a task when a button is pressed. |
|
| 270 | + |
|
| 271 | +--- |
|
| 272 | + |
|
| 273 | +### 10. StructArray |
|
| 274 | +- Demonstrates passing an **array of structs** between tasks. |
|
| 275 | +- Useful when you have structured data (like sensor packets). |
|
| 276 | +- Similar to ArrayQueue, but with custom struct types. |
|
| 277 | + |
|
| 278 | +--- |
|
| 279 | + |
|
| 280 | +### 11. StructQueue |
|
| 281 | +- Demonstrates using a **queue of structs**. |
|
| 282 | +- Example: Task A sends a struct `{temperature, humidity, timestamp}` to Task B. |
|
| 283 | +- More real-world than IntegerQueue because data usually comes in structs. |
|
| 284 | + |
|
| 285 | +--- |
|
| 286 | + |
|
| 287 | +### 12. TaskStatus |
|
| 288 | +- Demonstrates retrieving **task runtime statistics**. |
|
| 289 | +- Uses FreeRTOS APIs (`uxTaskGetSystemState`, `vTaskGetRunTimeStats`) to show: |
|
| 290 | + - Task names |
|
| 291 | + - CPU usage % |
|
| 292 | + - Stack high-water marks |
|
| 293 | +- Useful for debugging and optimization. |
|
| 294 | + |
|
| 295 | +--- |
|
| 296 | + |
|
| 297 | +### 13. TaskUtilities |
|
| 298 | +- Shows helper functions that make FreeRTOS task management easier. |
|
| 299 | +- Examples: delaying tasks (`vTaskDelay`), checking stack usage, suspending/resuming tasks. |
|
| 300 | +- A "toolbox" demo for common task patterns. |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + |
|
| 304 | +## example 2 |
|
| 305 | + |
|
| 306 | +queues + shared state |
|
| 307 | + |
|
| 308 | +``` |
|
| 309 | + struct ControlData { |
|
| 310 | + uint16_t throttle; |
|
| 311 | + uint16_t steering; |
|
| 312 | + uint16_t battery_mv; |
|
| 313 | + }; |
|
| 314 | + |
|
| 315 | + // Shared global (protected with mutex if multiple tasks write to it) |
|
| 316 | + volatile ControlData control; |
|
| 317 | +``` |
|
| 318 | + |
|
| 319 | +✅ Recommendation: Use FreeRTOS with 3–4 tasks (ELRS, motors, ADC, BLE) + one shared struct. It gives you the best modularity and avoids blocking. |
|
| 320 | + |
|
| 321 | +**ELRS Task (high priority)** |
|
| 322 | + |
|
| 323 | +- Reads UART (CRSF packets). |
|
| 324 | +- Parses channel values. |
|
| 325 | +- Updates control.throttle and control.steering. |
|
| 326 | + |
|
| 327 | +**Motor Control Task (medium/high priority)** |
|
| 328 | + |
|
| 329 | +- Runs periodically (e.g. every 10–20 ms). |
|
| 330 | +- Reads latest control.throttle / steering. |
|
| 331 | +- Writes PWM to motors (non-blocking). |
|
| 332 | + |
|
| 333 | +**Battery ADC Task (low priority / slow loop)** |
|
| 334 | + |
|
| 335 | +- Reads ADC every 500–1000 ms. |
|
| 336 | +- Updates control.battery_mv. |
|
| 337 | + |
|
| 338 | +**BLE Task (lowest priority)** |
|
| 339 | + |
|
| 340 | +- Takes control.battery_mv and updates BLE advertising packet. |
|
| 341 | +- Runs every 1–2 seconds. |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | +## simple example 1 |
|
| 347 | + |
|
| 348 | + #include "FreeRTOS.h" |
|
| 349 | + #include "task.h" |
|
| 350 | + #include <stdio.h> |
|
| 351 | + |
|
| 352 | + void vTask1(void *pvParameters) { |
|
| 353 | + while (1) { |
|
| 354 | + printf("Task 1 running\n"); |
|
| 355 | + vTaskDelay(pdMS_TO_TICKS(1000)); // Delay 1000 ms |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + void vTask2(void *pvParameters) { |
|
| 360 | + while (1) { |
|
| 361 | + printf("Task 2 running\n"); |
|
| 362 | + vTaskDelay(pdMS_TO_TICKS(2000)); // Delay 2000 ms |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + int main(void) { |
|
| 367 | + xTaskCreate(vTask1, "Task1", 128, NULL, 1, NULL); |
|
| 368 | + xTaskCreate(vTask2, "Task2", 128, NULL, 1, NULL); |
|
| 369 | + |
|
| 370 | + vTaskStartScheduler(); // Start FreeRTOS |
|
| 371 | + while (1); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | +## ref |
|
| 375 | + |
|
| 376 | +- [[system-dat]] |
|
| ... | ... | \ No newline at end of file |
Tech-dat/system-dat/2024-08-28-15-15-47.png
| ... | ... | Binary files a/Tech-dat/system-dat/2024-08-28-15-15-47.png and /dev/null differ |
Tech-dat/system-dat/RT-Thread-dat/2025-08-28-18-00-45.png
| ... | ... | Binary files a/Tech-dat/system-dat/RT-Thread-dat/2025-08-28-18-00-45.png and /dev/null differ |
Tech-dat/system-dat/RT-Thread-dat/RT-Thread-dat.md
| ... | ... | @@ -1,26 +0,0 @@ |
| 1 | - |
|
| 2 | -# RT-Thread-dat |
|
| 3 | - |
|
| 4 | -- [[allwinner-dat]] |
|
| 5 | - |
|
| 6 | -https://github.com/RT-Thread/rt-thread |
|
| 7 | - |
|
| 8 | -Nano 也得到了优秀国产物联网操作系统 RT-Thread 的官方支持,有rtt相关知识或经验,我们就可以对 Nano 进行快速高效的开发; |
|
| 9 | - |
|
| 10 | -RTT官方已经给出由 uestczyh222 所维护的 Nano固件详细的编译、烧录过程,搬运至此: |
|
| 11 | - |
|
| 12 | -https://github.com/RT-Thread/rt-thread/blob/master/bsp/allwinner_tina/README.md |
|
| 13 | - |
|
| 14 | -git clone https://github.com/RT-Thread/rt-thread.git |
|
| 15 | - |
|
| 16 | - |
|
| 17 | -project - [[wch-fly-dat]] |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - |
|
| 24 | -## ref |
|
| 25 | - |
|
| 26 | -- [[system-dat]] |
|
| ... | ... | \ No newline at end of file |
Tech-dat/system-dat/freertos-dat/freertos-dat.md
| ... | ... | @@ -1,218 +0,0 @@ |
| 1 | - |
|
| 2 | -# freertos-dat |
|
| 3 | - |
|
| 4 | - |
|
| 5 | -## freeRTOS debug |
|
| 6 | - |
|
| 7 | -Your sketch is written for ESP32 but you’re compiling it for ESP8266, and that’s why it’s failing. |
|
| 8 | - |
|
| 9 | -Why |
|
| 10 | - |
|
| 11 | -SemaphoreHandle_t, xSemaphoreCreateBinary(), xSemaphoreGive(), xSemaphoreTake(), and portMAX_DELAY are FreeRTOS API calls. |
|
| 12 | - |
|
| 13 | -ESP32 Arduino comes with FreeRTOS by default. |
|
| 14 | - |
|
| 15 | -ESP8266 Arduino does not use FreeRTOS — so those types and functions don’t exist unless you add a separate RTOS layer. |
|
| 16 | - |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - |
|
| 22 | -## ✅ When is it a Good Time to Use FreeRTOS? |
|
| 23 | - |
|
| 24 | -**FreeRTOS** is a real-time operating system designed for microcontrollers. It lets you split your application into multiple tasks that run seemingly in parallel. |
|
| 25 | - |
|
| 26 | ---- |
|
| 27 | - |
|
| 28 | -### 🧠 Use FreeRTOS When: |
|
| 29 | - |
|
| 30 | -#### 1. 🧵 **You Need to Run Multiple Tasks Concurrently** |
|
| 31 | -- Example: Reading sensor data, updating a display, and handling WiFi at the same time. |
|
| 32 | -- Each task can run independently using `xTaskCreate()`. |
|
| 33 | - |
|
| 34 | -#### 2. ⏱️ **You Require Real-Time Responsiveness** |
|
| 35 | -- Critical tasks (e.g., handling motor feedback or interrupts) can be given **higher priority**. |
|
| 36 | -- Guarantees **predictable response time**. |
|
| 37 | - |
|
| 38 | -#### 3. 🕓 **You Need Precise Timing or Scheduling** |
|
| 39 | -- Use `vTaskDelay()`, `xTimerCreate()`, etc., to run tasks at specific intervals. |
|
| 40 | -- Better than using `delay()` or busy-wait loops. |
|
| 41 | - |
|
| 42 | -#### 4. 📶 **You Have Asynchronous Events to Handle** |
|
| 43 | -- Great for UART, I2C, network communication, button presses, etc. |
|
| 44 | -- Use **queues**, **semaphores**, and **event groups** for clean async handling. |
|
| 45 | - |
|
| 46 | -#### 5. 🔄 **You Want to Structure a Large Project Cleanly** |
|
| 47 | -- Modular task-based design. |
|
| 48 | -- Easier to manage and debug than a giant `loop()` function. |
|
| 49 | - |
|
| 50 | -#### 6. 📦 **You're Using ESP32 or STM32 with Multiple Cores or Peripherals** |
|
| 51 | -- ESP32 has dual-core (PRO & APP cores). |
|
| 52 | -- FreeRTOS lets you **pin tasks to cores**, assign priority, and manage memory better. |
|
| 53 | - |
|
| 54 | ---- |
|
| 55 | - |
|
| 56 | -### 🧊 Not Always Necessary If: |
|
| 57 | -| Situation | Recommendation | |
|
| 58 | -|----------------------------------|---------------------------| |
|
| 59 | -| Simple blink or sensor reading | No need for FreeRTOS | |
|
| 60 | -| Single function, low resource | Use `loop()` and interrupts | |
|
| 61 | -| Ultra-low-power apps | May be better without RTOS | |
|
| 62 | - |
|
| 63 | ---- |
|
| 64 | - |
|
| 65 | -### ✅ Example: Good Use Case (ESP32 with Camera, Webserver, Sensors) |
|
| 66 | - |
|
| 67 | -- 📷 Task 1: Camera image capture |
|
| 68 | -- 🌐 Task 2: Web server and WiFi communication |
|
| 69 | -- 🌡️ Task 3: Sensor data read and logging |
|
| 70 | -- 🎯 Task 4: OTA update check |
|
| 71 | - |
|
| 72 | -All these tasks can run smoothly in parallel using FreeRTOS, each with its own stack and priority. |
|
| 73 | - |
|
| 74 | ---- |
|
| 75 | - |
|
| 76 | -### 🚀 Summary |
|
| 77 | - |
|
| 78 | -| Feature | Why FreeRTOS Helps | |
|
| 79 | -|--------------------------|-----------------------------------------| |
|
| 80 | -| Multitasking | Run multiple functions in parallel | |
|
| 81 | -| Real-time priority | Critical tasks get CPU first | |
|
| 82 | -| Precise scheduling | Timers, delays, and periodic execution | |
|
| 83 | -| Clean architecture | Organized, modular task-based design | |
|
| 84 | -| Event handling | Easy async using semaphores & queues | |
|
| 85 | - |
|
| 86 | ---- |
|
| 87 | - |
|
| 88 | -Let me know if you'd like a simple FreeRTOS project example! |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - |
|
| 93 | -## Use FreeRTOS primitives: |
|
| 94 | - |
|
| 95 | -Queue: for passing sensor/audio/display data between tasks |
|
| 96 | - |
|
| 97 | -Semaphore: to lock I2C bus or protect shared resources |
|
| 98 | - |
|
| 99 | -Timer: for periodic updates (e.g., sensor every 1s) |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - |
|
| 103 | -## 🧩 Inter-Task Communication |
|
| 104 | - |
|
| 105 | -✅ 1. SSD1306 (I2C) |
|
| 106 | - |
|
| 107 | -Use Adafruit SSD1306 or u8g2 with I2C. |
|
| 108 | - |
|
| 109 | -Share I2C bus with BMP280. |
|
| 110 | - |
|
| 111 | -Protect with mutex semaphore. |
|
| 112 | - |
|
| 113 | -xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
| 114 | -// update display |
|
| 115 | -xSemaphoreGive(i2c_mutex); |
|
| 116 | - |
|
| 117 | - |
|
| 118 | -✅ 2. BMP280 Sensor (I2C) |
|
| 119 | - |
|
| 120 | -Read temperature & pressure every 1–2 seconds. |
|
| 121 | - |
|
| 122 | -Send data to DisplayTask via queue. |
|
| 123 | - |
|
| 124 | -### Example Queues and Semaphores: |
|
| 125 | - |
|
| 126 | - QueueHandle_t sensor_data_queue; |
|
| 127 | - QueueHandle_t display_msg_queue; |
|
| 128 | - SemaphoreHandle_t i2c_mutex; |
|
| 129 | - |
|
| 130 | -### Sensor to Display Queue Message: |
|
| 131 | - |
|
| 132 | - typedef struct { |
|
| 133 | - float temperature; |
|
| 134 | - float pressure; |
|
| 135 | - } sensor_data_t |
|
| 136 | - |
|
| 137 | - |
|
| 138 | -## Pseudocode Overview |
|
| 139 | - |
|
| 140 | - void SensorTask(void *pvParams) { |
|
| 141 | - sensor_data_t data; |
|
| 142 | - while (1) { |
|
| 143 | - xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
| 144 | - data = read_bmp280(); |
|
| 145 | - xSemaphoreGive(i2c_mutex); |
|
| 146 | - |
|
| 147 | - xQueueSend(sensor_data_queue, &data, 0); |
|
| 148 | - vTaskDelay(pdMS_TO_TICKS(1000)); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - void DisplayTask(void *pvParams) { |
|
| 153 | - sensor_data_t data; |
|
| 154 | - while (1) { |
|
| 155 | - if (xQueueReceive(sensor_data_queue, &data, portMAX_DELAY)) { |
|
| 156 | - xSemaphoreTake(i2c_mutex, portMAX_DELAY); |
|
| 157 | - update_display(data.temperature, data.pressure); |
|
| 158 | - xSemaphoreGive(i2c_mutex); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | -## cores |
|
| 166 | - |
|
| 167 | - xTaskCreatePinnedToCore(task1, "Task1", 2048, NULL, 1, NULL, 0); // Run on Core 0 |
|
| 168 | - xTaskCreatePinnedToCore(task2, "Task2", 2048, NULL, 1, NULL, 1); // Run on Core 1 |
|
| 169 | - |
|
| 170 | -Core 0: PRO_CPU (usually handles Wi-Fi, BT stack) |
|
| 171 | - |
|
| 172 | -Core 1: APP_CPU (often used for your application) |
|
| 173 | - |
|
| 174 | -## compare |
|
| 175 | - |
|
| 176 | -| Feature / RTOS | FreeRTOS | Zephyr RTOS | ThreadX (Azure RTOS) | Bare-Metal (No RTOS) | |
|
| 177 | -| ----------------------- | --------------------------------- | ---------------------------------------- | ---------------------------------- | ------------------------------ | |
|
| 178 | -| **License** | MIT (Permissive, Free) | Apache 2.0 (Permissive, Free) | Microsoft EULA (Free, but limited) | None | |
|
| 179 | -| **Footprint** | Very Small (<10 KB) | Medium (~50–100 KB) | Small (~10–20 KB) | Very Small | |
|
| 180 | -| **Real-Time** | Yes (preemptive, deterministic) | Yes (configurable RT, preemptive) | Yes (deterministic RTOS) | Depends on implementation | |
|
| 181 | -| **Ease of Use** | Simple API, easy learning curve | More complex, powerful config system | Easy API, good documentation | Full control but more effort | |
|
| 182 | -| **Hardware Support** | Very wide (ARM, RISC-V, etc.) | Very wide + device trees | Good (mainly ARM, RISC-V, x86) | Manual per-device work | |
|
| 183 | -| **Task Management** | Yes (tasks, priorities) | Yes (threads, priorities, SMP) | Yes (threads, priorities) | Manual state machine | |
|
| 184 | -| **Synchronization** | Semaphores, mutexes, queues | Semaphores, FIFOs, message queues | Semaphores, mutexes, event flags | Manual implementation | |
|
| 185 | -| **File System Support** | External (e.g., FatFs) | Native FS (e.g., LittleFS, FatFS) | With Azure FileX | Manual or third-party | |
|
| 186 | -| **Networking** | External (e.g., lwIP) | Native (TCP/IP stack, 6LoWPAN) | Azure NetX Duo (IPv4/IPv6) | External, complex to integrate | |
|
| 187 | -| **Power Management** | Basic, user-implemented | Advanced (built-in PM framework) | Good (some MCU-specific features) | Manual | |
|
| 188 | -| **Security/IoT** | AWS IoT support (via Amazon RTOS) | Secure boot, crypto, OTA, TLS | Azure IoT support, TLS, OTA | Manual, very limited | |
|
| 189 | -| **Trace & Debug** | Tools: SystemView, Tracealyzer | Zephyr logging & tracing | NetX, ThreadX tracing tools | Manual logging | |
|
| 190 | -| **Community Support** | Huge, mature ecosystem | Growing fast, backed by Linux Foundation | Good, backed by Microsoft | None (solo dev) | |
|
| 191 | - |
|
| 192 | -## simple example 1 |
|
| 193 | - |
|
| 194 | - #include "FreeRTOS.h" |
|
| 195 | - #include "task.h" |
|
| 196 | - #include <stdio.h> |
|
| 197 | - |
|
| 198 | - void vTask1(void *pvParameters) { |
|
| 199 | - while (1) { |
|
| 200 | - printf("Task 1 running\n"); |
|
| 201 | - vTaskDelay(pdMS_TO_TICKS(1000)); // Delay 1000 ms |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - void vTask2(void *pvParameters) { |
|
| 206 | - while (1) { |
|
| 207 | - printf("Task 2 running\n"); |
|
| 208 | - vTaskDelay(pdMS_TO_TICKS(2000)); // Delay 2000 ms |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - int main(void) { |
|
| 213 | - xTaskCreate(vTask1, "Task1", 128, NULL, 1, NULL); |
|
| 214 | - xTaskCreate(vTask2, "Task2", 128, NULL, 1, NULL); |
|
| 215 | - |
|
| 216 | - vTaskStartScheduler(); // Start FreeRTOS |
|
| 217 | - while (1); |
|
| 218 | - } |
|
| ... | ... | \ No newline at end of file |
Tech-dat/system-dat/system-dat.md
| ... | ... | @@ -1,27 +0,0 @@ |
| 1 | - |
|
| 2 | -# system-dat |
|
| 3 | - |
|
| 4 | -- [[peripherals-dat]] |
|
| 5 | - |
|
| 6 | -## realtime system |
|
| 7 | - |
|
| 8 | -- [[FreeRTOS-dat]] - [[Zephyr-dat]] - [[MongooseOS-dat]] |
|
| 9 | - |
|
| 10 | -- [[openthread-dat]] - [[micropython-dat]] |
|
| 11 | - |
|
| 12 | -- [[RT-Thread-dat]] |
|
| 13 | - |
|
| 14 | - |
|
| 15 | - |
|
| 16 | -## intelligent-system |
|
| 17 | - |
|
| 18 | - |
|
| 19 | - |
|
| 20 | -## AC-DC |
|
| 21 | - |
|
| 22 | - |
|
| 23 | - |
|
| 24 | - |
|
| 25 | -## ref |
|
| 26 | - |
|
| 27 | -- [[tech-dat]] |
|
| ... | ... | \ No newline at end of file |