S3C2440 LED 驱动浅析(3)

1962阅读 0评论2011-10-11 chenliangmoran
分类:LINUX

四、 在应用层测试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灯。如果要使用我们自己写的测试代码来验证S3C2440LED驱动,需要修改 /etc/rc.d/init.d/leds,打开此文档,找到下面一句并注释掉:

  1. base=led-player

        可以使用如下的代码来测试LED驱动,编译成功后会生成led,将此文档下载到开发板上,跑起来后即可进行测试。

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/ioctl.h>

  5. int main(int argc, char** argv)
  6. {
  7.     int fd;
  8.     int led_no;
  9.     int led_cmd;
  10.     int i;

  11.     fd = open("/dev/leds", 0);
  12.     if (fd < 0)
  13.     {
  14.         printf("open /dev/leds err!\n");
  15.         exit(1);
  16.     }

  17.     while (1)
  18.     {
  19.         printf("pls choose which led you want to control:\n");
  20.         printf("0: all leds\n");
  21.         printf("1: led 1\n");
  22.         printf("2: led 2\n");
  23.         printf("3: led 3\n");
  24.         printf("4: led 4\n");

  25.         scanf("%d", &led_no);

  26.         printf("pls tell me what you want to do:\n");
  27.         printf("0: turn off led(s)\n");
  28.         printf("1: turn on led(s)\n");

  29.         scanf("%d", &led_cmd);

  30.         switch(led_no)
  31.         {
  32.             case 0:
  33.                 {
  34.                     for (i = 0; i < 4; i++)
  35.                     {
  36.                         ioctl(fd, led_cmd, i);
  37.                     }
  38.                 }
  39.                 break;
  40.             case 1:
  41.             case 2:
  42.             case 3:
  43.             case 4:
  44.                 ioctl(fd, led_cmd, (led_no - 1));
  45.                 break;
  46.             default:
  47.                 break;
  48.         }
  49.     }

  50.     close(fd);

  51.     return (0);
  52. }

对应的Makefile的内容如下:

  1. CROSS=arm-linux-

  2. all: led

  3. led: led.c
  4.     $(CROSS)gcc -o led led.c

  5. clean:
  6.     @rm -vf led *.o *~






上一篇:S3C2440 LED 驱动浅析(2)
下一篇:五、U-boot源码简要分析(一)