X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fhardware%2Fkingst-la2016%2Fprotocol.c;h=ace0cd51d590777ec658d6ffdbd9fc8473de0b41;hb=683f977e266eea4958839c561888f0f96c043ab6;hp=e9a8cb0ba5f3b8fc4903a657e28fe9d040d77ee1;hpb=f49837a58276890878ffa5e1530aff9a7d404b9b;p=libsigrok.git diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index e9a8cb0b..ace0cd51 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -54,6 +54,9 @@ static const struct kingst_model models[] = { { 0x08, 0x00, "LA2016", "la2016a1", SR_MHZ(200), 16, 1, 0, }, { 0x09, 0x00, "LA1016", "la1016a1", SR_MHZ(100), 16, 1, 0, }, { 0x0a, 0x00, "LA1010", "la1010a2", SR_MHZ(100), 16, 0, SR_MHZ(800), }, + { 0x0b, 0x10, "LA2016", "la2016a2", SR_MHZ(200), 16, 1, 0, }, + { 0x0c, 0x10, "LA5016", "la5016a2", SR_MHZ(500), 16, 2, SR_MHZ(800), }, + { 0x0c, 0x00, "LA5016", "la5016a2", SR_MHZ(500), 16, 2, SR_MHZ(800), }, { 0x41, 0x00, "LA5016", "la5016a1", SR_MHZ(500), 16, 2, SR_MHZ(800), }, }; @@ -1281,7 +1284,7 @@ static int la2016_start_download(const struct sr_dev_inst *sdi) devc->n_transfer_packets_to_read = devc->info.n_rep_packets; devc->n_transfer_packets_to_read /= devc->packets_per_chunk; devc->n_bytes_to_read = devc->n_transfer_packets_to_read; - devc->n_bytes_to_read *= TRANSFER_PACKET_LENGTH; + devc->n_bytes_to_read *= devc->transfer_size; devc->read_pos = devc->info.write_pos - devc->n_bytes_to_read; devc->n_reps_until_trigger = devc->info.n_rep_packets_before_trigger; @@ -1320,15 +1323,31 @@ static int la2016_start_download(const struct sr_dev_inst *sdi) } /* - * A chunk (received via USB) contains a number of transfers (USB length - * divided by 16) which contain a number of packets (5 per transfer) which - * contain a number of samples (8bit repeat count per 16bit sample data). + * A chunk of sample memory was received via USB. These chunks contain + * transfers of 16 or 32 bytes each (model dependent size and layout). + * Transfers contain a number of packets (5 or 6 per transfer), which + * contain a number of samples (16 or 32 sampled pin values, and an + * 8bit repeat count for these sampled pin values). A sequence number + * follows the packets within the transfer, allows to detect missing or + * out of order reception. + * + * Memory layout for 16-channel models: + * - 16 bytes per transfer + * - 5x (u16 pins, and u8 count) + * - 1x u8 sequence number + * + * Memory layout for 32-channel models: + * - 32 bytes per transfer + * - 6x (u32 pins, and u8 count) + * - 2x u8 sequence number (inverted, and normal) + * + * This implementation silently ignores the (weak) sequence number. */ static void send_chunk(struct sr_dev_inst *sdi, const uint8_t *data_buffer, size_t data_length) { struct dev_context *devc; - size_t num_xfers, num_pkts; + size_t num_xfers, num_pkts, num_seqs; const uint8_t *rp; uint32_t sample_value; size_t repetitions; @@ -1358,12 +1377,11 @@ static void send_chunk(struct sr_dev_inst *sdi, /* Process the received chunk of capture data. */ sample_value = 0; rp = data_buffer; - num_xfers = data_length / TRANSFER_PACKET_LENGTH; + num_xfers = data_length / devc->transfer_size; while (num_xfers--) { num_pkts = devc->packets_per_chunk; while (num_pkts--) { - /* TODO Verify 32channel layout. */ if (devc->model->channel_count == 32) sample_value = read_u32le_inc(&rp); else if (devc->model->channel_count == 16) @@ -1388,7 +1406,10 @@ static void send_chunk(struct sr_dev_inst *sdi, } } } - (void)read_u8_inc(&rp); /* Skip sequence number. */ + /* Skip the sequence number bytes. */ + num_seqs = devc->sequence_size; + while (num_seqs--) + (void)read_u8_inc(&rp); } /* @@ -1420,21 +1441,22 @@ static void send_chunk(struct sr_dev_inst *sdi, * above). In streaming mode data is not compressed, and memory cells * neither contain raw sampled pin values at a given point in time. The * memory content needs transformation. - * - The memory content can be seen as a sequence of memory cells. - * - Each cell contains samples that correspond to the same channel. - * The next cell contains samples for the next channel, etc. - * - Only enabled channels occupy memory cells. Disabled channels are - * not part of the capture data memory layout. - * - The LSB bit position in a cell is the sample which was taken first - * for this channel. Upper bit positions were taken later. + * + * All enabled channels get iterated over. Disabled channels will not + * occupy space in the streamed sample data. Per channel chunk there is + * one 16bit entity which carries samples that were taken at different + * times. The least significant bit was sampled first, higher bits were + * sampled later. After all 16bit entities for all enabled channels + * were seen, the first enabled channel's next chunk follows. * * Implementor's note: This routine is inspired by convert_sample_data() * in the https://github.com/AlexUg/sigrok implementation. Which in turn * appears to have been derived from the saleae-logic16 sigrok driver. * The code is phrased conservatively to verify the layout as discussed * above, performance was not a priority. Operation was verified with an - * LA2016 device. The memory layout of 32 channel models is yet to get - * determined. + * LA2016 device. The LA5032 reportedly shares the 16 samples per channel + * layout, just round-robins through a potentially larger set of enabled + * channels before returning to the first of the channels. */ static void stream_data(struct sr_dev_inst *sdi, const uint8_t *data_buffer, size_t data_length) @@ -1459,30 +1481,15 @@ static void stream_data(struct sr_dev_inst *sdi, /* TODO Add soft trigger support when in stream mode? */ - /* - * TODO Are memory cells always as wide as the channel count? - * Are they always 16bits wide? Verify for 32 channel devices. - */ - bit_count = devc->model->channel_count; - if (bit_count == 32) { - data_length /= sizeof(uint32_t); - } else if (bit_count == 16) { - data_length /= sizeof(uint16_t); - } else { - /* - * Unhandled case. Acquisition should not start. - * The statement silences the compiler. - */ - return; - } + /* All channels' chunks carry 16 samples for one channel. */ + bit_count = 16; + data_length /= sizeof(uint16_t); + rp = data_buffer; sample_value = 0; while (data_length--) { /* Get another entity. */ - if (bit_count == 32) - sample_value = read_u32le_inc(&rp); - else if (bit_count == 16) - sample_value = read_u16le_inc(&rp); + sample_value = read_u16le_inc(&rp); /* Map the entity's bits to a channel's samples. */ ch_mask = stream->channel_masks[stream->channel_index];