混杂设备驱动--输出两路PWM

来源:互联网 发布:泉州java培训机构 编辑:程序博客网 时间:2024/05/09 09:47
尝试用2440的TOUT0和TOUT1输出PWM驱动两个电机,电机的硬件驱动电路是使用L298N。
先单独测试TOUT0的PWM输出:
(1)驱动程序:使用misc混杂设备驱动模型,当然也可以使用基本的字符设备模型。
使用misc设备驱动模型步骤:
①初始化一个struct miscdevice结构体:主要是file_operation结构体成员和name
②使用misc_register和misc_deregister注册和注销这个结构体
代码示例:

[cpp] view plain copy
print?
  1. #include <linux/module.h>  
  2. #include <linux/kernel.h>  
  3. #include <linux/init.h>  
  4. #include <linux/gpio.h>  
  5. #include <asm/irq.h>  
  6. #include <asm/io.h>  
  7. #include <asm/uaccess.h>  
  8. #include <mach/regs-gpio.h>  
  9. #include <mach/hardware.h>  
  10. #include <plat/regs-timer.h>  
  11. #include <mach/regs-irq.h>  
  12. #include <linux/clk.h>  
  13. #include <linux/cdev.h>  
  14. #include <linux/device.h>  
  15. #include <linux/miscdevice.h>  
  16.   
  17. #define DEVICE_NAME "pwm" //设备名  
  18.   
  19. #define IOCTL_SET_PWM_DUTY  1   
  20. #define IOCTL_PWM_STOP      2  
  21.   
  22. /* 定义信号量 lock用于互斥,因此,改驱动程序只能同时有一个进程使用 */  
  23. static struct semaphore lock;  
  24.   
  25. static void pwm_set_duty(unsigned long duty)  
  26. {  
  27.     unsigned long tcon;  
  28.     unsigned long tcnt0,tcmp0;  
  29.     unsigned long tcfg1;  
  30.     unsigned long tcfg0;  
  31.       
  32.     tcfg0 = __raw_readl(S3C2410_TCFG0);  
  33.     tcfg0 &= ~S3C2410_TCFG_PRESCALER0_MASK;  
  34.     tcfg0 |= (50 - 1);   
  35.       
  36.     tcfg1 = __raw_readl(S3C2410_TCFG1);  
  37.     tcfg1 &= ~S3C2410_TCFG1_MUX0_MASK;   
  38.     tcfg1 |= S3C2410_TCFG1_MUX0_DIV16;  
  39.       
  40.     __raw_writel(tcfg0, S3C2410_TCFG0);  
  41.     __raw_writel(tcfg1, S3C2410_TCFG1);   
  42.       
  43.     tcnt0 = 1000;//设置PWM频率  
  44.     tcmp0 = duty;//设置PWM占空比  
  45.     __raw_writel(tcnt0, S3C2410_TCNTB(0));  
  46.     __raw_writel(tcmp0, S3C2410_TCMPB(0));  
  47.        
  48.     tcon = __raw_readl(S3C2410_TCON);  
  49.     tcon |= 0xf; //设置输出电平反转,start pwm output  
  50.     __raw_writel(tcon, S3C2410_TCON);   
  51.     tcon &= ~2;   /* clear manual update bit */  
  52.     __raw_writel(tcon, S3C2410_TCON);  
  53. }  
  54.   
  55. static void pwm_stop(void)  
  56. {  
  57.     unsigned long tcon;  
  58.     tcon = __raw_readl(S3C2410_TCON);  
  59.     tcon &= ~(1<<3);//Turn off the auto reload bit  
  60.     __raw_writel(tcon, S3C2410_TCON); //   
  61. }  
  62.   
  63. static int my_pwm_open(struct inode *inode, struct file *file)  
  64. {  
  65.     if (!down_trylock(&lock))//不会导致进程休眠  
  66.     {     
  67.         s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPB0_TOUT0);  
  68.         return 0;  
  69.     }  
  70.     else  
  71.         return -EBUSY;   
  72. }  
  73.   
  74. static int my_pwm_close(struct inode *inode, struct file *file)  
  75. {  
  76.     pwm_stop();  
  77.     s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPIO_INPUT);  
  78.     up(&lock);  
  79.     return 0;  
  80. }  
  81.   
  82. static int my_pwm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)  
  83. {  
  84.     switch (cmd) {  
  85.         case IOCTL_SET_PWM_DUTY:   
  86.             if (arg == 0)   
  87.                 return -EINVAL;  
  88.             pwm_set_duty(arg);  
  89.             break;  
  90.         case IOCTL_PWM_STOP:  
  91.             pwm_stop();  
  92.             break;  
  93.         default:  
  94.             printk(KERN_INFO"cmd error!\n");  
  95.             break;  
  96.     }  
  97.     return 0;  
  98. }  
  99.   
  100. static struct file_operations dev_fops = {  
  101.     .owner = THIS_MODULE,  
  102.     .open = my_pwm_open,  
  103.     .release = my_pwm_close,  
  104.     .ioctl = my_pwm_ioctl,  
  105. };  
  106.   
  107. //混杂设备驱动  
  108. static struct miscdevice misc = {  
  109.     .minor = MISC_DYNAMIC_MINOR,  
  110.     .name = DEVICE_NAME,  
  111.     .fops = &dev_fops,  
  112. };  
  113.   
  114. static int __init dev_init(void)  
  115. {  
  116.     int ret;  
  117.     init_MUTEX(&lock); /* 初始化一个互斥锁 */  
  118.     ret = misc_register(&misc);  
  119.     printk (DEVICE_NAME"\tinitialized\n");  
  120.     return ret;  
  121. }  
  122.   
  123. static void __exit dev_exit(void)  
  124. {  
  125.     misc_deregister(&misc);   
  126. }  
  127.   
  128. module_init(dev_init);  
  129. module_exit(dev_exit);  
  130.   
  131. MODULE_LICENSE("GPL");  
  132. MODULE_AUTHOR("CLBIAO");  
  133. MODULE_DESCRIPTION("S3C2440 Pwm Driver");  
