stm32 : deconflict pwm_get_rate_group from all other timer modes

This commit is contained in:
Mohammed Kabir 2017-04-11 12:23:53 +02:00 committed by Lorenz Meier
parent 3b3e2b275e
commit 3dee42b5ca
2 changed files with 13 additions and 9 deletions

View File

@ -125,8 +125,8 @@
#else
#define CCER_C1_INIT GTIM_CCER_CC1E
#endif
// NotUsed PWMOut PWMIn Capture OneShot
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT8_MAX, 0, 0, 0, 0 };
// NotUsed PWMOut PWMIn Capture OneShot Trigger
io_timer_channel_allocation_t channel_allocations[IOTimerChanModeSize] = { UINT8_MAX, 0, 0, 0, 0, 0 };
typedef uint8_t io_timer_allocation_t; /* big enough to hold MAX_IO_TIMERS */
@ -578,7 +578,6 @@ int io_timer_set_rate(unsigned timer, unsigned rate)
/* Check that all channels are either in PWM or Oneshot */
if ((channels & (channel_allocations[IOTimerChanMode_PWMOut] |
channel_allocations[IOTimerChanMode_Trigger] |
channel_allocations[IOTimerChanMode_OneShot] |
channel_allocations[IOTimerChanMode_NotUsed])) ==
channels) {
@ -813,7 +812,6 @@ int io_timer_set_enable(bool state, io_timer_channel_mode_t mode, io_timer_chann
rvalue |= action_cache[actions].dier_setbits;
_REG32(action_cache[actions].base, STM32_GTIM_DIER_OFFSET) = rvalue;
/* Any On ?*/
if (after != 0) {

View File

@ -76,9 +76,10 @@ servo_position_t up_pwm_servo_get(unsigned channel)
int up_pwm_servo_init(uint32_t channel_mask)
{
/* Init channels */
uint32_t current = io_timer_get_mode_channels(IOTimerChanMode_PWMOut);
uint32_t current = io_timer_get_mode_channels(IOTimerChanMode_PWMOut) |
io_timer_get_mode_channels(IOTimerChanMode_OneShot);
// First free the current set of PWMs
/* First free the current set of PWMs */
for (unsigned channel = 0; current != 0 && channel < MAX_TIMER_IO_CHANNELS; channel++) {
if (current & (1 << channel)) {
@ -88,17 +89,19 @@ int up_pwm_servo_init(uint32_t channel_mask)
}
// Now allocate the new set
/* Now allocate the new set */
for (unsigned channel = 0; channel_mask != 0 && channel < MAX_TIMER_IO_CHANNELS; channel++) {
if (channel_mask & (1 << channel)) {
// First free any that were not PWM mode before
/* First free any that were not PWM mode before */
if (-EBUSY == io_timer_is_channel_free(channel)) {
io_timer_free_channel(channel);
}
/* OneShot is set later, with the set_rate_group_update call. Init to PWM mode for now */
io_timer_channel_init(channel, IOTimerChanMode_PWMOut, NULL, NULL);
channel_mask &= ~(1 << channel);
}
@ -153,7 +156,10 @@ int up_pwm_servo_set_rate(unsigned rate)
uint32_t up_pwm_servo_get_rate_group(unsigned group)
{
return io_timer_get_group(group);
/* only return the set of channels in the group which we own */
return (io_timer_get_mode_channels(IOTimerChanMode_PWMOut) |
io_timer_get_mode_channels(IOTimerChanMode_OneShot)) &
io_timer_get_group(group);
}
void