Skip to content

Commit

Permalink
gatemate: fix configuration in jtag chains
Browse files Browse the repository at this point in the history
  • Loading branch information
pu-cc committed Dec 12, 2023
1 parent ed547ed commit 1dfdec6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/colognechip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "colognechip.hpp"

#include <memory>
#include <string.h>

#define JTAG_CONFIGURE 0x06
#define JTAG_SPI_BYPASS 0x05
Expand Down Expand Up @@ -279,6 +280,25 @@ void CologneChip::programJTAG_sram(const uint8_t *data, int length)

ProgressBar progress("Load SRAM via JTAG", length, 50, _quiet);

/* make sure to only send multiples of 8 bits */
int bits_before = _jtag->get_devices_list().size() - _jtag->get_device_index() - 1;
if (bits_before > 0) {
int n = 8 - (bits_before % 8);
_jtag->toggleClk(n);
}

/* the bypass register defaults to '0'.
* in order to generate a proper 'nop' command (0x00, 0xFF), send a
* sequence of zeros instead of ones.
*/
int bits_after = _jtag->get_device_index();
if (bits_after > 0) {
int n = (bits_after + 7) / 8;
uint8_t tx[n];
memset(tx, 0x00, n);
_jtag->shiftDR(tx, NULL, 8-bits_after, Jtag::SHIFT_DR);
}

for (int i = 0; i < length; i += size) {
if (length < i + size)
size = length-i;
Expand Down
6 changes: 6 additions & 0 deletions src/jtag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class Jtag {
*/
std::vector<int> get_devices_list() {return _devices_list;}

/*!
* \brief return device index in list
* \return device index
*/
int get_device_index() {return device_index;}

/*!
* \brief return current selected device idcode
* \return device idcode
Expand Down

0 comments on commit 1dfdec6

Please sign in to comment.