(2)测试app程序:
[cpp] view plain copy
print?
  1. #include <stdlib.h>  
  2. #include <stdio.h>    
  3. #include <sys/types.h>    
  4. #include <sys/stat.h>    
  5. #include <fcntl.h>    
  6. #include <unistd.h>  
  7. #include <string.h>   
  8.   
  9. #define IOCTL_SET_PWM_DUTY  1   
  10. #define IOCTL_PWM_STOP      2  
  11.   
  12. int main(int argc, char **argv)  
  13. {  
  14.     int fd,i;  
  15.     unsigned long duty;  
  16.     fd = open("/dev/pwm",O_RDWR);  
  17.       
  18.     for(i=0;i<4;i++)  
  19.     {  
  20.         ioctl(fd,IOCTL_SET_PWM_DUTY,duty);//duty=80%  
  21.         duty += 100;   
  22.         sleep(3);  
  23.     }  
  24.     close(fd);  
  25.     exit(0);  
  26. }  
实验现象是:
用外用表电压档测gpb0引脚会出现从大到小的变化,说明pwm实现了占空比可调,万用表测到的是引脚的平均电压。
对tout1的单独测试也是一样。
当我把两个单独可以工作的驱动代码合并到一起的时候就出现了奇怪的问题:只要我先设置其中一个timer输出之后另外一个就输出高电平,之后对他进行的配置工作不起效,相当于不受程序控制。
分析问题:在后面才配置的timer在进行操作寄存器之前是否对他有另外的操作?有,将gpb1配置为定时器1输出。
测试方案①:只设置了timer0寄存器,没有配置timer1的,同时gpb0和gpb1设置为定时器输出,使用printk函数打印寄存器的值
测试记录:
tout0实际电平输出:
0.27,0.82,1.67,->0.06
tout1实际电平输出:
3.31,3.31,3.31,->0.47
串口打印:
before set:tcfg0=512,tcfg1=0,tcon=5242894 - 10100000000000000001110 -> timer0/1未开始输出
 after set:tcfg0=561,tcfg1=3,tcon=5242893 - 10100000000000000001101 -> timer0开始输出,timer1未开始输出
