demo/linux/driver/hello_driver/app.c
2025-12-17 15:18:58 +08:00

37 lines
790 B
C

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
uint8_t buffer[512] = { 0 };
int main(int argc, char *argv[])
{
int fd;
int ret;
fd = open(argv[1], O_RDWR);
if (fd < 0) {
printf("open failed!\r\n");
return -1;
}
if (!strcmp("read", argv[2])) {
printf("read data from kernel\r\n");
ret = read(fd, buffer, sizeof(buffer));
printf("ret len:%d data:%s\r\n", ret, buffer);
} else if (!strcmp("write", argv[2])) {
printf("write data to kernel %s len:%ld\r\n", argv[3], strlen(argv[3]));
ret = write(fd, argv[3], strlen(argv[3]));
printf("ret len:%d\r\n", ret);
} else {
printf("please input correct para, read/write\r\n");
}
close(fd);
return 0;
}