mirror of
https://github.com/ioacademy-jikim/device_driver.git
synced 2026-08-22 05:42:54 +00:00
first sample
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_CFLAGS := -fPIE
|
||||
LOCAL_LDFLAGS := -fPIE -pie
|
||||
LOCAL_MODULE := myapp
|
||||
LOCAL_SRC_FILES := rdwr_app.c
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include <fcntl.h>
|
||||
int main()
|
||||
{
|
||||
int fd;
|
||||
fd = open( "/sys/devices/virtual/misc/mydev/uevent", O_WRONLY );
|
||||
write( fd, "add\n", 4 );
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main()
|
||||
{
|
||||
int fd, ret;
|
||||
char buff[10];
|
||||
fd = open( "/dev/mydev", O_RDONLY );
|
||||
ret = read( fd, buff, sizeof buff );
|
||||
buff[ret] = 0;
|
||||
printf( "buff[%s], ret=%d\n", buff, ret );
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main()
|
||||
{
|
||||
int fd, ret;
|
||||
int temp;
|
||||
fd = open( "/dev/mydev", O_RDONLY );
|
||||
ret = read( fd, &temp, sizeof temp );
|
||||
printf( "temp=%d, ret=%d\n", temp, ret );
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
int main()
|
||||
{
|
||||
int fd, ret;
|
||||
char buff[] = "LED_ON";
|
||||
fd = open( "/dev/mydev", O_WRONLY );
|
||||
ret = write( fd, buff, strlen(buff) );
|
||||
printf( "ret=%d\n", ret );
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
#include <fcntl.h>
|
||||
int main()
|
||||
{
|
||||
int fd;
|
||||
int flag=128;
|
||||
fd = open( "/dev/mydev", O_WRONLY );
|
||||
write( fd, &flag, sizeof flag );
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user