Skip to content

Commit 3508904

Browse files
committed
latticeBitParser, lattice: added 128 clock pulses padding before preamble: Required by ECP3 family
1 parent 0bc2594 commit 3508904

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/lattice.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool Lattice::program_mem()
331331
{
332332
bool err;
333333

334-
LatticeBitParser _bit(_filename, false, _verbose);
334+
LatticeBitParser _bit(_filename, false, false, _verbose);
335335

336336
printInfo("Open file: ", false);
337337
printSuccess("DONE");
@@ -950,7 +950,8 @@ bool Lattice::program_extFlash(unsigned int offset, bool unprotect_flash)
950950
if (_file_extension == "mcs")
951951
_bit = new McsParser(_filename, true, _verbose);
952952
else if (_file_extension == "bit")
953-
_bit = new LatticeBitParser(_filename, false, _verbose);
953+
_bit = new LatticeBitParser(_filename, false,
954+
_fpga_family==ECP3_FAMILY, _verbose);
954955
else
955956
_bit = new RawParser(_filename, false);
956957
printSuccess("DONE");

src/latticeBitParser.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121

2222
using namespace std;
2323

24-
LatticeBitParser::LatticeBitParser(const string &filename, bool machxo2,
24+
LatticeBitParser::LatticeBitParser(const string &filename, bool machxo2, bool ecp3,
2525
bool verbose):
2626
ConfigBitstreamParser(filename, ConfigBitstreamParser::BIN_MODE, verbose),
27-
_endHeader(0), _is_machXO2(machxo2)
27+
_endHeader(0), _is_machXO2(machxo2), _is_ecp3(ecp3)
2828
{}
2929

3030
LatticeBitParser::~LatticeBitParser()
@@ -135,8 +135,19 @@ int LatticeBitParser::parse()
135135

136136
/* read All data */
137137
if (!_is_machXO2) {
138-
_bit_data.resize(_raw_data.size() - _endHeader);
139-
std::move(_raw_data.begin()+_endHeader, _raw_data.end(), _bit_data.begin());
138+
/* According to FPGA-TN-02192-3.4
139+
* the Lattice ECP3 must trasnmit at least 128 clock pulses before
140+
* receiving the preamble.
141+
* Here the header contains 16 Dummy bit + preamble so only
142+
* 14bits 8x14= 112bits must be added as padding.
143+
*/
144+
const uint32_t offset = (_is_ecp3) ? 14 : 0;
145+
_bit_data.resize(_raw_data.size() - _endHeader + offset);
146+
if (_is_ecp3) {
147+
std::string tmp(14, 0xff);
148+
std::move(tmp.begin(), tmp.end(), _bit_data.begin());
149+
}
150+
std::move(_raw_data.begin() + _endHeader, _raw_data.end(), _bit_data.begin() + offset);
140151
_bit_length = _bit_data.size() * 8;
141152
} else {
142153
const uint32_t len = _raw_data.size() - _endHeader;

src/latticeBitParser.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class LatticeBitParser: public ConfigBitstreamParser {
1717
public:
18-
LatticeBitParser(const std::string &filename, bool machxo2,
18+
LatticeBitParser(const std::string &filename, bool machxo2, bool ecp3,
1919
bool verbose = false);
2020
~LatticeBitParser();
2121
int parse() override;
@@ -31,6 +31,7 @@ class LatticeBitParser: public ConfigBitstreamParser {
3131
bool parseCfgData();
3232
size_t _endHeader;
3333
bool _is_machXO2;
34+
bool _is_ecp3;
3435
/* data storage for machXO2 */
3536
std::vector<std::string> _bit_array;
3637
};

0 commit comments

Comments
 (0)