TDF and TDF script changes (application changes pending):
- Added new `pad` element to TDFs - Refactored `pin` and `signal` elements to accommodate new `pad` element - Improved validation of signal-to-pad relation in TDF validation script - Added key attribute to `variant` element - Removed `package` attribute from `variant` element
This commit is contained in:
14
build/scripts/Targets/TargetDescriptionFiles/Pad.php
Normal file
14
build/scripts/Targets/TargetDescriptionFiles/Pad.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
namespace Targets\TargetDescriptionFiles;
|
||||
|
||||
class Pad
|
||||
{
|
||||
public ?string $key = null;
|
||||
public ?string $name = null;
|
||||
|
||||
public function __construct(?string $key, ?string $name)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->name = $name;
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,11 @@ namespace Targets\TargetDescriptionFiles;
|
||||
class Pin
|
||||
{
|
||||
public ?string $position = null;
|
||||
public ?string $pad = null;
|
||||
public ?string $padKey = null;
|
||||
|
||||
public function __construct(?string $position, ?string $pad)
|
||||
public function __construct(?string $position, ?string $padKey)
|
||||
{
|
||||
$this->position = $position;
|
||||
$this->pad = $pad;
|
||||
$this->padKey = $padKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Targets\TargetDescriptionFiles\Register;
|
||||
use Targets\TargetDescriptionFiles\RegisterGroup;
|
||||
use Targets\TargetDescriptionFiles\RegisterGroupReference;
|
||||
use Targets\TargetDescriptionFiles\Signal;
|
||||
use Targets\TargetDescriptionFiles\Pad;
|
||||
use Targets\TargetDescriptionFiles\Pinout;
|
||||
use Targets\TargetDescriptionFiles\PinoutType;
|
||||
use Targets\TargetDescriptionFiles\Variant;
|
||||
@@ -119,6 +120,21 @@ class ValidationService
|
||||
$failures[] = 'Missing GPIO port peripherals';
|
||||
}
|
||||
|
||||
if (empty($tdf->pads)) {
|
||||
$failures[] = 'Missing pads';
|
||||
}
|
||||
|
||||
$processedPadKeys = [];
|
||||
foreach ($tdf->pads as $pad) {
|
||||
$failures = array_merge($failures, $this->validatePad($pad));
|
||||
|
||||
if ($pad->key !== null && in_array($pad->key, $processedPadKeys)) {
|
||||
$failures[] = 'Duplicate pad key ("' . $pad->key . '") detected';
|
||||
}
|
||||
|
||||
$processedPadKeys[] = $pad->key;
|
||||
}
|
||||
|
||||
if (empty($tdf->pinouts)) {
|
||||
$failures[] = 'Missing pinouts';
|
||||
|
||||
@@ -128,7 +144,7 @@ class ValidationService
|
||||
|
||||
$processedPinoutKeys = [];
|
||||
foreach ($tdf->pinouts as $pinout) {
|
||||
$failures = array_merge($failures, $this->validatePinout($pinout));
|
||||
$failures = array_merge($failures, $this->validatePinout($pinout, $tdf));
|
||||
|
||||
if ($pinout->key !== null && in_array($pinout->key, $processedPinoutKeys)) {
|
||||
$failures[] = 'Duplicate pinout key ("' . $pinout->key . '") detected';
|
||||
@@ -137,15 +153,15 @@ class ValidationService
|
||||
$processedPinoutKeys[] = $pinout->key;
|
||||
}
|
||||
|
||||
$processedVariantNames = [];
|
||||
$processedVariantKeys = [];
|
||||
foreach ($tdf->variants as $variant) {
|
||||
$failures = array_merge($failures, $this->validateVariant($variant, $tdf));
|
||||
|
||||
if ($variant->name !== null && in_array($variant->name, $processedVariantNames)) {
|
||||
$failures[] = 'Duplicate variant name ("' . $variant->name . '") detected';
|
||||
if ($variant->key !== null && in_array($variant->key, $processedVariantKeys)) {
|
||||
$failures[] = 'Duplicate variant key ("' . $variant->key . '") detected';
|
||||
}
|
||||
|
||||
$processedVariantNames[] = $variant->name;
|
||||
$processedVariantKeys[] = $variant->key;
|
||||
}
|
||||
|
||||
// Validate resolved peripherals
|
||||
@@ -699,7 +715,7 @@ class ValidationService
|
||||
}
|
||||
|
||||
foreach ($peripheral->signals as $signal) {
|
||||
$failures = array_merge($failures, $this->validateSignal($signal));
|
||||
$failures = array_merge($failures, $this->validateSignal($signal, $tdf));
|
||||
}
|
||||
|
||||
return array_map(
|
||||
@@ -750,12 +766,15 @@ class ValidationService
|
||||
);
|
||||
}
|
||||
|
||||
protected function validateSignal(Signal $signal): array
|
||||
protected function validateSignal(Signal $signal, TargetDescriptionFile $tdf): array
|
||||
{
|
||||
$failures = [];
|
||||
|
||||
if (empty($signal->padId)) {
|
||||
$failures[] = 'Missing pad ID';
|
||||
if (empty($signal->padKey)) {
|
||||
$failures[] = 'Missing pad key';
|
||||
|
||||
} elseif ($tdf->getPad($signal->padKey) === null) {
|
||||
$failures[] = 'Failed to resolve pad key "' . $signal->padKey . '"';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
@@ -764,7 +783,28 @@ class ValidationService
|
||||
);
|
||||
}
|
||||
|
||||
protected function validatePinout(Pinout $pinout): array
|
||||
protected function validatePad(Pad $pad): array
|
||||
{
|
||||
$failures = [];
|
||||
|
||||
if (empty($pad->key)) {
|
||||
$failures[] = 'Missing key';
|
||||
|
||||
} else {
|
||||
$failures = array_merge($failures, $this->validateKey($pad->key));
|
||||
}
|
||||
|
||||
if (empty($pad->name)) {
|
||||
$failures[] = 'Missing name';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
fn (string $failure): string => 'Pad validation failure: ' . $failure,
|
||||
$failures
|
||||
);
|
||||
}
|
||||
|
||||
protected function validatePinout(Pinout $pinout, TargetDescriptionFile $tdf): array
|
||||
{
|
||||
$failures = [];
|
||||
|
||||
@@ -806,7 +846,7 @@ class ValidationService
|
||||
|
||||
$processedPositions = [];
|
||||
foreach ($pinout->pins as $pin) {
|
||||
$failures = array_merge($failures, $this->validatePin($pin, $pinout));
|
||||
$failures = array_merge($failures, $this->validatePin($pin, $pinout, $tdf));
|
||||
|
||||
if ($pin->position !== null && in_array($pin->position, $processedPositions)) {
|
||||
$failures[] = 'Duplicate pin position (' . $pin->position . ') detected';
|
||||
@@ -821,7 +861,7 @@ class ValidationService
|
||||
);
|
||||
}
|
||||
|
||||
protected function validatePin(Pin $pin, Pinout $pinout): array
|
||||
protected function validatePin(Pin $pin, Pinout $pinout, TargetDescriptionFile $tdf): array
|
||||
{
|
||||
$failures = [];
|
||||
|
||||
@@ -839,12 +879,12 @@ class ValidationService
|
||||
. $pin->position . '")';
|
||||
}
|
||||
|
||||
if (empty($pin->pad)) {
|
||||
$failures[] = 'Missing pad';
|
||||
if (!empty($pin->padKey) && $tdf->getPad($pin->padKey) === null) {
|
||||
$failures[] = 'Failed to resolve pad key "' . $pin->padKey . '"';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
fn (string $failure): string => 'Pin validation failure: ' . $failure,
|
||||
fn (string $failure): string => 'Pin "' . $pin->position . '" validation failure: ' . $failure,
|
||||
$failures
|
||||
);
|
||||
}
|
||||
@@ -853,6 +893,13 @@ class ValidationService
|
||||
{
|
||||
$failures = [];
|
||||
|
||||
if (empty($variant->key)) {
|
||||
$failures[] = 'Missing key';
|
||||
|
||||
} else {
|
||||
$failures = array_merge($failures, $this->validateKey($variant->key));
|
||||
}
|
||||
|
||||
if (empty($variant->name)) {
|
||||
$failures[] = 'Missing name';
|
||||
}
|
||||
@@ -865,10 +912,6 @@ class ValidationService
|
||||
. '" - check pinout key';
|
||||
}
|
||||
|
||||
if (empty($variant->package)) {
|
||||
$failures[] = 'Missing package';
|
||||
}
|
||||
|
||||
return array_map(
|
||||
fn (string $failure): string => 'Variant "' . $variant->name . '" validation failure: ' . $failure,
|
||||
$failures
|
||||
|
||||
@@ -5,6 +5,7 @@ use DOMDocument;
|
||||
use DOMNode;
|
||||
use DOMNodeList;
|
||||
use DOMElement;
|
||||
use Targets\TargetDescriptionFiles\Pad;
|
||||
use Targets\TargetDescriptionFiles\Services\StringService;
|
||||
use Targets\TargetDescriptionFiles\Services\Xml\Exceptions\XmlParsingException;
|
||||
use Targets\TargetDescriptionFiles\AddressSpace;
|
||||
@@ -370,7 +371,7 @@ class FromXmlService
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
return new Signal(
|
||||
$attributes['pad-id'] ?? null,
|
||||
$attributes['pad-key'] ?? null,
|
||||
$this->stringService->tryStringToInt($attributes['index'] ?? null),
|
||||
$attributes['function'] ?? null,
|
||||
$attributes['group'] ?? null,
|
||||
@@ -378,6 +379,16 @@ class FromXmlService
|
||||
);
|
||||
}
|
||||
|
||||
public function padFromElement(DOMElement $element): Pad
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
return new Pad(
|
||||
$attributes['key'] ?? null,
|
||||
$attributes['name'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public function pinoutFromElement(DOMElement $element): Pinout
|
||||
{
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
@@ -409,7 +420,7 @@ class FromXmlService
|
||||
|
||||
return new Pin(
|
||||
$attributes['position'] ?? null,
|
||||
$attributes['pad'] ?? null
|
||||
$attributes['pad-key'] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
@@ -418,9 +429,9 @@ class FromXmlService
|
||||
$attributes = $this->getNodeAttributesByName($element);
|
||||
|
||||
return new Variant(
|
||||
$attributes['key'] ?? null,
|
||||
$attributes['name'] ?? null,
|
||||
$attributes['pinout-key'] ?? null,
|
||||
$attributes['package'] ?? null
|
||||
$attributes['pinout-key'] ?? null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Targets\TargetDescriptionFiles\BitField;
|
||||
use Targets\TargetDescriptionFiles\MemorySegment;
|
||||
use Targets\TargetDescriptionFiles\MemorySegmentSection;
|
||||
use Targets\TargetDescriptionFiles\Module;
|
||||
use Targets\TargetDescriptionFiles\Pad;
|
||||
use Targets\TargetDescriptionFiles\Peripheral;
|
||||
use Targets\TargetDescriptionFiles\RegisterGroupInstance;
|
||||
use Targets\TargetDescriptionFiles\PhysicalInterface;
|
||||
@@ -185,7 +186,7 @@ class ToXmlService
|
||||
public function signalToXml(Signal $signal, DOMDocument $document): DOMElement
|
||||
{
|
||||
$element = $document->createElement('signal');
|
||||
$element->setAttribute('pad-id', $signal->padId);
|
||||
$element->setAttribute('pad-key', $signal->padKey);
|
||||
|
||||
if ($signal->index !== null) {
|
||||
$element->setAttribute('index', $signal->index);
|
||||
@@ -349,6 +350,15 @@ class ToXmlService
|
||||
return $element;
|
||||
}
|
||||
|
||||
public function padToXml(Pad $pad, DOMDocument $document): DOMElement
|
||||
{
|
||||
$element = $document->createElement('pad');
|
||||
$element->setAttribute('key', $pad->key);
|
||||
$element->setAttribute('name', $pad->name);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
public function pinoutToXml(Pinout $pinout, DOMDocument $document): DOMElement
|
||||
{
|
||||
$element = $document->createElement('pinout');
|
||||
@@ -371,7 +381,10 @@ class ToXmlService
|
||||
{
|
||||
$element = $document->createElement('pin');
|
||||
$element->setAttribute('position', $pin->position);
|
||||
$element->setAttribute('pad', $pin->pad);
|
||||
|
||||
if (!empty($pin->padKey)) {
|
||||
$element->setAttribute('pad-key', $pin->padKey);
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
@@ -379,9 +392,9 @@ class ToXmlService
|
||||
public function variantToXml(Variant $variant, DOMDocument $document): DOMElement
|
||||
{
|
||||
$element = $document->createElement('variant');
|
||||
$element->setAttribute('key', $variant->key);
|
||||
$element->setAttribute('name', $variant->name);
|
||||
$element->setAttribute('pinout-key', $variant->pinoutKey);
|
||||
$element->setAttribute('package', $variant->package);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,14 @@ class XmlService
|
||||
$tdf->modules[] = $this->fromXmlService->moduleFromElement($element);
|
||||
}
|
||||
|
||||
$padElements = $this->fromXmlService->getDeviceElementsFromXPath(
|
||||
'pads/pad',
|
||||
$document
|
||||
);
|
||||
foreach ($padElements as $element) {
|
||||
$tdf->pads[] = $this->fromXmlService->padFromElement($element);
|
||||
}
|
||||
|
||||
$pinoutElements = $this->fromXmlService->getDeviceElementsFromXPath(
|
||||
'pinouts/pinout',
|
||||
$document
|
||||
@@ -186,6 +194,13 @@ class XmlService
|
||||
|
||||
$deviceElement->append($modulesElement);
|
||||
|
||||
$padsElement = $document->createElement('pads');
|
||||
foreach ($tdf->pads as $pad) {
|
||||
$padsElement->append($this->toXmlService->padToXml($pad, $document));
|
||||
}
|
||||
|
||||
$deviceElement->append($padsElement);
|
||||
|
||||
$pinoutsElement = $document->createElement('pinouts');
|
||||
foreach ($tdf->pinouts as $pinout) {
|
||||
$pinoutsElement->append($this->toXmlService->pinoutToXml($pinout, $document));
|
||||
|
||||
@@ -3,20 +3,20 @@ namespace Targets\TargetDescriptionFiles;
|
||||
|
||||
class Signal
|
||||
{
|
||||
public ?string $padId = null;
|
||||
public ?string $padKey = null;
|
||||
public ?int $index = null;
|
||||
public ?string $function = null;
|
||||
public ?string $group = null;
|
||||
public ?string $field = null;
|
||||
|
||||
public function __construct(
|
||||
?string $padId,
|
||||
?string $padKey,
|
||||
?int $index,
|
||||
?string $function,
|
||||
?string $group,
|
||||
?string $field
|
||||
) {
|
||||
$this->padId = $padId;
|
||||
$this->padKey = $padKey;
|
||||
$this->index = $index;
|
||||
$this->function = $function;
|
||||
$this->group = $group;
|
||||
|
||||
@@ -17,6 +17,7 @@ require_once __DIR__ . "/Module.php";
|
||||
require_once __DIR__ . "/RegisterGroup.php";
|
||||
require_once __DIR__ . "/RegisterGroupReference.php";
|
||||
require_once __DIR__ . "/Register.php";
|
||||
require_once __DIR__ . "/Pad.php";
|
||||
require_once __DIR__ . "/Pinout.php";
|
||||
require_once __DIR__ . "/Variant.php";
|
||||
require_once __DIR__ . "/TargetFamily.php";
|
||||
@@ -47,6 +48,9 @@ class TargetDescriptionFile
|
||||
/** @var Module[] */
|
||||
public array $modules = [];
|
||||
|
||||
/** @var Pad[] */
|
||||
public array $pads = [];
|
||||
|
||||
/** @var Pinout[] */
|
||||
public array $pinouts = [];
|
||||
|
||||
@@ -236,6 +240,17 @@ class TargetDescriptionFile
|
||||
$module->key = $newKey;
|
||||
}
|
||||
|
||||
public function getPad(string $key): ?Pad
|
||||
{
|
||||
foreach ($this->pads as $pad) {
|
||||
if ($pad->key === $key) {
|
||||
return $pad;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getPinout(string $key): ?Pinout
|
||||
{
|
||||
foreach ($this->pinouts as $pinout) {
|
||||
|
||||
@@ -3,14 +3,14 @@ namespace Targets\TargetDescriptionFiles;
|
||||
|
||||
class Variant
|
||||
{
|
||||
public ?string $key = null;
|
||||
public ?string $name = null;
|
||||
public ?string $pinoutKey = null;
|
||||
public ?string $package = null;
|
||||
|
||||
public function __construct(?string $name, ?string $pinoutKey, ?string $package)
|
||||
public function __construct(?string $key, ?string $name, ?string $pinoutKey)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->name = $name;
|
||||
$this->pinoutKey = $pinoutKey;
|
||||
$this->package = $package;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user