summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <jaylink-dev@marcschink.de>2016-08-04 17:33:59 +0200
committerMarc Schink <jaylink-dev@marcschink.de>2016-08-04 17:38:20 +0200
commite7c5a2c0c394e4114e3ff6cdc6634fedabd1a0d7 (patch)
tree8f0b631c54b011bd064f68ac8d6572c37a957de6
parent3805635e498f6d916eb15cfbb573036de7a441ab (diff)
device_info: Display all target interface speeds
-rw-r--r--device_info.c114
1 files changed, 84 insertions, 30 deletions
diff --git a/device_info.c b/device_info.c
index d260f3a..c89c080 100644
--- a/device_info.c
+++ b/device_info.c
@@ -22,6 +22,83 @@
#include <inttypes.h>
#include <libjaylink/libjaylink.h>
+#define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0]))
+
+static const struct {
+ enum jaylink_target_interface iface;
+ const char *name;
+} target_ifaces[] = {
+ {
+ .iface = JAYLINK_TIF_JTAG,
+ .name = "JTAG"
+ },
+ {
+ .iface = JAYLINK_TIF_SWD,
+ .name = "SWD"
+ },
+ {
+ .iface = JAYLINK_TIF_BDM3,
+ .name = "BDM3"
+ },
+ {
+ .iface = JAYLINK_TIF_FINE,
+ .name = "FINE"
+ },
+ {
+ .iface = JAYLINK_TIF_2W_JTAG_PIC32,
+ .name = "2-wire JTAG for PIC32"
+ }
+};
+
+static void print_interfaces(struct jaylink_device_handle *devh,
+ uint32_t interfaces)
+{
+ size_t i;
+
+ printf("\nTarget interfaces: %02x\n", interfaces);
+
+ for (i = 0; i < ARRAY_SIZE(target_ifaces); i++) {
+ if (interfaces & (1 << target_ifaces[i].iface))
+ printf(" - %s\n", target_ifaces[i].name);
+ }
+}
+
+static bool print_interface_speeds(struct jaylink_device_handle *devh,
+ uint32_t interfaces)
+{
+ int ret;
+ size_t i;
+ struct jaylink_speed speed;
+
+ for (i = 0; i < ARRAY_SIZE(target_ifaces); i++) {
+ if (!(interfaces & (1 << target_ifaces[i].iface)))
+ continue;
+
+ ret = jaylink_select_interface(devh, target_ifaces[i].iface,
+ NULL);
+
+ if (ret != JAYLINK_OK) {
+ printf("jaylink_select_interface() failed: %s.\n",
+ jaylink_strerror_name(ret));
+ return false;
+ }
+
+ ret = jaylink_get_speeds(devh, &speed);
+
+ if (ret != JAYLINK_OK) {
+ printf("jaylink_get_speeds() failed: %s.\n",
+ jaylink_strerror_name(ret));
+ return false;
+ }
+
+ printf(" - %s: %" PRIu32 " MHz / div; div >= %u\n",
+ target_ifaces[i].name, speed.freq / 1000000,
+ speed.div);
+ }
+
+ return true;
+}
+
int main(int argc, char **argv)
{
ssize_t ret;
@@ -31,7 +108,6 @@ int main(int argc, char **argv)
uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE];
struct jaylink_hardware_version hwver;
uint32_t interfaces;
- struct jaylink_speed speed;
struct jaylink_swo_speed swo_speed;
uint8_t config[JAYLINK_DEV_CONFIG_SIZE];
bool use_serial_number;
@@ -191,47 +267,25 @@ int main(int argc, char **argv)
if (ret != JAYLINK_OK) {
printf("jaylink_get_available_interfaces() failed: "
"%s.\n", jaylink_strerror_name(ret));
- jaylink_close(devh);
- jaylink_exit(ctx);
- return EXIT_FAILURE;
+ return false;
}
-
- printf("\nTarget interfaces: %02x\n", interfaces);
-
- if (interfaces & (1 << JAYLINK_TIF_JTAG))
- printf(" - JTAG\n");
-
- if (interfaces & (1 << JAYLINK_TIF_SWD))
- printf(" - SWD\n");
-
- if (interfaces & (1 << JAYLINK_TIF_BDM3))
- printf(" - BDM3\n");
-
- if (interfaces & (1 << JAYLINK_TIF_FINE))
- printf(" - FINE\n");
-
- if (interfaces & (1 << JAYLINK_TIF_2W_JTAG_PIC32))
- printf(" - 2-wire JTAG for PIC32\n");
+ } else {
+ interfaces = (1 << JAYLINK_TIF_JTAG);
}
+ print_interfaces(devh, interfaces);
+
if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_GET_SPEEDS)) {
- ret = jaylink_get_speeds(devh, &speed);
+ printf("\nTarget interface speeds:\n");
- if (ret != JAYLINK_OK) {
- printf("jaylink_get_speeds() failed: "
- "%s.\n", jaylink_strerror_name(ret));
+ if (!print_interface_speeds(devh, interfaces)) {
jaylink_close(devh);
jaylink_exit(ctx);
return EXIT_FAILURE;
}
- printf("\nTarget interface speeds:\n");
-
if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_ADAPTIVE_CLOCKING))
printf(" - Adaptive clocking\n");
-
- printf(" - %u MHz / div; div >= %u\n", speed.freq / 1000000,
- speed.div);
}
if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_SWO)) {