下面是应用程序
#include
#include
#include
#include
#defineon(1)
#defineoff(0)
int main(void)
{
int gpio_number = 0;
int fd;
fd = open("/dev/dm644x_gpios", 0);
if (fd < 0)
{
perror("open device /dev/dm644x_gpios");
exit(1);
}
printf("open gpio, here is app/n");
sleep(1);
printf("gpio_number = %d/n", gpio_number);
sleep(1);
while (1) {
ioctl(fd, 1, 0);
sleep(5);
ioctl(fd, 0, gpio_number);
sleep(5);
}
close(fd);
return 0;
}
下面是Makefile
#
# Makefile for the skeleton device drivers.
#
KDIR=/root/work/linux-2.6.18_pro500# 内核目录
PWD := $(shell pwd)#是指要编译的内核模块的源程序在哪个目录下,$(PWD)指与Makefile在同一目录下,也就是当前目录。
ifeq ($(KERNELRELEASE), )
modules:
$(MAKE) -C $(KDIR) M=$(PWD) modules#编译模块的规则,
arm_v5t_le-gcc -o gpio_test app.c#编译应用程序
cp -f *.ko gpio_test /nfsroot/dm644x/filesys#把编译好的驱动和应用程序复制到扳子的文件系统中去
#scp char-reg.kozlh@192.168.1.160:/home/zlh/opt/filesystem
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:#删除生成的所有文件
rm -rf gpio_test *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean
else
#obj-m += skeleton_dev_class.o
obj-m += gpio_driver.o#你要编译的模块名称,这里必须和$(PWD)目录下C程序文件的名称相对应,如果C程序文件为world.c,那么必须修改成obj-m = world.o,也可
#Obj-m = hello.o
#Hello-objs = hello1.o, hello2.o编译多个文件生成hello.o
endif
直接make 就行了如果不行的话make ARCH=arm CROSS_COMPILE=arm_v5t_le-加上编译工具
超级终端操作:
insmodgpio_drive.ko
mknod/dev/dm644x_gpiosc1990
./gpio_test