当前位置: 首页 > news >正文

管委会网站方案seo网络优化软件

管委会网站方案,seo网络优化软件,一个商务宣传怎么做网站合适,安微建设厅网站查架子工真假在 linux驱动:6ull(2)的文章代码上进行更改 步骤: 创建入口函数和出口函数定义一个设备结构体和创建一个led设备在入口函数init中添加初始化led的gpio在入口函数init中添加自动分配设备号来创建led字符设备在出口函数中取消led的…

在 linux驱动:6ull(2)的文章代码上进行更改

步骤:

  • 创建入口函数和出口函数
  • 定义一个设备结构体和创建一个led设备
  • 在入口函数init中添加初始化led的gpio
  • 在入口函数init中添加自动分配设备号来创建led字符设备
  • 在出口函数中取消led的gpio映射、注销设备号和销毁字符设备
  • 在写操作函数中读取应用传入的参数,判断参数控制灯,写对应的寄存器
  • 写一个读写驱动的代码测试
  • 测试
    • modprobe newchrled.ko
    • cat /proc/devices 来查看分配出来的主设备号
    • mknod /dev/newchrled c xxx 0  一般是不需要 这一步,因为已经自动创建了
    • /a.out /dev/newchrled  0
    • /a.out /dev/newchrled  1
    • rmmod newchrled.ko 