before set:tcfg0=561,tcfg1=3,tcon=5242893
 after set:tcfg0=561,tcfg1=3,tcon=5242893
before set:tcfg0=561,tcfg1=3,tcon=5242893
 after set:tcfg0=561,tcfg1=3,tcon=5242893
数据分析:
(512)->1000000000 => bit8-bit0:00000000 -> 00
(561)->1000110001 => bit8-bit0:00110001 -> 49
初步结论:
timer0处于正常工作状态,从读取的寄存器来看timer1并没有开始工作,之所以会在timer0工作时输出高电平猜测是在调用open函数时:执行完s3c2410_gpio_cfgpin(S3C2410_GPB1, S3C2410_GPB1_TOUT1);之后timer1的输出引脚本身就是高电平,之所以会这样的原因进一步猜测是程序中只对timer0进行配置:关键是Timer 0 output inverter on,而此时从读取的timer1来看 Timer 1 output inverter off 的,芯片手册上说关闭反转功能时引脚的初始状态是表现为高电平的。之所以timer0最后会输出0,而不是1,是因为在设置占空比过程中打开了位反转功能和最后引脚配置为INPUT,timer1最后也输出0同样是因为引脚配置为INPUT。
进一步验证:
测试方案②:在配置gpb0/1为timer输出时就进行设置位反转功能
测试数据:
tout0实际电平输出:
0.27,0.82,1.67,->0.06
tout1实际电平输出:
0.06,0.06,0.06,->0.62
串口打印:
before set:tcfg0=512,tcfg1=0,tcon=5243918 - 101000000000100 00001110
 after set:tcfg0=561,tcfg1=3,tcon=5243917 - 101000000000100 00001101
before set:tcfg0=561,tcfg1=3,tcon=5243917
 after set:tcfg0=561,tcfg1=3,tcon=5243917
before set:tcfg0=561,tcfg1=3,tcon=5243917
 after set:tcfg0=561,tcfg1=3,tcon=5243917
和上面的猜测完全吻合。
附上自己对s3c2440英文pdf手册第319页的翻译--即关于输出电平反转功能和输出电平状态的那部分:

The following procedure describes how to maintain TOUT as high or low (assume the inverter is off):
1. Turn off the auto reload bit. And then, TOUTn goes to high level and the timer is stopped after the TCNTn reaches
0 (recommended).
2. Stop the timer by clearing the timer start/stop bit to 0. 
If TCNTn<=TCMPn, the output level is high. 
If TCNTn>TCMPn, the output level is low.
3. The TOUTn can be inverted by the inverter on/off bit in TCON. The inverter removes the additional circuit to
adjust the output level.

