android timed gpio (linux 3.0.0) 受时钟控制的gpio【转】

本文转载自:https://blog.csdn.net/linxi_hnh/article/details/8043417

1 路径:

    drivers/staging/android/timed_gpio.c

    drivers/staging/android/timed_output.c

    drivers/staging/android/timed_output.h

    drivers/staging/android/timed_gpio.h

2 代码分析:

        实现一个设备的驱动,大概需要几个部分的数据:最基础的设备结构体,设备数据结构体和platform data等。

 19 struct timed_output_dev {
 20         const char      *name;
 21 
 22         /* enable the output and set the timer */
 23         void    (*enable)(struct timed_output_dev *sdev, int timeout);
 24 
 25         /* returns the current number of milliseconds remaining on the timer */
 26         int             (*get_time)(struct timed_output_dev *sdev);
 27 
 28         /* private data */
 29         struct device   *dev;
 30         int             index;
 31         int             state;
 32 }; 

此处是设备结构体;他表示一个Timed GPIO设备,

首先,name代表对应的Timed GPIO设备名称。

         enable用来设置定时器的过期时间,并使GPIO能输出指定的电平(在timed_gpio中,它最终是指向gpio_enable)

         get_time函数则用来获得定时器的剩余时间,即离过期还有多长时间(在timed_GPIO中,它最终是指gpio_get_time)。

         dev指向该Timed GPIO设备的设备结构体(struct device)对象,在linux2.6中,内核设备模型把每个设备用一个struct device来表示。

        index则是区分同一名称的多个设备(这些设备由同一个驱动管理)

        state则表示设备的当前状态。

猜你喜欢

转载自www.cnblogs.com/zzb-Dream-90Time/p/9389240.html
今日推荐