四、
在应用层测试S3C2440
LED驱动
开发环境:Ubuntu 10.04
开发板: Frindly ARM Micro 2440
Friendly
ARM Micro 2440在开机进入系统后,会自动运行一个LED服务程序(/etc/rc.d/init.d/leds),它其实是调用了
led_player
的一个脚本,led-player开始运行后,会不断的点亮/熄灭led灯。如果要使用我们自己写的测试代码来验证S3C2440的LED驱动,需要修改
/etc/rc.d/init.d/leds,打开此文档,找到下面一句并注释掉:
可以使用如下的代码来测试LED驱动,编译成功后会生成led,将此文档下载到开发板上,跑起来后即可进行测试。
- #include <stdio.h>
-
#include <stdlib.h>
-
#include <unistd.h>
-
#include <sys/ioctl.h>
-
-
int main(int argc, char** argv)
-
{
-
int fd;
-
int led_no;
-
int led_cmd;
-
int i;
-
-
fd = open("/dev/leds", 0);
-
if (fd < 0)
-
{
-
printf("open /dev/leds err!\n");
-
exit(1);
-
}
-
-
while (1)
-
{
-
printf("pls choose which led you want to control:\n");
-
printf("0: all leds\n");
-
printf("1: led 1\n");
-
printf("2: led 2\n");
-
printf("3: led 3\n");
-
printf("4: led 4\n");
-
-
scanf("%d", &led_no);
-
-
printf("pls tell me what you want to do:\n");
-
printf("0: turn off led(s)\n");
-
printf("1: turn on led(s)\n");
-
-
scanf("%d", &led_cmd);
-
-
switch(led_no)
-
{
-
case 0:
-
{
-
for (i = 0; i < 4; i++)
-
{
-
ioctl(fd, led_cmd, i);
-
}
-
}
-
break;
-
case 1:
-
case 2:
-
case 3:
-
case 4:
-
ioctl(fd, led_cmd, (led_no - 1));
-
break;
-
default:
-
break;
-
}
-
}
-
-
close(fd);
-
-
return (0);
-
}
对应的Makefile的内容如下:
- CROSS=arm-linux-
-
-
all: led
-
-
led: led.c
-
$(CROSS)gcc -o led led.c
-
-
clean:
-
@rm -vf led *.o *~
阅读(1978) | 评论(0) | 转发(1) |