Skip to content

Commit fd07bf1

Browse files
zeldinzougloub
authored andcommitted
fx2lafw: Make to_bytes_per_ms take unitsize into account
1 parent 08e12c1 commit fd07bf1

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/hardware/fx2lafw/protocol.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,9 +586,9 @@ static int configure_channels(const struct sr_dev_inst *sdi)
586586
return SR_OK;
587587
}
588588

589-
static unsigned int to_bytes_per_ms(unsigned int samplerate)
589+
static unsigned int to_bytes_per_ms(unsigned int samplerate, unsigned int unitsize)
590590
{
591-
return samplerate / 1000;
591+
return samplerate * unitsize / 1000;
592592
}
593593

594594
static size_t get_buffer_size(struct dev_context *devc)
@@ -599,7 +599,7 @@ static size_t get_buffer_size(struct dev_context *devc)
599599
* The buffer should be large enough to hold 10ms of data and
600600
* a multiple of 1024.
601601
*/
602-
s = 10 * to_bytes_per_ms(devc->cur_samplerate);
602+
s = 10 * to_bytes_per_ms(devc->cur_samplerate, devc->unitsize);
603603
if (devc->unitsize == 3) {
604604
/* Make it a multiple of 3K, to make sure we have an
605605
integral number of samples */
@@ -614,7 +614,7 @@ static unsigned int get_number_of_transfers(struct dev_context *devc)
614614
unsigned int n;
615615

616616
/* Total buffer size should be able to hold about 500ms of data. */
617-
n = (500 * to_bytes_per_ms(devc->cur_samplerate) /
617+
n = (500 * to_bytes_per_ms(devc->cur_samplerate, devc->unitsize) /
618618
get_buffer_size(devc));
619619

620620
if (n > NUM_SIMUL_TRANSFERS)
@@ -630,7 +630,7 @@ static unsigned int get_timeout(struct dev_context *devc)
630630

631631
total_size = get_buffer_size(devc) *
632632
get_number_of_transfers(devc);
633-
timeout = total_size / to_bytes_per_ms(devc->cur_samplerate);
633+
timeout = total_size / to_bytes_per_ms(devc->cur_samplerate, devc->unitsize);
634634
return timeout + timeout / 4; /* Leave a headroom of 25% percent. */
635635
}
636636

0 commit comments

Comments
 (0)