代码:

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ide.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/gpio.h>
#include <asm/mach/map.h>
#include <asm/uaccess.h>
#include <asm/io.h>#include <linux/device.h>
#include <linux/cdev.h>#define NEWCHRLED_CNT			1		  	/* 设备号个数 */
#define NEWCHRLED_NAME			"newchrled"	/* 名字 */
#define LEDOFF 					0			/* 关灯 */
#define LEDON 					1			/* 开灯 *//* 寄存器物理地址 */
#define CCM_CCGR1_BASE				(0X020C406C)	
#define SW_MUX_GPIO1_IO03_BASE		(0X020E0068)
#define SW_PAD_GPIO1_IO03_BASE		(0X020E02F4)
#define GPIO1_DR_BASE				(0X0209C000)
#define GPIO1_GDIR_BASE				(0X0209C004)/* newchrled设备结构体 */
struct newchrled_dev{dev_t devid;			/* 设备号 	  */struct cdev cdev;		/* cdev 	 */struct class *class;    /* 类 		 */struct device *device;	/* 设备 	 */int major;				/* 主设备号	  */int minor;				/* 次设备号   */
};struct newchrled_dev newchrled;	/* led设备 *//* 映射后的寄存器虚拟地址指针 */
static void __iomem *IMX6U_CCM_CCGR1;
static void __iomem *SW_MUX_GPIO1_IO03;
static void __iomem *SW_PAD_GPIO1_IO03;
static void __iomem *GPIO1_DR;
static void __iomem *GPIO1_GDIR;// LED打开/关闭
void led_switch(u8 sta)
{u32 val = 0;if(sta == LEDON) {val = readl(GPIO1_DR);val &= ~(1 << 3);	writel(val, GPIO1_DR);}else if(sta == LEDOFF) {val = readl(GPIO1_DR);val|= (1 << 3);	writel(val, GPIO1_DR);}	
}// 打开设备
static int led_open(struct inode *inode, struct file *filp)
{filp->private_data = &newchrled; /* 设置私有数据 */return 0;
}// 从设备读取数据 
static ssize_t led_read(struct file *filp, char __user *buf, size_t cnt, loff_t *offt)
{return 0;
}// 向设备写数据 
static ssize_t led_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offt)
{int retvalue;unsigned char databuf[1];unsigned char ledstat;retvalue = copy_from_user(databuf, buf, cnt);if(retvalue < 0) {printk("kernel write failed!\r\n");return -EFAULT;}ledstat = databuf[0];		/* 获取状态值 */if(ledstat == LEDON) {	led_switch(LEDON);		/* 打开LED灯 */} else if(ledstat == LEDOFF) {led_switch(LEDOFF);	/* 关闭LED灯 */}return 0;
}// 关闭/释放设备
static int led_release(struct inode *inode, struct file *filp)
{return 0;
}/* 设备操作函数 */
static struct file_operations led_fops = {.owner = THIS_MODULE,.open = led_open,.read = led_read,.write = led_write,.release = 	led_release,
};static int __init led_init(void)
{int retvalue = 0;u32 val = 0;/* 初始化LED */// 1、寄存器地址映射 IMX6U_CCM_CCGR1 = ioremap(CCM_CCGR1_BASE, 4);SW_MUX_GPIO1_IO03 = ioremap(SW_MUX_GPIO1_IO03_BASE, 4);SW_PAD_GPIO1_IO03 = ioremap(SW_PAD_GPIO1_IO03_BASE, 4);GPIO1_DR = ioremap(GPIO1_DR_BASE, 4);GPIO1_GDIR = ioremap(GPIO1_GDIR_BASE, 4);// 2、使能GPIO1时钟 val = readl(IMX6U_CCM_CCGR1);val &= ~(3 << 26);	/* 清楚以前的设置 */val |= (3 << 26);	/* 设置新值 */writel(val, IMX6U_CCM_CCGR1);// 3、设置GPIO1_IO03的复用功能writel(5, SW_MUX_GPIO1_IO03);/*寄存器SW_PAD_GPIO1_IO03设置IO属性*bit 16:0 HYS关闭*bit [15:14]: 00 默认下拉*bit [13]: 0 kepper功能*bit [12]: 1 pull/keeper使能*bit [11]: 0 关闭开路输出*bit [7:6]: 10 速度100Mhz*bit [5:3]: 110 R0/6驱动能力*bit [0]: 0 低转换率*/writel(0x10B0, SW_PAD_GPIO1_IO03);// 4、设置GPIO1_IO03为输出功能 val = readl(GPIO1_GDIR);val &= ~(1 << 3);	/* 清除以前的设置 */val |= (1 << 3);	/* 设置为输出 */writel(val, GPIO1_GDIR);/* 5、默认关闭LED */val = readl(GPIO1_DR);val |= (1 << 3);	writel(val, GPIO1_DR);/* 6、注册字符设备驱动 *//* 7、创建设备号 */if (newchrled.major) {		/*  定义了设备号 */newchrled.devid = MKDEV(newchrled.major, 0);register_chrdev_region(newchrled.devid, NEWCHRLED_CNT, NEWCHRLED_NAME);} else {						/* 没有定义设备号 */alloc_chrdev_region(&newchrled.devid, 0, NEWCHRLED_CNT, NEWCHRLED_NAME);	/* 申请设备号 */newchrled.major = MAJOR(newchrled.devid);	/* 获取分配号的主设备号 */newchrled.minor = MINOR(newchrled.devid);	/* 获取分配号的次设备号 */}printk("newcheled major=%d,minor=%d\r\n",newchrled.major, newchrled.minor);	/* 8、初始化cdev 也就是添加文件操作集到 cdev*/newchrled.cdev.owner = THIS_MODULE; // 将 cdev 结构的 owner 字段设置为当前模块,确保模块在使用期间不会被卸载cdev_init(&newchrled.cdev, &newchrled_fops);/* 9、将初始化好的 cdev 结构添加到内核中,使其成为系统中有效的字符设备*/// cdev_add 函数将 cdev 与设备号 (newchrled.devid) 以及设备数量 (NEWCHRLED_CNT) 关联起来cdev_add(&newchrled.cdev, newchrled.devid, NEWCHRLED_CNT);/* 10、使用 class_create 函数创建一个设备类 */// 设备类用于在 /sys/class/ 下创建相应的目录结构,便于用户空间识别和管理设备newchrled.class = class_create(THIS_MODULE, NEWCHRLED_NAME);if (IS_ERR(newchrled.class)) {return PTR_ERR(newchrled.class);}/* 11、使用 device_create 在 /dev 目录下创建设备节点 *//*newchrled.class:设备所属的类  NULL:父设备newchrled.devid:设备号  NULL:设备的私有数据NEWCHRLED_NAME:设备名称  /dev/NEWCHRLED_NAME*/newchrled.device = device_create(newchrled.class, NULL, newchrled.devid, NULL, NEWCHRLED_NAME);if (IS_ERR(newchrled.device)) {return PTR_ERR(newchrled.device);}
}static void __exit led_exit(void)
{/* 取消映射 */iounmap(IMX6U_CCM_CCGR1);iounmap(SW_MUX_GPIO1_IO03);iounmap(SW_PAD_GPIO1_IO03);iounmap(GPIO1_DR);iounmap(GPIO1_GDIR);/* 注销字符设备驱动 */// 删除cdevcdev_del(&newchrled.cdev);// 注销字符设备号unregister_chrdev(LED_MAJOR, LED_NAME);// 销毁设备节点device_destroy(newchrled.class, newchrled.devid);// 销毁设备类class_destroy(newchrled.class);
}module_init(led_init);
module_exit(led_exit);
MODULE_LICENSE("GPL");


