Files
IC-Coder-Plugin/docs/Vivado联动功能技术设计文档.md
Roe-xin fa5c2cdafd feat: 实现 Vivado 创建工程功能
- 添加 createVivadoProject 工具
   - 实现 Vivado 自动检测(支持所有盘符和版本)
   - 添加 TCL 脚本生成器
   - 添加配置管理模块
   - 添加测试命令
2026-03-16 17:46:25 +08:00

154 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Vivado 联动功能技术设计文档
## 1. 架构设计
```
后端 AI
↓ 调用工具
前端 Extension (messageHandler.ts)
↓ 调用
VivadoRunner (utils/vivadoRunner.ts)
↓ 生成 TCL 脚本并执行
本地 Vivado
```
## 2. 核心模块
### 2.1 VivadoRunner
**职责**:执行单个 Vivado 命令
**主要方法**
- `createProject()` - 创建工程
- `runSynthesis()` - 执行综合
- `runImplementation()` - 执行实现
- `runBitstream()` - 生成比特流
**实现要点**
- 根据参数生成 TCL 脚本
- 启动子进程执行 Vivado
- 捕获输出日志
- 解析报告文件
- 返回结果
### 2.2 TCL 脚本生成
**创建工程**
```tcl
create_project {projectName} {workDir} -part {part} -force
add_files -norecurse {files}
set_property top {topModule} [current_fileset]
```
**综合**
```tcl
synth_design -part {part} -top {topModule}
report_utilization -file utilization.rpt
write_checkpoint -force synth.dcp
```
**实现**
```tcl
open_checkpoint {dcpFile}
opt_design
place_design
route_design
report_timing_summary -file timing.rpt
write_checkpoint -force impl.dcp
```
**生成比特流**
```tcl
open_checkpoint {dcpFile}
write_bitstream -force output.bit
```
### 2.3 MessageHandler 集成
```typescript
// 处理工具调用
async function handleToolCall(toolName: string, params: any) {
switch(toolName) {
case 'createVivadoProject':
return await vivadoRunner.createProject(params);
case 'runVivadoSynthesis':
return await vivadoRunner.runSynthesis(params);
case 'runVivadoImplementation':
return await vivadoRunner.runImplementation(params);
case 'runVivadoBitstream':
return await vivadoRunner.runBitstream(params);
}
}
```
## 3. 配置管理
**配置文件位置**
- 全局:`settings.json` 中的 `ic-coder.vivado`
- 项目:`.vscode/ic-coder-vivado.json`
**配置项**
```json
{
"vivado": {
"enabled": true,
"executablePath": "C:/Xilinx/Vivado/2023.1/bin/vivado.bat",
"workingDir": "${workspaceFolder}/vivado_project"
}
}
```
## 4. 文件结构
```
src/
├── utils/
│ ├── vivadoRunner.ts # Vivado 执行器
│ ├── vivadoConfig.ts # 配置读取
│ └── tclGenerator.ts # TCL 脚本生成
└── utils/
└── messageHandler.ts # 工具调用处理(新增部分)
```
## 5. 实现要点
### 5.1 子进程执行
```typescript
const process = spawn(vivadoPath, ['-mode', 'batch', '-source', tclPath]);
process.stdout.on('data', (data) => {
output += data.toString();
});
process.on('close', (code) => {
resolve({ success: code === 0, output });
});
```
### 5.2 报告解析
`.rpt` 文件中提取关键信息:
- 资源使用LUT、FF、BRAM 数量
- 时序信息WNS、TNS
### 5.3 错误处理
捕获常见错误:
- Vivado 未配置
- 文件不存在
- 综合/实现失败
- 时序不满足
返回清晰的错误信息给后端。
## 6. 测试
**单元测试**
- TCL 脚本生成正确性
- 配置读取
**集成测试**
- 完整流程测试(需要本地 Vivado
- 错误处理测试