資源簡介
6818開發(fā)板Linux系統(tǒng)下的超聲波驅(qū)動(dòng)6818開發(fā)板Linux系統(tǒng)下的超聲波驅(qū)動(dòng)

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
static?struct?cdev?gec6818_chao_cdev; //字符設(shè)備結(jié)構(gòu)體
static?dev_t chao_num=0; //設(shè)備號(hào)
static?struct?class? *chaos_class;
static?struct?device? *chaos_device;
static?void?__iomem *gpiod_base_va; //gpioe的虛擬地址基址
static?void?__iomem *gpiod_out_va;
static?void?__iomem *gpiod_outenb_va;
static?void?__iomem *gpiod_altfn0_va;
static?void?__iomem *gpiod_altfn1_va;
static?int??gec6818_chao_open?(struct?inode?*?inode?struct?file?*file)
{
printk(“gec6818_chao_open?\n“);
return?0;
}
static?int??gec6818_chao_release?(struct?inode?*?inode?struct?file?*file)
{
printk(“gec6818_chao_release?\n“);
return?0;
}
static?ssize_t?gec6818_chao_write?(struct?file?*?file?const?char?__user?*?buf?size_t?len?loff_t?*?off)
{
int?rt;
int?v;
char?kbuf[2]={0};
//配置GPIOD15GPIOD19為輸出模式
iowrite32((ioread32(gpiod_altfn1_va)&(~(3<<6)))|(1<<6)gpiod_altfn1_va);
iowrite32(ioread32(gpiod_outenb_va)|(1<<19)gpiod_outenb_va);
iowrite32(ioread32(gpiod_altfn0_va)&(~(3<<30))gpiod_altfn0_va);
iowrite32(ioread32(gpiod_outenb_va)|(1<<15)gpiod_outenb_va);
printk(“[gec6818_chao_write]len=%d\n“l(fā)en);
//判斷當(dāng)前l(fā)en是否合法
if(len?>?sizeof?kbuf)
return?-EINVAL; //返回參數(shù)無效錯(cuò)誤碼
//從用戶空間拷貝數(shù)據(jù)
rt?=?copy_from_user(kbufbuflen);
if(rt?!=0?)
return?-EFAULT;
printk(“[gec6818_chao_write]kbuf[0]=%dkbuf[1]=%d\n“kbuf[0]kbuf[1]);
switch(kbuf[0])
{
case?5: //D5
{
if(kbuf[1]==1)
{
v?=?ioread32(gpiod_out_va);
v?&=~(1<<15);
iowrite32(vgpiod_out_va);
}
else?if(kbuf[1]==0)
{
v?=?ioread32(gpiod_out_va);
v?|=(1<<15);
iowrite32(vgpiod_out_va);
}
else
return?-EINVAL;
}break;
case?9: //D9
{
if(kbuf[1]==1)
{
v?=?ioread32(gpiod_out_va);
v?&=~(1<<19);
iowrite32(vgpiod_out_va);
}
else?if(kbuf[1]==0)
{
v?=?ioread32(gpiod_out_va);
v?|=(1<<19);
iowrite32(vgpiod_out_va);
}
else
return?-EINVAL;
}break;
default:
return?-EINVAL;
}
return?len;
}
static?ssize_t?gec6818_chao_read?(struct?file?*file?char?__user?*buf?size_t?len?loff_t?*?offs)
{
int?rt;
char?key_val=0;
//按鍵的狀態(tài)高電平-1,低電平-0
//bit019的狀態(tài)
//bit115的狀態(tài)
//判斷當(dāng)前l(fā)en是否合法
if(len?>?sizeof?key_val)
return?-EINVAL; //返回參數(shù)無效錯(cuò)誤碼
key_val?=ioread32(gpiod_out_va)&(1<<19)???0:?1;
key_val|=ioread32(gpiod_out_va)&(1<<15)????0:(1<<1);
//從內(nèi)核空間拷貝到用戶空間
rt?=?copy_to_user(buf&key_vallen);
//獲取成功復(fù)制的字節(jié)數(shù)
len?=?len?-?rt;
//printk(“gec6818_key_read__user?buf[%s]len[%d]\n“buflen);
return?len;
}
static?const?struct?file_operations?gec6818_chao_fops?=?{
? .owner? =?THIS_MODULE
.
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-11-05?19:08??1超聲波\
?????目錄???????????0??2018-11-06?09:35??1超聲波\demo3\
?????文件?????????374??2018-11-05?20:12??1超聲波\demo3\Makefile
?????文件????????6462??2018-11-06?16:00??1超聲波\demo3\chao_drv.c
?????文件???????82599??2018-11-05?20:19??1超聲波\demo3\chao_drv.ko
?????文件????????7023??2018-11-05?17:22??1超聲波\demo3\key_drv.c
?????文件???????81356??2018-11-05?20:19??1超聲波\demo3\key_drv.ko
?????文件????????8445??2018-11-06?15:55??1超聲波\demo3\led_drv.c
?????文件???????84166??2018-11-05?20:19??1超聲波\demo3\led_drv.ko
?????文件????????7156??2018-11-06?09:35??1超聲波\demo3\led_key_test
?????文件????????2118??2018-11-06?15:55??1超聲波\demo3\led_key_test.c
?????文件????????7352??2018-11-06?09:26??1超聲波\demo3\led_test
?????文件????????5641??2018-11-06?09:33??1超聲波\demo3\pp
?????文件??????????61??2018-11-06?09:33??1超聲波\demo3\pp.c
- 上一篇:700多個(gè)降水量站點(diǎn)shp圖層
- 下一篇:LUTmanager
評(píng)論
共有 條評(píng)論