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 = @" 5 gw5a25a-008 "@ [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"