当前位置: 代码迷 >> 综合 >> 嵌入式Linux移植4. Linux LED测试程序(前提:驱动已经装好编译进内核)
  详细解决方案

嵌入式Linux移植4. Linux LED测试程序(前提:驱动已经装好编译进内核)

热度:44   发布时间:2024-02-10 18:04:04.0

前提:LED驱动编译进内核,系统可以正常启动

操作方法:1.编写myledtest.c LED程序,添加以下代码

                  2.使用交叉编译器在Ubuntu上编译myledtest.c成ledtest .o文件

                     arm-arago-linux-gnueabi-gcc -o ledtest  myledtest.c

                  3.通过NFS服务将ledtest  传输到板子上的/mnt

                  4.在/mnt下执行: ./ledtest

                  5.闪灯正常

操作思路:首先准备好测试程序,才能测试自己的驱动移植是否成功,

                  本文先使用飞凌的驱动测试测试程序,为自己的LED驱动移植做准备

 

#include <stdio.h>
#include <stdlib.h>    //system
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <sys/ioctl.h>

#define DEV_NAME "/dev/led"

int main(int argc, char *argv[])
{
int fd;

fd=open(DEV_NAME, O_RDWR);
if(fd<0) {
perror("can not open device");
exit(1);
}


while(1)
{

ioctl(fd, 1, 2);
usleep(3200000/16);    
ioctl(fd, 0, 2);
usleep(3200000/16);    
}

close(fd);
return 0;
}