bmp: Use tab instead of spaces.

This commit is contained in:
Uwe Bonnes 2021-09-29 11:30:25 +02:00
parent 3027636002
commit c4c1da6205
2 changed files with 327 additions and 325 deletions

View File

@ -25,367 +25,369 @@
#define FREQ_FIXED -1 #define FREQ_FIXED -1
void Bmp::DEBUG_WARN(const char *format, ...) void Bmp::DEBUG_WARN(const char *format, ...)
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
va_end(ap); va_end(ap);
} }
void Bmp::DEBUG_WIRE(const char *format, ...) void Bmp::DEBUG_WIRE(const char *format, ...)
{ {
if (!_verbose) if (!_verbose)
return; return;
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
va_end(ap); va_end(ap);
} }
void Bmp::DEBUG_PROBE(const char *format, ...) void Bmp::DEBUG_PROBE(const char *format, ...)
{ {
if (!_verbose) if (!_verbose)
return; return;
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
va_end(ap); va_end(ap);
} }
static const char hexdigits[] = "0123456789abcdef"; static const char hexdigits[] = "0123456789abcdef";
Bmp::Bmp(std::string dev, Bmp::Bmp(std::string dev,
const std::string &serial, uint32_t clkHZ, bool verbose) const std::string &serial, uint32_t clkHZ, bool verbose)
{ {
char name[4096]; char name[4096];
_verbose = verbose; _verbose = verbose;
if (dev.empty()) { if (dev.empty()) {
DEBUG_PROBE("No device given\n"); DEBUG_PROBE("No device given\n");
/* Try to find some BMP if0*/ /* Try to find some BMP if0*/
struct dirent *dp; struct dirent *dp;
DIR *dir = opendir(DEVICE_BY_ID); DIR *dir = opendir(DEVICE_BY_ID);
if (!dir) { if (!dir) {
fprintf(stderr,"No serial device found\n"); fprintf(stderr,"No serial device found\n");
return; return;
} }
int num_devices = 0; int num_devices = 0;
int num_total = 0; int num_total = 0;
while ((dp = readdir(dir)) != NULL) {
if ((strstr(dp->d_name, BMP_IDSTRING)) &&
(strstr(dp->d_name, "-if00"))) {
num_total++;
if ((!serial.empty()) && (!strstr(dp->d_name, serial.c_str())))
continue;
num_devices++;
strcpy(name, DEVICE_BY_ID);
strncat(name, dp->d_name, sizeof(name) - strlen(name) - 1);
}
}
closedir(dir);
if ((num_devices == 0) && (num_total == 0)){
fprintf(stderr,"No BMP probe found\n");
return;
} else if (num_devices != 1) {
fprintf(stderr,"Available Probes:\n");
dir = opendir(DEVICE_BY_ID);
if (dir) {
while ((dp = readdir(dir)) != NULL) { while ((dp = readdir(dir)) != NULL) {
if ((strstr(dp->d_name, BMP_IDSTRING)) && if ((strstr(dp->d_name, BMP_IDSTRING)) &&
(strstr(dp->d_name, "-if00"))) (strstr(dp->d_name, "-if00"))) {
fprintf(stderr, "%s\n", dp->d_name); num_total++;
if ((!serial.empty()) && (!strstr(dp->d_name, serial.c_str())))
continue;
num_devices++;
strcpy(name, DEVICE_BY_ID);
strncat(name, dp->d_name, sizeof(name) - strlen(name) - 1);
}
} }
closedir(dir); closedir(dir);
if (serial.empty()) if ((num_devices == 0) && (num_total == 0)){
fprintf(stderr, "Select Probe with -s <(Partial) Serial " fprintf(stderr,"No BMP probe found\n");
"Number\n"); return;
else } else if (num_devices != 1) {
fprintf(stderr, "Do no match given serial \"%s\"\n", serial.c_str()); fprintf(stderr,"Available Probes:\n");
} else { dir = opendir(DEVICE_BY_ID);
fprintf(stderr, "Could not opendir %s: %s\n", name, strerror(errno)); if (dir) {
} while ((dp = readdir(dir)) != NULL) {
return; if ((strstr(dp->d_name, BMP_IDSTRING)) &&
(strstr(dp->d_name, "-if00")))
fprintf(stderr, "%s\n", dp->d_name);
}
closedir(dir);
if (serial.empty())
fprintf(stderr, "Select Probe with -s <(Partial) Serial "
"Number\n");
else
fprintf(stderr, "Do no match given serial \"%s\"\n",
serial.c_str());
} else {
fprintf(stderr, "Could not opendir %s: %s\n", name,
strerror(errno));
}
return;
}
} else {
strncpy(name, dev.c_str(), sizeof(name) - 1);
} }
} else { fd = open(name, O_RDWR | O_SYNC | O_NOCTTY);
strncpy(name, dev.c_str(), sizeof(name) - 1); if (fd < 0) {
} fprintf(stderr, "Couldn't open serial port %s\n", name);
fd = open(name, O_RDWR | O_SYNC | O_NOCTTY); return;
if (fd < 0) { }
fprintf(stderr, "Couldn't open serial port %s\n", name); fprintf(stderr, "Found %s\n", name);
return; if (set_interface_attribs()) {
} fprintf(stderr, "Can not set line\n");
fprintf(stderr, "Found %s\n", name); throw std::runtime_error("_buffer malloc failed");
if (set_interface_attribs()) { }
fprintf(stderr, "Can not set line\n"); char construct[REMOTE_MAX_MSG_SIZE];
throw std::runtime_error("_buffer malloc failed"); int c = snprintf(construct, REMOTE_MAX_MSG_SIZE, "%s", REMOTE_START_STR);
} platform_buffer_write(construct, c);
char construct[REMOTE_MAX_MSG_SIZE]; c = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
int c = snprintf(construct, REMOTE_MAX_MSG_SIZE, "%s", REMOTE_START_STR); if ((!c) || (construct[0] == REMOTE_RESP_ERR)) {
platform_buffer_write(construct, c); DEBUG_WARN("Remote Start failed, error %s\n",
c = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); c ? (char *)&(construct[1]) : "unknown");
if ((!c) || (construct[0] == REMOTE_RESP_ERR)) { throw std::runtime_error("remote_init failed");
DEBUG_WARN("Remote Start failed, error %s\n", }
c ? (char *)&(construct[1]) : "unknown"); DEBUG_PROBE("Remote is %s\n", &construct[1]);
throw std::runtime_error("remote_init failed");
}
DEBUG_PROBE("Remote is %s\n", &construct[1]);
/* Init JTAG */ /* Init JTAG */
c = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s", c = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s",
REMOTE_JTAG_INIT_STR); REMOTE_JTAG_INIT_STR);
platform_buffer_write(construct, c); platform_buffer_write(construct, c);
c = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); c = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((!c) || (construct[0] == REMOTE_RESP_ERR)) { if ((!c) || (construct[0] == REMOTE_RESP_ERR)) {
DEBUG_WARN("jtagtap_init failed, error %s\n", DEBUG_WARN("jtagtap_init failed, error %s\n",
c ? (char *)&(construct[1]) : "unknown"); c ? (char *)&(construct[1]) : "unknown");
throw std::runtime_error("jtag_init failed"); throw std::runtime_error("jtag_init failed");
} }
/* Get Version*/ /* Get Version*/
int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s", int s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, "%s",
REMOTE_HL_CHECK_STR); REMOTE_HL_CHECK_STR);
platform_buffer_write(construct, s); platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
#define NEEDED_BMP_VERSION 2 #define NEEDED_BMP_VERSION 2
if ((!s) || (construct[0] == REMOTE_RESP_ERR) || if ((!s) || (construct[0] == REMOTE_RESP_ERR) ||
((construct[1] - '0') < NEEDED_BMP_VERSION)) { ((construct[1] - '0') < NEEDED_BMP_VERSION)) {
fprintf(stderr, fprintf(stderr,
"Please update BMP, expected version %d, got %d!\n", "Please update BMP, expected version %d, got %d!\n",
NEEDED_BMP_VERSION, construct[1] - '0'); NEEDED_BMP_VERSION, construct[1] - '0');
return; return;
} }
setClkFreq(clkHZ); setClkFreq(clkHZ);
}; };
Bmp::~Bmp() Bmp::~Bmp()
{ {
close(fd); close(fd);
fprintf(stderr, "Close\n"); fprintf(stderr, "Close\n");
} }
int Bmp::setClkFreq(uint32_t clkHZ) int Bmp::setClkFreq(uint32_t clkHZ)
{ {
char construct[REMOTE_MAX_MSG_SIZE]; char construct[REMOTE_MAX_MSG_SIZE];
int s; int s;
s = snprintf(construct, REMOTE_MAX_MSG_SIZE, REMOTE_FREQ_SET_STR, s = snprintf(construct, REMOTE_MAX_MSG_SIZE, REMOTE_FREQ_SET_STR,
clkHZ); clkHZ);
platform_buffer_write(construct, s); platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { if ((!s) || (construct[0] == REMOTE_RESP_ERR)) {
fprintf(stderr,"Update Firmware to allow to set max SWJ frequency\n"); fprintf(stderr,"Update Firmware to allow to set max SWJ frequency\n");
} }
s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,"%s", s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,"%s",
REMOTE_FREQ_GET_STR); REMOTE_FREQ_GET_STR);
platform_buffer_write(construct, s); platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((!s) || (construct[0] == REMOTE_RESP_ERR)) if ((!s) || (construct[0] == REMOTE_RESP_ERR))
return FREQ_FIXED; return FREQ_FIXED;
uint32_t freq[1]; uint32_t freq[1];
unhexify(freq, &construct[1], 4); unhexify(freq, &construct[1], 4);
fprintf(stderr, "%d Hz\n", freq[0]); fprintf(stderr, "%d Hz\n", freq[0]);
_clkHZ = freq[0]; _clkHZ = freq[0];
return freq[0]; return freq[0];
} }
int Bmp::writeTMS(uint8_t *tms, int len, bool flush_buffer) int Bmp::writeTMS(uint8_t *tms, int len, bool flush_buffer)
{ {
char construct[REMOTE_MAX_MSG_SIZE]; char construct[REMOTE_MAX_MSG_SIZE];
int s; int s;
uint32_t tms_word; uint32_t tms_word;
int ret = len; int ret = len;
while (len) { while (len) {
int chunk = len; int chunk = len;
if (chunk > 32) if (chunk > 32)
chunk = 32; chunk = 32;
tms_word = *tms++; tms_word = *tms++;
if (chunk > 8) if (chunk > 8)
tms_word |= *tms++ << 8; tms_word |= *tms++ << 8;
if (chunk > 16) if (chunk > 16)
tms_word |= *tms++ << 16; tms_word |= *tms++ << 16;
if (chunk > 24) if (chunk > 24)
tms_word |= *tms++ << 24; tms_word |= *tms++ << 24;
len -= chunk; len -= chunk;
s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE, s = snprintf((char *)construct, REMOTE_MAX_MSG_SIZE,
REMOTE_JTAG_TMS_STR, chunk, tms_word); REMOTE_JTAG_TMS_STR, chunk, tms_word);
platform_buffer_write(construct, s); platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { if ((!s) || (construct[0] == REMOTE_RESP_ERR)) {
DEBUG_WARN("jtagtap_tms_seq failed, error %s\n", DEBUG_WARN("jtagtap_tms_seq failed, error %s\n",
s ? (char *)&(construct[1]) : "unknown"); s ? (char *)&(construct[1]) : "unknown");
throw std::runtime_error("writeTMS failed"); throw std::runtime_error("writeTMS failed");
}
} }
} (void)flush_buffer;
(void)flush_buffer; return ret;
return ret;
} }
int Bmp::writeTDI(uint8_t *tdi, uint8_t *tdo, uint32_t len, bool end) int Bmp::writeTDI(uint8_t *tdi, uint8_t *tdo, uint32_t len, bool end)
{ {
int ret = len; int ret = len;
if(!len || (!tdi && !tdo)) if(!len || (!tdi && !tdo))
return len; return len;
while (len) { while (len) {
int chunk = (len > 4000) ? 4000 : len; int chunk = (len > 4000) ? 4000 : len;
len -= chunk; len -= chunk;
int byte_count = (chunk + 7) >> 3; int byte_count = (chunk + 7) >> 3;
char construct[REMOTE_MAX_MSG_SIZE]; char construct[REMOTE_MAX_MSG_SIZE];
int s = snprintf( int s = snprintf(
construct, REMOTE_MAX_MSG_SIZE, construct, REMOTE_MAX_MSG_SIZE,
REMOTE_JTAG_IOSEQ_STR, REMOTE_JTAG_IOSEQ_STR,
(!len && end) ? REMOTE_IOSEQ_TMS : REMOTE_IOSEQ_NOTMS, (!len && end) ? REMOTE_IOSEQ_TMS : REMOTE_IOSEQ_NOTMS,
(((tdi) ? REMOTE_IOSEQ_FLAG_IN : REMOTE_IOSEQ_FLAG_NONE) | (((tdi) ? REMOTE_IOSEQ_FLAG_IN : REMOTE_IOSEQ_FLAG_NONE) |
((tdo) ? REMOTE_IOSEQ_FLAG_OUT : REMOTE_IOSEQ_FLAG_NONE)), ((tdo) ? REMOTE_IOSEQ_FLAG_OUT : REMOTE_IOSEQ_FLAG_NONE)),
chunk); chunk);
char *p = construct + s; char *p = construct + s;
if (tdi) { if (tdi) {
hexify(p, tdi, byte_count); hexify(p, tdi, byte_count);
p += 2 * byte_count; p += 2 * byte_count;
tdi += byte_count; tdi += byte_count;
}
*p++ = REMOTE_EOM;
*p = 0;
platform_buffer_write(construct, p - construct);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((s > 0) && (construct[0] == REMOTE_RESP_OK)) {
if (tdo) {
unhexify(tdo, (const char*)&construct[1], byte_count);
tdo += byte_count;
}
continue;
}
DEBUG_WARN("%s error %d\n",
__func__, s);
break;
} }
*p++ = REMOTE_EOM; return ret;
*p = 0;
platform_buffer_write(construct, p - construct);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((s > 0) && (construct[0] == REMOTE_RESP_OK)) {
if (tdo) {
unhexify(tdo, (const char*)&construct[1], byte_count);
tdo += byte_count;
}
continue;
}
DEBUG_WARN("%s error %d\n",
__func__, s);
break;
}
return ret;
} }
int Bmp::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len) int Bmp::toggleClk(uint8_t tms, uint8_t tdi, uint32_t clk_len)
{ {
char construct[REMOTE_MAX_MSG_SIZE]; char construct[REMOTE_MAX_MSG_SIZE];
int s = snprintf( int s = snprintf(
construct, REMOTE_MAX_MSG_SIZE, REMOTE_JTAG_JTCK_STR, construct, REMOTE_MAX_MSG_SIZE, REMOTE_JTAG_JTCK_STR,
(tms) ? 1 : 0, (tdi) ? 1 : 0, clk_len); (tms) ? 1 : 0, (tdi) ? 1 : 0, clk_len);
platform_buffer_write(construct, s); platform_buffer_write(construct, s);
s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE); s = platform_buffer_read(construct, REMOTE_MAX_MSG_SIZE);
if ((!s) || (construct[0] == REMOTE_RESP_ERR)) { if ((!s) || (construct[0] == REMOTE_RESP_ERR)) {
DEBUG_WARN("toggleClk, error %s\n", DEBUG_WARN("toggleClk, error %s\n",
s ? (char *)&(construct[1]) : "unknown"); s ? (char *)&(construct[1]) : "unknown");
throw std::runtime_error("toggleClk"); throw std::runtime_error("toggleClk");
} }
return clk_len; return clk_len;
} }
int Bmp::set_interface_attribs(void) int Bmp::set_interface_attribs(void)
{ {
struct termios tty; struct termios tty;
memset (&tty, 0, sizeof tty); memset (&tty, 0, sizeof tty);
if (tcgetattr (fd, &tty) != 0) { if (tcgetattr (fd, &tty) != 0) {
fprintf(stderr, "error %d from tcgetattr", errno); fprintf(stderr, "error %d from tcgetattr", errno);
return -1; return -1;
} }
tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars
// disable IGNBRK for mismatched speed tests; otherwise receive break // disable IGNBRK for mismatched speed tests; otherwise receive break
// as \000 chars // as \000 chars
tty.c_iflag &= ~IGNBRK; // disable break processing tty.c_iflag &= ~IGNBRK; // disable break processing
tty.c_lflag = 0; // no signaling chars, no echo, tty.c_lflag = 0; // no signaling chars, no echo,
// no canonical processing // no canonical processing
tty.c_oflag = 0; // no remapping, no delays tty.c_oflag = 0; // no remapping, no delays
tty.c_cc[VMIN] = 0; // read doesn't block tty.c_cc[VMIN] = 0; // read doesn't block
tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout
tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl
tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls, tty.c_cflag |= (CLOCAL | CREAD);// ignore modem controls,
// enable reading // enable reading
tty.c_cflag &= ~CSTOPB; tty.c_cflag &= ~CSTOPB;
#if defined(CRTSCTS) #if defined(CRTSCTS)
tty.c_cflag &= ~CRTSCTS; tty.c_cflag &= ~CRTSCTS;
#endif #endif
if (tcsetattr(fd, TCSANOW, &tty) != 0) { if (tcsetattr(fd, TCSANOW, &tty) != 0) {
fprintf(stderr, "error %d from tcsetattr", errno); fprintf(stderr, "error %d from tcsetattr", errno);
return -1; return -1;
} }
return 0; return 0;
} }
int Bmp::platform_buffer_write(const char *data, int size) int Bmp::platform_buffer_write(const char *data, int size)
{ {
int s; int s;
DEBUG_WIRE("%s\n", data); DEBUG_WIRE("%s\n", data);
s = write(fd, data, size); s = write(fd, data, size);
if (s < 0) { if (s < 0) {
fprintf(stdout, "Failed to write\n"); fprintf(stdout, "Failed to write\n");
throw std::runtime_error("bmp write failed"); throw std::runtime_error("bmp write failed");
} }
return size; return size;
} }
int Bmp::platform_buffer_read(char *data, int maxsize) int Bmp::platform_buffer_read(char *data, int maxsize)
{ {
char *c; char *c;
int s; int s;
int ret; int ret;
fd_set rset; fd_set rset;
struct timeval tv; struct timeval tv;
c = data; c = data;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_sec = 500 * 1000 ; tv.tv_sec = 500 * 1000 ;
tv.tv_usec = 0; tv.tv_usec = 0;
/* Look for start of response */ /* Look for start of response */
do { do {
FD_ZERO(&rset); FD_ZERO(&rset);
FD_SET(fd, &rset); FD_SET(fd, &rset);
ret = select(fd + 1, &rset, NULL, NULL, &tv); ret = select(fd + 1, &rset, NULL, NULL, &tv);
if (ret < 0) { if (ret < 0) {
DEBUG_WARN("Failed on select\n"); DEBUG_WARN("Failed on select\n");
return(-3); return(-3);
} }
if(ret == 0) { if(ret == 0) {
DEBUG_WARN("Timeout on read RESP\n"); DEBUG_WARN("Timeout on read RESP\n");
return(-4); return(-4);
} }
s = read(fd, c, 1); s = read(fd, c, 1);
}
while ((s > 0) && (*c != REMOTE_RESP));
/* Now collect the response */
do {
FD_ZERO(&rset);
FD_SET(fd, &rset);
ret = select(fd + 1, &rset, NULL, NULL, &tv);
if (ret < 0) {
DEBUG_WARN("Failed on select\n");
exit(-4);
} }
if(ret == 0) { while ((s > 0) && (*c != REMOTE_RESP));
DEBUG_WARN("Timeout on read\n"); /* Now collect the response */
return(-5); do {
} FD_ZERO(&rset);
s = read(fd, c, 1); FD_SET(fd, &rset);
if (*c==REMOTE_EOM) { ret = select(fd + 1, &rset, NULL, NULL, &tv);
*c = 0; if (ret < 0) {
DEBUG_WIRE(" %s\n",data); DEBUG_WARN("Failed on select\n");
return (c - data); exit(-4);
} else { }
c++; if(ret == 0) {
} DEBUG_WARN("Timeout on read\n");
}while ((s >= 0) && ((c - data) < maxsize)); return(-5);
DEBUG_WARN("Failed to read\n"); }
return(-6); s = read(fd, c, 1);
return 0; if (*c==REMOTE_EOM) {
*c = 0;
DEBUG_WIRE(" %s\n",data);
return (c - data);
} else {
c++;
}
} while ((s >= 0) && ((c - data) < maxsize));
DEBUG_WARN("Failed to read\n");
return(-6);
return 0;
} }
char *Bmp::hexify(char *hex, const void *buf, size_t size) char *Bmp::hexify(char *hex, const void *buf, size_t size)
@ -404,20 +406,20 @@ char *Bmp::hexify(char *hex, const void *buf, size_t size)
uint8_t unhex_digit(char hex) uint8_t unhex_digit(char hex)
{ {
uint8_t tmp = hex - '0'; uint8_t tmp = hex - '0';
if(tmp > 9) if(tmp > 9)
tmp -= 'A' - '0' - 10; tmp -= 'A' - '0' - 10;
if(tmp > 16) if(tmp > 16)
tmp -= 'a' - 'A'; tmp -= 'a' - 'A';
return tmp; return tmp;
} }
char *Bmp::unhexify(void *buf, const char *hex, size_t size) char *Bmp::unhexify(void *buf, const char *hex, size_t size)
{ {
uint8_t *b = (uint8_t *)buf; uint8_t *b = (uint8_t *)buf;
while (size--) { while (size--) {
*b = unhex_digit(*hex++) << 4; *b = unhex_digit(*hex++) << 4;
*b++ |= unhex_digit(*hex++); *b++ |= unhex_digit(*hex++);
} }
return (char *)buf; return (char *)buf;
} }

