⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pwm.c

📁 LPC2210--LPC2220系列的ADC,GPOI,I2C,PWM,RLT,SPI的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)**************************************************
**                               Guangzou ZLG-MCU Development Co.,LTD.
**                                     graduate school
**                                 http://www.zlgmcu.com
**
**--------------File Info-------------------------------------------------------------------------------
** File name:			pwm.c
** Last modified Date:  2005-04-21
** Last Version:		1.0
** Descriptions:		This is a Kernel module for uClinux 2.4.x .**                      This module let uClinux 2.4.x can use pwm. 
**------------------------------------------------------------------------------------------------------
** Created by:			Chenmingji
** Created date:		2005-04-21
** Version:				1.0
** Descriptions:		The original version
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**

********************************************************************************************************/
#define IN_PWM#include "config.h"/********************************************************************************************************
              function announce********************************************************************************************************/
#if 0static loff_t pwm_llseek(struct file *filp, loff_t off, int whence);static ssize_t pwm_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);static ssize_t pwm_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos);#endifstatic int pwm_open(struct inode *inode, struct file *filp);static int pwm_release(struct inode *inode, struct file *filp); static int pwm_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,		              unsigned long param);int  pwm_init(void);void pwm_cleanup(void);
static void pwm_irq_handle(int irq, void *dev_id, struct pt_regs *regs);/********************************************************************************************************
              function announce********************************************************************************************************/
#define MAJOR_NR majormodule_init(pwm_init);module_exit(pwm_cleanup);MODULE_PARM(major, "i");MODULE_LICENSE("Proprietary");MODULE_DESCRIPTION("Guangzou ZLG-MCU Development Co.,LTD.\ngraduate school\nhttp://www.zlgmcu.com");MODULE_SUPPORTED_DEVICE("uClinux2.4.x LPC2200 pwm");MODULE_AUTHOR("chenmingji");/*********************************************************************************************************
**                  "全局和静态变量在这里定义"         
**        global variables and static variables define here
********************************************************************************************************/
static int major = PWM_MAJOR_NR;
static u32 RunTime;static u32 PinSel0Save, PinSel1Save;
static unsigned int usage;/********************************************************************************************************/
static struct file_operations pwm_fops =        /* driver info  */{    owner:      THIS_MODULE,#if 0    llseek:     pwm_llseek,    read:       pwm_read,    write:      pwm_write,#endif    ioctl:      pwm_ioctl,    open:       pwm_open,    release:    pwm_release,};#if 0/*********************************************************************************************************
** Function name: pwm_llseek
** Descriptions:  move read and write point
** Input: filp:   pointer of file
**        off:    ofset
**        whence: move mode
**                0: seek set
**                1: seek file' current point
**                2: seek file' end
** Output :      new point
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static loff_t pwm_llseek(struct file *filp, loff_t off, int whence){    return 0;}/*********************************************************************************************************
** Function name: pwm_read
** Descriptions:  read device
** Input: filp:   pointer of file
**        buf:    buf for save data
**        count:  size for read
**        f_pos:  *f_pos = read point
** Output : read size    
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static ssize_t pwm_read(struct file *filp, char *buf, size_t count,                           loff_t *f_pos){    return 0;}/*********************************************************************************************************
** Function name: pwm_write
** Descriptions:  write device
** Input: filp:   pointer of file
**        buf:    buf to write data
**        count:  size for read
**        f_pos:  *f_pos = read point
** Output : write size    
** Created by:   Chenmingji
** Created Date: 2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static ssize_t pwm_write(struct file *filp, const char *buf, size_t count,                            loff_t *f_pos){    return 0;}#endif                /*********************************************************************************************************
** Function name: pwm_open
** Descriptions:  open device
** Input:inode:   information of device
**       filp:    pointer of file
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int pwm_open(struct inode *inode, struct file *filp){
    unsigned long flag;
    if (usage == 0)
    {
        request_irq(IRQ_PWM, pwm_irq_handle, SA_INTERRUPT, "my" DEVICE_NAME, NULL);
        local_irq_save(flag);        PinSel0Save = inl(PINSEL0) & 0xfc00f;
        PinSel1Save = inl(PINSEL1) & (0x03 << 10);
        outl(0x0f | (0x07 << 8), PWMIR);
        outl(0x00, PWMPR);
        outl(10000, PWMMR0);
        outl(0x03, PWMMCR);
        outl(3 | (1 << 3), PWMTCR);
        outl(1 | (1 << 3), PWMTCR);
        outl(inl(PWMLER) | 1, PWMLER);
        RunTime = 0;
        local_irq_restore(flag);    }    usage++;
    MOD_INC_USE_COUNT;    return 0;          /* success */} /*********************************************************************************************************
** Function name: pwm_release
** Descriptions:  release device
** Input:inode:   information of device
**       filp:    pointer of file
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int pwm_release(struct inode *inode, struct file *filp) {    unsigned long flag;
    MOD_DEC_USE_COUNT;    usage--;
    if (usage == 0)
    {
        local_irq_save(flag);
        outl(0, PWMTCR);
        outl(0, PWMPCR);
        outl(PinSel0Save | (inl(PINSEL0) & (~0xfc00f)), PINSEL0);
        outl(PinSel1Save | (inl(PINSEL1) & (~(0x3 << 10))), PINSEL1);
        local_irq_restore(flag);        free_irq(IRQ_PWM, NULL);
    }
    return(0); } 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -