X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fasix-sigma%2Fasix-sigma.c;h=0a2ec990ac38d47467715d015b9cab1d3c09366d;hb=41812aca436805b0614f2a8f31cf2f8ce494aea0;hp=c02827461214329deae2c411d9fbe8657ff06bbe;hpb=f57d8ffe66612a1fdc20ed09c222f8ea59bd84d4;p=libsigrok.git diff --git a/src/hardware/asix-sigma/asix-sigma.c b/src/hardware/asix-sigma/asix-sigma.c index c0282746..0a2ec990 100644 --- a/src/hardware/asix-sigma/asix-sigma.c +++ b/src/hardware/asix-sigma/asix-sigma.c @@ -39,7 +39,6 @@ #define USB_MODEL_NAME "SIGMA" SR_PRIV struct sr_dev_driver asix_sigma_driver_info; -static struct sr_dev_driver *di = &asix_sigma_driver_info; static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data); /* @@ -131,13 +130,23 @@ static int sigma_write(void *buf, size_t size, struct dev_context *devc) return ret; } +/* + * NOTE: We chose the buffer size to be large enough to hold any write to the + * device. We still print a message just in case. + */ static int sigma_write_register(uint8_t reg, uint8_t *data, size_t len, struct dev_context *devc) { size_t i; - uint8_t buf[len + 2]; + uint8_t buf[80]; int idx = 0; + if ((len + 2) > sizeof(buf)) { + sr_err("Attempted to write %zu bytes, but buffer is too small.", + len + 2); + return SR_ERR_BUG; + } + buf[idx++] = REG_ADDR_LOW | (reg & 0xf); buf[idx++] = REG_ADDR_HIGH | (reg >> 4); @@ -312,20 +321,19 @@ static void clear_helper(void *priv) ftdi_deinit(&devc->ftdic); } -static int dev_clear(void) +static int dev_clear(const struct sr_dev_driver *di) { return std_dev_clear(di, clear_helper); } -static int init(struct sr_context *sr_ctx) +static int init(struct sr_dev_driver *di, struct sr_context *sr_ctx) { return std_init(sr_ctx, di, LOG_PREFIX); } -static GSList *scan(GSList *options) +static GSList *scan(struct sr_dev_driver *di, GSList *options) { struct sr_dev_inst *sdi; - struct sr_channel *ch; struct drv_context *drvc; struct dev_context *devc; GSList *devices; @@ -337,7 +345,7 @@ static GSList *scan(GSList *options) (void)options; - drvc = di->priv; + drvc = di->context; devices = NULL; @@ -383,13 +391,8 @@ static GSList *scan(GSList *options) sdi->model = g_strdup(USB_MODEL_NAME); sdi->driver = di; - for (i = 0; i < ARRAY_SIZE(channel_names); i++) { - ch = sr_channel_new(i, SR_CHANNEL_LOGIC, TRUE, - channel_names[i]); - if (!ch) - return NULL; - sdi->channels = g_slist_append(sdi->channels, ch); - } + for (i = 0; i < ARRAY_SIZE(channel_names); i++) + sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_names[i]); devices = g_slist_append(devices, sdi); drvc->instances = g_slist_append(drvc->instances, sdi); @@ -406,9 +409,9 @@ free: return NULL; } -static GSList *dev_list(void) +static GSList *dev_list(const struct sr_dev_driver *di) { - return ((struct drv_context *)(di->priv))->instances; + return ((struct drv_context *)(di->context))->instances; } /* @@ -426,7 +429,7 @@ static int sigma_fpga_init_bitbang(struct dev_context *devc) 0x01, 0x03, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, }; - int i, ret, timeout = 10000; + int i, ret, timeout = (10 * 1000); uint8_t data; /* Section 2. part 1), do the FPGA suicide. */ @@ -448,7 +451,7 @@ static int sigma_fpga_init_bitbang(struct dev_context *devc) if (data & (1 << 5)) return 0; /* The D6 was not asserted yet, wait a bit. */ - usleep(10000); + g_usleep(10 * 1000); } return SR_ERR_TIMEOUT; @@ -597,7 +600,7 @@ static int upload_firmware(int firmware_idx, struct dev_context *devc) } /* Four times the speed of sigmalogan - Works well. */ - ret = ftdi_set_baudrate(ftdic, 750000); + ret = ftdi_set_baudrate(ftdic, 750 * 1000); if (ret < 0) { sr_err("ftdi_set_baudrate failed: %s", ftdi_get_error_string(ftdic)); @@ -612,12 +615,12 @@ static int upload_firmware(int firmware_idx, struct dev_context *devc) /* Prepare firmware. */ ret = sigma_fw_2_bitbang(firmware, &buf, &buf_size); if (ret != SR_OK) { - sr_err("An error occured while reading the firmware: %s", + sr_err("An error occurred while reading the firmware: %s", firmware); return ret; } - /* Upload firmare. */ + /* Upload firmware. */ sr_info("Uploading firmware file '%s'.", firmware); sigma_write(buf, buf_size, devc); @@ -789,7 +792,6 @@ static int convert_trigger(const struct sr_dev_inst *sdi) } } - return SR_OK; } @@ -808,9 +810,9 @@ static int dev_close(struct sr_dev_inst *sdi) return SR_OK; } -static int cleanup(void) +static int cleanup(const struct sr_dev_driver *di) { - return dev_clear(); + return dev_clear(di); } static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, @@ -891,7 +893,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst * GVariant *gvar; GVariantBuilder gvb; - (void)sdi; (void)cg; switch (key) { @@ -955,7 +956,6 @@ static int get_trigger_offset(uint8_t *samples, uint16_t last_sample, return i & 0x7; } - /* * Return the timestamp of "DRAM cluster". */ @@ -1090,7 +1090,7 @@ static int decode_chunk_ts(struct sigma_dram_line *dram_line, trigger_event); } - /* Find in which cluster the trigger occured. */ + /* Find in which cluster the trigger occurred. */ trigger_cluster = trigger_event / EVENTS_PER_CLUSTER; } @@ -1375,7 +1375,7 @@ static int build_basic_trigger(struct triggerlut *lut, struct dev_context *devc) memset(lut, 0, sizeof(struct triggerlut)); - /* Contant for simple triggers. */ + /* Constant for simple triggers. */ lut->m4 = 0xa000; /* Value/mask trigger support. */ @@ -1554,5 +1554,5 @@ SR_PRIV struct sr_dev_driver asix_sigma_driver_info = { .dev_close = dev_close, .dev_acquisition_start = dev_acquisition_start, .dev_acquisition_stop = dev_acquisition_stop, - .priv = NULL, + .context = NULL, };