aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <jaylink-dev@marcschink.de>2017-03-06 20:17:57 +0100
committerMarc Schink <jaylink-dev@marcschink.de>2017-03-09 16:59:33 +0100
commitf8022ab9e76da186889fcbb98e1675a80c90b258 (patch)
tree1ecae50cbc9655b0ccd2686ada5a93dc946af65b
parent486776f98a7f8fb70a9154272439f3ab92645b51 (diff)
downloadlibjaylink-f8022ab9e76da186889fcbb98e1675a80c90b258.zip
libjaylink-f8022ab9e76da186889fcbb98e1675a80c90b258.tar.gz
libjaylink-f8022ab9e76da186889fcbb98e1675a80c90b258.tar.bz2
device: Add function to retrieve counter values
Signed-off-by: Marc Schink <jaylink-dev@marcschink.de>
-rw-r--r--libjaylink/device.c80
-rw-r--r--libjaylink/libjaylink.h15
2 files changed, 95 insertions, 0 deletions
diff --git a/libjaylink/device.c b/libjaylink/device.c
index 8b4ad16..e14a304 100644
--- a/libjaylink/device.c
+++ b/libjaylink/device.c
@@ -43,6 +43,7 @@
#define CMD_GET_HW_STATUS 0x07
#define CMD_REGISTER 0x09
#define CMD_GET_HW_INFO 0xc1
+#define CMD_GET_COUNTERS 0xc2
#define CMD_GET_FREE_MEMORY 0xd4
#define CMD_GET_CAPS 0xe8
#define CMD_GET_EXT_CAPS 0xed
@@ -615,6 +616,85 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
}
/**
+ * Retrieve the counter values of a device.
+ *
+ * @note This function must only be used if the device has the
+ * #JAYLINK_DEV_CAP_GET_COUNTERS capability.
+ *
+ * @param[in,out] devh Device handle.
+ * @param[in] mask A bit field where each set bit represents a counter value to
+ * request. See #jaylink_counter for a description of the
+ * counters and their bit positions.
+ * @param[out] values Array to store the counter values on success. Its content
+ * is undefined on failure. The array must be large enough
+ * to contain at least as many elements as bits set in @p
+ * mask.
+ *
+ * @retval JAYLINK_OK Success.
+ * @retval JAYLINK_ERR_ARG Invalid arguments.
+ * @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
+ * @retval JAYLINK_ERR_IO Input/output error.
+ * @retval JAYLINK_ERR Other error conditions.
+ *
+ * @since 0.2.0
+ */
+JAYLINK_API int jaylink_get_counters(struct jaylink_device_handle *devh,
+ uint32_t mask, uint32_t *values)
+{
+ int ret;
+ struct jaylink_context *ctx;
+ uint8_t buf[5];
+ unsigned int i;
+ unsigned int num;
+ unsigned int length;
+
+ if (!devh || !mask || !values)
+ return JAYLINK_ERR_ARG;
+
+ ctx = devh->dev->ctx;
+ num = 0;
+
+ for (i = 0; i < 32; i++) {
+ if (mask & (1 << i))
+ num++;
+ }
+
+ length = num * sizeof(uint32_t);
+ ret = transport_start_write_read(devh, 5, length, true);
+
+ if (ret != JAYLINK_OK) {
+ log_err(ctx, "transport_start_write_read() failed: %s.",
+ jaylink_strerror(ret));
+ return ret;
+ }
+
+ buf[0] = CMD_GET_COUNTERS;
+ buffer_set_u32(buf, mask, 1);
+
+ ret = transport_write(devh, buf, 5);
+
+ if (ret != JAYLINK_OK) {
+ log_err(ctx, "transport_write() failed: %s.",
+ jaylink_strerror(ret));
+ return ret;
+ }
+
+ ret = transport_read(devh, (uint8_t *)values, length);
+
+ if (ret != JAYLINK_OK) {
+ log_err(ctx, "transport_read() failed: %s.",
+ jaylink_strerror(ret));
+ return ret;
+ }
+
+ for (i = 0; i < num; i++)
+ values[i] = buffer_get_u32((uint8_t *)values,
+ i * sizeof(uint32_t));
+
+ return JAYLINK_OK;
+}
+
+/**
* Retrieve the hardware version of a device.
*
* @note This function must only be used if the device has the
diff --git a/libjaylink/libjaylink.h b/libjaylink/libjaylink.h
index 9c34119..f3bb959 100644
--- a/libjaylink/libjaylink.h
+++ b/libjaylink/libjaylink.h
@@ -135,6 +135,8 @@ enum jaylink_device_capability {
JAYLINK_DEV_CAP_SET_TARGET_POWER = 13,
/** Device supports target interface selection. */
JAYLINK_DEV_CAP_SELECT_TIF = 17,
+ /** Device supports retrieval of counter values. */
+ JAYLINK_DEV_CAP_GET_COUNTERS = 19,
/** Device supports capturing of SWO trace data. */
JAYLINK_DEV_CAP_SWO = 23,
/** Device supports file I/O operations. */
@@ -166,6 +168,17 @@ enum jaylink_hardware_info {
JAYLINK_HW_INFO_ITARGET_PEAK = (1 << 3)
};
+/** Device counters. */
+enum jaylink_counter {
+ /** Time the device is connected to a target in milliseconds. */
+ JAYLINK_COUNTER_TARGET_TIME = (1 << 0),
+ /**
+ * Number of times the device was connected or disconnected from a
+ * target.
+ */
+ JAYLINK_COUNTER_TARGET_CONNECTIONS = (1 << 1)
+};
+
/** Device hardware types. */
enum jaylink_hardware_type {
/** J-Link. */
@@ -411,6 +424,8 @@ JAYLINK_API int jaylink_get_firmware_version(
size_t *length);
JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh,
uint32_t mask, uint32_t *info);
+JAYLINK_API int jaylink_get_counters(struct jaylink_device_handle *devh,
+ uint32_t mask, uint32_t *values);
JAYLINK_API int jaylink_get_hardware_version(
struct jaylink_device_handle *devh,
struct jaylink_hardware_version *version);