Skip to content

Commit

Permalink
long term programming
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Mar 22, 2024
1 parent 102a4f1 commit 424088d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/OneWare.Quartus/OneWare.Quartus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OneWare.Essentials" Version="0.4.5" Private="false" ExcludeAssets="runtime;Native"/>
<PackageReference Include="OneWare.UniversalFpgaProjectSystem" Version="0.16.7" Private="false" ExcludeAssets="runtime;Native"/>
<PackageReference Include="OneWare.Essentials" Version="0.4.6" Private="false" ExcludeAssets="runtime;Native"/>
<PackageReference Include="OneWare.UniversalFpgaProjectSystem" Version="0.16.8" Private="false" ExcludeAssets="runtime;Native"/>
</ItemGroup>

</Project>
111 changes: 95 additions & 16 deletions src/OneWare.Quartus/QuartusLoader.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using Microsoft.Extensions.Logging;
using AvaloniaEdit.Utils;
using DynamicData;
using Microsoft.Extensions.Logging;
using OneWare.Essentials.Enums;
using OneWare.Essentials.Services;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Parser;
using OneWare.UniversalFpgaProjectSystem.Services;
using ILogger = OneWare.Essentials.Services.ILogger;

namespace OneWare.Quartus;

public class QuartusLoader(IChildProcessService childProcessService, ILogger logger) : IFpgaLoader
public class QuartusLoader(IChildProcessService childProcessService, ISettingsService settingsService, ILogger logger)
: IFpgaLoader
{
public string Name => "Quartus";

Expand All @@ -19,33 +24,107 @@ public class QuartusLoader(IChildProcessService childProcessService, ILogger log
.FirstOrDefault(x => Path.GetExtension(x).Equals(extension, StringComparison.OrdinalIgnoreCase));
}
catch (Exception e)
{
{
logger.Error(e.Message, e);
return null;
}
}

public async Task DownloadAsync(UniversalFpgaProjectRoot project)
{
var fpga = project.Properties["Fpga"];
var fpga = project.GetProjectProperty("Fpga");
if (fpga == null) return;
var fpgaModel = fpga.ToString();
var mode = "JTAG";

var longTerm = settingsService.GetSettingValue<bool>("UniversalFpgaProjectSystem_LongTermProgramming");

var properties = FpgaSettingsParser.LoadSettings(project, fpga);

var cableSetting = "Auto";
var cableName = cableSetting == "Auto"
? "1"
: "\"" + cableSetting + "\"";

var sofFile = Path.GetFileName(FirstFileInPath(project.FullPath, ".sof") ?? "");

if (string.IsNullOrEmpty(sofFile))

if (!longTerm)
{
logger.Error("no .sof found! compile Design first!");
return;
var sofFile = Path.GetFileName(FirstFileInPath(project.FullPath, ".sof") ?? "");

if (string.IsNullOrEmpty(sofFile))
{
logger.Error("no .sof found! compile Design first!");
return;
}

var shortTermMode = properties.GetValueOrDefault("QuartusProgrammer_ShortTermMode") ?? "JTAG";
var shortTermOperation = properties.GetValueOrDefault("QuartusProgrammer_ShortTermOperation") ?? "P";
var shortTermArgs = properties.GetValueOrDefault("QuartusProgrammer_ShortTerm_Arguments")?.Split(' ') ?? [];

List<string> pgmArgs = ["-c", cableName, "-m", shortTermMode];
pgmArgs.AddRange(shortTermArgs);
pgmArgs.AddRange(["-o", $"p;{sofFile}"]);

await childProcessService.ExecuteShellAsync("quartus_pgm", pgmArgs,
project.FullPath, "Running Quartus programmer (Short-Term)...", AppState.Loading, true);
}
else
{
var longTermFormat = properties.GetValueOrDefault("QuartusProgrammer_LongTerm_Format") ?? "POF";

string programFile;

if (longTermFormat.Equals("pof", StringComparison.OrdinalIgnoreCase))
{
var pofFile = Path.GetFileName(FirstFileInPath(project.FullPath, ".pof") ?? "");

if (string.IsNullOrEmpty(pofFile))
{
logger.Error("no .pof found! compile Design first!");
return;
}

programFile = pofFile;
}
else
{
//Use CPF to convert SOF in given format
var sofFile = Path.GetFileName(FirstFileInPath(project.FullPath, ".sof") ?? "");

if (string.IsNullOrEmpty(sofFile))
{
logger.Error("no .sof found! compile Design first!");
return;
}

var configurationMode = properties.GetValueOrDefault("QuartusProgrammer_LongTerm_CpfArguments");

if (configurationMode == null)
{
logger.Error("Cpf Arguments cannot be empty!");
return;
}

var convertedFilePath = Path.GetFileNameWithoutExtension(sofFile) + $".{longTermFormat.ToLower()}";

var cpfArgs = configurationMode.Split(' ').ToList();
cpfArgs.AddRange(["-c", sofFile, convertedFilePath]);

var result = await childProcessService.ExecuteShellAsync("quartus_cpf", cpfArgs,
project.FullPath, $"Converting .sof to .{longTermFormat.ToLower()}...");

if (!result.success) return;

programFile = convertedFilePath;
}

var longTermMode = properties.GetValueOrDefault("QuartusProgrammer_LongTermMode") ?? "JTAG";
var longTermOperation = properties.GetValueOrDefault("QuartusProgrammer_LongTermOperation") ?? "P";
var longTermArgs = properties.GetValueOrDefault("QuartusProgrammer_LongTerm_Arguments")?.Split(' ') ?? [];

List<string> pgmArgs = ["-c", cableName, "-m", longTermMode];
pgmArgs.AddRange(longTermArgs);
pgmArgs.AddRange(["-o", $"{longTermOperation};{programFile}"]);

await childProcessService.ExecuteShellAsync("quartus_pgm", pgmArgs,
project.FullPath, "Running Quartus programmer (Long-Term)...", AppState.Loading, true);
}

await childProcessService.ExecuteShellAsync("quartus_pgm", ["-c", cableName, "-m", mode, "-o", $"p;{sofFile}"],
project.FullPath, "Running Quartus programmer (Short-Term)...");
}
}
8 changes: 4 additions & 4 deletions src/OneWare.Quartus/oneware.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"Dependencies": [
{
"Name": "OneWare.Essentials",
"MinVersion": "0.4.5.0",
"MaxVersion": "0.4.5.0"
"MinVersion": "0.4.6.0",
"MaxVersion": "0.4.6.0"
},
{
"Name": "OneWare.UniversalFpgaProjectSystem",
"MinVersion": "0.16.7.0",
"MaxVersion": "0.16.7.0"
"MinVersion": "0.16.8.0",
"MaxVersion": "0.16.8.0"
}
]
}

0 comments on commit 424088d

Please sign in to comment.