cem-dt-885x: Mark serial access as nonblocking, remove SERIAL_NONBLOCK flag.
These calls were already nonblocking since this driver opened the port with the SERIAL_NONBLOCK flag. Having marked them as such, we can remove the flag. Also remove an unnecessary reopen of the port to change its blocking status.
This commit is contained in:
parent
ca4266a02f
commit
d7b269da8f
|
@ -97,14 +97,14 @@ static GSList *scan(GSList *options)
|
||||||
if (!(serial = sr_serial_dev_inst_new(conn, SERIALCOMM)))
|
if (!(serial = sr_serial_dev_inst_new(conn, SERIALCOMM)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (serial_open(serial, SERIAL_RDONLY | SERIAL_NONBLOCK) != SR_OK)
|
if (serial_open(serial, SERIAL_RDONLY) != SR_OK)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
devices = NULL;
|
devices = NULL;
|
||||||
drvc = di->priv;
|
drvc = di->priv;
|
||||||
start = g_get_monotonic_time();
|
start = g_get_monotonic_time();
|
||||||
while (g_get_monotonic_time() - start < MAX_SCAN_TIME) {
|
while (g_get_monotonic_time() - start < MAX_SCAN_TIME) {
|
||||||
if (serial_read(serial, &c, 1) == 1 && c == 0xa5) {
|
if (serial_read_nonblocking(serial, &c, 1) == 1 && c == 0xa5) {
|
||||||
/* Found one. */
|
/* Found one. */
|
||||||
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "CEM",
|
if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, "CEM",
|
||||||
"DT-885x", NULL)))
|
"DT-885x", NULL)))
|
||||||
|
|
|
@ -385,7 +385,7 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data)
|
||||||
devc = sdi->priv;
|
devc = sdi->priv;
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
if (revents == G_IO_IN) {
|
if (revents == G_IO_IN) {
|
||||||
if (serial_read(serial, &c, 1) != 1)
|
if (serial_read_nonblocking(serial, &c, 1) != 1)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
process_byte(sdi, c, TRUE);
|
process_byte(sdi, c, TRUE);
|
||||||
|
|
||||||
|
@ -396,7 +396,7 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data)
|
||||||
} else {
|
} else {
|
||||||
/* Tell device to start transferring from memory. */
|
/* Tell device to start transferring from memory. */
|
||||||
cmd = CMD_TRANSFER_MEMORY;
|
cmd = CMD_TRANSFER_MEMORY;
|
||||||
serial_write(serial, &cmd, 1);
|
serial_write_nonblocking(serial, &cmd, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,7 +418,7 @@ static int wait_for_token(const struct sr_dev_inst *sdi, int8_t *tokens, int tim
|
||||||
devc->state = ST_INIT;
|
devc->state = ST_INIT;
|
||||||
start_time = g_get_monotonic_time() / 1000;
|
start_time = g_get_monotonic_time() / 1000;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (serial_read(serial, &c, 1) != 1)
|
if (serial_read_nonblocking(serial, &c, 1) != 1)
|
||||||
/* Device might have gone away. */
|
/* Device might have gone away. */
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
process_byte(sdi, c, FALSE);
|
process_byte(sdi, c, FALSE);
|
||||||
|
@ -453,7 +453,7 @@ static int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd,
|
||||||
* only thing to do is wait for the token that will confirm
|
* only thing to do is wait for the token that will confirm
|
||||||
* whether the command worked or not, and resend if needed. */
|
* whether the command worked or not, and resend if needed. */
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (serial_write(serial, (const void *)&cmd, 1) != 1)
|
if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
if (wait_for_token(sdi, tokens, timeout) == SR_ERR)
|
if (wait_for_token(sdi, tokens, timeout) == SR_ERR)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
@ -811,20 +811,14 @@ SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi)
|
||||||
|
|
||||||
serial = sdi->conn;
|
serial = sdi->conn;
|
||||||
|
|
||||||
/* Reopen the port in non-blocking mode, so we can properly
|
|
||||||
* detect when the device stops communicating. */
|
|
||||||
serial_close(serial);
|
|
||||||
if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK)
|
|
||||||
return SR_ERR;
|
|
||||||
|
|
||||||
cmd = CMD_TOGGLE_POWER_OFF;
|
cmd = CMD_TOGGLE_POWER_OFF;
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
serial_flush(serial);
|
serial_flush(serial);
|
||||||
if (serial_write(serial, (const void *)&cmd, 1) != 1)
|
if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1)
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
/* It never takes more than 23ms for the next token to arrive. */
|
/* It never takes more than 23ms for the next token to arrive. */
|
||||||
g_usleep(25 * 1000);
|
g_usleep(25 * 1000);
|
||||||
if (serial_read(serial, &c, 1) != 1)
|
if (serial_read_nonblocking(serial, &c, 1) != 1)
|
||||||
/* Device is no longer responding. Good! */
|
/* Device is no longer responding. Good! */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue