Skip to content

Commit 963c817

Browse files
grasci-armedrioukbrondani
authored
Add methods to get devices and boards (#1277) (#2164)
* Added GetDeviceList and GetDeviceData methods and corresponding structures * Unit Tests and corrections * Use id string * Board data * Tests and fixes * Update `csolution-rpc` version * add #include <list> --------- Co-authored-by: Daniel Brondani <[email protected]> --------- Co-authored-by: Evgueni Driouk <[email protected]> Co-authored-by: Daniel Brondani <[email protected]>
1 parent 8b49f0e commit 963c817

File tree

15 files changed

+681
-145
lines changed

15 files changed

+681
-145
lines changed

libs/rtemodel/include/RteDevice.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ class RteDeviceItem : public RteDeviceElement
10541054
* @brief get list of all effective properties for given tag and processor name
10551055
* @param tag property tag
10561056
* @param pName processor name
1057-
* @return list of RteDeviceProperty pointers
1057+
* @return reference to the list of RteDeviceProperty pointers
10581058
*/
10591059
const std::list<RteDeviceProperty*>& GetEffectiveProperties(const std::string& tag, const std::string& pName);
10601060

@@ -1066,6 +1066,13 @@ class RteDeviceItem : public RteDeviceElement
10661066
*/
10671067
RteDeviceProperty* GetSingleEffectiveProperty(const std::string& tag, const std::string& pName);
10681068

1069+
/**
1070+
* @brief return list of all effective memory properties for all processors
1071+
* @param tag property tag
1072+
* @return list of RteDeviceProperty* pointers
1073+
*/
1074+
std::list<RteDeviceProperty*> GetAllEffectiveProperties(const std::string& tag);
1075+
10691076
/**
10701077
* @brief get list of immediate RteDeviceItem children
10711078
* @return list to RteDeviceItem pointers
@@ -1429,7 +1436,7 @@ class RteDeviceItemAggregate
14291436
bool IsDeprecated() const { return m_bDeprecated; }
14301437

14311438
private:
1432-
static std::string GetMemorySizeString(unsigned int size);
1439+
static std::string GetMemorySizeString(unsigned long long size);
14331440
static std::string GetScaledClockFrequency(const std::string& dclock);
14341441

14351442
std::string m_name;

libs/rtemodel/include/RteItem.h

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,41 +750,53 @@ class RteItem : public XmlTreeItem<RteItem>
750750
* @return value of memory attribute "access"
751751
*/
752752
virtual const std::string& GetAccess() const { return GetAttribute("access"); }
753+
754+
/**
755+
* @brief return a string of memory access permissions
756+
* @return value of memory attribute "access" or construct it
757+
*/
758+
virtual std::string GetAccessPermissions() const;
759+
760+
/**
761+
* @brief return a string of memory access attributes permissions
762+
* @return pair of strings with access permissions (rwx) and attributes (psnc)
763+
*/
764+
virtual std::pair<std::string, std::string> GetAccessAttributes() const;
753765
/**
754766
* @brief check for memory read access
755767
* @return true if read access specified
756768
*/
757-
virtual bool IsReadAccess();
769+
virtual bool IsReadAccess() const;
758770
/**
759771
* @brief check for memory write access
760772
* @return true if write access specified
761773
*/
762-
virtual bool IsWriteAccess();
774+
virtual bool IsWriteAccess() const;
763775
/**
764776
* @brief check for memory executable access
765777
* @return true if executable access specified
766778
*/
767-
virtual bool IsExecuteAccess();
779+
virtual bool IsExecuteAccess() const;
768780
/**
769781
* @brief check for memory secure access
770782
* @return true if secure access specified
771783
*/
772-
virtual bool IsSecureAccess();
784+
virtual bool IsSecureAccess() const;
773785
/**
774786
* @brief check for memory non-secure access
775787
* @return true if non-secure access specified
776788
*/
777-
virtual bool IsNonSecureAccess();
789+
virtual bool IsNonSecureAccess() const;
778790
/**
779791
* @brief check for memory callable access
780792
* @return true if callable access specified
781793
*/
782-
virtual bool IsCallableAccess();
794+
virtual bool IsCallableAccess() const;
783795
/**
784796
* @brief check for memory peripheral area
785797
* @return true if memory peripheral area specified
786798
*/
787-
virtual bool IsPeripheralAccess();
799+
virtual bool IsPeripheralAccess() const;
788800

789801
/**
790802
* @brief get RteCondition associated with the item

libs/rtemodel/include/RteTarget.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,6 @@ class RteTarget : public RteItem
596596
void FilterComponents();
597597
std::string GenerateRegionsHeaderContent() const;
598598
std::string GenerateMemoryRegionContent(const std::vector<RteItem*> memVec, const std::string& id, const std::string& dfp) const;
599-
std::pair<std::string, std::string> GetAccessAttributes(RteItem* mem) const;
600599
bool GenerateRTEComponentsH();
601600
bool GenerateRteHeaderFile(const std::string& headerName, const std::string& content,
602601
bool bRegionsHeader = false, const std::string& directory = EMPTY_STRING);

libs/rtemodel/src/RteDevice.cpp

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "XMLTree.h"
2121

22+
#include <algorithm>
23+
2224
using namespace std;
2325

2426
static const list<RteDeviceProperty*> EMPTY_PROPERTY_LIST;
@@ -813,6 +815,23 @@ RteDeviceProperty* RteDeviceItem::GetSingleEffectiveProperty(const string& tag,
813815
return nullptr;
814816
}
815817

818+
std::list<RteDeviceProperty*> RteDeviceItem::GetAllEffectiveProperties(const std::string& tag)
819+
{
820+
// Make a copy, simpler to merge with potential processor specific memories
821+
list<RteDeviceProperty*> properties = GetEffectiveProperties(tag, RteUtils::EMPTY_STRING);
822+
// Iterate over processors
823+
for(auto [pname, _] : GetProcessors()) {
824+
// Collect processor - unique memories
825+
const list<RteDeviceProperty*>& procProps = GetEffectiveProperties(tag, pname);
826+
for(auto p : procProps) {
827+
if(std::find(properties.begin(), properties.end(), p) == properties.end()) {
828+
properties.push_back(p);
829+
}
830+
}
831+
}
832+
return properties;
833+
}
834+
816835

817836
void RteDeviceItem::GetEffectiveFilterAttributes(const string& pName, XmlItem& attributes)
818837
{
@@ -1175,9 +1194,6 @@ string RteDeviceItemAggregate::GetSummaryString() const
11751194
list<RteDeviceProperty*> processors;
11761195
item->GetEffectiveProcessors(processors);
11771196

1178-
// Make a copy, simpler to merge with potential processor specific memories
1179-
list<RteDeviceProperty*> mems = item->GetEffectiveProperties("memory", RteUtils::EMPTY_STRING);
1180-
11811197
// Iterate over processors
11821198
for (auto it = processors.begin(); it != processors.end(); ++it) {
11831199
procProperties = *it;
@@ -1205,39 +1221,21 @@ string RteDeviceItemAggregate::GetSummaryString() const
12051221
}
12061222
summary += GetScaledClockFrequency(dclock);
12071223
}
1208-
1209-
// Collect unique memory attributes
1210-
const list<RteDeviceProperty*>& procMems = item->GetEffectiveProperties("memory", procProperties->GetAttribute("Pname"));
1211-
list<RteDeviceProperty*> addMems;
1212-
for (auto procMemIt = procMems.begin(); procMemIt != procMems.end(); ++procMemIt) {
1213-
auto memsIt = mems.begin();
1214-
for (; memsIt != mems.end(); ++memsIt) {
1215-
if ((*memsIt) == (*procMemIt)) {
1216-
break;
1217-
}
1218-
}
1219-
if (memsIt == mems.end()) {
1220-
addMems.push_back(*procMemIt);
1221-
}
1222-
}
1223-
1224-
if (!addMems.empty()) {
1225-
mems.insert(mems.end(), addMems.begin(), addMems.end());
1226-
}
12271224
}
12281225

12291226
// Memory (RAM/ROM)
1230-
unsigned int ramSize = 0, romSize = 0;
1231-
1227+
unsigned long long ramSize = 0, romSize = 0;
1228+
// Get all memory properties
1229+
list<RteDeviceProperty*> mems = item->GetAllEffectiveProperties("memory");
12321230
for (auto memsIt = mems.begin(); memsIt != mems.end(); ++memsIt) {
12331231
RteDeviceMemory* mem = dynamic_cast<RteDeviceMemory*>(*memsIt);
12341232
if (!mem) {
12351233
continue;
12361234
}
12371235
if (mem->IsWriteAccess()) {
1238-
ramSize += mem->GetAttributeAsUnsigned("size");
1236+
ramSize += mem->GetAttributeAsULL("size");
12391237
} else if (mem->IsReadAccess()) {
1240-
romSize += mem->GetAttributeAsUnsigned("size");
1238+
romSize += mem->GetAttributeAsULL("size");
12411239
}
12421240
}
12431241

@@ -1258,24 +1256,24 @@ string RteDeviceItemAggregate::GetSummaryString() const
12581256
return summary;
12591257
}
12601258

1261-
string RteDeviceItemAggregate::GetMemorySizeString(unsigned int size)
1259+
string RteDeviceItemAggregate::GetMemorySizeString(unsigned long long size)
12621260
{
12631261
if (size == 0) {
12641262
return RteUtils::EMPTY_STRING;
12651263
}
12661264

12671265
if (size < 1024) {
1268-
return (to_string((unsigned long long)size) + " Byte");
1266+
return (to_string(size) + " Byte");
12691267
}
12701268

12711269
size >>= 10; // Scale to kByte
12721270
if (size < 1024 || size % 1024) {
12731271
// Less than a MByte or division with rest => show kByte
1274-
return (to_string((unsigned long long)size) + " kB");
1272+
return (to_string(size) + " KiB");
12751273
}
12761274

12771275
size >>= 10; // Scale to MByte
1278-
return (to_string((unsigned long long)size) + " MB");
1276+
return (to_string(size) + " MiB");
12791277
}
12801278

12811279
string RteDeviceItemAggregate::GetScaledClockFrequency(const string& dclock)

libs/rtemodel/src/RteItem.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,31 @@ string RteItem::GetDocFile() const
762762
return EMPTY_STRING;
763763
}
764764

765-
bool RteItem::IsReadAccess()
765+
766+
string RteItem::GetAccessPermissions() const
767+
{
768+
string access = GetAccess();
769+
if (access.empty()) {
770+
access = string(IsReadAccess() ? "r" : "") + (IsWriteAccess() ? "w" : "") + (IsExecuteAccess() ? "x" : "");
771+
}
772+
return access;
773+
}
774+
775+
std::pair<std::string, std::string> RteItem::GetAccessAttributes() const
776+
{
777+
return {
778+
string(IsReadAccess() ? "r" : "") +
779+
(IsWriteAccess() ? "w" : "") +
780+
(IsExecuteAccess() ? "x" : ""),
781+
string(IsPeripheralAccess() ? "p" : "") +
782+
(IsSecureAccess() ? "s" : "") +
783+
(IsNonSecureAccess() ? "n" : "") +
784+
(IsCallableAccess() ? "c" : "")
785+
};
786+
}
787+
788+
789+
bool RteItem::IsReadAccess() const
766790
{
767791
if (HasAttribute("id")) {
768792
return true;
@@ -771,7 +795,7 @@ bool RteItem::IsReadAccess()
771795
return access.empty() || access.find('r') != string::npos;
772796
}
773797

774-
bool RteItem::IsWriteAccess()
798+
bool RteItem::IsWriteAccess() const
775799
{
776800
const string& id = GetAttribute("id");
777801
if (!id.empty()) {
@@ -781,7 +805,7 @@ bool RteItem::IsWriteAccess()
781805
return access.find('w') != string::npos;
782806
}
783807

784-
bool RteItem::IsExecuteAccess()
808+
bool RteItem::IsExecuteAccess() const
785809
{
786810
const string& id = GetAttribute("id");
787811
if (!id.empty()) {
@@ -791,15 +815,15 @@ bool RteItem::IsExecuteAccess()
791815
return access.find('x') != string::npos;
792816
}
793817

794-
bool RteItem::IsSecureAccess()
818+
bool RteItem::IsSecureAccess() const
795819
{
796820
if (HasAttribute("id")) {
797821
return true;
798822
}
799823
const string& access = GetAccess();
800824
return access.find('s') != string::npos && access.find('n') == string::npos;
801825
}
802-
bool RteItem::IsNonSecureAccess()
826+
bool RteItem::IsNonSecureAccess() const
803827
{
804828
if (HasAttribute("id")) {
805829
return false;
@@ -808,7 +832,7 @@ bool RteItem::IsNonSecureAccess()
808832
return access.find('n') != string::npos && access.find('s') == string::npos;
809833
}
810834

811-
bool RteItem::IsCallableAccess()
835+
bool RteItem::IsCallableAccess() const
812836
{
813837
if (HasAttribute("id")) {
814838
return false;
@@ -817,7 +841,7 @@ bool RteItem::IsCallableAccess()
817841
return access.find('c') != string::npos;
818842
}
819843

820-
bool RteItem::IsPeripheralAccess()
844+
bool RteItem::IsPeripheralAccess() const
821845
{
822846
if (HasAttribute("id")) {
823847
return false;

libs/rtemodel/src/RteTarget.cpp

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,26 +1750,13 @@ std::string RteTarget::GetRegionsHeader() const
17501750
return GetDeviceFolder() + "/regions_" + filename + ".h";
17511751
}
17521752

1753-
std::pair<std::string, std::string> RteTarget::GetAccessAttributes(RteItem* mem) const
1754-
{
1755-
return {
1756-
string(mem->IsReadAccess() ? "r" : "") +
1757-
(mem->IsWriteAccess() ? "w" : "") +
1758-
(mem->IsExecuteAccess() ? "x" : ""),
1759-
string(mem->IsPeripheralAccess() ? "p" : "") +
1760-
(mem->IsSecureAccess() ? "s" : "") +
1761-
(mem->IsNonSecureAccess() ? "n" : "") +
1762-
(mem->IsCallableAccess() ? "c" : "")
1763-
};
1764-
}
1765-
17661753
std::string RteTarget::GenerateMemoryRegionContent(const std::vector<RteItem*> memVec, const std::string& id, const std::string& dfp) const
17671754
{
17681755
string pack, access, name, start, size;
17691756
bool unused = memVec.empty();
17701757
if (!unused) {
17711758
pack = memVec.front()->GetPackageID() == dfp ? "DFP" : "BSP";
1772-
access = GetAccessAttributes(memVec.front()).first;
1759+
access = memVec.front()->GetAccessPermissions();
17731760
for (const auto& mem : memVec) {
17741761
name += (mem == memVec.front() ? "" : "+") + mem->GetName();
17751762
}
@@ -1860,7 +1847,7 @@ std::string RteTarget::GenerateRegionsHeaderContent() const
18601847
} else {
18611848
// search contiguous memory region (same pack, same access)
18621849
if ((mem->GetPackageID() == alloc.back()->GetPackageID()) &&
1863-
GetAccessAttributes(mem) == GetAccessAttributes(alloc.back()) &&
1850+
mem->GetAccessAttributes() == alloc.back()->GetAccessAttributes() &&
18641851
stoul(mem->GetAttribute("start"), nullptr, 16) == stoul(alloc.back()->GetAttribute("start"), nullptr, 16) +
18651852
stoul(alloc.back()->GetAttribute("size"), nullptr, 16)) {
18661853
alloc.push_back(mem);
@@ -1924,7 +1911,7 @@ std::string RteTarget::GenerateRegionsHeaderContent() const
19241911
}
19251912
for (const auto& mem : notAllocated) {
19261913
oss << "// <i> ";
1927-
oss << left << setw(10) << GetAccessAttributes(mem).first + (mem->IsWriteAccess() ? " RAM:" : " ROM:");
1914+
oss << left << setw(10) << mem->GetAccessPermissions() + (mem->IsWriteAccess() ? " RAM:" : " ROM:");
19281915
oss << left << setw(maxNameLength + 12) << mem->GetName() + " from" + (mem->GetPackageID() == device->GetPackageID() ? " DFP:" : " BSP:");
19291916
oss << "BASE: " << mem->GetAttribute("start") << " SIZE: " << mem->GetAttribute("size");
19301917
oss << (mem->GetProcessorName().empty() ? "" : " Pname: " + mem->GetProcessorName()) << RteUtils::LF_STRING;

libs/rtemodel/test/src/RteModelTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ TEST(RteModelTest, LoadPacks) {
150150
ASSERT_NE(da, nullptr);
151151
// test deprecated memory attributes: IROM and IRAM
152152
string summary = da->GetSummaryString();
153-
EXPECT_EQ(summary, "ARM Cortex-M3, 10 MHz, 128 kB RAM, 256 kB ROM");
153+
EXPECT_EQ(summary, "ARM Cortex-M3, 10 MHz, 128 KiB RAM, 256 KiB ROM");
154154

155155
da = rteModel->GetDeviceAggregate("RteTest_ARMCM4", "ARM:82");
156156
ASSERT_NE(da, nullptr);
157157
// test recommended memory attributes: name and access
158158
summary = da->GetSummaryString();
159-
EXPECT_EQ(summary, "ARM Cortex-M4, 10 MHz, 128 kB RAM, 256 kB ROM");
159+
EXPECT_EQ(summary, "ARM Cortex-M4, 10 MHz, 128 KiB RAM, 256 KiB ROM");
160160

161161
RteBoard* board = rteModel->FindBoard("RteTest board listing (Rev.C)");
162162
ASSERT_NE(board, nullptr);

libs/rteutils/include/RteConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class RteConstants
189189
static constexpr const char* RTE_SECURE_ONLY = "Secure-only";
190190
static constexpr const char* RTE_NON_SECURE = "Non-secure";
191191
static constexpr const char* RTE_TZ_DISABLED = "TZ-disabled";
192+
static constexpr const char* RTE_TZ = "TZ";
192193
static constexpr const char* RTE_NO_TZ = "NO_TZ";
193194
static constexpr const char* RTE_BTI = "BTI";
194195
static constexpr const char* RTE_BTI_SIGNRET = "BTI_SIGNRET";

tools/projmgr/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ include(FetchContent)
1717
FetchContent_Declare(
1818
rpc-interface
1919
DOWNLOAD_EXTRACT_TIMESTAMP ON
20-
URL https://github.com/Open-CMSIS-Pack/csolution-rpc/releases/download/v0.0.2/csolution-rpc.zip
21-
URL_HASH SHA256=bc00342a240d2fded19981524bb286c91541504d4271e936f68c646a8b62908f
20+
URL https://github.com/Open-CMSIS-Pack/csolution-rpc/releases/download/v0.0.3/csolution-rpc.zip
21+
URL_HASH SHA256=edc762373b3b7dad5b966ecb271f03866b12841675e0967a809c10c9883f29f4
2222
)
2323
FetchContent_MakeAvailable(rpc-interface)
2424

0 commit comments

Comments
 (0)