X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fasix-sigma%2Fasix-sigma.c;h=e7d6f7833103bd608a4a29344bbec7ec2ad9f4ea;hb=719c5a934c7705466a449854b876b9962eb4cb5e;hp=50bb932db26030405a611ebd684c916a8ff02521;hpb=86f5e3d826fc9059e110f07221cb1a30652ceac2;p=libsigrok.git diff --git a/hardware/asix-sigma/asix-sigma.c b/hardware/asix-sigma/asix-sigma.c index 50bb932d..e7d6f783 100644 --- a/hardware/asix-sigma/asix-sigma.c +++ b/hardware/asix-sigma/asix-sigma.c @@ -98,7 +98,7 @@ static const char *firmware_files[] = { "asix-sigma-phasor.fw", /* Frequency counter */ }; -static void hw_stop_acquisition(int device_index, gpointer session_device_id); +static void hw_stop_acquisition(int device_index, gpointer session_data); static int sigma_read(void *buf, size_t size, struct sigma *sigma) { @@ -332,13 +332,13 @@ static int bin2bitbang(const char *filename, fseek(f, 0, SEEK_SET); if (!(compressed_buf = g_try_malloc(file_size))) { - sr_err("asix: %s: compressed_buf malloc failed", __func__); + sr_err("sigma: %s: compressed_buf malloc failed", __func__); fclose(f); return SR_ERR_MALLOC; } if (!(firmware = g_try_malloc(buffer_size))) { - sr_err("asix: %s: firmware malloc failed", __func__); + sr_err("sigma: %s: firmware malloc failed", __func__); fclose(f); g_free(compressed_buf); return SR_ERR_MALLOC; @@ -366,7 +366,7 @@ static int bin2bitbang(const char *filename, *buf = p = (unsigned char *)g_try_malloc(*buf_size); if (!p) { - sr_err("asix: %s: buf/p malloc failed", __func__); + sr_err("sigma: %s: buf/p malloc failed", __func__); g_free(compressed_buf); g_free(firmware); return SR_ERR_MALLOC; @@ -403,7 +403,7 @@ static int hw_init(const char *deviceinfo) deviceinfo = deviceinfo; if (!(sigma = g_try_malloc(sizeof(struct sigma)))) { - sr_err("asix: %s: sigma malloc failed", __func__); + sr_err("sigma: %s: sigma malloc failed", __func__); return 0; /* FIXME: Should be SR_ERR_MALLOC. */ } @@ -415,6 +415,7 @@ static int hw_init(const char *deviceinfo) goto free; sigma->cur_samplerate = 0; + sigma->period_ps = 0; sigma->limit_msec = 0; sigma->cur_firmware = -1; sigma->num_probes = 0; @@ -585,6 +586,7 @@ static int set_samplerate(struct sr_device_instance *sdi, } sigma->cur_samplerate = samplerate; + sigma->period_ps = 1000000000000 / samplerate; sigma->samples_per_event = 16 / sigma->num_probes; sigma->state.state = SIGMA_IDLE; @@ -675,19 +677,28 @@ static int configure_probes(struct sr_device_instance *sdi, GSList *probes) return SR_OK; } -static void hw_closedev(int device_index) +static int hw_closedev(int device_index) { struct sr_device_instance *sdi; struct sigma *sigma; - if ((sdi = sr_get_device_instance(device_instances, device_index))) - { - sigma = sdi->priv; - if (sdi->status == SR_ST_ACTIVE) - ftdi_usb_close(&sigma->ftdic); + if (!(sdi = sr_get_device_instance(device_instances, device_index))) { + sr_err("sigma: %s: sdi was NULL", __func__); + return SR_ERR; /* TODO: SR_ERR_ARG? */ + } - sdi->status = SR_ST_INACTIVE; + if (!(sigma = sdi->priv)) { + sr_err("sigma: %s: sdi->priv was NULL", __func__); + return SR_ERR; /* TODO: SR_ERR_ARG? */ } + + /* TODO */ + if (sdi->status == SR_ST_ACTIVE) + ftdi_usb_close(&sigma->ftdic); + + sdi->status = SR_ST_INACTIVE; + + return SR_OK; } static void hw_cleanup(void) @@ -832,13 +843,14 @@ static int get_trigger_offset(uint16_t *samples, uint16_t last_sample, */ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, uint16_t *lastsample, int triggerpos, - uint16_t limit_chunk, void *user_data) + uint16_t limit_chunk, void *session_data) { - struct sr_device_instance *sdi = user_data; + struct sr_device_instance *sdi = session_data; struct sigma *sigma = sdi->priv; uint16_t tsdiff, ts; uint16_t samples[65536 * sigma->samples_per_event]; struct sr_datafeed_packet packet; + struct sr_datafeed_logic logic; int i, j, k, l, numpad, tosend; size_t n = 0, sent = 0; int clustersize = EVENTS_PER_CLUSTER * sigma->samples_per_event; @@ -883,9 +895,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, tosend = MIN(2048, n - sent); packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; sr_session_bus(sigma->session_id, &packet); sent += tosend; @@ -927,9 +943,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, if (tosend > 0) { packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples; sr_session_bus(sigma->session_id, &packet); sent += tosend; @@ -938,8 +958,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, /* Only send trigger if explicitly enabled. */ if (sigma->use_triggers) { packet.type = SR_DF_TRIGGER; - packet.length = 0; - packet.payload = 0; + /* TODO: fill in timeoffset only */ + packet.timeoffset = 0; + packet.duration = 0; sr_session_bus(sigma->session_id, &packet); } } @@ -949,9 +970,13 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, if (tosend > 0) { packet.type = SR_DF_LOGIC; - packet.length = tosend * sizeof(uint16_t); - packet.unitsize = 2; - packet.payload = samples + sent; + /* TODO: fill in timeoffset and duration */ + packet.timeoffset = 0; + packet.duration = 0; + packet.payload = &logic; + logic.length = tosend * sizeof(uint16_t); + logic.unitsize = 2; + logic.data = samples + sent; sr_session_bus(sigma->session_id, &packet); } @@ -961,9 +986,9 @@ static int decode_chunk_ts(uint8_t *buf, uint16_t *lastts, return SR_OK; } -static int receive_data(int fd, int revents, void *user_data) +static int receive_data(int fd, int revents, void *session_data) { - struct sr_device_instance *sdi = user_data; + struct sr_device_instance *sdi = session_data; struct sigma *sigma = sdi->priv; struct sr_datafeed_packet packet; const int chunks_per_read = 32; @@ -990,7 +1015,7 @@ static int receive_data(int fd, int revents, void *user_data) if (running_msec < sigma->limit_msec && numchunks < 32767) return FALSE; - hw_stop_acquisition(sdi->index, user_data); + hw_stop_acquisition(sdi->index, session_data); return FALSE; @@ -998,7 +1023,6 @@ static int receive_data(int fd, int revents, void *user_data) if (sigma->state.chunks_downloaded >= numchunks) { /* End of samples. */ packet.type = SR_DF_END; - packet.length = 0; sr_session_bus(sigma->session_id, &packet); sigma->state.state = SIGMA_IDLE; @@ -1014,6 +1038,8 @@ static int receive_data(int fd, int revents, void *user_data) bufsz = sigma_read_dram(sigma->state.chunks_downloaded, newchunks, buf, sigma); + /* TODO: Check bufsz. For now, just avoid compiler warnings. */ + (void)bufsz; /* Find first ts. */ if (sigma->state.chunks_downloaded == 0) { @@ -1037,12 +1063,12 @@ static int receive_data(int fd, int revents, void *user_data) &sigma->state.lastts, &sigma->state.lastsample, sigma->state.triggerpos & 0x1ff, - limit_chunk, user_data); + limit_chunk, session_data); else decode_chunk_ts(buf + (i * CHUNK_SIZE), &sigma->state.lastts, &sigma->state.lastsample, - -1, limit_chunk, user_data); + -1, limit_chunk, session_data); ++sigma->state.chunks_downloaded; } @@ -1207,7 +1233,7 @@ static int build_basic_trigger(struct triggerlut *lut, struct sigma *sigma) return SR_OK; } -static int hw_start_acquisition(int device_index, gpointer session_device_id) +static int hw_start_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct sigma *sigma; @@ -1219,7 +1245,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) struct triggerinout triggerinout_conf; struct triggerlut lut; - session_device_id = session_device_id; + session_data = session_data; if (!(sdi = sr_get_device_instance(device_instances, device_index))) return SR_ERR; @@ -1304,19 +1330,17 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) gettimeofday(&sigma->start_tv, 0); sigma_set_register(WRITE_MODE, 0x0d, sigma); - sigma->session_id = session_device_id; + sigma->session_id = session_data; /* Send header packet to the session bus. */ packet.type = SR_DF_HEADER; - packet.length = sizeof(struct sr_datafeed_header); packet.payload = &header; header.feed_version = 1; gettimeofday(&header.starttime, NULL); header.samplerate = sigma->cur_samplerate; - header.protocol_id = SR_PROTO_RAW; header.num_logic_probes = sigma->num_probes; header.num_analog_probes = 0; - sr_session_bus(session_device_id, &packet); + sr_session_bus(session_data, &packet); /* Add capture source. */ sr_source_add(0, G_IO_IN, 10, receive_data, sdi); @@ -1326,7 +1350,7 @@ static int hw_start_acquisition(int device_index, gpointer session_device_id) return SR_OK; } -static void hw_stop_acquisition(int device_index, gpointer session_device_id) +static void hw_stop_acquisition(int device_index, gpointer session_data) { struct sr_device_instance *sdi; struct sigma *sigma; @@ -1337,7 +1361,7 @@ static void hw_stop_acquisition(int device_index, gpointer session_device_id) sigma = sdi->priv; - session_device_id = session_device_id; + session_data = session_data; /* Stop acquisition. */ sigma_set_register(WRITE_MODE, 0x11, sigma);