static int jlink_speed(int speed)
{
int ret;
- uint32_t freq;
- uint16_t divider;
+ struct jaylink_speed tmp;
int max_speed;
if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
- ret = jaylink_get_speeds(devh, &freq, ÷r);
+ ret = jaylink_get_speeds(devh, &tmp);
if (ret != JAYLINK_OK) {
LOG_ERROR("jaylink_get_speeds() failed: %s.",
return ERROR_JTAG_DEVICE_ERROR;
}
- freq = freq / 1000;
- max_speed = freq / divider;
+ tmp.freq /= 1000;
+ max_speed = tmp.freq / tmp.div;
} else {
max_speed = JLINK_MAX_SPEED;
}
static int jlink_register(void)
{
int ret;
- int i;
+ size_t i;
bool handle_found;
+ size_t count;
if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_REGISTER))
return ERROR_OK;
- ret = jaylink_register(devh, &conn, connlist, NULL, NULL);
+ ret = jaylink_register(devh, &conn, connlist, &count);
- if (ret < 0) {
+ if (ret != JAYLINK_OK) {
LOG_ERROR("jaylink_register() failed: %s.",
jaylink_strerror_name(ret));
return ERROR_FAIL;
handle_found = false;
- for (i = 0; i < ret; i++) {
+ for (i = 0; i < count; i++) {
if (connlist[i].handle == conn.handle) {
handle_found = true;
break;
return true;
}
-static int jaylink_log_handler(const struct jaylink_context *ctx, int level,
- const char *format, va_list args, void *user_data)
+static int jaylink_log_handler(const struct jaylink_context *ctx,
+ enum jaylink_log_level level, const char *format, va_list args,
+ void *user_data)
{
enum log_levels tmp;
return ERROR_JTAG_INIT_FAILED;
}
- ret = jaylink_get_device_list(jayctx, &devs);
+ ret = jaylink_discovery_scan(jayctx, 0);
- if (ret < 0) {
- LOG_ERROR("jaylink_get_device_list() failed: %s.",
+ if (ret != JAYLINK_OK) {
+ LOG_ERROR("jaylink_discovery_scan() failed: %s.",
+ jaylink_strerror_name(ret));
+ jaylink_exit(jayctx);
+ return ERROR_JTAG_INIT_FAILED;
+ }
+
+ ret = jaylink_get_devices(jayctx, &devs, NULL);
+
+ if (ret != JAYLINK_OK) {
+ LOG_ERROR("jaylink_get_devices() failed: %s.",
jaylink_strerror_name(ret));
jaylink_exit(jayctx);
return ERROR_JTAG_INIT_FAILED;
LOG_ERROR("Failed to open device: %s.", jaylink_strerror_name(ret));
}
- jaylink_free_device_list(devs, 1);
+ jaylink_free_devices(devs, true);
if (!found_device) {
LOG_ERROR("No J-Link device found.");
conn.handle = 0;
conn.pid = 0;
- conn.hid = 0;
+ strcpy(conn.hid, "0.0.0.0");
conn.iid = 0;
conn.cid = 0;
static int jlink_quit(void)
{
int ret;
+ size_t count;
if (trace_enabled) {
ret = jaylink_swo_stop(devh);
}
if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_REGISTER)) {
- ret = jaylink_unregister(devh, &conn, connlist, NULL, NULL);
+ ret = jaylink_unregister(devh, &conn, connlist, &count);
- if (ret < 0)
+ if (ret != JAYLINK_OK)
LOG_ERROR("jaylink_unregister() failed: %s.",
jaylink_strerror_name(ret));
}
COMMAND_HANDLER(jlink_serial_command)
{
+ int ret;
+
if (CMD_ARGC != 1) {
command_print(CMD_CTX, "Need exactly one argument for jlink serial.");
return ERROR_COMMAND_SYNTAX_ERROR;
}
- if (sscanf(CMD_ARGV[0], "%" SCNd32, &serial_number) != 1) {
+ ret = jaylink_parse_serial_number(CMD_ARGV[0], &serial_number);
+
+ if (ret == JAYLINK_ERR) {
command_print(CMD_CTX, "Invalid serial number: %s.", CMD_ARGV[0]);
return ERROR_FAIL;
+ } else if (ret != JAYLINK_OK) {
+ command_print(CMD_CTX, "jaylink_parse_serial_number() failed: %s.",
+ jaylink_strerror_name(ret));
+ return ERROR_FAIL;
}
use_serial_number = true;