知不足,然后能自反也;知困,然后能自强也 ——《礼记》
前面学习了platform总线驱动,虽然它的测试程序和普通总线LED差不多,但是还是给一个测试程序吧。
/*********************************************************************************
* Copyright: (C) 2017 minda
* All rights reserved.
*
* Filename: myplat.c
* Description: This file
*
* Version: 1.0.0(04/05/2017)
* Author: tangyanjun <519656780@qq.com>
* ChangeLog: 1, Release initial version on "04/05/2017 02:40:02 PM"
*
********************************************************************************/
#include <stdio.h>
#include "plat_ioctl.h" //for ioctl
/* ******open******/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h> //for strcmp
#include <unistd.h> //for sleep
int main(int argc, char **argv)
{
int fd = open("/dev/led", O_RDWR);
if (argc > 1)
{
if (!strcmp (argv[1], "0" ))
{
while(1)
{
ioctl(fd, LED_ON, 0);
printf("turn on the LED0\n");
sleep(1);
ioctl(fd, LED_OFF, 0);
sleep(2);
}
}
else if (!strcmp (argv[1], "1" ))
{
ioctl(fd, LED_ON, 1);
printf("turn on the LED1\n");
sleep(1);
ioctl(fd, LED_OFF, 1);
}
else if (!strcmp (argv[1], "2" ))
{
ioctl(fd, LED_ON, 2);
printf("turn on the LED2\n");
sleep(1);
ioctl(fd, LED_OFF, 2);
}
else if (!strcmp (argv[1], "3" ))
{
ioctl(fd, LED_ON, 3);
printf("turn on the LED3\n");
sleep(1);
ioctl(fd, LED_OFF, 3);
}
}
else
{
printf("please input the status, 0, 1, 2 or 3");
}
close(fd);
return 0;
}
同样用交叉编译器编译完成后传到开发板,然后给权限,在此之前记得用insmod命令安装我们的plat_led.ko模块,我们这里是不用手动创建节点的,驱动模块一旦安装好,就会自动创建节点,我们只需要执行测试文件,记得在后面加参数,现象是先开,后关,最后闪烁,一直循环。