projects
/
bertos.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix undefined behaviour.
[bertos.git]
/
bertos
/
cpu
/
arm
/
drv
/
pwm_at91.c
diff --git
a/bertos/cpu/arm/drv/pwm_at91.c
b/bertos/cpu/arm/drv/pwm_at91.c
index 7030dd2a9d375c37ed934d486dfc264205125ae4..397240ec2318f51e6971c52c3639aee3f5796351 100644
(file)
--- a/
bertos/cpu/arm/drv/pwm_at91.c
+++ b/
bertos/cpu/arm/drv/pwm_at91.c
@@
-33,19
+33,17
@@
*
* \brief PWM hardware-specific implementation
*
*
* \brief PWM hardware-specific implementation
*
- * \version $Id$
- *
* \author Daniele Basile <asterix@develer.com>
*/
#include "pwm_at91.h"
#include "hw/pwm_map.h"
* \author Daniele Basile <asterix@develer.com>
*/
#include "pwm_at91.h"
#include "hw/pwm_map.h"
-#include
"hw/hw_cpu.h"
+#include
<hw/hw_cpufreq.h>
#include "cfg/cfg_pwm.h"
// Define logging setting (for cfg/log.h module).
#define LOG_LEVEL PWM_LOG_LEVEL
#include "cfg/cfg_pwm.h"
// Define logging setting (for cfg/log.h module).
#define LOG_LEVEL PWM_LOG_LEVEL
-#define LOG_
VERBOSITY PWM_LOG_VERBOSITY
+#define LOG_
FORMAT PWM_LOG_FORMAT
#include <cfg/log.h>
#include <cfg/macros.h>
#include <cfg/log.h>
#include <cfg/macros.h>
@@
-121,8
+119,8
@@
void pwm_hw_setFrequency(PwmDev dev, uint32_t freq)
for(int i = 0; i <= PWM_HW_MAX_PRESCALER_STEP; i++)
{
for(int i = 0; i <= PWM_HW_MAX_PRESCALER_STEP; i++)
{
- period = C
LOCK
_FREQ / (BV(i) * freq);
-
//
LOG_INFO("period[%ld], prescale[%d]\n", period, i);
+ period = C
PU
_FREQ / (BV(i) * freq);
+
LOG_INFO("period[%ld], prescale[%d]\n", period, i);
if ((period < PWM_HW_MAX_PERIOD) && (period != 0))
{
//Clean previous channel prescaler, and set new
if ((period < PWM_HW_MAX_PERIOD) && (period != 0))
{
//Clean previous channel prescaler, and set new
@@
-147,35
+145,36
@@
void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty)
ASSERT(duty <= (uint16_t)*pwm_map[dev].period_reg);
ASSERT(duty <= (uint16_t)*pwm_map[dev].period_reg);
+ /*
+ * If polarity flag is true we must invert
+ * PWM polarity.
+ */
+ if (pwm_map[dev].pol)
+ {
+ duty = (uint16_t)*pwm_map[dev].period_reg - duty;
+ LOG_INFO("Inverted duty[%d], pol[%d]\n", duty, pwm_map[dev].pol);
+ }
+
/*
* WARNING: is forbidden to write 0 to duty cycle value,
* and so for duty = 0 we must enable PIO and clear output!
*/
if (!duty)
{
/*
* WARNING: is forbidden to write 0 to duty cycle value,
* and so for duty = 0 we must enable PIO and clear output!
*/
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
{
pwm_map[dev].duty_zero = true;
}
else
{
- ASSERT(PWM_CCNT0);
- /*
- * If polarity flag is true we must invert
- * PWM polarity.
- */
- if (pwm_map[dev].pol)
- {
- duty = (uint16_t)*pwm_map[dev].period_reg - duty;
- LOG_INFO("Inverted duty[%d], pol[%d]\n", duty, pwm_map[dev].pol);
- }
-
PWM_PIO_PDR = pwm_map[dev].pwm_pin;
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);
*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);
}
LOG_INFO("PWM ch[%d] duty[%d], period[%ld]\n", dev, duty, *pwm_map[dev].period_reg);
}
@@
-186,7
+185,10
@@
void pwm_hw_setDutyUnlock(PwmDev dev, uint16_t duty)
void pwm_hw_enable(PwmDev dev)
{
if (!pwm_map[dev].duty_zero)
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;
+ }
}
/**
}
/**
@@
-222,8
+224,8
@@
void pwm_hw_init(void)
* - Power on PWM
*/
PWM_PIO_CODR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
* - 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);
PWM_PIO_ABSR = BV(PWM0) | BV(PWM1) | BV(PWM2) | BV(PWM3);
PMC_PCER |= BV(PWMC_ID);