X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fchronovu-la8%2Fchronovu-la8.c;h=9c6235112a5aec51689bfc38bde4ca6fb8154a4f;hb=1d9a8a5fe1458d4b1ecd250161a7962988359350;hp=1eb52a2ec8ca193ca229c08bd36b7e803f6ed30a;hpb=e7bad06355ea218d83e6df1d1137e67a58513b35;p=libsigrok.git diff --git a/hardware/chronovu-la8/chronovu-la8.c b/hardware/chronovu-la8/chronovu-la8.c index 1eb52a2e..9c623511 100644 --- a/hardware/chronovu-la8/chronovu-la8.c +++ b/hardware/chronovu-la8/chronovu-la8.c @@ -21,8 +21,9 @@ #include #include #include -#include -#include +#include +#include "sigrok.h" +#include "sigrok-internal.h" #define USB_VENDOR_ID 0x0403 #define USB_PRODUCT_ID 0x6001 @@ -39,7 +40,19 @@ #define BS 4096 /* Block size */ #define NUM_BLOCKS 2048 /* Number of blocks */ -static GSList *device_instances = NULL; +static GSList *dev_insts = NULL; + +static const char *probe_names[NUM_PROBES + 1] = { + "0", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + NULL, +}; struct la8 { /** FTDI device context (used by libftdi). */ @@ -48,9 +61,6 @@ struct la8 { /** The currently configured samplerate of the device. */ uint64_t cur_samplerate; - /** period in picoseconds corresponding to the samplerate */ - uint64_t period_ps; - /** The current sampling limit (in ms). */ uint64_t limit_msec; @@ -101,7 +111,7 @@ struct la8 { uint8_t divcount; }; -/* This will be initialized via hw_get_device_info()/SR_DI_SAMPLERATES. */ +/* This will be initialized via hw_get_dev_info()/SR_DI_SAMPLERATES. */ static uint64_t supported_samplerates[255 + 1] = { 0 }; /* @@ -126,7 +136,7 @@ static int capabilities[] = { /* Function prototypes. */ static int la8_close_usb_reset_sequencer(struct la8 *la8); -static void hw_stop_acquisition(int device_index, gpointer session_data); +static int hw_stop_acquisition(int dev_index, gpointer session_data); static int la8_reset(struct la8 *la8); static void fill_supported_samplerates_if_needed(void) @@ -160,8 +170,8 @@ static int is_valid_samplerate(uint64_t samplerate) return 1; } - sr_warn("la8: %s: invalid samplerate (%" PRIu64 "Hz)", - __func__, samplerate); + sr_err("la8: %s: invalid samplerate (%" PRIu64 "Hz)", + __func__, samplerate); return 0; } @@ -227,12 +237,12 @@ static int la8_write(struct la8 *la8, uint8_t *buf, int size) bytes_written = ftdi_write_data(la8->ftdic, buf, size); if (bytes_written < 0) { - sr_warn("la8: %s: ftdi_write_data: (%d) %s", __func__, - bytes_written, ftdi_get_error_string(la8->ftdic)); + sr_err("la8: %s: ftdi_write_data: (%d) %s", __func__, + bytes_written, ftdi_get_error_string(la8->ftdic)); (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ } else if (bytes_written != size) { - sr_warn("la8: %s: bytes to write: %d, bytes written: %d", - __func__, size, bytes_written); + sr_err("la8: %s: bytes to write: %d, bytes written: %d", + __func__, size, bytes_written); (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ } @@ -274,11 +284,11 @@ static int la8_read(struct la8 *la8, uint8_t *buf, int size) bytes_read = ftdi_read_data(la8->ftdic, buf, size); if (bytes_read < 0) { - sr_warn("la8: %s: ftdi_read_data: (%d) %s", __func__, - bytes_read, ftdi_get_error_string(la8->ftdic)); + sr_err("la8: %s: ftdi_read_data: (%d) %s", __func__, + bytes_read, ftdi_get_error_string(la8->ftdic)); } else if (bytes_read != size) { - // sr_warn("la8: %s: bytes to read: %d, bytes read: %d", - // __func__, size, bytes_read); + // sr_err("la8: %s: bytes to read: %d, bytes read: %d", + // __func__, size, bytes_read); } return bytes_read; @@ -299,8 +309,8 @@ static int la8_close(struct la8 *la8) } if ((ret = ftdi_usb_close(la8->ftdic)) < 0) { - sr_warn("la8: %s: ftdi_usb_close: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); + sr_err("la8: %s: ftdi_usb_close: (%d) %s", + __func__, ret, ftdi_get_error_string(la8->ftdic)); } return ret; @@ -318,8 +328,6 @@ static int la8_close_usb_reset_sequencer(struct la8 *la8) uint8_t buf[8] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; int ret; - sr_spew("la8: entering %s", __func__); - if (!la8) { sr_err("la8: %s: la8 was NULL", __func__); return SR_ERR_ARG; @@ -341,16 +349,14 @@ static int la8_close_usb_reset_sequencer(struct la8 *la8) /* Log errors, but ignore them (i.e., don't abort). */ if ((ret = ftdi_usb_purge_buffers(la8->ftdic)) < 0) - sr_warn("la8: %s: ftdi_usb_purge_buffers: (%d) %s", + sr_err("la8: %s: ftdi_usb_purge_buffers: (%d) %s", __func__, ret, ftdi_get_error_string(la8->ftdic)); if ((ret = ftdi_usb_reset(la8->ftdic)) < 0) - sr_warn("la8: %s: ftdi_usb_reset: (%d) %s", __func__, - ret, ftdi_get_error_string(la8->ftdic)); + sr_err("la8: %s: ftdi_usb_reset: (%d) %s", __func__, + ret, ftdi_get_error_string(la8->ftdic)); if ((ret = ftdi_usb_close(la8->ftdic)) < 0) - sr_warn("la8: %s: ftdi_usb_close: (%d) %s", __func__, - ret, ftdi_get_error_string(la8->ftdic)); - } else { - sr_spew("la8: %s: usb_dev was NULL, nothing to do", __func__); + sr_err("la8: %s: ftdi_usb_close: (%d) %s", __func__, + ret, ftdi_get_error_string(la8->ftdic)); } ftdi_free(la8->ftdic); /* Returns void. */ @@ -461,16 +467,14 @@ static int configure_probes(struct la8 *la8, GSList *probes) return SR_OK; } -static int hw_init(const char *deviceinfo) +static int hw_init(const char *devinfo) { int ret; - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; - sr_spew("la8: entering %s", __func__); - /* Avoid compiler errors. */ - deviceinfo = deviceinfo; + (void)devinfo; /* Allocate memory for our private driver context. */ if (!(la8 = g_try_malloc(sizeof(struct la8)))) { @@ -481,7 +485,6 @@ static int hw_init(const char *deviceinfo) /* Set some sane defaults. */ la8->ftdic = NULL; la8->cur_samplerate = SR_MHZ(100); /* 100MHz == max. samplerate */ - la8->period_ps = 10000; la8->limit_msec = 0; la8->limit_samples = 0; la8->session_id = NULL; @@ -510,24 +513,22 @@ static int hw_init(const char *deviceinfo) /* Check for the device and temporarily open it. */ if ((ret = ftdi_usb_open_desc(la8->ftdic, USB_VENDOR_ID, USB_PRODUCT_ID, USB_DESCRIPTION, NULL)) < 0) { - sr_dbg("la8: %s: ftdi_usb_open_desc: (%d) %s", - __func__, ret, ftdi_get_error_string(la8->ftdic)); (void) la8_close_usb_reset_sequencer(la8); /* Ignore errors. */ goto err_free_ftdic; } sr_dbg("la8: found device"); /* Register the device with libsigrok. */ - sdi = sr_device_instance_new(0, SR_ST_INITIALIZING, + sdi = sr_dev_inst_new(0, SR_ST_INITIALIZING, USB_VENDOR_NAME, USB_MODEL_NAME, USB_MODEL_VERSION); if (!sdi) { - sr_err("la8: %s: sr_device_instance_new failed", __func__); + sr_err("la8: %s: sr_dev_inst_new failed", __func__); goto err_close_ftdic; } sdi->priv = la8; - device_instances = g_slist_append(device_instances, sdi); + dev_insts = g_slist_append(dev_insts, sdi); sr_spew("la8: %s finished successfully", __func__); @@ -549,13 +550,13 @@ err_free_nothing: return 0; } -static int hw_opendev(int device_index) +static int hw_opendev(int dev_index) { int ret; - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -607,7 +608,7 @@ err_opendev_close_ftdic: return SR_ERR; } -static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate) +static int set_samplerate(struct sr_dev_inst *sdi, uint64_t samplerate) { struct la8 *la8; @@ -631,19 +632,18 @@ static int set_samplerate(struct sr_device_instance *sdi, uint64_t samplerate) /* Set the new samplerate. */ la8->cur_samplerate = samplerate; - la8->period_ps = 1000000000000 / samplerate; sr_dbg("la8: samplerate set to %" PRIu64 "Hz", la8->cur_samplerate); return SR_OK; } -static int hw_closedev(int device_index) +static int hw_closedev(int dev_index) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -671,39 +671,37 @@ static int hw_closedev(int device_index) return SR_OK; } -static void hw_cleanup(void) +static int hw_cleanup(void) { GSList *l; - struct sr_device_instance *sdi; - - sr_spew("la8: entering %s", __func__); + struct sr_dev_inst *sdi; + int ret = SR_OK; /* Properly close all devices. */ - for (l = device_instances; l; l = l->next) { - if ((sdi = l->data) == NULL) { - sr_warn("la8: %s: sdi was NULL, continuing", __func__); + for (l = dev_insts; l; l = l->next) { + if (!(sdi = l->data)) { + /* Log error, but continue cleaning up the rest. */ + sr_err("la8: %s: sdi was NULL, continuing", __func__); + ret = SR_ERR_BUG; continue; } - if (sdi->priv != NULL) - free(sdi->priv); - else - sr_warn("la8: %s: sdi->priv was NULL, nothing " - "to do", __func__); - sr_device_instance_free(sdi); /* Returns void. */ - } - g_slist_free(device_instances); /* Returns void. */ - device_instances = NULL; + sr_dev_inst_free(sdi); /* Returns void. */ + } + g_slist_free(dev_insts); /* Returns void. */ + dev_insts = NULL; + + return ret; } -static void *hw_get_device_info(int device_index, int device_info_id) +static void *hw_get_dev_info(int dev_index, int dev_info_id) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; void *info; sr_spew("la8: entering %s", __func__); - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return NULL; } @@ -713,13 +711,16 @@ static void *hw_get_device_info(int device_index, int device_info_id) return NULL; } - switch (device_info_id) { - case SR_DI_INSTANCE: + switch (dev_info_id) { + case SR_DI_INST: info = sdi; break; case SR_DI_NUM_PROBES: info = GINT_TO_POINTER(NUM_PROBES); break; + case SR_DI_PROBE_NAMES: + info = probe_names; + break; case SR_DI_SAMPLERATES: fill_supported_samplerates_if_needed(); info = &samplerates; @@ -740,12 +741,12 @@ static void *hw_get_device_info(int device_index, int device_info_id) return info; } -static int hw_get_status(int device_index) +static int hw_get_status(int dev_index) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { - sr_warn("la8: %s: sdi was NULL, device not found", __func__); + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { + sr_err("la8: %s: sdi was NULL, device not found", __func__); return SR_ST_NOT_FOUND; } @@ -761,14 +762,14 @@ static int *hw_get_capabilities(void) return capabilities; } -static int hw_set_configuration(int device_index, int capability, void *value) +static int hw_set_configuration(int dev_index, int capability, void *value) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; sr_spew("la8: entering %s", __func__); - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -853,7 +854,7 @@ static int la8_read_block(struct la8 *la8) /* Check if block read was successful or a timeout occured. */ if (bytes_read != BS) { - sr_warn("la8: %s: trigger timed out", __func__); + sr_err("la8: %s: trigger timed out", __func__); (void) la8_reset(la8); /* Ignore errors. */ return SR_ERR; } @@ -914,8 +915,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block) sr_spew("la8: sending SR_DF_LOGIC packet (%d bytes) for " "block %d", BS, block); packet.type = SR_DF_LOGIC; - packet.timeoffset = block * BS * la8->period_ps; - packet.duration = BS * la8->period_ps; packet.payload = &logic; logic.length = BS; logic.unitsize = 1; @@ -939,8 +938,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block) sr_spew("la8: sending pre-trigger SR_DF_LOGIC packet, " "start = %d, length = %d", block * BS, trigger_point); packet.type = SR_DF_LOGIC; - packet.timeoffset = block * BS * la8->period_ps; - packet.duration = trigger_point * la8->period_ps; packet.payload = &logic; logic.length = trigger_point; logic.unitsize = 1; @@ -952,8 +949,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block) sr_spew("la8: sending SR_DF_TRIGGER packet, sample = %d", (block * BS) + trigger_point); packet.type = SR_DF_TRIGGER; - packet.timeoffset = (block * BS + trigger_point) * la8->period_ps; - packet.duration = 0; packet.payload = NULL; sr_session_bus(la8->session_id, &packet); @@ -964,8 +959,6 @@ static void send_block_to_session_bus(struct la8 *la8, int block) "start = %d, length = %d", (block * BS) + trigger_point, BS - trigger_point); packet.type = SR_DF_LOGIC; - packet.timeoffset = (block * BS + trigger_point) * la8->period_ps; - packet.duration = (BS - trigger_point) * la8->period_ps; packet.payload = &logic; logic.length = BS - trigger_point; logic.unitsize = 1; @@ -977,15 +970,15 @@ static void send_block_to_session_bus(struct la8 *la8, int block) static int receive_data(int fd, int revents, void *session_data) { int i, ret; - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; /* Avoid compiler errors. */ - fd = fd; - revents = revents; + (void)fd; + (void)revents; if (!(sdi = session_data)) { - sr_err("la8: %s: user_data was NULL", __func__); + sr_err("la8: %s: session_data was NULL", __func__); return FALSE; } @@ -1019,9 +1012,9 @@ static int receive_data(int fd, int revents, void *session_data) return TRUE; } -static int hw_start_acquisition(int device_index, gpointer session_data) +static int hw_start_acquisition(int dev_index, gpointer session_data) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; struct sr_datafeed_packet packet; struct sr_datafeed_header header; @@ -1030,7 +1023,7 @@ static int hw_start_acquisition(int device_index, gpointer session_data) sr_spew("la8: entering %s", __func__); - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); return SR_ERR; /* TODO: SR_ERR_ARG? */ } @@ -1080,7 +1073,6 @@ static int hw_start_acquisition(int device_index, gpointer session_data) gettimeofday(&header.starttime, NULL); header.samplerate = la8->cur_samplerate; header.num_logic_probes = NUM_PROBES; - header.num_analog_probes = 0; sr_session_bus(session_data, &packet); /* Time when we should be done (for detecting trigger timeouts). */ @@ -1095,31 +1087,33 @@ static int hw_start_acquisition(int device_index, gpointer session_data) return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_data) +static int hw_stop_acquisition(int dev_index, gpointer session_data) { - struct sr_device_instance *sdi; + struct sr_dev_inst *sdi; struct la8 *la8; struct sr_datafeed_packet packet; sr_dbg("la8: stopping acquisition"); - if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + if (!(sdi = sr_dev_inst_get(dev_insts, dev_index))) { sr_err("la8: %s: sdi was NULL", __func__); - return; + return SR_ERR_BUG; } if (!(la8 = sdi->priv)) { sr_err("la8: %s: sdi->priv was NULL", __func__); - return; + return SR_ERR_BUG; } /* Send end packet to the session bus. */ sr_dbg("la8: %s: sending SR_DF_END", __func__); packet.type = SR_DF_END; sr_session_bus(session_data, &packet); + + return SR_OK; } -struct sr_device_plugin chronovu_la8_plugin_info = { +SR_PRIV struct sr_dev_plugin chronovu_la8_plugin_info = { .name = "chronovu-la8", .longname = "ChronoVu LA8", .api_version = 1, @@ -1127,7 +1121,7 @@ struct sr_device_plugin chronovu_la8_plugin_info = { .cleanup = hw_cleanup, .opendev = hw_opendev, .closedev = hw_closedev, - .get_device_info = hw_get_device_info, + .get_dev_info = hw_get_dev_info, .get_status = hw_get_status, .get_capabilities = hw_get_capabilities, .set_configuration = hw_set_configuration,