下面的步骤是描述如何维持TOUT为高电平或低电平(假设电平反转功能关闭):
1.关掉自动重新加载位,然后TOUTn引脚变为高电平,当TCNTn自减到0时,定时器停止工作
2.通过清除定时器的start/stop位来停止定时器
①如果清除停止位时:TCNTn<=TCMPn,那么输出维持为高电平
②如果清除停止位时:TCNTn>TCMPn,那么输出维持为低电平
3.TOUTn引脚的电平反转可以通过TCON寄存器的“inverter on/off”位来进行设置,反转器移除附加的回路来调整输出电平
小结:
也就是说,如果我需要在停止pwm之后引脚的电平保持为确定的电平,就只能考虑第一点,通过关掉自动重新加载位来
停止pwm,然后再来清除start/stop位
---------------------------------------------------------------------------------------------------------------------------------------------------------
之后引脚连接到电机驱动电路之后又遇到类似调不了速的奇葩问题,得到一个结论就是tcon寄存器里的控制各种功能的位不要一次性写进去,有些位写完之后还要稍加延时才能实现对两路PWM占空比的独立控制。
最终可以使用的驱动代码:2440_pwm.c
[cpp] view plain copy
print?
  1. #include <linux/module.h>  
  2. #include <linux/kernel.h>  
  3. #include <linux/fs.h>  
  4. #include <linux/init.h>  
  5. #include <linux/delay.h>  
  6. #include <linux/poll.h>  
  7. #include <linux/interrupt.h>  
  8. #include <linux/gpio.h>  
  9. #include <asm/irq.h>  
  10. #include <asm/io.h>  
  11. #include <asm/uaccess.h>  
  12. #include <mach/regs-gpio.h>  
  13. #include <mach/hardware.h>  
  14. #include <plat/regs-timer.h>  
  15. #include <mach/regs-irq.h>  
  16. #include <asm/mach/time.h>  
  17. #include <linux/clk.h>  
  18. #include <linux/cdev.h>  
  19. #include <linux/device.h>  
  20. #include <linux/miscdevice.h>  
  21.   
  22. #define DEVICE_NAME "pwm"  
  23.   
  24. #define IOCTL_CONFIG_PWM0   1  
  25. #define IOCTL_CONFIG_PWM1   2  
  26. #define IOCTL_PWM0_STOP     3  
  27. #define IOCTL_PWM1_STOP     4  
  28.       
  29. #define TIMER0              5  
  30. #define TIMER1              6  
  31. #define AUTO_RELOAD_ON      7  
  32. #define AUTO_RELOAD_OFF     8  
  33. #define INVER_ON            9  
  34. #define INVER_OFF          (10)  
  35.   
  36. static struct semaphore lock;  
  37.   
  38. static void set_input_clock(void)  
  39. {  
  40.     unsigned int tcfg0,tcfg1;  
  41.     tcfg0 = __raw_readl(S3C2410_TCFG0);  
  42.     tcfg1 = __raw_readl(S3C2410_TCFG1);  
  43.     tcfg0 &= ~S3C2410_TCFG_PRESCALER0_MASK;  
  44.     tcfg0 |= (50- 1);   
  45.     tcfg1 &= ~S3C2410_TCFG1_MUX0_MASK;   
  46.     tcfg1 |= S3C2410_TCFG1_MUX0_DIV16;  
  47.     __raw_writel(tcfg0, S3C2410_TCFG0);  
  48.     __raw_writel(tcfg1, S3C2410_TCFG1);  
  49. }  
  50.   
  51. static void set_pwm_duty(int select,unsigned int duty)  
  52. {  
  53.     unsigned int tcon;  
  54.     tcon = __raw_readl(S3C2410_TCON);  
  55.     switch(select)  
  56.     {  
  57.         case TIMER0:  
  58.             __raw_writel(1000, S3C2410_TCNTB(0));  
  59.             __raw_writel(duty, S3C2410_TCMPB(0));  
  60.             break;  
  61.           
  62.         case TIMER1:  
  63.             __raw_writel(1000, S3C2410_TCNTB(1));  
  64.             __raw_writel(duty, S3C2410_TCMPB(1));  
  65.             break;  
  66.     }  
  67. }  
  68. static void auto_reload_on_off(int select,int status)  
  69. {  
  70.     unsigned int tcon;  
  71.     tcon = __raw_readl(S3C2410_TCON);  
  72.     switch(select)  
  73.     {  
  74.         case TIMER0:  
  75.             if(status==7)  
  76.             {  
  77.                 tcon |= (1<<3);  
  78.                 __raw_writel(tcon,S3C2410_TCON);  
  79.                 mdelay(1);  
  80.             }  
  81.             else if(status==8)  
  82.             {  
  83.                 tcon &= ~(1<<3);  
  84.                 __raw_writel(tcon,S3C2410_TCON);  
  85.                 mdelay(1);  
  86.             }  
  87.             break;  
  88.               
  89.         case TIMER1:  
  90.             if(status==7)  
  91.             {  
  92.                 tcon |= (1<<11);  
  93.                 __raw_writel(tcon,S3C2410_TCON);  
  94.                 mdelay(1);  
  95.             }  
  96.             else if(status==8)  
  97.             {  
  98.                 tcon &= ~(1<<11);  
  99.                 __raw_writel(tcon,S3C2410_TCON);  
  100.                 mdelay(1);  
  101.             }  
  102.             break;  
  103.     }  
  104. }  
  105. static void start_pwm_out(int select)  
  106. {  
  107.     unsigned int tcon;  
  108.     tcon = __raw_readl(S3C2410_TCON);  
  109.     switch(select)  
  110.     {  
  111.         case TIMER0:  
  112.               
  113.             tcon |= 1;  
  114.             __raw_writel(tcon, S3C2410_TCON);  
  115.             break;  
  116.               
  117.         case TIMER1:  
  118.               
  119.             tcon |= (1<<8);  
  120.             __raw_writel(tcon, S3C2410_TCON);  
  121.             break;  
  122.     }  
  123. }  
  124. static void stop_pwm_out(int select)  
  125. {  
  126.     unsigned int tcon;  
  127.     tcon = __raw_readl(S3C2410_TCON);  
  128.     switch(select)  
  129.     {  
  130.         case TIMER0:  
  131.             auto_reload_on_off(TIMER0,AUTO_RELOAD_OFF);  
  132.             mdelay(5);  
  133.             tcon &= ~(1<<0);  
  134.             __raw_writel(tcon,S3C2410_TCON);  
  135.             break;  
  136.               
  137.         case TIMER1:  
  138.             auto_reload_on_off(TIMER1,AUTO_RELOAD_OFF);  
  139.             mdelay(1);  
  140.             tcon &= ~(1<<8);  
  141.             __raw_writel(tcon,S3C2410_TCON);  
  142.             break;  
  143.     }  
  144. }  
  145.   
  146. static void manual_update_tcont_tcmp(int select)  
  147. {  
  148.     unsigned int tcon;  
  149.     tcon = __raw_readl(S3C2410_TCON);  
  150.     switch(select)  
  151.     {  
  152.         case TIMER0:  
  153.             tcon |= (1<<1);//Update TCNTB0 & TCMPB0  
  154.             __raw_writel(tcon, S3C2410_TCON);  
  155.             break;  
  156.           
  157.         case TIMER1:  
  158.             tcon |= (1<<9);//Update TCNTB1 & TCMPB1  
  159.             __raw_writel(tcon, S3C2410_TCON);  
  160.             break;  
  161.     }  
  162. }  
  163. static void clear_manual_bit(int select)  
  164. {  
  165.     unsigned int tcon;  
  166.     tcon = __raw_readl(S3C2410_TCON);  
  167.     switch(select)  
  168.     {  
  169.         case TIMER0:  
  170.             tcon &= ~(1<<1);  
  171.             __raw_writel(tcon, S3C2410_TCON);  
  172.             break;  
  173.               
  174.         case TIMER1:  
  175.             tcon &= ~(1<<9);  
  176.             __raw_writel(tcon, S3C2410_TCON);  
  177.         break;  
  178.     }  
  179. }  
  180. static void output_inverte_on_off(int status)  
  181. {  
  182.     unsigned long tcon;  
  183.     switch(status)  
  184.     {  
  185.         case INVER_ON:  
  186.             tcon = __raw_readl(S3C2410_TCON);  
  187.             tcon |= ((1<<2)|(1<<10));  
  188.             __raw_writel(tcon, S3C2410_TCON);  
  189.             break;  
  190.         case INVER_OFF:  
  191.             tcon = __raw_readl(S3C2410_TCON);  
  192.             tcon &= ~((1<<2)|(1<<10));  
  193.             __raw_writel(tcon, S3C2410_TCON);  
  194.             break;  
  195.     }  
  196. }  
  197. static void print_tcon(int status)  
  198. {  
  199.     unsigned int tcon;  
  200.     tcon = __raw_readl(S3C2410_TCON);  
  201.     switch(status)  
  202.     {  
  203.         case 0:  
  204.             printk(KERN_INFO"beford set tcon:tcon=%d\n",tcon);  
  205.             break;  
  206.         case 1:  
  207.             printk(KERN_INFO" after set tcon:tcon=%d\n",tcon);  
  208.             break;  
  209.     }  
  210. }  
  211.   
  212. static int s3c2440_pwm_open(struct inode *inode, struct file *file)  
  213. {  
  214.     if (!down_trylock(&lock))  
  215.     {     
  216.         s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPB0_TOUT0);//靠外边的一个TOUT0  
  217.         s3c2410_gpio_cfgpin(S3C2410_GPB1, S3C2410_GPB1_TOUT1);//  
  218.         s3c2410_gpio_setpin(S3C2410_GPB6,1);  
  219.   
  220.         output_inverte_on_off(INVER_ON);  
  221.         stop_pwm_out(TIMER0);  
  222.         stop_pwm_out(TIMER1);  
  223.         set_input_clock();  
  224.           
  225.         return 0;  
  226.     }  
  227.     else  
  228.     {  
  229.         printk(KERN_INFO"/dev/pwm opened!\n");  
  230.         return -EBUSY;   
  231.     }  
  232. }  
  233.   
  234. static int s3c2440_pwm_close(struct inode *inode, struct file *file)  
  235. {  
  236.     auto_reload_on_off(TIMER0,AUTO_RELOAD_OFF);  
  237.     auto_reload_on_off(TIMER1,AUTO_RELOAD_OFF);  
  238.     stop_pwm_out(TIMER0);  
  239.     stop_pwm_out(TIMER1);  
  240.     output_inverte_on_off(INVER_OFF);  
  241.     s3c2410_gpio_cfgpin(S3C2410_GPB0, S3C2410_GPIO_INPUT);  
  242.     s3c2410_gpio_cfgpin(S3C2410_GPB1, S3C2410_GPIO_INPUT);  
  243.     s3c2410_gpio_setpin(S3C2410_GPB6,0);  
  244.     up(&lock);  
  245.     return 0;  
  246. }  
  247. static void config_pwm0(unsigned long duty)  
  248. {  
  249.     stop_pwm_out(TIMER0);  
  250.     set_pwm_duty(TIMER0,duty);  
  251.     manual_update_tcont_tcmp(TIMER0);  
  252.     auto_reload_on_off(TIMER0,AUTO_RELOAD_ON);  
  253.     start_pwm_out(TIMER0);  
  254.     clear_manual_bit(TIMER0);  
  255. }  
  256.   
  257. static void config_pwm1(unsigned long duty)  
  258. {  
  259.     stop_pwm_out(TIMER1);  
  260.     set_pwm_duty(TIMER1,duty);  
  261.     manual_update_tcont_tcmp(TIMER1);  
  262.     auto_reload_on_off(TIMER1,AUTO_RELOAD_ON);  
  263.     start_pwm_out(TIMER1);  
  264.     clear_manual_bit(TIMER1);  
  265. }  
  266. static int s3c2440_pwm_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)  
  267. {  
  268.     switch (cmd) {  
  269.         case IOCTL_CONFIG_PWM0:  
  270.             printk(KERN_INFO"config timer0:\n");  
  271.             print_tcon(0);  
  272.             config_pwm0(arg);  
  273.             print_tcon(1);  
  274.             break;  
  275.         case IOCTL_CONFIG_PWM1:  
  276.             printk(KERN_INFO"config timer1:\n");  
  277.             print_tcon(0);  
  278.             config_pwm1(arg);  
  279.             print_tcon(1);  
  280.             break;  
  281.         case IOCTL_PWM0_STOP:  
  282.             printk(KERN_INFO"stop timer0:\n");  
  283.             print_tcon(0);  
  284.             stop_pwm_out(TIMER0);  
  285.             print_tcon(1);  
  286.             break;  
  287.         case IOCTL_PWM1_STOP:  
  288.             printk(KERN_INFO"stop timer1:\n");  
  289.             print_tcon(0);  
  290.             stop_pwm_out(TIMER1);  
  291.             print_tcon(1);  
  292.             break;  
  293.         default:  
  294.             printk(KERN_INFO"ioctl cmd error!\n");  
  295.             break;  
  296.     }  
  297.     return 0;  
  298. }  
  299.   
  300. static struct file_operations dev_fops = {  
  301.     .owner   = THIS_MODULE,  
  302.     .open    = s3c2440_pwm_open,  
  303.     .release = s3c2440_pwm_close,  
  304.     .ioctl   = s3c2440_pwm_ioctl,  
  305. };  
  306.   
  307. static struct miscdevice misc = {  
  308.     .minor = MISC_DYNAMIC_MINOR,  
  309.     .name = DEVICE_NAME,  
  310.     .fops = &dev_fops,  
  311. };  
  312.   
  313. static int __init dev_init(void)  
  314. {  
  315.     int ret;  
  316.     init_MUTEX(&lock); /* 初始化一个互斥锁 */  
  317.     ret = misc_register(&misc);  
  318.     printk (DEVICE_NAME"\tinitialized\n");  
  319.     return ret;  
  320. }  
  321.   
  322. static void __exit dev_exit(void)  
  323. {  
  324.     misc_deregister(&misc);   
  325. }  
  326.   
  327. module_init(dev_init);  
  328. module_exit(dev_exit);  
  329.   
  330. MODULE_LICENSE("GPL");  
  331. MODULE_AUTHOR("CLBIAO");  
  332. MODULE_DESCRIPTION("S3C2440 Pwm Driver");  
