Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cyclic mode to IIOD v0.x #1099

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ struct iio_block {
size_t size;
void *data;

struct iio_task_token *token, *old_token;
struct iio_task_token *token;
size_t bytes_used;
bool cyclic;
};

struct iio_block *
Expand Down Expand Up @@ -83,9 +82,6 @@ void iio_block_destroy(struct iio_block *block)
struct iio_buffer *buf = block->buffer;
const struct iio_backend_ops *ops = buf->dev->ctx->ops;

/* Stop the cyclic task */
block->cyclic = false;

if (block->token) {
iio_task_cancel(block->token);
iio_task_sync(block->token, 0);
Expand Down Expand Up @@ -132,20 +128,12 @@ int iio_block_io(struct iio_block *block)
if (!iio_device_is_tx(block->buffer->dev))
return iio_block_read(block);

if (block->old_token)
iio_task_sync(block->old_token, 0);

if (block->cyclic) {
block->old_token = block->token;
block->token = iio_task_enqueue(block->buffer->worker, block);
}

return iio_block_write(block);
}

int iio_block_enqueue(struct iio_block *block, size_t bytes_used, bool cyclic)
{
const struct iio_buffer *buffer = block->buffer;
struct iio_buffer *buffer = block->buffer;
const struct iio_device *dev = buffer->dev;
const struct iio_backend_ops *ops = dev->ctx->ops;

Expand All @@ -164,7 +152,7 @@ int iio_block_enqueue(struct iio_block *block, size_t bytes_used, bool cyclic)
}

block->bytes_used = bytes_used;
block->cyclic = cyclic;
buffer->cyclic = cyclic;
block->token = iio_task_enqueue(buffer->worker, block);

return iio_err(block->token);
Expand Down
4 changes: 3 additions & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ static int iio_buffer_set_enabled(const struct iio_buffer *buf, bool enabled)
{
const struct iio_backend_ops *ops = buf->dev->ctx->ops;
size_t sample_size, nb_samples = 0;
bool cyclic = false;

if (buf->block_size) {
sample_size = iio_device_get_sample_size(buf->dev, buf->mask);
nb_samples = buf->block_size / sample_size;
cyclic = buf->cyclic;
}

if (ops->enable_buffer)
return ops->enable_buffer(buf->pdata, nb_samples, enabled);
return ops->enable_buffer(buf->pdata, nb_samples, enabled, cyclic);

return -ENOSYS;
}
Expand Down
3 changes: 3 additions & 0 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ struct iio_buffer {

struct iio_task *worker;

/* These two fields are set by the last block created. They are only
* used when communicating with v0.x IIOD. */
size_t block_size;
bool cyclic;

struct iio_attr_list attrlist;

Expand Down
4 changes: 2 additions & 2 deletions iiod-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ void iiod_client_free_buffer(struct iiod_client_buffer_pdata *pdata)
}

int iiod_client_enable_buffer(struct iiod_client_buffer_pdata *pdata,
size_t nb_samples, bool enable)
size_t nb_samples, bool enable, bool cyclic)
{
struct iiod_client *client = pdata->client;
struct iiod_client_io *client_io;
Expand All @@ -1511,7 +1511,7 @@ int iiod_client_enable_buffer(struct iiod_client_buffer_pdata *pdata,
if (enable) {
client_io = iiod_client_open_with_mask(client, pdata->dev,
pdata->mask,
nb_samples, false);
nb_samples, cyclic);
err = iio_err(client_io);
pdata->io = err ? NULL : client_io;
} else {
Expand Down
2 changes: 1 addition & 1 deletion iiod/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ static int create_buf_and_blocks(struct DevEntry *entry, size_t samples_count,
for (; i; i--)
iio_block_destroy(entry->blocks[i - 1]);
iio_buffer_destroy(entry->buf);
entry->buf = NULL;
err_free_blocks_array:
entry->buf = NULL;
free(entry->blocks);
entry->blocks = NULL;
return err;
Expand Down
2 changes: 1 addition & 1 deletion include/iio/iio-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct iio_backend_ops {
struct iio_channels_mask *mask);
void (*free_buffer)(struct iio_buffer_pdata *pdata);
int (*enable_buffer)(struct iio_buffer_pdata *pdata,
size_t nb_samples, bool enable);
size_t nb_samples, bool enable, bool cyclic);
void (*cancel_buffer)(struct iio_buffer_pdata *pdata);

ssize_t (*readbuf)(struct iio_buffer_pdata *pdata,
Expand Down
2 changes: 1 addition & 1 deletion include/iio/iiod-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ iiod_client_create_buffer(struct iiod_client *client,
struct iio_channels_mask *mask);
__api void iiod_client_free_buffer(struct iiod_client_buffer_pdata *pdata);
__api int iiod_client_enable_buffer(struct iiod_client_buffer_pdata *pdata,
size_t nb_samples, bool enable);
size_t nb_samples, bool enable, bool cyclic);

__api struct iio_block_pdata *
iiod_client_create_block(struct iiod_client_buffer_pdata *pdata,
Expand Down
2 changes: 1 addition & 1 deletion local.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ static int local_do_enable_buffer(struct iio_buffer_pdata *pdata, bool enable)
}

static int local_enable_buffer(struct iio_buffer_pdata *pdata,
size_t nb_samples, bool enable)
size_t nb_samples, bool enable, bool cyclic)
{
int ret;

Expand Down
4 changes: 2 additions & 2 deletions network.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ void network_free_buffer(struct iio_buffer_pdata *pdata)
}

int network_enable_buffer(struct iio_buffer_pdata *pdata,
size_t block_size, bool enable)
size_t block_size, bool enable, bool cyclic)
{
return iiod_client_enable_buffer(pdata->pdata, block_size, enable);
return iiod_client_enable_buffer(pdata->pdata, block_size, enable, cyclic);
}

struct iio_block_pdata * network_create_block(struct iio_buffer_pdata *pdata,
Expand Down
4 changes: 2 additions & 2 deletions serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ static void serial_free_buffer(struct iio_buffer_pdata *buf)
}

static int serial_enable_buffer(struct iio_buffer_pdata *buf,
size_t nb_samples, bool enable)
size_t nb_samples, bool enable, bool cyclic)
{
return iiod_client_enable_buffer(buf->pdata, nb_samples, enable);
return iiod_client_enable_buffer(buf->pdata, nb_samples, enable, cyclic);
}

static ssize_t
Expand Down
4 changes: 2 additions & 2 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,9 @@ static void usb_free_buffer(struct iio_buffer_pdata *buf)
}

static int usb_enable_buffer(struct iio_buffer_pdata *pdata,
size_t nb_samples, bool enable)
size_t nb_samples, bool enable, bool cyclic)
{
return iiod_client_enable_buffer(pdata->pdata, nb_samples, enable);
return iiod_client_enable_buffer(pdata->pdata, nb_samples, enable, cyclic);
}

static struct iio_block_pdata *
Expand Down
2 changes: 1 addition & 1 deletion utils/iio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ uint64_t get_time_us(void)
#ifdef _MSC_BUILD
timespec_get(&tp, TIME_UTC);
#else
clock_gettime(CLOCK_REALTIME, &tp);
clock_gettime(CLOCK_MONOTONIC, &tp);
#endif

return tp.tv_sec * 1000000ull + tp.tv_nsec / 1000;
Expand Down
Loading