Initial support to parse a Chip Data File
Change-Id: Ib5a7d8344922f8288c23f5bedd304e282dcfaada
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
diff --git a/src/chip_data/hei_chip_data.cpp b/src/chip_data/hei_chip_data.cpp
new file mode 100644
index 0000000..f10589d
--- /dev/null
+++ b/src/chip_data/hei_chip_data.cpp
@@ -0,0 +1,54 @@
+#include <chip_data/hei_chip_data.hpp>
+#include <chip_data/hei_chip_data_stream.hpp>
+
+namespace libhei
+{
+
+//------------------------------------------------------------------------------
+
+using FileKeyword_t = uint64_t;
+
+constexpr FileKeyword_t KW_CHIPDATA = 0x4348495044415441; // "CHIPDATA" ASCII
+
+using SectionKeyword_t = uint32_t;
+
+constexpr SectionKeyword_t KW_REGS = 0x43484950; // "REGS" ASCII
+constexpr SectionKeyword_t KW_NODE = 0x4e4f4445; // "NODE" ASCII
+constexpr SectionKeyword_t KW_ROOT = 0x524f4f54; // "ROOT" ASCII
+
+using Version_t = uint8_t;
+
+constexpr Version_t VERSION_1 = 0x01;
+
+//------------------------------------------------------------------------------
+
+void parseChipDataFile(void* i_buffer, size_t i_bufferSize,
+ IsolationChipMap& io_isoChips)
+{
+ ChipDataStream stream{i_buffer, i_bufferSize};
+
+ // Read the file metadata.
+ FileKeyword_t file_kw = 0;
+ ChipType_t chipType = 0;
+ Version_t version = 0;
+ stream >> file_kw >> chipType >> version;
+
+ // Check the file ID.
+ HEI_ASSERT(KW_CHIPDATA == file_kw);
+
+ // This chip type should not already exist.
+ HEI_ASSERT(io_isoChips.end() == io_isoChips.find(chipType));
+
+ // Allocate memory for the new isolation chip.
+ auto isoChip = std::make_unique<IsolationChip>(chipType);
+
+ // TODO
+
+ // Add this isolation chip to the collective list of isolation chips.
+ auto ret = io_isoChips.emplace(chipType, std::move(isoChip));
+ HEI_ASSERT(ret.second); // Just in case.
+}
+
+//------------------------------------------------------------------------------
+
+} // namespace libhei
diff --git a/src/chip_data/hei_chip_data.hpp b/src/chip_data/hei_chip_data.hpp
index 26cfb75..f35cdc1 100644
--- a/src/chip_data/hei_chip_data.hpp
+++ b/src/chip_data/hei_chip_data.hpp
@@ -1,6 +1,25 @@
#pragma once
-#include <hei_includes.hpp>
+#include <isolator/hei_isolation_chip.hpp>
namespace libhei
-{} // end namespace libhei
+{
+
+/**
+ * @brief Parses a buffer containing a Chip Data File and builds the necessary
+ * objects.
+ *
+ * This function will assert:
+ * - The buffer is a properly formated Chip Data File and contains valid data.
+ * - An IsolationChip object has not already been created for the chip type
+ * associated with the given buffer.
+ *
+ * @param i_buffer First address of the Chip Data File buffer.
+ * @param i_bufferSize Size of the Chip Data File buffer.
+ * @param io_isoChips This map will contain all current IsolationChip objects
+ * for each of the user applications chip types.
+ */
+void parseChipDataFile(void* i_buffer, size_t i_bufferSize,
+ IsolationChipMap& io_isoChips);
+
+} // end namespace libhei