测试APP:
[cpp] view plain copy
print?
  1. #include <stdlib.h>  
  2. #include <stdio.h>    
  3. #include <sys/types.h>    
  4. #include <sys/stat.h>    
  5. #include <fcntl.h>    
  6. #include <unistd.h>  
  7. #include <string.h>   
  8.   
  9. #define IOCTL_CONFIG_PWM0   1  
  10. #define IOCTL_CONFIG_PWM1   2  
  11. #define IOCTL_PWM0_STOP     3  
  12. #define IOCTL_PWM1_STOP     4  
  13.   
  14. int main(int argc, char **argv)  
  15. {  
  16.     int fd;  
  17.   
  18.     fd = open("/dev/pwm",O_RDWR);  
  19.     sleep(12);  
  20.     ioctl(fd,IOCTL_CONFIG_PWM0,900);  
  21.     ioctl(fd,IOCTL_CONFIG_PWM1,100);  
  22.     sleep(6);  
  23.     ioctl(fd,IOCTL_CONFIG_PWM0,700);  
  24.     ioctl(fd,IOCTL_CONFIG_PWM1,300);  
  25.     sleep(6);  
  26.     ioctl(fd,IOCTL_PWM0_STOP);  
  27.     ioctl(fd,IOCTL_PWM1_STOP);  
  28.     sleep(6);  
  29.     ioctl(fd,IOCTL_CONFIG_PWM0,500);  
  30.     ioctl(fd,IOCTL_CONFIG_PWM1,500);  
  31.     sleep(6);  
  32.     close(fd);  
  33.     exit(0);  
  34. }  
感想:s3c2440芯片手册上并没有说到两路timer同时输出时应该注意哪些方面,我想这就是这次调试过程中遇到最蛋疼的问题了,只能靠自己通过实验现象一点一点去摸索,醉了醉了.............