-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce iio_channels_mask private struct
This struct will be used later to store a bitmask of enabled channels. Add iio_channels_mask_set_bit(), iio_channels_mask_clear_bit(), and iio_channels_mask_test_bit() inline functions to manipulate this new object. Signed-off-by: Paul Cercueil <[email protected]>
- Loading branch information
Showing
3 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later | ||
/* | ||
* libiio - Library for interfacing industrial I/O (IIO) devices | ||
* | ||
* Copyright (C) 2022 Analog Devices, Inc. | ||
* Author: Paul Cercueil <[email protected]> | ||
*/ | ||
|
||
#include "iio-private.h" | ||
|
||
#include <errno.h> | ||
#include <string.h> | ||
|
||
struct iio_channels_mask * iio_create_channels_mask(unsigned int nb_channels) | ||
{ | ||
struct iio_channels_mask *mask; | ||
size_t nb_words = (nb_channels + 31) / 32; | ||
|
||
mask = zalloc(sizeof(*mask) + nb_words * sizeof(uint32_t)); | ||
if (mask) | ||
mask->words = nb_words; | ||
|
||
return mask; | ||
} | ||
|
||
int iio_channels_mask_copy(struct iio_channels_mask *dst, | ||
const struct iio_channels_mask *src) | ||
{ | ||
if (dst->words != src->words) | ||
return -EINVAL; | ||
|
||
memcpy(dst->mask, src->mask, src->words * sizeof(uint32_t)); | ||
|
||
return 0; | ||
} |