i.MX6ULL终结者Linux并发与竞争实验自旋锁实验

1 实验程序编写

本实验例程路径:i.MX6UL终结者光盘资料/06_Linux驱动例程/05_gpiold_spinlock
创建gpioled_spinlock.c文件,具体内容如下:

 1 #include <linux/types.h>
  2 #include <linux/kernel.h>
  3 #include <linux/delay.h>
  4 #include <linux/ide.h>
  5 #include <linux/init.h>
  6 #include <linux/module.h>
  7 #include <linux/errno.h>
  8 #include <linux/gpio.h>
  9 #include <linux/cdev.h>
 10 #include <linux/device.h>
 11 #include <linux/of.h>
 12 #include <linux/of_address.h>
 13 #include <linux/of_gpio.h>
 14 #include <asm/mach/map.h>
 15 #include <asm/uaccess.h>
 16 #include <asm/io.h>
 17 
 18 #define GPIOLED_CNT 1 /* 设备号个数 */
 19 #define GPIOLED_NAME "gpioled" /* 名字 */
 20 #define LEDOFF 0 /* 关灯 */
 21 #define LEDON 1 /* 开灯 */
 22 
 23 /* gpioled 设备结构体 */
 24 struct gpioled_dev{
   
   
 25         dev_t devid; /* 设备号 */
 26         struct cdev cdev; /* cdev */
 27         struct class *class; /* 类 */
 28         struct device *device; /* 设备 */
 29         int major; /* 主设备号 */
 30         int minor; /* 次设备号 */
 31         struct device_node *nd; /* 设备节点 */
 32         int led_gpio; /* led 所使用的 GPIO 编号 */
 33         int dev_stats; /* 设备状态,0,设备未使用;>0,设备已经被使用 */
 34         spinlock_t lock; /* 自旋锁 */
 35 };
 36 
 37 struct gpioled_dev gpioled; /* led 设备 */
 38 
 39 /*
 40  * @description : 打开设备
 41  * @param – inode : 传递给驱动的 inode
 42  * @param - filp : 设备文件,file 结构体有个叫做 private_data 的成员变量
 43  * 一般在 open 的时候将 private_data 指向设备结构体。
 44  * @return : 0 成功;其他 失败
 45  */
 46 static int led_open(struct inode *inode, struct file *filp)
 47 {
   
   
 48         unsigned long flags;
 49         filp->private_data = &gpioled; /* 设置私有数据 */
 50 
 51         spin_lock_irqsave(&gpioled.lock, flags); /* 上锁 */
 <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值