Fix the pio pins settings everty time we change configuration.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 18 Apr 2010 21:38:19 +0000 (21:38 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Sun, 18 Apr 2010 21:38:19 +0000 (21:38 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3448 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cpu/arm/drv/pwm_at91.c

index a95e60613fa6d0e5e8140735f24d468eec0ecc79..411f3ab690df18f31c2d7c945f55aa036c8fcd9d 100644 (file)
@@ -121,7 +121,7 @@ void pwm_hw_setFrequency(PwmDev dev, uint32_t freq)
        for(int i = 0; i <= PWM_HW_MAX_PRESCALER_STEP; i++)
        {
                period = CPU_FREQ / (BV(i) * freq);
-//             LOG_INFO("period[%ld], prescale[%d]\n", period, i);
+               LOG_INFO("period[%ld], prescale[%d]\n", period, i);
                if ((period < PWM_HW_MAX_PERIOD) && (period != 0))
                {
                        //Clean previous channel prescaler, and set new
@@ -152,12 +152,13 @@ void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty)
         */
        if (!duty)
        {
-               PWM_PIO_PER = pwm_map[dev].pwm_pin;
+               PWM_PIO_CODR = pwm_map[dev].pwm_pin;
+               PWM_PIO_PER  = pwm_map[dev].pwm_pin;
                pwm_map[dev].duty_zero = true;
        }
        else
        {
-       /*
+        /*
          * If polarity flag is true we must invert
          * PWM polarity.
          */
@@ -168,12 +169,13 @@ void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty)
         }
 
                PWM_PIO_PDR = pwm_map[dev].pwm_pin;
+               PWM_PIO_ABSR = pwm_map[dev].pwm_pin;
+
                *pwm_map[dev].update_reg = duty;
                pwm_map[dev].duty_zero = false;
        }
 
        PWM_ENA = BV(dev);
-
        LOG_INFO("PWM ch[%d] duty[%d], period[%ld]\n", dev, duty, *pwm_map[dev].period_reg);
 }
 
@@ -184,7 +186,10 @@ void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty)
 void pwm_hw_enable(PwmDev dev)
 {
        if (!pwm_map[dev].duty_zero)
-               PWM_PIO_PDR = pwm_map[dev].pwm_pin;
+       {
+               PWM_PIO_PDR  = pwm_map[dev].pwm_pin;
+               PWM_PIO_ABSR = pwm_map[dev].pwm_pin;
+       }
 }
 
 /**
@@ -220,8 +225,8 @@ void pwm_hw_init(void)
         * - Power on PWM
         */
        PWM_PIO_CODR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
-       PWM_PIO_OER = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
-       PWM_PIO_PDR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
+       PWM_PIO_OER  = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
+       PWM_PIO_PDR  = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
        PWM_PIO_ABSR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
        PMC_PCER |= BV(PWMC_ID);