|
| 1 | +# GitHub Copilot Instructions for RT-Thread / RT-Thread GitHub Copilot 指南 |
| 2 | + |
| 3 | +## Overview / 概述 |
| 4 | + |
| 5 | +RT-Thread is a real-time operating system (RTOS) for embedded devices. When working with RT-Thread code, please follow these guidelines to ensure high-quality contributions. |
| 6 | + |
| 7 | +RT-Thread 是一个面向嵌入式设备的实时操作系统(RTOS)。在处理 RT-Thread 代码时,请遵循以下指南以确保高质量的贡献。 |
| 8 | + |
| 9 | +## Code Review Guidelines / 代码审查指南 |
| 10 | + |
| 11 | +### Language Requirements / 语言要求 |
| 12 | + |
| 13 | +When reviewing code, provide feedback in **both English and Chinese** to ensure accessibility for all contributors. |
| 14 | + |
| 15 | +在审查代码时,请同时使用**英文和中文**提供反馈,以确保所有贡献者都能理解。 |
| 16 | + |
| 17 | +### Review Focus Areas / 审查重点领域 |
| 18 | + |
| 19 | +1. **Real-Time Performance / 实时性能** |
| 20 | + - Verify interrupt handling efficiency / 验证中断处理效率 |
| 21 | + |
| 22 | +2. **Memory Management / 内存管理** |
| 23 | + - Detect memory leaks / 检测内存泄漏 |
| 24 | + - Verify proper memory allocation/deallocation / 验证正确的内存分配/释放 |
| 25 | + - Check stack usage optimization / 检查栈使用优化 |
| 26 | + |
| 27 | +3. **Code Style / 代码风格** |
| 28 | + - Follow RT-Thread coding standards / 遵循 RT-Thread 编码标准 |
| 29 | + - Maintain consistent naming conventions / 保持一致的命名约定 |
| 30 | + - Ensure proper code comments (not documentation) / 确保适当的代码注释(而非文档) |
| 31 | + |
| 32 | +### Review Comment Format / 审查评论格式 |
| 33 | + |
| 34 | +When providing review comments, use the following format: |
| 35 | + |
| 36 | +提供审查评论时,请使用以下格式: |
| 37 | + |
| 38 | +``` |
| 39 | +[Category/类别]: Brief description / 简要描述 |
| 40 | +
|
| 41 | +English: Detailed explanation of the issue and suggested improvement. |
| 42 | +中文:问题的详细说明和改进建议。 |
| 43 | +
|
| 44 | +Example/示例: |
| 45 | +```c |
| 46 | +// Your code example here / 你的代码示例 |
| 47 | +``` |
| 48 | +``` |
| 49 | +
|
| 50 | +### Common Issues to Check / 常见问题检查 |
| 51 | +
|
| 52 | +1. **Resource Management / 资源管理** |
| 53 | + - Unclosed file handles / 未关闭的文件句柄 |
| 54 | + - Unreleased semaphores / 未释放的信号量 |
| 55 | + - Memory not freed after malloc / malloc 后未释放内存 |
| 56 | +
|
| 57 | +2. **Error Handling / 错误处理** |
| 58 | + - Missing error checks / 缺少错误检查 |
| 59 | + - Improper error propagation / 不当的错误传播 |
| 60 | + - Silent failures / 静默失败 |
| 61 | +
|
| 62 | +3. **Performance Concerns / 性能问题** |
| 63 | + - Unnecessary polling / 不必要的轮询 |
| 64 | + - Inefficient algorithms in ISRs / ISR 中的低效算法 |
| 65 | + - Excessive context switching / 过度的上下文切换 |
| 66 | +
|
| 67 | +### Severity Levels / 严重程度级别 |
| 68 | +
|
| 69 | +- **🔴 Critical/严重**: Issues that may cause system crashes or data corruption / 可能导致系统崩溃或数据损坏的问题 |
| 70 | +- **🟠 Major/主要**: Significant bugs or performance issues / 重大错误或性能问题 |
| 71 | +- **🟡 Minor/次要**: Code style or minor optimization opportunities / 代码风格或次要优化机会 |
| 72 | +- **🟢 Suggestion/建议**: Best practices or enhancement ideas / 最佳实践或增强建议 |
| 73 | +
|
| 74 | +## RT-Thread Specific Guidelines / RT-Thread 特定指南 |
| 75 | +
|
| 76 | +### Kernel Components / 内核组件 |
| 77 | +
|
| 78 | +When reviewing kernel-related code: |
| 79 | +审查内核相关代码时: |
| 80 | +
|
| 81 | +- Verify rt_thread structure usage / 验证 rt_thread 结构使用 |
| 82 | +
|
| 83 | +### Device Drivers / 设备驱动 |
| 84 | +
|
| 85 | +For device driver reviews: |
| 86 | +对于设备驱动审查: |
| 87 | +
|
| 88 | +- Ensure proper device registration / 确保正确的设备注册 |
| 89 | +- Verify I/O operation handling / 验证 I/O 操作处理 |
| 90 | +
|
| 91 | +### Network Stack / 网络协议栈 |
| 92 | +
|
| 93 | +When reviewing network code: |
| 94 | +审查网络代码时: |
| 95 | +
|
| 96 | +- Validate SAL (Socket Abstraction Layer) usage / 验证 SAL(套接字抽象层)使用 |
| 97 | +- Check protocol implementations / 检查协议实现 |
| 98 | +- Ensure proper buffer management / 确保正确的缓冲区管理 |
| 99 | +
|
| 100 | +## Coding Standards / 编码标准 |
| 101 | +
|
| 102 | +### Object-Oriented Design in C / C语言面向对象设计 |
| 103 | +
|
| 104 | +1. **Inheritance Pattern / 继承模式** |
| 105 | + - First member should be base struct / 第一个成员希望是基类结构体 |
| 106 | + - Use pointer casting for type conversion / 通过指针强制转换实现类型转换 |
| 107 | +
|
| 108 | +2. **Polymorphism via ops / 通过ops实现多态** |
| 109 | + - Define ops struct with function pointers / 定义包含函数指针的ops结构体 |
| 110 | + - Share single ops table across instances / 多个实例共享同一ops表 |
| 111 | +
|
| 112 | +### Naming Conventions / 命名规范 |
| 113 | +
|
| 114 | +- **Structures / 结构体**: `rt_[name]` |
| 115 | +- **Public Functions / 公开函数**: `rt_[class]_[action]` |
| 116 | +- **Static Functions / 静态函数**: `_[class]_[action]` |
| 117 | +- **Hardware Functions / 硬件函数**: `rt_hw_` |
| 118 | +- **Macros / 宏定义**: UPPERCASE (except for local function/variable macros) |
| 119 | +- **Error Codes / 错误码**: `RT_` + POSIX error code, `RT_EOK` for success |
| 120 | +
|
| 121 | +### Object Lifecycle / 对象生命周期 |
| 122 | +
|
| 123 | +- Provide dual APIs / 提供双模式API: |
| 124 | + - `init/detach` for static objects / 用于静态对象 |
| 125 | + - `create/delete` for dynamic objects / 用于动态对象 |
| 126 | +- Use reference counting / 使用引用计数 |
| 127 | +- Return unified error codes / 返回统一错误码 |
| 128 | +
|
| 129 | +### Code Format / 代码格式 |
| 130 | +
|
| 131 | +- 4 spaces indentation, no tabs / 4空格缩进,不使用tab |
| 132 | +- Braces on separate lines / 大括号独占一行 |
| 133 | +- Align parameters on line breaks / 参数换行时对齐 |
| 134 | +
|
| 135 | +## Documentation Standards / 文档标准 |
| 136 | +
|
| 137 | +### Language and Format / 语言和格式 |
| 138 | +
|
| 139 | +- Use English for code comments / 所有代码注释使用英文 |
| 140 | +- Markdown format for documentation / 文档使用Markdown格式 |
| 141 | +- Prefer Mermaid for diagrams, or PlantUML (hide footbox in sequence diagrams) / 优先使用Mermaid绘图,或PlantUML(时序图隐藏footbox) |
| 142 | +
|
| 143 | +### Document Structure / 文档结构 |
| 144 | +
|
| 145 | +1. **Main Level / 主干层**: Overall overview / 整体概述 |
| 146 | +2. **Branch Level / 分支层**: Module introduction / 子模块介绍 |
| 147 | +3. **Node Level / 节点层**: Detailed knowledge points / 知识点详解 |
| 148 | +
|
| 149 | +### Documentation Principles / 文档原则 |
| 150 | +
|
| 151 | +- Keep structure flat / 保持扁平结构 |
| 152 | +- Modular organization / 模块化组织 |
| 153 | +- Clear and concise content / 内容简洁直接 |
| 154 | +- Complete executable examples / 完整可执行示例 |
| 155 | +
|
| 156 | +## Best Practices / 最佳实践 |
| 157 | +
|
| 158 | +1. **Always consider embedded constraints** / **始终考虑嵌入式约束** |
| 159 | + - Limited RAM and ROM / 有限的 RAM 和 ROM |
| 160 | + - Power consumption / 功耗 |
| 161 | + - Real-time requirements / 实时要求 |
| 162 | + - Prefer static allocation / 优先静态分配 |
| 163 | + - Use memory alignment / 使用内存对齐 |
| 164 | +
|
| 165 | +2. **Verify on real hardware or at least QEMU** / **尽可能在真实硬件上验证,或至少在QEMU上验证** |
| 166 | + - Test on actual hardware when available / 有条件时在真实硬件上测试 |
| 167 | + - Use QEMU simulation as minimum verification / 至少使用QEMU仿真进行验证 |
| 168 | + - Consider various BSP configurations / 考虑各种 BSP 配置 |
| 169 | +
|
| 170 | +3. **Document hardware dependencies** / **记录硬件依赖** |
| 171 | + - Specify required peripherals / 指定所需外设 |
| 172 | + - Note timing constraints / 注意时序约束 |
| 173 | + - List supported MCU/MPU families / 列出支持的 MCU/MPU 系列 |
| 174 | +
|
| 175 | +4. **Code Optimization / 代码优化** |
| 176 | + - Use `rt_inline` for simple functions / 简单函数使用rt_inline |
| 177 | + - Avoid deep nesting / 避免深层嵌套 |
| 178 | + - Single responsibility per function / 函数功能单一 |
| 179 | + - Minimize code duplication / 减少代码重复 |
| 180 | +
|
| 181 | +## Contributing / 贡献 |
| 182 | +
|
| 183 | +When suggesting improvements: |
| 184 | +提出改进建议时: |
| 185 | +
|
| 186 | +1. Provide clear, actionable feedback / 提供清晰、可操作的反馈 |
| 187 | +2. Include code examples when possible / 尽可能包含代码示例 |
| 188 | +3. Reference RT-Thread documentation / 引用 RT-Thread 文档 |
| 189 | +4. Consider backward compatibility / 考虑向后兼容性 |
| 190 | +
|
| 191 | +## References / 参考资料 |
| 192 | +
|
| 193 | +- [RT-Thread Documentation](https://www.rt-thread.io/document/site/) |
| 194 | +- [RT-Thread Coding Style Guide](https://github.com/RT-Thread/rt-thread/blob/master/documentation/coding_style_en.md) |
| 195 | +- [RT-Thread 文档中心](https://www.rt-thread.org/document/site/) |
| 196 | +- [RT-Thread 编码规范](https://github.com/RT-Thread/rt-thread/blob/master/documentation/coding_style_cn.md) |
0 commit comments