forked from trabucayre/openFPGALoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpofParser.hpp
89 lines (73 loc) · 2.41 KB
/
pofParser.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2022 Gwenhael Goavec-Merou <gwenhael.goavec-merou@trabucayre.com>
*/
#ifndef SRC_POFPARSER_HPP_
#define SRC_POFPARSER_HPP_
#include <stdint.h>
#include <string>
#include <map>
#include "configBitstreamParser.hpp"
#define ARRAY2INT16(_array_) ( \
(static_cast<uint16_t>(_array_[0] & 0x00ff) << 0) | \
(static_cast<uint16_t>(_array_[1] & 0x00ff) << 8))
#define ARRAY2INT32(_array_) ( \
(static_cast<uint16_t>(_array_[0] & 0x00ff) << 0) | \
(static_cast<uint16_t>(_array_[1] & 0x00ff) << 8) | \
(static_cast<uint16_t>(_array_[2] & 0x00ff) << 16) | \
(static_cast<uint16_t>(_array_[3] & 0x00ff) << 24))
/*!
* \file pofParser.hpp
* \class POFParser
* \brief basic implementation for intel/altera POF format
* \author Gwenhael Goavec-Merou
*/
class POFParser: public ConfigBitstreamParser {
public:
POFParser(const std::string &filename, bool verbose = false);
~POFParser();
int parse() override;
/**
* \brief return pointer to cfg data section when name is provided
* when "" -> return full cfg_data
* \return a pointer
*/
uint8_t *getData(const std::string §ion_name);
/**
* \brief return length (bits) to a cfg data section when name is
* provided or full cfg_data length when ""
* \return size in bits
*/
int getLength(const std::string §ion_name);
/**
* \brief display header informations
*/
void displayHeader() override;
private:
/* packet 0x1A content */
typedef struct {
uint8_t flag; // 1 Byte before section name
std::string section; // UFM/CFM/ICB
uint32_t offset; // start offset in packet 17 area
uint8_t *data; // memory pointer
uint32_t len; // area length (bits)
} memory_section_t;
std::map<std::string, memory_section_t> mem_section;
/*!
* \brief parse a section 0x1A (list of sections)
* \param[in] flag: 16Bits flag
* \param[in] pos : 32bits _raw_data's offset
* \param[in] size: 32bits content's size
*/
void parseFlag26(uint16_t flag, uint32_t pos,
uint32_t size, const std::string &payload);
/*!
* \brief parse a section (flag + pos + size)
* \param[in] flag: 16Bits flag
* \param[in] pos : 32bits _raw_data's offset
* \param[in] size: 32bits content's size
* \return size
*/
uint32_t parseSection(uint16_t flag, uint32_t pos, uint32_t size);
};
#endif // SRC_POFPARSER_HPP_