62 lines
2.1 KiB
PowerShell
62 lines
2.1 KiB
PowerShell
param(
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Name,
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$TargetDir,
|
|
[string]$TopModule = "top"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$templateRoot = Join-Path (Split-Path $PSScriptRoot -Parent) "templates"
|
|
|
|
if (Test-Path $TargetDir) {
|
|
throw "Target already exists: $TargetDir"
|
|
}
|
|
|
|
New-Item -ItemType Directory -Force -Path (Join-Path $TargetDir "src") | Out-Null
|
|
|
|
# gprj
|
|
$gprj = @"
|
|
<?xml version="1" encoding="UTF-8"?>
|
|
<!DOCTYPE gowin-fpga-project>
|
|
<Project>
|
|
<Template>FPGA</Template>
|
|
<Version>5</Version>
|
|
<Device name="GW5A-25A" pn="GW5A-LV25UG324C2/I1">gw5a25a-008</Device>
|
|
<FileList>
|
|
<File path="src/$TopModule.v" type="file.verilog" enable="1"/>
|
|
<File path="src/$TopModule.cst" type="file.cst" enable="1"/>
|
|
<File path="src/$TopModule.sdc" type="file.sdc" enable="1"/>
|
|
</FileList>
|
|
</Project>
|
|
"@
|
|
[System.IO.File]::WriteAllText((Join-Path $TargetDir "$Name.gprj"), $gprj, (New-Object System.Text.UTF8Encoding $false))
|
|
|
|
# build.tcl (ASCII, no BOM)
|
|
$tcl = @"
|
|
open_project $Name.gprj
|
|
set_option -output_base_name $Name
|
|
set_option -synthesis_tool gowinsynthesis
|
|
set_option -top_module $TopModule
|
|
set_option -use_sspi_as_gpio 1
|
|
set_option -use_mspi_as_gpio 1
|
|
set_option -use_ready_as_gpio 1
|
|
set_option -use_done_as_gpio 1
|
|
set_option -use_cpu_as_gpio 1
|
|
run all
|
|
exit
|
|
"@
|
|
[System.IO.File]::WriteAllText((Join-Path $TargetDir "build.tcl"), $tcl, (New-Object System.Text.UTF8Encoding $false))
|
|
|
|
Copy-Item (Join-Path $templateRoot "src\top.v") (Join-Path $TargetDir "src\$TopModule.v")
|
|
Copy-Item (Join-Path $templateRoot "src\top.cst") (Join-Path $TargetDir "src\$TopModule.cst")
|
|
Copy-Item (Join-Path $templateRoot "src\top.sdc") (Join-Path $TargetDir "src\$TopModule.sdc")
|
|
|
|
# fix module name inside copied files
|
|
$v = Get-Content (Join-Path $TargetDir "src\$TopModule.v") -Raw
|
|
$v = $v -replace "module top", "module $TopModule"
|
|
[System.IO.File]::WriteAllText((Join-Path $TargetDir "src\$TopModule.v"), $v, (New-Object System.Text.UTF8Encoding $false))
|
|
|
|
Write-Host "Created project: $TargetDir"
|
|
Write-Host "Next: gwin-skill\scripts\build_and_download.ps1 -ProjectDir $TargetDir"
|