X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fsysclk-lwla%2Fprotocol.c;h=b4c3171e240ceb73dc3cbc3337085045a4efa534;hb=1c47e0da8f2571bc34dbdc368c3c1f55318c3aa0;hp=46a9d6c9d56a7dc37e443f1127e34d6d69b78e92;hpb=be64f90b53d09d9720dc6e06ff8ab61d96c03932;p=libsigrok.git diff --git a/src/hardware/sysclk-lwla/protocol.c b/src/hardware/sysclk-lwla/protocol.c index 46a9d6c9..b4c3171e 100644 --- a/src/hardware/sysclk-lwla/protocol.c +++ b/src/hardware/sysclk-lwla/protocol.c @@ -19,12 +19,8 @@ #include #include -#include "lwla.h" #include "protocol.h" - -/* Status polling interval during acquisition. - */ -#define POLL_INTERVAL 100 /* ms */ +#include "lwla.h" /* Submit an already filled-in USB transfer. */ @@ -145,7 +141,7 @@ static void handle_status_response(const struct sr_dev_inst *sdi) } devc->state = STATE_STATUS_WAIT; - sr_spew("Captured %zu words, %" PRIu64 " ms, status 0x%02X.", + sr_spew("Captured %u words, %" PRIu64 " ms, status 0x%02X.", acq->mem_addr_fill, acq->duration_now, acq->status); if ((~old_status & acq->status & STATUS_TRIGGERED) != 0) @@ -189,13 +185,13 @@ static void handle_length_response(const struct sr_dev_inst *sdi) submit_request(sdi, STATE_READ_FINISH); return; } - sr_dbg("%zu words in capture buffer.", + sr_dbg("%u words in capture buffer.", acq->mem_addr_stop - acq->mem_addr_next); submit_request(sdi, STATE_READ_PREPARE); } -/* Evaluate and act on the response to a capture length request. +/* Evaluate and act on the response to a capture memory read request. */ static void handle_read_response(const struct sr_dev_inst *sdi) { @@ -203,7 +199,7 @@ static void handle_read_response(const struct sr_dev_inst *sdi) struct acquisition_state *acq; struct sr_datafeed_packet packet; struct sr_datafeed_logic logic; - size_t end_addr; + unsigned int end_addr; devc = sdi->priv; acq = devc->acquisition; @@ -216,6 +212,7 @@ static void handle_read_response(const struct sr_dev_inst *sdi) end_addr = MIN(acq->mem_addr_next, acq->mem_addr_stop); acq->in_index = 0; + /* * Repeatedly call the model-specific read response handler until * all data received in the transfer has been accounted for. @@ -280,7 +277,6 @@ static int transfer_event(int fd, int revents, void *cb_data) struct dev_context *devc; struct drv_context *drvc; struct timeval tv; - struct sr_datafeed_packet packet; int ret; (void)fd; @@ -320,10 +316,7 @@ static int transfer_event(int fd, int revents, void *cb_data) /* We are done, clean up and send end packet to session bus. */ clear_acquisition_state(sdi); - - packet.type = SR_DF_END; - packet.payload = NULL; - sr_session_send(sdi, &packet); + std_session_send_df_end(sdi, LOG_PREFIX); return G_SOURCE_REMOVE; } @@ -341,7 +334,8 @@ static void LIBUSB_CALL transfer_out_completed(struct libusb_transfer *transfer) acq = devc->acquisition; if (transfer->status != LIBUSB_TRANSFER_COMPLETED) { - sr_err("Transfer to device failed: %d.", transfer->status); + sr_err("Transfer to device failed (state %d): %s.", + devc->state, libusb_error_name(transfer->status)); devc->transfer_error = TRUE; return; } @@ -548,6 +542,7 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi) struct drv_context *drvc; struct dev_context *devc; int ret; + const int poll_interval_ms = 100; drvc = sdi->driver->context; devc = sdi->priv; @@ -570,7 +565,7 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi) return ret; } /* Register event source for asynchronous USB I/O. */ - ret = usb_source_add(sdi->session, drvc->sr_ctx, POLL_INTERVAL, + ret = usb_source_add(sdi->session, drvc->sr_ctx, poll_interval_ms, &transfer_event, (struct sr_dev_inst *)sdi); if (ret != SR_OK) { clear_acquisition_state(sdi); @@ -578,13 +573,13 @@ SR_PRIV int lwla_start_acquisition(const struct sr_dev_inst *sdi) } ret = submit_request(sdi, STATE_START_CAPTURE); - if (ret == SR_OK) { - /* Send header packet to the session bus. */ + if (ret == SR_OK) ret = std_session_send_df_header(sdi, LOG_PREFIX); - } + if (ret != SR_OK) { usb_source_remove(sdi->session, drvc->sr_ctx); clear_acquisition_state(sdi); } + return ret; }