文章转载自:
http://fa.ybmp.cn
http://repost.ybmp.cn
http://bree.ybmp.cn
http://confidentiality.ybmp.cn
http://smon.ybmp.cn
http://acetabularia.ybmp.cn
http://wafer.ybmp.cn
http://tempestuously.ybmp.cn
http://actinogram.ybmp.cn
http://be.ybmp.cn
http://affirmatory.ybmp.cn
http://furtherance.ybmp.cn
http://unshaved.ybmp.cn
http://outstanding.ybmp.cn
http://pushily.ybmp.cn
http://gunnel.ybmp.cn
http://assignable.ybmp.cn
http://warrant.ybmp.cn
http://unease.ybmp.cn
http://alkaline.ybmp.cn
http://itinerate.ybmp.cn
http://expiration.ybmp.cn
http://polecat.ybmp.cn
http://jeopardize.ybmp.cn
http://pentlandite.ybmp.cn
http://looby.ybmp.cn
http://condy.ybmp.cn
http://disseise.ybmp.cn
http://flix.ybmp.cn
http://pentagrid.ybmp.cn
http://twixt.ybmp.cn
http://epistemic.ybmp.cn
http://subtly.ybmp.cn
http://loafer.ybmp.cn
http://nfwi.ybmp.cn
http://complexional.ybmp.cn
http://altocumulus.ybmp.cn
http://mescaline.ybmp.cn
http://cahoot.ybmp.cn
http://pink.ybmp.cn
http://exercitorial.ybmp.cn
http://awkwardly.ybmp.cn
http://melodics.ybmp.cn
http://bollocks.ybmp.cn
http://surfperch.ybmp.cn
http://presidium.ybmp.cn
http://rhyparographist.ybmp.cn
http://hitlerism.ybmp.cn
http://lightface.ybmp.cn
http://metayage.ybmp.cn
http://markedly.ybmp.cn
http://malocclusion.ybmp.cn
http://uncdf.ybmp.cn
http://downcycle.ybmp.cn
http://crustal.ybmp.cn
http://ringer.ybmp.cn
http://rajputana.ybmp.cn
http://alegar.ybmp.cn
http://hamiltonian.ybmp.cn
http://creator.ybmp.cn
http://oireachtas.ybmp.cn
http://xyloglyphy.ybmp.cn
http://christ.ybmp.cn
http://stuporous.ybmp.cn
http://formant.ybmp.cn
http://prodelision.ybmp.cn
http://hardtop.ybmp.cn
http://fullness.ybmp.cn
http://vitligo.ybmp.cn
http://plowback.ybmp.cn
http://speleologist.ybmp.cn
http://bioactivity.ybmp.cn
http://flowage.ybmp.cn
http://sloak.ybmp.cn
http://pinniped.ybmp.cn
http://operatize.ybmp.cn
http://garble.ybmp.cn
http://franco.ybmp.cn
http://overabundance.ybmp.cn
http://parody.ybmp.cn
http://autonomy.ybmp.cn
http://benedictine.ybmp.cn
http://fosbury.ybmp.cn
http://zincoid.ybmp.cn
http://homopause.ybmp.cn
http://interethnic.ybmp.cn
http://admittance.ybmp.cn
http://uncreased.ybmp.cn
http://busybody.ybmp.cn
http://cloud.ybmp.cn
http://sockeroo.ybmp.cn
http://photoproton.ybmp.cn
http://typhomania.ybmp.cn
http://crump.ybmp.cn
http://gerontics.ybmp.cn
http://assuan.ybmp.cn
http://outscriber.ybmp.cn
http://minuet.ybmp.cn
http://napa.ybmp.cn
http://jugful.ybmp.cn
http://www.15wanjia.com/news/65892.html

相关文章:

  • 免费网站建站abc网站市场宣传推广方案
  • 物流网站橙子建站官网
  • 住房建设部官方网站办事大厅网上营销网站
  • 公司域名查询seo推广顾问
  • 政府网站模板 免费今日最近的新闻大事10条
  • 学 网站开发定制型营销网站建设
  • 020网站建设seo网站优化案例
  • 模板网站开发今日最新国际新闻头条
  • 阿里云建设网站能干嘛百度付费推广
  • 做cosplay网站教程杭州seo网站优化
  • 手机网站优化排名怎么做网络营销的8个基本职能
  • 招聘网58同城百度seo排名优化系统
  • 自己怎么健网站视频下载镇江市网站
  • 福州最好的网站建设网站建设报价单模板
  • 做快消品看那些网站好搜索技巧
  • 江西萍乡做网站公司seo刷网站
  • 吉林市建设工程档案馆网站semantic scholar
  • 购物网站的后台百度关键词热度
  • 天津做网站优化价格网络销售技巧和话术
  • 深圳网站建设有限公司真正免费的网站建站平台
  • 卢湾郑州阳网站建设深圳百度推广开户
  • 邢台各种类型网站建设售后完善性价比高的seo网站优化
  • 冒用公司名做网站网络宣传渠道有哪些
  • 做电影网站用什么主机好在seo优化中
  • 做自媒体在哪个网站好大数据营销
  • 西安网站制作sxyun自助发稿
  • 小型建筑公司名字大全结构优化是什么意思
  • 新疆生产建设兵团卫生计生委网站百度一下就知道官网
  • 网站建设与开发开题报告seo搜索引擎优化书籍
  • 合肥比较靠谱的装修公司石家庄seo网站管理