Zane Shelley | dd69c96 | 2020-05-05 22:19:11 -0500 | [diff] [blame] | 1 | #include <chip_data/hei_chip_data.hpp> |
| 2 | #include <chip_data/hei_chip_data_stream.hpp> |
| 3 | |
| 4 | namespace libhei |
| 5 | { |
| 6 | |
| 7 | //------------------------------------------------------------------------------ |
| 8 | |
| 9 | using FileKeyword_t = uint64_t; |
| 10 | |
| 11 | constexpr FileKeyword_t KW_CHIPDATA = 0x4348495044415441; // "CHIPDATA" ASCII |
| 12 | |
| 13 | using SectionKeyword_t = uint32_t; |
| 14 | |
| 15 | constexpr SectionKeyword_t KW_REGS = 0x43484950; // "REGS" ASCII |
| 16 | constexpr SectionKeyword_t KW_NODE = 0x4e4f4445; // "NODE" ASCII |
| 17 | constexpr SectionKeyword_t KW_ROOT = 0x524f4f54; // "ROOT" ASCII |
| 18 | |
| 19 | using Version_t = uint8_t; |
| 20 | |
| 21 | constexpr Version_t VERSION_1 = 0x01; |
| 22 | |
| 23 | //------------------------------------------------------------------------------ |
| 24 | |
| 25 | void parseChipDataFile(void* i_buffer, size_t i_bufferSize, |
| 26 | IsolationChipMap& io_isoChips) |
| 27 | { |
| 28 | ChipDataStream stream{i_buffer, i_bufferSize}; |
| 29 | |
| 30 | // Read the file metadata. |
| 31 | FileKeyword_t file_kw = 0; |
| 32 | ChipType_t chipType = 0; |
| 33 | Version_t version = 0; |
| 34 | stream >> file_kw >> chipType >> version; |
| 35 | |
| 36 | // Check the file ID. |
| 37 | HEI_ASSERT(KW_CHIPDATA == file_kw); |
| 38 | |
| 39 | // This chip type should not already exist. |
| 40 | HEI_ASSERT(io_isoChips.end() == io_isoChips.find(chipType)); |
| 41 | |
| 42 | // Allocate memory for the new isolation chip. |
| 43 | auto isoChip = std::make_unique<IsolationChip>(chipType); |
| 44 | |
| 45 | // TODO |
| 46 | |
| 47 | // Add this isolation chip to the collective list of isolation chips. |
| 48 | auto ret = io_isoChips.emplace(chipType, std::move(isoChip)); |
| 49 | HEI_ASSERT(ret.second); // Just in case. |
| 50 | } |
| 51 | |
| 52 | //------------------------------------------------------------------------------ |
| 53 | |
| 54 | } // namespace libhei |