Refactored physical interfaces in TDFs and TDF scripts
This commit is contained in:
@@ -13,7 +13,6 @@ use Targets\TargetRegisterGroup;
|
||||
require_once __DIR__ . "/../TargetDescriptionFile.php";
|
||||
require_once __DIR__ . "/../Services/StringService.php";
|
||||
require_once __DIR__ . "/AvrFamily.php";
|
||||
require_once __DIR__ . "/AvrPhysicalInterface.php";
|
||||
require_once __DIR__ . "/Signature.php";
|
||||
require_once __DIR__ . "/DebugWireParameters.php";
|
||||
require_once __DIR__ . "/IspParameters.php";
|
||||
@@ -61,39 +60,6 @@ class Avr8TargetDescriptionFile extends TargetDescriptionFile
|
||||
return AvrFamily::tryFrom($this->deviceAttributesByName['avr-family']);
|
||||
}
|
||||
|
||||
public function getSupportedPhysicalInterfaces(): array
|
||||
{
|
||||
$physicalInterfacesByName = [
|
||||
'isp' => AvrPhysicalInterface::ISP,
|
||||
'debugwire' => AvrPhysicalInterface::DEBUG_WIRE,
|
||||
'updi' => AvrPhysicalInterface::UPDI,
|
||||
'pdi' => AvrPhysicalInterface::PDI,
|
||||
'jtag' => AvrPhysicalInterface::JTAG,
|
||||
];
|
||||
|
||||
return array_filter(array_map(
|
||||
fn (PhysicalInterface $interface): ?AvrPhysicalInterface
|
||||
=> $physicalInterfacesByName[strtolower($interface->name ?? '')] ?? null,
|
||||
$this->physicalInterfaces
|
||||
));
|
||||
}
|
||||
|
||||
public function getSupportedDebugPhysicalInterfaces(): array
|
||||
{
|
||||
$physicalInterfacesByName = [
|
||||
'debugwire' => AvrPhysicalInterface::DEBUG_WIRE,
|
||||
'updi' => AvrPhysicalInterface::UPDI,
|
||||
'pdi' => AvrPhysicalInterface::PDI,
|
||||
'jtag' => AvrPhysicalInterface::JTAG,
|
||||
];
|
||||
|
||||
return array_filter(array_map(
|
||||
fn (PhysicalInterface $interface): ?AvrPhysicalInterface
|
||||
=> $physicalInterfacesByName[strtolower($interface->name ?? '')] ?? null,
|
||||
$this->physicalInterfaces
|
||||
));
|
||||
}
|
||||
|
||||
public function getDebugWireParameters(): DebugWireParameters
|
||||
{
|
||||
$output = new DebugWireParameters();
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
namespace Targets\TargetDescriptionFiles\Avr8;
|
||||
|
||||
enum AvrPhysicalInterface: string
|
||||
{
|
||||
case ISP = 'ISP';
|
||||
case JTAG = 'JTAG';
|
||||
case PDI = 'PDI';
|
||||
case UPDI = 'UPDI';
|
||||
case DEBUG_WIRE = 'DEBUG_WIRE';
|
||||
}
|
||||
@@ -3,13 +3,13 @@ namespace Targets\TargetDescriptionFiles\AVR8\Services;
|
||||
|
||||
use Targets\TargetDescriptionFiles\Avr8\Avr8TargetDescriptionFile;
|
||||
use Targets\TargetDescriptionFiles\Avr8\AvrFamily;
|
||||
use Targets\TargetDescriptionFiles\Avr8\AvrPhysicalInterface;
|
||||
use Targets\TargetDescriptionFiles\Avr8\DebugWireParameters;
|
||||
use Targets\TargetDescriptionFiles\Avr8\IspParameters;
|
||||
use Targets\TargetDescriptionFiles\Avr8\JtagParameters;
|
||||
use Targets\TargetDescriptionFiles\Avr8\PdiParameters;
|
||||
use Targets\TargetDescriptionFiles\Avr8\UpdiParameters;
|
||||
use Targets\TargetDescriptionFiles\MemorySegment;
|
||||
use Targets\TargetPhysicalInterface;
|
||||
use Targets\TargetRegister;
|
||||
use Targets\TargetRegisterGroup;
|
||||
|
||||
@@ -122,13 +122,13 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
|
||||
$failures[] = 'Missing fuse register group (in fuse peripheral)';
|
||||
}
|
||||
|
||||
if (in_array(AvrPhysicalInterface::DEBUG_WIRE, $debugPhysicalInterfaces)) {
|
||||
if (in_array(TargetPhysicalInterface::DEBUG_WIRE, $debugPhysicalInterfaces)) {
|
||||
$failures = array_merge(
|
||||
$failures,
|
||||
$this->validateDebugWireParameters($tdf->getDebugWireParameters(), $tdf)
|
||||
);
|
||||
|
||||
if (!in_array(AvrPhysicalInterface::ISP, $physicalInterfaces)) {
|
||||
if (!in_array(TargetPhysicalInterface::ISP, $physicalInterfaces)) {
|
||||
$failures[] = 'Missing ISP interface for debugWIRE target';
|
||||
}
|
||||
|
||||
@@ -149,12 +149,12 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array(AvrPhysicalInterface::ISP, $physicalInterfaces)) {
|
||||
if (in_array(TargetPhysicalInterface::ISP, $physicalInterfaces)) {
|
||||
$failures = array_merge($failures, $this->validateIspParameters($tdf->getIspParameters()));
|
||||
}
|
||||
|
||||
if (
|
||||
in_array(AvrPhysicalInterface::JTAG, $debugPhysicalInterfaces)
|
||||
in_array(TargetPhysicalInterface::JTAG, $debugPhysicalInterfaces)
|
||||
&& $family == AvrFamily::MEGA
|
||||
) {
|
||||
$failures = array_merge($failures, $this->validateJtagParameters($tdf->getJtagParameters(), $tdf));
|
||||
@@ -168,11 +168,11 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array(AvrPhysicalInterface::PDI, $debugPhysicalInterfaces)) {
|
||||
if (in_array(TargetPhysicalInterface::PDI, $debugPhysicalInterfaces)) {
|
||||
$failures = array_merge($failures, $this->validatePdiParameters($tdf->getPdiParameters()));
|
||||
}
|
||||
|
||||
if (in_array(AvrPhysicalInterface::UPDI, $debugPhysicalInterfaces)) {
|
||||
if (in_array(TargetPhysicalInterface::UPDI, $debugPhysicalInterfaces)) {
|
||||
$failures = array_merge($failures, $this->validateUpdiParameters($tdf->getUpdiParameters()));
|
||||
|
||||
/*
|
||||
@@ -187,8 +187,8 @@ class ValidationService extends \Targets\TargetDescriptionFiles\Services\Validat
|
||||
}
|
||||
|
||||
if (
|
||||
in_array(AvrPhysicalInterface::JTAG, $debugPhysicalInterfaces)
|
||||
|| in_array(AvrPhysicalInterface::UPDI, $debugPhysicalInterfaces)
|
||||
in_array(TargetPhysicalInterface::JTAG, $debugPhysicalInterfaces)
|
||||
|| in_array(TargetPhysicalInterface::UPDI, $debugPhysicalInterfaces)
|
||||
) {
|
||||
if (empty($tdf->getFuseBitsDescriptor('eesave'))) {
|
||||
$failures[] = 'Could not find EESAVE fuse bit field for JTAG/UPDI target';
|
||||
|
||||
@@ -3,12 +3,10 @@ namespace Targets\TargetDescriptionFiles;
|
||||
|
||||
class PhysicalInterface
|
||||
{
|
||||
public ?string $name = null;
|
||||
public ?string $type = null;
|
||||
public ?string $value = null;
|
||||
|
||||
public function __construct(?string $name, ?string $type)
|
||||
public function __construct(?string $value)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ use Targets\TargetDescriptionFiles\AVR8\Services\ValidationService;
|
||||
use Targets\TargetDescriptionFiles\Services\StringService;
|
||||
use Targets\TargetDescriptionFiles\Avr8\Avr8TargetDescriptionFile;
|
||||
use Targets\TargetDescriptionFiles\Avr8\AvrFamily;
|
||||
use Targets\TargetDescriptionFiles\Avr8\AvrPhysicalInterface;
|
||||
use Targets\TargetDescriptionFiles\TargetFamily;
|
||||
use Targets\TargetDescriptionFiles\PropertyGroup;
|
||||
use Targets\TargetDescriptionFiles\Property;
|
||||
@@ -31,6 +30,7 @@ use Targets\TargetDescriptionFiles\Pinout;
|
||||
use Targets\TargetDescriptionFiles\PinoutType;
|
||||
use Targets\TargetDescriptionFiles\Pin;
|
||||
use Targets\TargetDescriptionFiles\Variant;
|
||||
use Targets\TargetPhysicalInterface;
|
||||
|
||||
require_once __DIR__ . '/StringService.php';
|
||||
require_once __DIR__ . '/../AVR8/Avr8TargetDescriptionFile.php';
|
||||
@@ -187,7 +187,7 @@ class AtdfService
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array(AvrPhysicalInterface::UPDI, $tdf->getSupportedDebugPhysicalInterfaces())) {
|
||||
if (in_array(TargetPhysicalInterface::UPDI, $tdf->getSupportedDebugPhysicalInterfaces())) {
|
||||
/*
|
||||
* ATDFs for UPDI-enabled targets do not typically possess an `ocd_base_addr` property in the updi_interface
|
||||
* property group. Bloom needs this property to configure EDBG debug tools, so we add it here.
|
||||
@@ -598,10 +598,18 @@ class AtdfService
|
||||
|
||||
private function physicalInterfaceFromElement(DOMElement $element): PhysicalInterface
|
||||
{
|
||||
$physicalInterfacesByName = [
|
||||
'isp' => TargetPhysicalInterface::ISP,
|
||||
'debugwire' => TargetPhysicalInterface::DEBUG_WIRE,
|
||||
'updi' => TargetPhysicalInterface::UPDI,
|
||||
'pdi' => TargetPhysicalInterface::PDI,
|
||||
'jtag' => TargetPhysicalInterface::JTAG,
|
||||
];
|
||||
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
return new PhysicalInterface(
|
||||
$attributes['name'] ?? null,
|
||||
$attributes['type'] ?? null,
|
||||
$physicalInterfacesByName[strtolower($attributes['name'] ?? '')]?->value
|
||||
?? (!empty($attributes['type']) ? strtolower($attributes['type']) : null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,10 +189,7 @@ class FromXmlService
|
||||
public function physicalInterfaceFromElement(DOMElement $element): PhysicalInterface
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
return new PhysicalInterface(
|
||||
$attributes['name'] ?? null,
|
||||
$attributes['type'] ?? null,
|
||||
);
|
||||
return new PhysicalInterface($attributes['value'] ?? null);
|
||||
}
|
||||
|
||||
public function moduleFromElement(DOMElement $element): Module
|
||||
|
||||
@@ -125,8 +125,7 @@ class ToXmlService
|
||||
public function physicalInterfaceToXml(PhysicalInterface $physicalInterface, DOMDocument $document): DOMElement
|
||||
{
|
||||
$element = $document->createElement('physical-interface');
|
||||
$element->setAttribute('name', $physicalInterface->name);
|
||||
$element->setAttribute('type', $physicalInterface->type);
|
||||
$element->setAttribute('value', $physicalInterface->value);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace Targets\TargetDescriptionFiles;
|
||||
|
||||
use Targets\TargetPeripheral;
|
||||
use Targets\TargetPhysicalInterface;
|
||||
use Targets\TargetRegister;
|
||||
use Targets\TargetRegisterBitField;
|
||||
use Targets\TargetRegisterGroup;
|
||||
@@ -20,6 +21,7 @@ require_once __DIR__ . "/Pinout.php";
|
||||
require_once __DIR__ . "/Variant.php";
|
||||
require_once __DIR__ . "/TargetFamily.php";
|
||||
|
||||
require_once __DIR__ . "/../TargetPhysicalInterface.php";
|
||||
require_once __DIR__ . "/../TargetPeripheral.php";
|
||||
require_once __DIR__ . "/../TargetRegisterGroup.php";
|
||||
require_once __DIR__ . "/../TargetRegister.php";
|
||||
@@ -81,6 +83,22 @@ class TargetDescriptionFile
|
||||
return $this->deviceAttributesByName['vendor'] ?? null;
|
||||
}
|
||||
|
||||
public function getSupportedPhysicalInterfaces(): array
|
||||
{
|
||||
return array_filter(array_map(
|
||||
fn (PhysicalInterface $interface) => TargetPhysicalInterface::tryFrom($interface->value),
|
||||
$this->physicalInterfaces
|
||||
));
|
||||
}
|
||||
|
||||
public function getSupportedDebugPhysicalInterfaces(): array
|
||||
{
|
||||
return array_filter(
|
||||
$this->getSupportedPhysicalInterfaces(),
|
||||
fn (TargetPhysicalInterface $interface): bool => $interface->supportsDebugging()
|
||||
);
|
||||
}
|
||||
|
||||
public function getPropertyGroup(array|string $keys): ?PropertyGroup
|
||||
{
|
||||
if (is_string($keys)) {
|
||||
|
||||
27
build/scripts/Targets/TargetPhysicalInterface.php
Normal file
27
build/scripts/Targets/TargetPhysicalInterface.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace Targets;
|
||||
|
||||
enum TargetPhysicalInterface: string
|
||||
{
|
||||
case ISP = 'isp';
|
||||
case JTAG = 'jtag';
|
||||
case PDI = 'pdi';
|
||||
case UPDI = 'updi';
|
||||
case DEBUG_WIRE = 'debug_wire';
|
||||
|
||||
public function supportsDebugging(): bool
|
||||
{
|
||||
return $this !== self::ISP;
|
||||
}
|
||||
|
||||
public function marketingName(): string
|
||||
{
|
||||
return match($this) {
|
||||
self::ISP => 'ISP',
|
||||
self::JTAG => 'JTAG',
|
||||
self::PDI => 'PDI',
|
||||
self::UPDI => 'UPDI',
|
||||
self::DEBUG_WIRE => 'debugWIRE',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user