


下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、一個(gè)GPIO輸出高低電平的驅(qū)動源代碼 2009-08-11 一個(gè)GPIO的驅(qū)動,輸出高低電平JDg電子資料網(wǎng)驅(qū)動源代碼: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è)備號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)測試程序: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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年甘肅白銀市初中學(xué)業(yè)水平考試生物試卷真題(含答案詳解)
- 初中語文名著閱讀教學(xué)中的情感體驗(yàn)與價(jià)值引領(lǐng)研究論文
- 藝考生集訓(xùn)管理制度
- 蘇聯(lián)式戶口管理制度
- 茶水間就餐管理制度
- 融資租賃的會計(jì)處理和稅務(wù)處理
- 萍鄉(xiāng)市幼兒園教師招聘幼兒考試試題及答案
- 邯鄲叢臺小學(xué)語文五班班級學(xué)習(xí)簡報(bào)第5期
- 服裝導(dǎo)購技巧實(shí)戰(zhàn)培訓(xùn)
- 設(shè)備租賃合同書
- 鋼琴課件教學(xué)課件
- 國家開放大學(xué)《四史通講》形考作業(yè)1-3+大作業(yè)試卷ABC答案
- 電氣施工管理
- 【MOOC】天文探秘-南京大學(xué) 中國大學(xué)慕課MOOC答案
- FES手冊完整版本
- 云南省保山市(2024年-2025年小學(xué)六年級語文)部編版小升初模擬((上下)學(xué)期)試卷及答案
- 2024年西藏初中學(xué)業(yè)水平考試地理卷試題真題(含答案解析)
- 2024年廣西職業(yè)院校技能大賽高職組《供應(yīng)鏈管理》賽項(xiàng)規(guī)程
- 一年級口算題卡大全(80套口算練習(xí)題直接打印版)
- 手術(shù)室儀器設(shè)備管理制度
- 高速列車安全性能提升
評論
0/150
提交評論