Skip to content
Digital Rhyme
Embedded Linux board with oscilloscope probe and driver architecture flow blocks

drhyme_ioctl_test.c Source

Platform driver, probe/remove, modprobe, misc devices, ioctl ABI, and user-space testing.

1// SPDX-License-Identifier: GPL-2.0
2#include <errno.h>
3#include <fcntl.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <sys/ioctl.h>
8#include <unistd.h>
9
10#include "drhyme_sensor_uapi.h"
11
12static void die(const char *what)
13{
14 fprintf(stderr, "%s: %s\n", what, strerror(errno));
15 exit(1);
16}
17
18int main(int argc, char **argv)
19{
20 const char *path = argc > 1 ? argv[1] : "/dev/drhyme_sensor0";
21 struct drhyme_sensor_config config = { .config = 42 };
22 struct drhyme_sensor_status status;
23 int fd;
24
25 fd = open(path, O_RDONLY);
26 if (fd < 0)
27 die("open");
28
29 if (ioctl(fd, DRHYME_IOCTL_SET_CONFIG, &config) < 0)
30 die("DRHYME_IOCTL_SET_CONFIG");
31
32 memset(&status, 0, sizeof(status));
33 if (ioctl(fd, DRHYME_IOCTL_GET_STATUS, &status) < 0)
34 die("DRHYME_IOCTL_GET_STATUS");
35
36 printf("abi=%u enabled=%u config=%u read_count=%llu\n",
37 status.abi_version, status.enabled, status.config,
38 (unsigned long long)status.read_count);
39
40 close(fd);
41 return 0;
42}