- /* Prepare session packet. */
- packet.type = SR_DF_LOGIC;
- packet.payload = &logic;
- logic.unitsize = UNIT_SIZE;
- logic.data = acq->out_packet;
-
- slice = acq->xfer_buf_in;
- si = 0; /* word index within slice */
-
- for (;;) {
- /* Calculate number of samples to write into packet. */
- out_max_samples = MIN(acq->samples_max - acq->samples_done,
- PACKET_LENGTH - acq->out_index);
- out_run_samples = MIN(acq->run_len, out_max_samples);
-
- /* Expand run-length samples into session packet. */
- sample = acq->sample;
- out_p = &acq->out_packet[acq->out_index * UNIT_SIZE];
-
- for (ri = 0; ri < out_run_samples; ++ri) {
- out_p[0] = sample & 0xFF;
- out_p[1] = (sample >> 8) & 0xFF;
- out_p[2] = (sample >> 16) & 0xFF;
- out_p[3] = (sample >> 24) & 0xFF;
- out_p[4] = (sample >> 32) & 0xFF;
- out_p += UNIT_SIZE;
- }
- acq->run_len -= out_run_samples;
- acq->out_index += out_run_samples;
- acq->samples_done += out_run_samples;
-
- /* Packet full or sample count limit reached? */
- if (out_run_samples == out_max_samples) {
- logic.length = acq->out_index * UNIT_SIZE;
- sr_session_send(sdi, &packet);
- acq->out_index = 0;
-
- if (acq->samples_done >= acq->samples_max)
- return SR_OK; /* sample limit reached */
- if (acq->run_len > 0)
- continue; /* need another packet */
- }
-
- if (in_words_left == 0)
- break; /* done with current chunk */
-
- /* Now work on the current slice. */
- high_nibbles = LWLA_TO_UINT32(slice[8]);
- word = LWLA_TO_UINT32(slice[si]);
- word |= (high_nibbles << (4 * si + 4)) & ((uint64_t)0xF << 32);
-
- if (acq->rle == RLE_STATE_DATA) {
- acq->sample = word & ALL_CHANNELS_MASK;
- acq->run_len = ((word >> NUM_CHANNELS) & 1) + 1;
- if (word & RLE_FLAG_LEN_FOLLOWS)
- acq->rle = RLE_STATE_LEN;
- } else {
- acq->run_len += word << 1;
- acq->rle = RLE_STATE_DATA;
- }
-
- /* Move to next word. */
- si = (si + 1) % 8;
- if (si == 0)
- slice += 9;
- --in_words_left;
- }
-
- /* Send out partially filled packet if this was the last chunk. */
- if (acq->mem_addr_done >= acq->mem_addr_stop && acq->out_index > 0) {
- logic.length = acq->out_index * UNIT_SIZE;
- sr_session_send(sdi, &packet);
- acq->out_index = 0;