static int config_commit(const struct sr_dev_inst *sdi) { uint8_t state = hung_chang_dso_2100_read_mbox(sdi->conn, 0.02); int ret; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; switch (state) { case 0x03: case 0x14: case 0x21: /* we will travel the complete config path on our way to state 1 */ break; case 0x00: state = 0x01; default: ret = hung_chang_dso_2100_move_to(sdi, 1); if (ret != SR_OK) return ret; case 0x01: hung_chang_dso_2100_write_mbox(sdi->conn, 4); } ret = hung_chang_dso_2100_move_to(sdi, 1); if (ret != SR_OK) return ret; return hung_chang_dso_2100_move_to(sdi, state); }
SR_PRIV int hung_chang_dso_2100_poll(int fd, int revents, void *cb_data) { struct sr_datafeed_packet packet = { .type = SR_DF_FRAME_BEGIN }; const struct sr_dev_inst *sdi; struct dev_context *devc; uint8_t state, buf[1000]; (void)fd; (void)revents; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; if (devc->state_known) hung_chang_dso_2100_write_mbox(sdi->conn, 0x99); state = hung_chang_dso_2100_read_mbox(sdi->conn, 0.00025); devc->state_known = (state != 0x00); if (!devc->state_known || state == 0x21) return TRUE; if (state != 0x03) { sr_err("Unexpected state 0x%X while checking for trigger", state); return FALSE; } sr_session_send(sdi, &packet); if (devc->channel) { while (read_subframe(sdi, buf)) { if (hung_chang_dso_2100_move_to(sdi, 1) != SR_OK) break; hung_chang_dso_2100_write_mbox(sdi->conn, 3); g_usleep(1700); if (hung_chang_dso_2100_read_mbox(sdi->conn, 0.02) != 0x03) break; } } packet.type = SR_DF_FRAME_END; sr_session_send(sdi, &packet); if (++devc->frame >= devc->frame_limit) hung_chang_dso_2100_dev_acquisition_stop(sdi); else hung_chang_dso_2100_move_to(sdi, 0x21); return TRUE; }
static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc = sdi->priv; int ret; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; if (devc->channel) { static const float res_array[] = {0.5, 1, 2, 5}; static const uint8_t relays[] = {100, 10, 10, 1}; devc->factor = devc->probe[devc->channel - 1] / 32.0; devc->factor *= res_array[devc->cctl[devc->channel - 1] & 0x03]; devc->factor /= relays[(devc->cctl[devc->channel - 1] >> 4) & 0x03]; } devc->frame = 0; devc->cb_data = cb_data; devc->state_known = TRUE; devc->step = 0; devc->adc2 = FALSE; devc->retries = MAX_RETRIES; ret = hung_chang_dso_2100_move_to(sdi, 0x21); if (ret != SR_OK) return ret; std_session_send_df_header(cb_data, LOG_PREFIX); sr_session_source_add(sdi->session, 0, 0, 8, hung_chang_dso_2100_poll, (void *)sdi); return SR_OK; }
static int dev_open(struct sr_dev_inst *sdi) { struct dev_context *devc = sdi->priv; int i; if (ieee1284_open(sdi->conn, 0, &i) != E1284_OK) goto fail1; if (ieee1284_claim(sdi->conn) != E1284_OK) goto fail2; if (ieee1284_data_dir(sdi->conn, 1) != E1284_OK) goto fail3; if (hung_chang_dso_2100_move_to(sdi, 1)) goto fail3; devc->samples = g_try_malloc(1000 * sizeof(*devc->samples)); if (!devc->samples) goto fail3; return SR_OK; fail3: hung_chang_dso_2100_reset_port(sdi->conn); ieee1284_release(sdi->conn); fail2: ieee1284_close(sdi->conn); fail1: return SR_ERR; }
static int dev_acquisition_stop(struct sr_dev_inst *sdi) { std_session_send_df_end(sdi); sr_session_source_remove(sdi->session, -1); hung_chang_dso_2100_move_to(sdi, 1); return SR_OK; }
SR_PRIV int hung_chang_dso_2100_dev_acquisition_stop(const struct sr_dev_inst *sdi) { if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; std_session_send_df_end(sdi); sr_session_source_remove(sdi->session, -1); hung_chang_dso_2100_move_to(sdi, 1); return SR_OK; }
SR_PRIV int hung_chang_dso_2100_dev_acquisition_stop(const struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet = { .type = SR_DF_END }; if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; sr_session_send(cb_data, &packet); sr_session_source_remove(sdi->session, 0); hung_chang_dso_2100_move_to(sdi, 1); return SR_OK; }