From 8c36783432fff9cc413f9576e72af7d52471bc17 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Tue, 9 Sep 2014 02:37:05 -0400 Subject: [PATCH] device: Add function to retrieve hardware version. --- libjaylink/device.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ libjaylink/libjaylink.h | 27 +++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/libjaylink/device.c b/libjaylink/device.c index 4de1f32..98bebc4 100644 --- a/libjaylink/device.c +++ b/libjaylink/device.c @@ -29,6 +29,7 @@ #define CMD_GET_FREE_MEMORY 0xd4 #define CMD_GET_CAPS 0xe8 #define CMD_GET_EXT_CAPS 0xed +#define CMD_GET_HW_VERSION 0xf0 struct jaylink_device *device_allocate(struct jaylink_context *ctx) { @@ -272,6 +273,67 @@ int jaylink_get_firmware_version(struct jaylink_device_handle *devh, } /** + * Retrieve the hardware version of a device. + * + * @note This function must only be used if the device has the + * #JAYLINK_DEV_CAP_GET_HW_VERSION capability. + * + * @param[in,out] devh Device handle. + * @param[out] version Hardware version on success, and undefined on failure. + * + * @retval JAYLINK_OK Success. + * @retval JAYLINK_ERR_ARG Invalid arguments. + * @retval JAYLINK_ERR_TIMEOUT A timeout occurred. + * @retval JAYLINK_ERR Other error conditions. + * + * @see jaylink_get_caps() to retrieve device capabilities. + */ +int jaylink_get_hardware_version(struct jaylink_device_handle *devh, + struct jaylink_hardware_version *version) +{ + int ret; + struct jaylink_context *ctx; + uint8_t buf[4]; + uint32_t tmp; + + if (!devh || !version) + return JAYLINK_ERR_ARG; + + ctx = devh->dev->ctx; + ret = transport_start_write_read(devh, 1, 4, 1); + + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_start_write_read() failed: %i.", ret); + return ret; + } + + buf[0] = CMD_GET_HW_VERSION; + + ret = transport_write(devh, buf, 1); + + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_write() failed: %i.", ret); + return ret; + } + + ret = transport_read(devh, buf, 4); + + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_read() failed: %i.", ret); + return ret; + } + + tmp = buffer_get_u32(buf, 0); + + version->type = (tmp / 1000000) % 100; + version->major = (tmp / 10000) % 100; + version->minor = (tmp / 100) % 100; + version->revision = tmp % 100; + + return JAYLINK_OK; +} + +/** * Retrieve the hardware status of a device. * * @param[in,out] devh Device handle. diff --git a/libjaylink/libjaylink.h b/libjaylink/libjaylink.h index 1000e9c..bb61658 100644 --- a/libjaylink/libjaylink.h +++ b/libjaylink/libjaylink.h @@ -41,6 +41,8 @@ enum jaylink_log_level { /** Device capabilities. */ enum jaylink_device_capability { + /** Device supports retrieval of the hardware version. */ + JAYLINK_DEV_CAP_GET_HW_VERSION = 1, /** Device supports adaptive clocking. */ JAYLINK_DEV_CAP_ADAPTIVE_CLOCKING = 3, /** Device supports retrieval of free memory size. */ @@ -49,6 +51,28 @@ enum jaylink_device_capability { JAYLINK_DEV_CAP_GET_EXT_CAPS = 31 }; +/** Device hardware types. */ +enum jaylink_hardware_type { + /** J-Link BASE. */ + JAYLINK_HW_TYPE_BASE = 0 +}; + +/** Device hardware version. */ +struct jaylink_hardware_version { + /** + * Hardware type. + * + * See #jaylink_hardware_type for a description of the hardware types. + */ + uint8_t type; + /** Major version. */ + uint8_t major; + /** Minor version. */ + uint8_t minor; + /** Revision number. */ + uint8_t revision; +}; + /** Device hardware status. */ struct jaylink_hardware_status { /** Target reference voltage in mV. */ @@ -107,6 +131,9 @@ void jaylink_close(struct jaylink_device_handle *devh); int jaylink_get_firmware_version(struct jaylink_device_handle *devh, char **version); +int jaylink_get_hardware_version(struct jaylink_device_handle *devh, + struct jaylink_hardware_version *version); + int jaylink_get_hardware_status(struct jaylink_device_handle *devh, struct jaylink_hardware_status *status); -- 2.11.4.GIT