View File

@ -18,33 +18,33 @@
*/ */
class Bmp : public JtagInterface { class Bmp : public JtagInterface {
public: public:
Bmp(std::string dev, Bmp(std::string dev,
const std::string &serial, uint32_t clkHZ, bool verbose); const std::string &serial, uint32_t clkHZ, bool verbose);
~Bmp(void); ~Bmp(void);
int setClkFreq(uint32_t clkHZ) override; int setClkFreq(uint32_t clkHZ) override;
uint32_t getClkFreq() { return _clkHZ;} uint32_t getClkFreq() { return _clkHZ;}
/* TMS */ /* TMS */
int writeTMS(uint8_t *tms, int len, bool flush_buffer) override; int writeTMS(uint8_t *tms, int len, bool flush_buffer) override;
/* TDI */ /* TDI */
int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override; int writeTDI(uint8_t *tx, uint8_t *rx, uint32_t len, bool end) override;
/* clk */ /* clk */
int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override; int toggleClk(uint8_t tms, uint8_t tdo, uint32_t clk_len) override;
int get_buffer_size() override { return 0;} int get_buffer_size() override { return 0;}
bool isFull() override {return false;} bool isFull() override {return false;}
int flush() override { return 0;}; int flush() override { return 0;};
private: private:
bool _verbose; /**< display more message */ bool _verbose; /**< display more message */
int fd; int fd;
int set_interface_attribs(void); int set_interface_attribs(void);
int platform_buffer_write(const char *data, int size); int platform_buffer_write(const char *data, int size);
int platform_buffer_read(char *data, int maxsize); int platform_buffer_read(char *data, int maxsize);
char *unhexify(void *buf, const char *hex, size_t size); char *unhexify(void *buf, const char *hex, size_t size);
char *hexify(char *hex, const void *buf, size_t size); char *hexify(char *hex, const void *buf, size_t size);
void DEBUG_WARN(const char *format, ...); void DEBUG_WARN(const char *format, ...);
void DEBUG_WIRE(const char *format, ...); void DEBUG_WIRE(const char *format, ...);
void DEBUG_PROBE(const char *format, ...); void DEBUG_PROBE(const char *format, ...);
protected: protected:
uint32_t _clkHZ; uint32_t _clkHZ;
}; };
#endif // SRC_BMP_HPP_ #endif // SRC_BMP_HPP_