www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當前位置:首頁 > 電源 > 數(shù)字電源
[導讀]========================================================================== */ /* */ /* Filename.c

========================================================================== */
/*                                                                            */
/*   Filename.c                                                               */
/*   (c) 2001 Author  Zhang Haibo                                             */
/*                                                                            */
/*   Description  driver program with interrupt and poll                      */
/*                                                                            */
/* ========================================================================== */

#include <linux/device.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <asm/uaccess.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/mm.h>
#include <linux/sched.h>
#include <linux/cdev.h>
#include <linux/kdev_t.h>
#include <asm/system.h>
#include <linux/poll.h>
#include <linux/irq.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/interrupt.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/gpio.h>

static struct class *cpld_class;                  //自動創(chuàng)建設備文件時需要先創(chuàng)建類
static struct class_device *cpld_class_dev;       //再創(chuàng)建驅(qū)動
static DECLARE_WAIT_QUEUE_HEAD(eint1_waitq);      //將中斷放入等待隊列
static struct fasync_struct *eint1_async;         //
static volatile int ev_eint1 = 0;                 //中斷標志,為1表示中斷發(fā)生,在中斷服務程序里置1
volatile unsigned long *cpld_data = NULL;         //CPLD的物理地址映射的虛擬地址指針  0x08000000
volatile unsigned long *gpfcon = NULL;            //GPF控制寄存器
volatile unsigned long *gpfdat = NULL;            //GPF數(shù)據(jù)寄存器,0位為使能位

static irqreturn_t eint1_irq(int irq, void *dev_id) //中斷服務程序
{
    ev_eint1 = 1;                                   //中斷標志位置1
    *gpfdat &= ~(1<<2);                             //進入中斷GPF2清0
    wake_up_interruptible(&eint1_waitq);            //喚醒休眠的進程
    kill_fasync (&eint1_async, SIGIO, POLL_IN);     //產(chǎn)生中斷后,驅(qū)動向應用程序發(fā)送信號     
    return IRQ_RETVAL(IRQ_HANDLED);
}

static int cpld_drv_open(struct inode *inode, struct file *file)
{
    request_irq(IRQ_EINT1,  eint1_irq, IRQ_TYPE_EDGE_FALLING, "EINT1", 1);//注冊中斷:中斷號,中斷程序入口,中斷方式,中斷名,代號
    return 0;
}
 
static ssize_t cpld_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{
    int val;
    *gpfdat &=~(1<<0);                //使能位置0,使能CPLD產(chǎn)生PWM,計數(shù)器開始計數(shù)
    copy_from_user(&val, buf, count); //產(chǎn)生PWM的值從用戶空間傳入
    iowrite16(val,cpld_data);         //寫入CPLD
    return 0;
}
 

 

static ssize_t cpld_drv_read(struct file *file, const char __user *buf, size_t count, loff_t * ppos)
{
    int val;
    wait_event_interruptible(eint1_waitq, ev_eint1);  //若無中斷產(chǎn)生,即ev_eint1=0,則休眠
    val=ioread16(cpld_data);                          //若中斷產(chǎn)生,則從CPLD讀取數(shù)據(jù),即編碼器值
    copy_to_user(buf,&val,count);                     //將讀取值傳遞到用戶空間
    ev_eint1 = 0;                                     //中斷標志清0
    *gpfdat |= (1<<2);                               //中斷讀數(shù)后,GPF2置1
    return 0;
} [!--empirenews.page--]

 

static unsigned cpld_drv_poll(struct file *file, poll_table *wait)
{
   unsigned int mask = 0;
   poll_wait(file, &eint1_waitq, wait);       //不會立即休眠
   if (ev_eint1)
   mask |= POLLIN | POLLRDNORM;               //若產(chǎn)生中斷,mask賦值,表示有數(shù)據(jù)可讀
   return mask;
}
 
static int cpld_drv_fasync (int fd, struct file *filp, int on)
{
 //printk("driver: cpld_drv_fasyncn");
 return fasync_helper (fd, filp, on, &eint1_async);
}

int cpld_drv_close(struct inode *inode, struct file *file)
{
    free_irq(IRQ_EINT1, 1);       //釋放中斷  
    return 0;
}
 
static struct file_operations cpld_drv_fops = {
    .owner    = THIS_MODULE,                  
    .write    = cpld_drv_write,
    .read     = cpld_drv_read,
    .open     = cpld_drv_open,
    .release  = cpld_drv_close,
    .poll     = cpld_drv_poll,
    .fasync   = cpld_drv_fasync,  
};
 

 

int major;
static int cpld_drv_init(void)
{
    major = register_chrdev(0, "cpld_drv", &cpld_drv_fops);                 //注冊設備
    cpld_class = class_create(THIS_MODULE, "cplddrv");                      //創(chuàng)建類
    cpld_class_dev = device_create(cpld_class, NULL, MKDEV(major, 0), NULL, "cpld_drv"); //自動創(chuàng)建設備文件 /dev/cpld_drv
    cpld_data = (volatile unsigned long *)ioremap(0x08000000,4);            //映射CPLD物理地址到虛擬地址
    gpfcon = (volatile unsigned long *)ioremap(0x56000050, 8);              //映射GPF寄存器物理地址到虛擬地址
    gpfdat = gpfcon+1;
    *gpfcon &=~((0x3<<0) | (0x3<<(2*2)));
    *gpfcon |=((0x1<<0) | (0x01<<(2*2)));     //設置GPF0、2為輸出
    *gpfdat |=0x1;          //將使能位置1,加載驅(qū)動時CPLD不輸出PWM
    printk("cpld_drv initialized!n");
    return 0;
}
 
static void cpld_drv_exit(void)
{
    *gpfdat |=0x1;          //將使能位置1,卸載驅(qū)動后CPLD不輸出PWM
    unregister_chrdev(major, "cpld_drv"); //注銷驅(qū)動
    device_unregister(cpld_class_dev);    //注銷設備
    class_destroy(cpld_class);            //注銷類
    iounmap(cpld_data);                   //取消映射
    iounmap(gpfcon);
}
 
module_init(cpld_drv_init);
module_exit(cpld_drv_exit);
 
MODULE_LICENSE("GPL");

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫毥谦F公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務中斷的風險,如企業(yè)系統(tǒng)復雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術(shù)學會聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(shù)(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