tools/iio/iio_generic_buffer.c
Source file repositories/reference/linux-study-clean/tools/iio/iio_generic_buffer.c
File Facts
- System
- Linux kernel
- Corpus path
tools/iio/iio_generic_buffer.c- Extension
.c- Size
- 19115 bytes
- Lines
- 783
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.hstdlib.hdirent.hfcntl.hstdio.herrno.hsys/stat.hsys/dir.hlinux/types.hstring.hpoll.hendian.hgetopt.hinttypes.hstdbool.hsignal.hsys/ioctl.hlinux/iio/buffer.hiio_utils.h
Detected Declarations
enum autochanfunction size_from_channelarrayfunction print1bytefunction print2bytefunction print4bytefunction print8bytefunction process_scanfunction enable_disable_all_channelsfunction print_usagefunction cleanupfunction sig_handlerfunction register_cleanupfunction main
Annotated Snippet
switch (channels[k].bytes) {
/* only a few cases implemented so far */
case 1:
print1byte(*(uint8_t *)(data + channels[k].location),
&channels[k]);
break;
case 2:
print2byte(*(uint16_t *)(data + channels[k].location),
&channels[k]);
break;
case 4:
print4byte(*(uint32_t *)(data + channels[k].location),
&channels[k]);
break;
case 8:
print8byte(*(uint64_t *)(data + channels[k].location),
&channels[k]);
break;
default:
break;
}
printf("\n");
}
static int enable_disable_all_channels(char *dev_dir_name, int buffer_idx, int enable)
{
const struct dirent *ent;
char scanelemdir[256];
DIR *dp;
int ret;
snprintf(scanelemdir, sizeof(scanelemdir),
FORMAT_SCAN_ELEMENTS_DIR, dev_dir_name, buffer_idx);
scanelemdir[sizeof(scanelemdir)-1] = '\0';
dp = opendir(scanelemdir);
if (!dp) {
fprintf(stderr, "Enabling/disabling channels: can't open %s\n",
scanelemdir);
return -EIO;
}
ret = -ENOENT;
while (ent = readdir(dp), ent) {
if (iioutils_check_suffix(ent->d_name, "_en")) {
printf("%sabling: %s\n",
enable ? "En" : "Dis",
ent->d_name);
ret = write_sysfs_int(ent->d_name, scanelemdir,
enable);
if (ret < 0)
fprintf(stderr, "Failed to enable/disable %s\n",
ent->d_name);
}
}
if (closedir(dp) == -1) {
perror("Enabling/disabling channels: "
"Failed to close directory");
return -errno;
}
return 0;
}
static void print_usage(void)
{
fprintf(stderr, "Usage: generic_buffer [options]...\n"
"Capture, convert and output data from IIO device buffer\n"
" -a Auto-activate all available channels\n"
" -A Force-activate ALL channels\n"
" -b <n> The buffer which to open (by index), default 0\n"
" -c <n> Do n conversions, or loop forever if n < 0\n"
" -e Disable wait for event (new data)\n"
" -g Use trigger-less mode\n"
" -l <n> Set buffer length to n samples\n"
" --device-name -n <name>\n"
" --device-num -N <num>\n"
" Set device by name or number (mandatory)\n"
" --trigger-name -t <name>\n"
" --trigger-num -T <num>\n"
" Set trigger by name or number\n"
" -w <n> Set delay between reads in us (event-less mode)\n");
}
static enum autochan autochannels = AUTOCHANNELS_DISABLED;
static char *dev_dir_name = NULL;
static char *buf_dir_name = NULL;
static int buffer_idx = 0;
static bool current_trigger_set = false;
Annotation
- Immediate include surface: `unistd.h`, `stdlib.h`, `dirent.h`, `fcntl.h`, `stdio.h`, `errno.h`, `sys/stat.h`, `sys/dir.h`.
- Detected declarations: `enum autochan`, `function size_from_channelarray`, `function print1byte`, `function print2byte`, `function print4byte`, `function print8byte`, `function process_scan`, `function enable_disable_all_channels`, `function print_usage`, `function cleanup`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.