mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-23 08:09:58 -05:00
CPLD: Method to calculate bitstream CRC32.
This commit is contained in:
parent
df825807d6
commit
3ed1d9e24a
@ -114,6 +114,13 @@ bool CPLD::verify(
|
|||||||
return block_0_success && block_1_success;
|
return block_0_success && block_1_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t CPLD::crc() {
|
||||||
|
crc_t crc { 0x04c11db7, 0xffffffff, 0xffffffff };
|
||||||
|
block_crc(0, 3328, crc);
|
||||||
|
block_crc(1, 512, crc);
|
||||||
|
return crc.checksum();
|
||||||
|
}
|
||||||
|
|
||||||
void CPLD::sector_select(const uint16_t id) {
|
void CPLD::sector_select(const uint16_t id) {
|
||||||
shift_ir(0x203); // Sector select
|
shift_ir(0x203); // Sector select
|
||||||
jtag.runtest_tck(93); // 5us
|
jtag.runtest_tck(93); // 5us
|
||||||
@ -219,6 +226,17 @@ bool CPLD::is_blank_block(const uint16_t id, const size_t count) {
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CPLD::block_crc(const uint16_t id, const size_t count, crc_t& crc) {
|
||||||
|
sector_select(id);
|
||||||
|
shift_ir(0x205); // Read
|
||||||
|
jtag.runtest_tck(93); // 5us
|
||||||
|
|
||||||
|
for(size_t i=0; i<count; i++) {
|
||||||
|
const uint16_t from_device = jtag.shift_dr(16, 0xffff);
|
||||||
|
crc.process_bytes(&from_device, sizeof(from_device));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CPLD::is_blank() {
|
bool CPLD::is_blank() {
|
||||||
const auto block_0_blank = is_blank_block(0x0000, 3328);
|
const auto block_0_blank = is_blank_block(0x0000, 3328);
|
||||||
const auto block_1_blank = is_blank_block(0x0001, 512);
|
const auto block_1_blank = is_blank_block(0x0001, 512);
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#define __CPLD_MAX5_H__
|
#define __CPLD_MAX5_H__
|
||||||
|
|
||||||
#include "jtag.hpp"
|
#include "jtag.hpp"
|
||||||
|
#include "crc.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
@ -75,6 +76,8 @@ public:
|
|||||||
|
|
||||||
bool is_blank();
|
bool is_blank();
|
||||||
|
|
||||||
|
uint32_t crc();
|
||||||
|
|
||||||
std::pair<bool, uint8_t> boundary_scan();
|
std::pair<bool, uint8_t> boundary_scan();
|
||||||
|
|
||||||
enum class Instruction {
|
enum class Instruction {
|
||||||
@ -135,6 +138,9 @@ private:
|
|||||||
|
|
||||||
bool is_blank_block(const uint16_t id, const size_t count);
|
bool is_blank_block(const uint16_t id, const size_t count);
|
||||||
|
|
||||||
|
using crc_t = CRC<32, true, true>;
|
||||||
|
void block_crc(const uint16_t id, const size_t count, crc_t& crc);
|
||||||
|
|
||||||
const uint32_t IDCODE = 0b00000010000010100101000011011101;
|
const uint32_t IDCODE = 0b00000010000010100101000011011101;
|
||||||
|
|
||||||
const size_t IR_LENGTH = 10;
|
const size_t IR_LENGTH = 10;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user