Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Split core make into multiple functions #791

Merged
merged 8 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fpga/include/villas/fpga/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ class CoreFactory : public plugin::Plugin {
public:
using plugin::Plugin::Plugin;

static std::list<IpIdentifier> parseIpIdentifier(json_t *json_ips);
static std::list<IpIdentifier> reorderIps(std::list<IpIdentifier> allIps);
static std::list<std::shared_ptr<Core>>
configureIps(std::list<IpIdentifier> orderedIps, json_t *json_ips,
Card *card);
static void initIps(std::list<std::shared_ptr<Core>> orderedIps, Card *card);

// Returns a running and checked FPGA IP
static std::list<std::shared_ptr<Core>> make(Card *card, json_t *json_ips);

Expand Down
61 changes: 46 additions & 15 deletions fpga/lib/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,10 @@ static std::list<Vlnv> vlnvInitializationOrder = {
Vlnv("xilinx.com:ip:axi_iic:"),
};

std::list<std::shared_ptr<Core>> CoreFactory::make(Card *card,
json_t *json_ips) {
// We only have this logger until we know the factory to build an IP with
auto loggerStatic = getStaticLogger();

std::list<IpIdentifier> allIps; // All IPs available in config
std::list<IpIdentifier> orderedIps; // IPs ordered in initialization order

std::list<std::shared_ptr<Core>> configuredIps; // Successfully configured IPs

if (!card->ips.empty()) {
loggerStatic->error("IP list of card {} already contains IPs.", card->name);
throw RuntimeError("IP list of card {} already contains IPs.", card->name);
}
std::list<IpIdentifier> CoreFactory::parseIpIdentifier(json_t *json_ips) {
// Parse all IP instance names and their VLNV into list `allIps`
std::list<IpIdentifier> allIps;

const char *ipName;
json_t *json_ip;
json_object_foreach(json_ips, ipName, json_ip) {
Expand All @@ -64,9 +53,14 @@ std::list<std::shared_ptr<Core>> CoreFactory::make(Card *card,

allIps.push_back({vlnv, ipName});
}
return allIps;
}

std::list<IpIdentifier>
CoreFactory::reorderIps(std::list<IpIdentifier> allIps) {
IgnoreWarnings marked this conversation as resolved.
Show resolved Hide resolved
// Pick out IPs to be initialized first.
//
std::list<IpIdentifier> orderedIps;

// Reverse walktrough, because we push to the
// front of the output list, so that the first element will also be the
// first to be initialized.
Expand All @@ -84,11 +78,20 @@ std::list<std::shared_ptr<Core>> CoreFactory::make(Card *card,
// Insert all other IPs at the end
orderedIps.splice(orderedIps.end(), allIps);

auto loggerStatic = CoreFactory::getStaticLogger();
loggerStatic->debug("IP initialization order:");
for (auto &id : orderedIps) {
loggerStatic->debug(" " CLR_BLD("{}"), id.getName());
}

return orderedIps;
}

std::list<std::shared_ptr<Core>>
CoreFactory::configureIps(std::list<IpIdentifier> orderedIps, json_t *json_ips,
Card *card) {
std::list<std::shared_ptr<Core>> configuredIps;
auto loggerStatic = CoreFactory::getStaticLogger();
// Configure all IPs
for (auto &id : orderedIps) {
loggerStatic->info("Configuring {}", id);
Expand Down Expand Up @@ -237,6 +240,12 @@ std::list<std::shared_ptr<Core>> CoreFactory::make(Card *card,
configuredIps.push_back(std::move(ip));
}

return configuredIps;
}

void CoreFactory::initIps(std::list<std::shared_ptr<Core>> configuredIps,
Card *card) {
auto loggerStatic = CoreFactory::getStaticLogger();
// Start and check IPs now
for (auto &ip : configuredIps) {
loggerStatic->info("Initializing {}", *ip);
Expand Down Expand Up @@ -280,6 +289,28 @@ std::list<std::shared_ptr<Core>> CoreFactory::make(Card *card,
for (auto &ip : card->ips) {
loggerStatic->debug(" {}", *ip);
}
}

std::list<std::shared_ptr<Core>> CoreFactory::make(Card *card,
json_t *json_ips) {
// We only have this logger until we know the factory to build an IP with
auto loggerStatic = getStaticLogger();

if (!card->ips.empty()) {
loggerStatic->error("IP list of card {} already contains IPs.", card->name);
throw RuntimeError("IP list of card {} already contains IPs.", card->name);
}

std::list<IpIdentifier> allIps =
parseIpIdentifier(json_ips); // All IPs available in config

std::list<IpIdentifier> orderedIps =
reorderIps(allIps); // IPs ordered in initialization order

std::list<std::shared_ptr<Core>> configuredIps =
configureIps(orderedIps, json_ips, card); // Successfully configured IPs

initIps(configuredIps, card);

return card->ips;
}
Expand Down