From: Uwe Hermann Date: Tue, 23 Apr 2013 21:06:02 +0000 (+0200) Subject: mic-985xx: Use sr_dev_inst to store connection handle. X-Git-Tag: dsupstream~78 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=886bd5e05686617c928be2d600ce91ed298a2331;p=libsigrok.git mic-985xx: Use sr_dev_inst to store connection handle. --- diff --git a/hardware/mic-985xx/api.c b/hardware/mic-985xx/api.c index 8a18313f..866acb41 100644 --- a/hardware/mic-985xx/api.c +++ b/hardware/mic-985xx/api.c @@ -54,6 +54,7 @@ static int clear_instances(int idx) struct sr_dev_inst *sdi; struct drv_context *drvc; struct dev_context *devc; + struct sr_serial_dev_inst *serial; GSList *l; struct sr_dev_driver *di; @@ -67,7 +68,8 @@ static int clear_instances(int idx) continue; if (!(devc = sdi->priv)) continue; - sr_serial_dev_inst_free(devc->serial); + serial = sdi->conn; + sr_serial_dev_inst_free(serial); sr_dev_inst_free(sdi); } @@ -118,7 +120,8 @@ static GSList *scan(const char *conn, const char *serialcomm, int idx) goto scan_cleanup; } - devc->serial = serial; + sdi->inst_type = SR_INST_SERIAL; + sdi->conn = serial; sdi->priv = devc; sdi->driver = mic_devs[idx].di; @@ -181,11 +184,10 @@ static GSList *hw_dev_list(int idx) static int hw_dev_open(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - devc = sdi->priv; + struct sr_serial_dev_inst *serial; - if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) + serial = sdi->conn; + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; sdi->status = SR_ST_ACTIVE; @@ -195,12 +197,11 @@ static int hw_dev_open(struct sr_dev_inst *sdi) static int hw_dev_close(struct sr_dev_inst *sdi) { - struct dev_context *devc; - - devc = sdi->priv; + struct sr_serial_dev_inst *serial; - if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial); + serial = sdi->conn; + if (serial && serial->fd != -1) { + serial_close(serial); sdi->status = SR_ST_INACTIVE; } @@ -265,6 +266,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data, int idx) { struct dev_context *devc; + struct sr_serial_dev_inst *serial; devc = sdi->priv; @@ -277,7 +279,8 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN); /* Poll every 100ms, or whenever some data comes in. */ - sr_source_add(devc->serial->fd, G_IO_IN, 100, + serial = sdi->conn; + sr_source_add(serial->fd, G_IO_IN, 100, mic_devs[idx].receive_data, (void *)sdi); return SR_OK; @@ -286,7 +289,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { return std_hw_dev_acquisition_stop_serial(sdi, cb_data, hw_dev_close, - ((struct dev_context *)(sdi->priv))->serial, DRIVER_LOG_DOMAIN); + sdi->conn, DRIVER_LOG_DOMAIN); } /* Driver-specific API function wrappers */ diff --git a/hardware/mic-985xx/protocol.c b/hardware/mic-985xx/protocol.c index 5f2825e6..15368065 100644 --- a/hardware/mic-985xx/protocol.c +++ b/hardware/mic-985xx/protocol.c @@ -146,13 +146,15 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx) static void handle_new_data(struct sr_dev_inst *sdi, int idx) { struct dev_context *devc; + struct sr_serial_dev_inst *serial; int len, i, offset = 0; devc = sdi->priv; + serial = sdi->conn; /* Try to get as much data as the buffer can hold. */ len = SERIAL_BUFSIZE - devc->buflen; - len = serial_read(devc->serial, devc->buf + devc->buflen, len); + len = serial_read(serial, devc->buf + devc->buflen, len); if (len < 1) { sr_err("Serial port read error: %d.", len); return; @@ -182,6 +184,7 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) struct dev_context *devc; int64_t t; static gboolean first_time = TRUE; + struct sr_serial_dev_inst *serial; (void)fd; @@ -191,13 +194,15 @@ static int receive_data(int fd, int revents, int idx, void *cb_data) if (!(devc = sdi->priv)) return TRUE; + serial = sdi->conn; + if (revents == G_IO_IN) { /* New data arrived. */ handle_new_data(sdi, idx); } else { /* Timeout. */ if (first_time) { - mic_cmd_set_realtime_mode(devc->serial); + mic_cmd_set_realtime_mode(serial); first_time = FALSE; } } diff --git a/hardware/mic-985xx/protocol.h b/hardware/mic-985xx/protocol.h index af926a02..0e7aeb0c 100644 --- a/hardware/mic-985xx/protocol.h +++ b/hardware/mic-985xx/protocol.h @@ -78,8 +78,6 @@ struct dev_context { int64_t starttime; - struct sr_serial_dev_inst *serial; - uint8_t buf[SERIAL_BUFSIZE]; int bufoffset; int buflen;