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

📄 pwm.c

📁 LPC2210--LPC2220系列的ADC,GPOI,I2C,PWM,RLT,SPI的驱动程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************************************************
** Function name: pwm_ioctl
** Descriptions:  IO control function
** Input:inode:   information of device
**       filp:    pointer of file
**       cmd:     command
**       arg:     additive parameter
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static int pwm_ioctl(struct inode *inode, struct file *filp,                        unsigned int cmd, unsigned long arg){    if (_IOC_TYPE(cmd) != PWM_IOC_MAGIC)    {        return -ENOTTY;    }    if (_IOC_NR(cmd) >= PWM_MAXNR)    {        return -ENOTTY;    }
    switch(cmd)    {        case PWM_SET_CYC:            outl(arg ,PWMMR0);            outl(inl(PWMLER) | 1, PWMLER);            break;        case PWM_GET_RUN_TIME:            if (!access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd)))
            {
                return -EFAULT;            }
            put_user(RunTime, (u32 *)arg);            break;
        case PWM_1_ENABLE:
            outl(inl(PWMLER) | (1 << 9), PWMPCR);
            outl(0x02 | (inl(PINSEL0) & ~0x03), PINSEL0);
            break;        case PWM_1_DISABLE:            outl(inl(PWMPCR) & ~(1 << 9), PWMPCR);
            outl((PinSel0Save & 0x03) | (inl(PINSEL0) & ~0x03), PINSEL0);
            break;        case PWM_1_SET_DUTY:
            if (arg < inl(PWMMR0))
            {
                outl(arg, PWMMR1);
                outl(inl(PWMLER) | (1 << 1), PWMLER);            }            break;
        case PWM_2_ENABLE:
            outl(inl(PWMPCR) & ~(1 << 2), PWMPCR);
            outl(inl(PWMPCR) | (1 << 10), PWMPCR);
            outl((0x02 << 14) | (inl(PINSEL0) & (~(0x03 << 14))), PINSEL0);
            break;        case PWM_2_DISABLE:            outl(inl(PWMPCR) & ~(1 << 10), PWMPCR);
            outl((PinSel0Save & (0x03 << 14)) | (inl(PINSEL0) & (~(0x03 << 14))), PINSEL0);
            break;        case PWM_2_SET_DUTY:
            if (arg < inl(PWMMR0))
            {
                outl(arg, PWMMR2);
                outl(inl(PWMLER) | (1 << 2), PWMLER);            }            break;
        case PWM_3_ENABLE:
            outl(inl(PWMPCR) & ~(1 << 3), PWMPCR);
            outl(inl(PWMPCR) | (1 << 11), PWMPCR);
            outl((0x02 << 2) | (inl(PINSEL0) & (~(0x03 << 2))), PINSEL0);
            break;        case PWM_3_DISABLE:            outl(inl(PWMPCR) & ~(1 << 11), PWMPCR);
            outl((PinSel0Save & (0x03 << 2)) | (inl(PINSEL0) & (~(0x03 << 2))), PINSEL0);
            break;        case PWM_3_SET_DUTY:
            if (arg < inl(PWMMR0))
            {
                outl(arg, PWMMR3);
                outl(inl(PWMLER) | (1 << 3), PWMLER);            }            break;
        case PWM_4_ENABLE:
            outl(inl(PWMPCR) & ~(1 << 4), PWMPCR);
            outl(inl(PWMPCR) | (1 << 12), PWMPCR);
            outl((0x02 << 16) | (inl(PINSEL0) & (~(0x03 << 16))), PINSEL0);
            break;        case PWM_4_DISABLE:            outl(inl(PWMPCR) & ~(1 << 12), PWMPCR);
            outl((PinSel0Save & (0x03 << 16)) | (inl(PINSEL0) & (~(0x03 << 16))), PINSEL0);
            break;        case PWM_4_SET_DUTY:
            if (arg < inl(PWMMR0))
            {
                outl(arg, PWMMR4);
                outl(inl(PWMLER) | (1 << 4), PWMLER);            }            break;
        case PWM_5_ENABLE:
            outl(inl(PWMPCR) & ~(1 << 5), PWMPCR);
            outl(inl(PWMPCR) | (1 << 13), PWMPCR);
            outl((0x01 << 10) | (inl(PINSEL1) & (~(0x03 << 10))), PINSEL1);
            break;        case PWM_5_DISABLE:            outl(inl(PWMPCR) & ~(1 << 13), PWMPCR);
            outl((PinSel1Save & (0x03 << 10)) | (inl(PINSEL1) & (~(0x03 << 10))), PINSEL1);
            break;        case PWM_5_SET_DUTY:
            if (arg < inl(PWMMR0))
            {
                outl(arg, PWMMR5);
                outl(inl(PWMLER) | (1 << 5), PWMLER);            }            break;
        case PWM_6_ENABLE:
            outl(inl(PWMPCR) & ~(1 << 6), PWMPCR);
            outl(inl(PWMPCR) | (1 << 14), PWMPCR);
            outl((0x02 << 18) | (inl(PINSEL0) & (~(0x03 << 18))), PINSEL0);
            break;        case PWM_6_DISABLE:            outl(inl(PWMPCR) & ~(1 << 14), PWMPCR);
            outl((PinSel0Save & (0x03 << 18)) | (inl(PINSEL0) & (~(0x03 << 18))), PINSEL0);
            break;        case PWM_6_SET_DUTY:
            if (arg < inl(PWMMR0))
            {
                outl(arg, PWMMR6);
                outl(inl(PWMLER) | (1 << 6), PWMLER);            }            break;
        default:            return -ENOTTY;            break;    }    return 0;}
/*********************************************************************************************************
** Function name: pwm_irq_handle
** Descriptions:  The top-half interrupt handler
** Input:
** Output none
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        static void pwm_irq_handle(int irq, void *dev_id, struct pt_regs *regs){    outl(0x0f | (0x07 << 8), PWMIR);
    RunTime++;
}
/*********************************************************************************************************
** Function name: pwm_init
** Descriptions:  init driver
** Input:none
** Output 0:      OK
**        other:  not OK
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        int pwm_init(void){    int  result;    
    result = register_chrdev(MAJOR_NR,  DEVICE_NAME,  &pwm_fops);     if (result < 0)    {        printk(KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR );        return(result);     } 
    if (MAJOR_NR == 0)    {        MAJOR_NR = result; /* dynamic */    }
    printk(KERN_INFO DEVICE_NAME ": init OK\n");    return(0); }/*********************************************************************************************************
** Function name: pwm_cleanup
** Descriptions:  exit driver
** Input:none
** Output none
** Created by:    Chenmingji
** Created Date:  2005-4-21
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified Date: 
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
        void pwm_cleanup(void){
    unregister_chrdev(MAJOR_NR, DEVICE_NAME);}/***********************************************************************************************************                            End Of File********************************************************************************************************/

⌨️ 快捷键说明

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