From 8121513c096626f8ff73b733627826bfd8b5c64e Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Thu, 7 Jul 2016 17:21:10 +0200 Subject: [PATCH] Use JAYLINK_ERR_DEV_NO_MEMORY Signed-off-by: Marc Schink --- libjaylink/jtag.c | 32 +++++++++++++++++++++----------- libjaylink/swd.c | 12 +++++++++++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/libjaylink/jtag.c b/libjaylink/jtag.c index 06bf4fe..ff81060 100644 --- a/libjaylink/jtag.c +++ b/libjaylink/jtag.c @@ -34,6 +34,12 @@ #define CMD_JTAG_IO_V3 0xcf #define CMD_JTAG_CLEAR_TRST 0xde #define CMD_JTAG_SET_TRST 0xdf + +/** + * Error code indicating that there is not enough free memory on the device to + * perform the JTAG I/O operation. + */ +#define JTAG_IO_ERR_NO_MEMORY 0x06 /** @endcond */ /** @@ -56,6 +62,8 @@ * @retval JAYLINK_ERR_ARG Invalid arguments. * @retval JAYLINK_ERR_TIMEOUT A timeout occurred. * @retval JAYLINK_ERR_DEV Unspecified device error. + * @retval JAYLINK_ERR_DEV_NO_MEMORY Not enough memory on the device to perform + * the operation. * @retval JAYLINK_ERR Other error conditions. * * @see jaylink_select_interface() to select the target interface. @@ -135,19 +143,21 @@ JAYLINK_API int jaylink_jtag_io(struct jaylink_device_handle *devh, return ret; } - if (version == JAYLINK_JTAG_V3) { - ret = transport_read(devh, &status, 1); + if (version == JAYLINK_JTAG_V2) + return JAYLINK_OK; + + ret = transport_read(devh, &status, 1); - if (ret != JAYLINK_OK) { - log_err(ctx, "transport_read() failed: %i.", ret); - return ret; - } + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_read() failed: %i.", ret); + return ret; + } - if (status > 0) { - log_err(ctx, "JTAG I/O operation failed: %02x.", - status); - return JAYLINK_ERR_DEV; - } + if (status == JTAG_IO_ERR_NO_MEMORY) { + return JAYLINK_ERR_DEV_NO_MEMORY; + } else if (status > 0) { + log_err(ctx, "JTAG I/O operation failed: %02x.", status); + return JAYLINK_ERR_DEV; } return JAYLINK_OK; diff --git a/libjaylink/swd.c b/libjaylink/swd.c index e9adebb..6be4130 100644 --- a/libjaylink/swd.c +++ b/libjaylink/swd.c @@ -31,6 +31,12 @@ /** @cond PRIVATE */ #define CMD_SWD_IO 0xcf + +/** + * Error code indicating that there is not enough free memory on the device to + * perform the SWD I/O operation. + */ +#define SWD_IO_ERR_NO_MEMORY 0x06 /** @endcond */ /** @@ -52,6 +58,8 @@ * @retval JAYLINK_ERR_ARG Invalid arguments. * @retval JAYLINK_ERR_TIMEOUT A timeout occurred. * @retval JAYLINK_ERR_DEV Unspecified device error. + * @retval JAYLINK_ERR_DEV_NO_MEMORY Not enough memory on the device to perform + * the operation. * @retval JAYLINK_ERR Other error conditions. * * @see jaylink_select_interface() to select the target interface. @@ -122,7 +130,9 @@ JAYLINK_API int jaylink_swd_io(struct jaylink_device_handle *devh, return ret; } - if (status > 0) { + if (status == SWD_IO_ERR_NO_MEMORY) { + return JAYLINK_ERR_DEV_NO_MEMORY; + } else if (status > 0) { log_err(ctx, "SWD I/O operation failed: %02x.", status); return JAYLINK_ERR_DEV; } -- 2.11.4.GIT