Add set freq and enable function. Refactor init funtions. Add other test.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 30 Apr 2008 15:23:21 +0000 (15:23 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 30 Apr 2008 15:23:21 +0000 (15:23 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1242 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/pwm.c
bertos/drv/pwm.h
bertos/drv/pwm_test.c

index 3946188262263c0f406062adef2fac522a19d77b..dd1f13491412b1c5c6eee179f1938f2e5995aaf9 100644 (file)
@@ -62,7 +62,7 @@ void pwm_setDuty(PwmDev dev, pwm_duty_t duty)
 
        real_duty = (uint64_t)(duty * period) >> (uint64_t)PWM_MAX_PERIOD_LOG2;
 
-//     kprintf("real_duty[%d] duty[%d], period[%d]\n", real_duty, duty, period);
+//     TRACEMSG("real_duty[%d] duty[%d], period[%d]", real_duty, duty, period);
        pwm_hw_setDutyUnlock(dev, real_duty);
 }
 
@@ -95,12 +95,12 @@ void pwm_init(void)
 
        IRQ_SAVE_DISABLE(flags);
 
+       pwm_hw_init();
+
        /* set all pwm to 0 */
        for (dev = 0; dev < PWM_CNT; dev++)
                pwm_setDuty(dev, 0);
 
-       pwm_hw_init();
-
        IRQ_RESTORE(flags);
 }
 
index 03d98453499af5f23a6fb4643a414acfefebc1b9..58c4ee5ae5794530dc3d31e52302cd85ea0441f7 100644 (file)
@@ -35,6 +35,7 @@
  *
  * \version $Id$
  * \author Francesco Sacchi <batt@develer.com>
+ * \author Daniele Basile <asterix@develer.com>
  */
 
 #ifndef DRV_PWM_H
 #include <pwm_map.h>
 #include <cfg/compiler.h>
 
+#define PWM_MAX_DUTY              ((pwm_duty_t)0xFFFF)
+#define PWM_MAX_PERIOD            0xFFFF
+#define PWM_MAX_PERIOD_LOG2           16
+
 typedef uint16_t pwm_duty_t;
+typedef uint32_t pwm_freq_t;
 
 void pwm_setDuty(PwmDev dev, pwm_duty_t duty);
+void pwm_setFrequency(PwmDev dev, pwm_freq_t freq);
+void pwm_enable(PwmDev dev, bool state);
 void pwm_init(void);
 
-#define PWM_MAX_DUTY 100
+void pwm_test(void);
 
 #endif /* DRV_PWM_H */
index cb2dc84ce8f7361ff6d3db4cbdc9fbeb848245f5..3ef10e9d7278f8243cb9ff52772f0039e4cad766 100644 (file)
 
 #include <drv/pwm.h>
 #include <drv/pwm_at91.h>
+#include <drv/timer.h>
+#include <drv/sysirq_at91.h>
 
 #include <cfg/macros.h>
 #include <cfg/debug.h>
 
+#include <io/arm.h>
+
 /*
  * Esample of value for duty cycle"
  *
 
 #define PWM_TEST_CH0                     0
 #define PWM_TEST_CH0_FREQ            100UL // 100Hz
-#define PWM_TEST_CH0_DUTY           0xCCCC // 80%
+#define PWM_TEST_CH0_DUTY           0xBFFF // 80%
 
 #define PWM_TEST_CH1                     1
 #define PWM_TEST_CH1_FREQ           1000UL  // 1000Hz
 #define PWM_TEST_CH1_DUTY           0xBFFF  // 75%
 
 #define PWM_TEST_CH2                     2
-#define PWM_TEST_CH2_FREQ            12356  // 12356Hz
+#define PWM_TEST_CH2_FREQ          12356UL  // 12356Hz
 #define PWM_TEST_CH2_DUTY           0x7FFF  // 50%
 
 #define PWM_TEST_CH3                     3
 void pwm_test(void)
 {
 
+       kputs("PWM test\n\n");
+
+       kputs("Init pwm..");
+
        pwm_init();
-       kputs("Init pwm..\n");
+       kputs("done.\n");
 
        PWM_TEST_CH_SET(0);
-       kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
+       kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH0, PWM_TEST_CH0_FREQ, PWM_TEST_CH0_DUTY);
        PWM_TEST_CH_SET(1);
-       kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
+       kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH1, PWM_TEST_CH1_FREQ, PWM_TEST_CH1_DUTY);
        PWM_TEST_CH_SET(2);
-       kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
+       kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH2, PWM_TEST_CH2_FREQ, PWM_TEST_CH2_DUTY);
        PWM_TEST_CH_SET(3);
-       kprintf("Set pwm ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
+       kprintf("PWM test set ch[%d] =>freq[%ld], duty[%d]\n", PWM_TEST_CH3, PWM_TEST_CH3_FREQ, PWM_TEST_CH3_DUTY);
 }
 
+int main(void)
+{
+       IRQ_ENABLE;
+       kdbg_init();
+       sysirq_init();
+       timer_init();
+       pwm_test();
+
+
+
+       kputs("Parto con il test!\n");
+       kprintf("PWM CURRENT ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH0, PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
+
+       for(;;)
+       {
+
+               pwm_setDuty(0,0);
+               timer_delay(5000);
+               kprintf("TEST10 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
 
 
+               pwm_setDuty(0,0x7FFF);
+               timer_delay(5000);
+               kprintf("TEST50 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
+
+
+               pwm_setDuty(0,0x5555);
+               timer_delay(5000);
+               kprintf("TEST33 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
+
+
+               pwm_setDuty(0,0xCCCC);
+               timer_delay(5000);
+               kprintf("TEST80 => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
+               kputs("--------\n");
+
+
+//             kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH0, PWM_CMR0, PWM_CDTY0, PWM_CPRD0, PWM_CUPD0);
+//             kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH1, PWM_CMR1, PWM_CDTY1, PWM_CPRD1, PWM_CUPD1);
+//             kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH2, PWM_CMR2, PWM_CDTY2, PWM_CPRD2, PWM_CUPD2);
+//             kprintf("PWM test ch[%d] => cmr[%ld], dty[%ld], prd[%ld], up[%ld]\n", PWM_TEST_CH3, PWM_CMR3, PWM_CDTY3, PWM_CPRD3, PWM_CUPD3);
+       }
+
+}
+