diff --git a/host/utilities/bladeRF-cli/src/cmd/tx.c b/host/utilities/bladeRF-cli/src/cmd/tx.c index 03ab59045..e62ed15e7 100644 --- a/host/utilities/bladeRF-cli/src/cmd/tx.c +++ b/host/utilities/bladeRF-cli/src/cmd/tx.c @@ -44,7 +44,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) { int status = 0; unsigned int samples_per_buffer; - int16_t *tx_buffer; + void *tx_buffer; struct tx_params *tx_params = tx->params; unsigned int repeats_remaining; unsigned int delay_us; @@ -55,6 +55,9 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) bladerf_sample_rate sample_rate = 0; int i; + unsigned int size_of_format = + (s->bit_mode_8bit) ? sizeof(int8_t) : sizeof(int16_t); + enum state { INIT, READ_FILE, DELAY, PAD_TRAILING, DONE }; enum state state = INIT; @@ -93,7 +96,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) delay_samples_remaining = delay_samples; /* Allocate a buffer to hold each block of samples to transmit */ - tx_buffer = (int16_t *)malloc(samples_per_buffer * 2 * sizeof(int16_t)); + tx_buffer = malloc(samples_per_buffer * 2 * size_of_format); if (tx_buffer == NULL) { status = CLI_RET_MEM; set_last_error(&tx->last_error, ETYPE_ERRNO, @@ -105,7 +108,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) while (state != DONE && status == 0) { unsigned char requests; unsigned int buffer_samples_remaining = samples_per_buffer; - int16_t *tx_buffer_current = tx_buffer; + void *tx_buffer_current = tx_buffer; /* Stop stream on STOP or SHUTDOWN, but only clear STOP. This will keep * the SHUTDOWN request around so we can read it when determining @@ -127,7 +130,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) /* Read from the input file */ samples_populated = - fread(tx_buffer_current, 2 * sizeof(int16_t), + fread(tx_buffer_current, 2 * size_of_format, buffer_samples_remaining, tx->file_mgmt.file); assert(samples_populated <= UINT_MAX); @@ -168,7 +171,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) delay_samples_remaining); memset(tx_buffer_current, 0, - samples_populated * 2 * sizeof(uint16_t)); + samples_populated * 2 * size_of_format); delay_samples_remaining -= (unsigned int)samples_populated; @@ -180,7 +183,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) case PAD_TRAILING: /* Populate the remainder of the buffer with zeros */ memset(tx_buffer_current, 0, - buffer_samples_remaining * 2 * sizeof(uint16_t)); + buffer_samples_remaining * 2 * size_of_format); state = DONE; break; @@ -193,7 +196,9 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) /* Advance the buffer pointer. * Remember, two int16_t's make up 1 sample in the SC16Q11 format */ buffer_samples_remaining -= (unsigned int)samples_populated; - tx_buffer_current += (2 * samples_populated); + /* GCC allows for void pointer arithmetic, but not the C standard */ + tx_buffer_current = (int8_t*) tx_buffer_current + + (2 * samples_populated * size_of_format); } /* If there were no errors, transmit the data buffer */ @@ -211,7 +216,7 @@ static int tx_task_exec_running(struct rxtx_data *tx, struct cli_state *s) const unsigned int num_buffers = tx->data_mgmt.num_buffers; unsigned int i; - memset(tx_buffer, 0, samples_per_buffer * 2 * sizeof(int16_t)); + memset(tx_buffer, 0, samples_per_buffer * 2 * size_of_format); for (i = 0; i < (num_buffers + 1) && status == 0; i++) { status = bladerf_sync_tx(s->dev, tx_buffer, samples_per_buffer, NULL, timeout_ms);