platform之LED测试

本文介绍了一种基于平台总线的LED驱动测试程序。该程序通过ioctl进行LED的开关操作,并支持不同的LED编号。文章提供了完整的源代码及运行说明。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

知不足,然后能自反也;知困,然后能自强也 ——《礼记》


前面学习了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模块,我们这里是不用手动创建节点的,驱动模块一旦安装好,就会自动创建节点,我们只需要执行测试文件,记得在后面加参数,现象是先开,后关,最后闪烁,一直循环。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值