


下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、一個(gè)GPIO輸出高低電平的驅(qū)動(dòng)源代碼 2009-08-11 一個(gè)GPIO的驅(qū)動(dòng),輸出高低電平JDg電子資料網(wǎng)驅(qū)動(dòng)源代碼:GPIO_DRIVER.CJDg電子資料網(wǎng)#include <linux/fs.h>JDg電子資料網(wǎng)/#include <linux/iobuf.h>JDg電子資料網(wǎng)#include <linux/major.h>JDg電子資料網(wǎng)#include <linux/blkdev.h>JDg電子資料網(wǎng)#include <linux/capability.h>JDg電子資料網(wǎng)#include <linux/smp_lo
2、ck.h>JDg電子資料網(wǎng)#include <asm/uaccess.h>JDg電子資料網(wǎng)#include <asm/hardware.h>JDg電子資料網(wǎng)#include <asm/arch/AT91RM9200.h>JDg電子資料網(wǎng)#include <linux/vmalloc.h>JDg電子資料網(wǎng)#include <linux/delay.h>JDg電子資料網(wǎng)#include <linux/kernel.h>JDg電子資料網(wǎng)#include <linux/init.h>JDg電子資料網(wǎng)#includ
3、e <linux/config.h>JDg電子資料網(wǎng)#include <linux/module.h>JDg電子資料網(wǎng)#include <linux/fs.h>JDg電子資料網(wǎng)#include <linux/ioport.h>JDg電子資料網(wǎng)#include <linux/sched.h>JDg電子資料網(wǎng)#include <asm/io.h>JDg電子資料網(wǎng)#include <asm/arch/gpio.h>JDg電子資料網(wǎng)#include <linux/delay.h>JDg電子資料網(wǎng)MODULE
4、_LICENSE("GPL");JDg電子資料網(wǎng)#define IOPORT_MAJOR 220 /定義主設(shè)備號(hào)JDg電子資料網(wǎng)typedef char ioport_device_t;JDg電子資料網(wǎng)static ioport_device_t gpio_devices257;JDg電子資料網(wǎng)#define IOWRITE 1;JDg電子資料網(wǎng)#define IOCLEAR
5、; 2;JDg電子資料網(wǎng)static int gpio_open(struct inode *inode,struct file *filp)JDg電子資料網(wǎng)JDg電子資料網(wǎng) int minor;JDg電子資料網(wǎng) minor = MINOR(inode->i
6、_rdev);JDg電子資料網(wǎng) at91_set_gpio_output(AT91_PIN_PB3,0 );JDg電子資料網(wǎng) gpio_devicesminor+;JDg電子資料網(wǎng) return 0;JDg電子資料網(wǎng)JDg電子資料網(wǎng)static int gpio_release(struct inode *inode,struct f
7、ile *filp)JDg電子資料網(wǎng)JDg電子資料網(wǎng) int minor;JDg電子資料網(wǎng) minor = MINOR(inode->i_rdev);JDg電子資料網(wǎng) if(gpio_devicesminor)JDg電子資料網(wǎng)
8、0; gpio_devicesminor-;JDg電子資料網(wǎng) return 0;JDg電子資料網(wǎng)JDg電子資料網(wǎng)static int gpio_ctl_ioctl(struct inode *inode, struct file *filp,JDg電子資料網(wǎng)unsigned int command, unsigned long arg)JDg電子資料網(wǎng)JDg電子資料網(wǎng) &
9、#160; int err = 0;JDg電子資料網(wǎng) int minor = MINOR(inode->i_rdev);JDg電子資料網(wǎng) JDg電子資料網(wǎng) switch(command)JDg電子資料網(wǎng) JDg電子資料網(wǎng) &
10、#160; case IOWRITE:JDg電子資料網(wǎng) err = at91_set_gpio_value(AT91_PIN_PB3,1);/輸出1高電平JDg電子資料網(wǎng) break;JDg電子資料網(wǎng)
11、160; case IOCLEAR:JDg電子資料網(wǎng) err = at91_set_gpio_value(AT91_PIN_PB3,0);/輸出0低電平JDg電子資料網(wǎng)
12、 break;JDg電子資料網(wǎng)JDg電子資料網(wǎng) return err;JDg電子資料網(wǎng)JDg電子資料網(wǎng)static struct file_operations gpio_ctl_fops=JDg電子資料網(wǎng) owner: THIS_MODULE,JDg電子資料網(wǎng) &
13、#160; ioctl: gpio_ctl_ioctl,/成員初始化;.a=1與a:1; JDg電子資料網(wǎng) open:
14、gpio_open,JDg電子資料網(wǎng) release: gpio_release,JDg電子資料網(wǎng);JDg電子資料網(wǎng)static int _init gpio_init(void)JDg電子資料網(wǎng)JDg電子資料網(wǎng) register_chrdev(IOPORT_MAJOR ,"gpiotest",&gpio_ctl_fo
15、ps);JDg電子資料網(wǎng) return 0;JDg電子資料網(wǎng)JDg電子資料網(wǎng)static void _exit gpio_exit(void)JDg電子資料網(wǎng)JDg電子資料網(wǎng) unregister_chrdev(IOPORT_MAJOR,"gpiotest"); JDg電子資料網(wǎng) return 0;JDg電子資料網(wǎng)JDg電子資
16、料網(wǎng)module_init(gpio_init);JDg電子資料網(wǎng)module_exit(gpio_exit);JDg電子資料網(wǎng)測(cè)試程序:JDg電子資料網(wǎng)#include <stdio.h>JDg電子資料網(wǎng)#include <stdlib.h>JDg電子資料網(wǎng)#include <sys/ioctl.h>JDg電子資料網(wǎng)#include <unistd.h>JDg電子資料網(wǎng)#include <sys/mman.h>JDg電子資料網(wǎng)#include <sys/types.h>JDg電子資料網(wǎng)#include <sys/s
17、tat.h>JDg電子資料網(wǎng)#include <fcntl.h>JDg電子資料網(wǎng)#define DEVICE_GPIOTEST "/dev/gpiotest"JDg電子資料網(wǎng)#define IOWRITE
18、; 1;JDg電子資料網(wǎng)#define IOCLEAR 2;JDg電子資料網(wǎng)int main()JDg電子資料網(wǎng)JDg電子資料網(wǎng) int fd;JDg電子資料網(wǎng) int val=-1;JDg電子資料網(wǎng)
19、160; JDg電子資料網(wǎng) if( (fd=open(DEVICE_GPIOTEST,O_WRITE | O_NONBLOCK) < 0 )JDg電子資料網(wǎng) JDg電子資料網(wǎng) perror("can not op
20、en device");JDg電子資料網(wǎng) exit(1);JDg電子資料網(wǎng) JDg電子資料網(wǎng) JDg電子資料網(wǎng) while(1)JDg電子資料網(wǎng) &
21、#160; JDg電子資料網(wǎng) printf("0:set,1:clear,2:quit;");JDg電子資料網(wǎng) scanf("%d",&am
22、p;val);JDg電子資料網(wǎng) JDg電子資料網(wǎng) if(val=0)JDg電子資料網(wǎng)
23、 ioctl(fd,IOWRITE,0);JDg電子資料網(wǎng) else if(val=1)JDg電子資料網(wǎng) ioctl(
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 藥品采用周期管理制度
- 藥庫(kù)藥品批次管理制度
- 藥店培訓(xùn)檔案管理制度
- 營(yíng)業(yè)終端安全管理制度
- 設(shè)備修理量化管理制度
- 設(shè)備安裝公司管理制度
- 設(shè)備搭建維護(hù)管理制度
- 設(shè)備清掃潤(rùn)滑管理制度
- 設(shè)備維修清場(chǎng)管理制度
- 設(shè)備設(shè)施維護(hù)管理制度
- 《事業(yè)單位人事管理?xiàng)l例》考試參考題庫(kù)100題(含答案)
- 通用包裝作業(yè)指導(dǎo)書(shū)SOP
- 浙江中考生物知識(shí)點(diǎn)大全
- 2023宿遷地生中考試卷
- 一人力資源轉(zhuǎn)型和價(jià)值
- 國(guó)家公務(wù)員考試準(zhǔn)考證模板
- 設(shè)備采購(gòu)質(zhì)量保證措施
- 《可見(jiàn)的學(xué)習(xí)與深度學(xué)習(xí)》讀書(shū)筆記思維導(dǎo)圖PPT模板下載
- GB/T 97.1-2002平墊圈A級(jí)
- GB/T 5121.27-2008銅及銅合金化學(xué)分析方法第27部分:電感耦合等離子體原子發(fā)射光譜法
- GB/T 4436-2012鋁及鋁合金管材外形尺寸及允許偏差
評(píng)論
0/150
提交評(píng)論