Skip to content

Commit da1df53

Browse files
bkuengdagar
authored andcommitted
fix pwm: only update oneshot timers owned by the current pwm_out instance
This fixes the case where oneshot was enabled with multi-instance pwm_out, triggering oneshot updates too close to each other and as a result could lead to spinning motors while disarmed.
1 parent 2ed623c commit da1df53

File tree

16 files changed

+24
-24
lines changed

16 files changed

+24
-24
lines changed

platforms/nuttx/src/px4/nxp/imxrt/include/px4_arch/io_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ __EXPORT int io_timer_allocate_channel(unsigned channel, io_timer_channel_mode_t
142142
__EXPORT int io_timer_unallocate_channel(unsigned channel);
143143
__EXPORT int io_timer_get_channel_mode(unsigned channel);
144144
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
145-
__EXPORT extern void io_timer_trigger(void);
145+
__EXPORT extern void io_timer_trigger(unsigned channel_mask);
146146

147147
/**
148148
* Reserve a timer

platforms/nuttx/src/px4/nxp/imxrt/io_pins/io_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ static inline void io_timer_set_PWM_mode(unsigned channel)
429429
px4_leave_critical_section(flags);
430430
}
431431

432-
void io_timer_trigger(void)
432+
void io_timer_trigger(unsigned channel_mask)
433433
{
434-
int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot);
434+
int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot) & channel_mask;
435435
struct {
436436
uint32_t base;
437437
uint16_t triggers;

platforms/nuttx/src/px4/nxp/imxrt/io_pins/pwm_servo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ int up_pwm_servo_set_rate_group_update(unsigned channel, unsigned rate)
144144
return io_timer_set_pwm_rate(channel, rate);
145145
}
146146

147-
void up_pwm_update(void)
147+
void up_pwm_update(unsigned channel_mask)
148148
{
149-
io_timer_trigger();
149+
io_timer_trigger(channel_mask);
150150
}
151151

152152
uint32_t up_pwm_servo_get_rate_group(unsigned group)

platforms/nuttx/src/px4/nxp/kinetis/include/px4_arch/io_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ __EXPORT int io_timer_allocate_channel(unsigned channel, io_timer_channel_mode_t
138138
__EXPORT int io_timer_unallocate_channel(unsigned channel);
139139
__EXPORT int io_timer_get_channel_mode(unsigned channel);
140140
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
141-
__EXPORT extern void io_timer_trigger(void);
141+
__EXPORT extern void io_timer_trigger(unsigned channel_mask);
142142

143143
/**
144144
* Reserve a timer

platforms/nuttx/src/px4/nxp/kinetis/io_pins/io_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ static inline void io_timer_set_PWM_mode(unsigned timer)
518518
px4_leave_critical_section(flags);
519519
}
520520

521-
void io_timer_trigger(void)
521+
void io_timer_trigger(unsigned channel_mask)
522522
{
523-
int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot);
523+
int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot) & channel_mask;
524524
uint32_t action_cache[MAX_IO_TIMERS] = {0};
525525
int actions = 0;
526526

platforms/nuttx/src/px4/nxp/kinetis/io_pins/pwm_servo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ int up_pwm_servo_set_rate_group_update(unsigned group, unsigned rate)
143143
return io_timer_set_pwm_rate(group, rate);
144144
}
145145

146-
void up_pwm_update(void)
146+
void up_pwm_update(unsigned channel_mask)
147147
{
148-
io_timer_trigger();
148+
io_timer_trigger(channel_mask);
149149
}
150150

151151
uint32_t up_pwm_servo_get_rate_group(unsigned group)

platforms/nuttx/src/px4/nxp/s32k1xx/include/px4_arch/io_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ __EXPORT int io_timer_allocate_channel(unsigned channel, io_timer_channel_mode_t
131131
__EXPORT int io_timer_unallocate_channel(unsigned channel);
132132
__EXPORT int io_timer_get_channel_mode(unsigned channel);
133133
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
134-
__EXPORT extern void io_timer_trigger(void);
134+
__EXPORT extern void io_timer_trigger(unsigned channel_mask);
135135

136136
/**
137137
* Reserve a timer

platforms/nuttx/src/px4/nxp/s32k1xx/io_pins/io_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ static inline void io_timer_set_PWM_mode(unsigned timer)
514514
px4_leave_critical_section(flags);
515515
}
516516

517-
void io_timer_trigger(void)
517+
void io_timer_trigger(unsigned channel_mask)
518518
{
519-
int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot);
519+
int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot) & channel_mask;
520520
uint32_t action_cache[MAX_IO_TIMERS] = {0};
521521
int actions = 0;
522522

platforms/nuttx/src/px4/nxp/s32k1xx/io_pins/pwm_servo.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ int up_pwm_servo_set_rate_group_update(unsigned group, unsigned rate)
142142
return io_timer_set_pwm_rate(group, rate);
143143
}
144144

145-
void up_pwm_update(void)
145+
void up_pwm_update(unsigned channel_mask)
146146
{
147-
io_timer_trigger();
147+
io_timer_trigger(channel_mask);
148148
}
149149

150150
uint32_t up_pwm_servo_get_rate_group(unsigned group)

platforms/nuttx/src/px4/stm/stm32_common/include/px4_arch/io_timer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ __EXPORT int io_timer_allocate_channel(unsigned channel, io_timer_channel_mode_t
147147
__EXPORT int io_timer_unallocate_channel(unsigned channel);
148148
__EXPORT int io_timer_get_channel_mode(unsigned channel);
149149
__EXPORT int io_timer_get_mode_channels(io_timer_channel_mode_t mode);
150-
__EXPORT extern void io_timer_trigger(void);
150+
__EXPORT extern void io_timer_trigger(unsigned channels_mask);
151151
__EXPORT void io_timer_update_dma_req(uint8_t timer, bool enable);
152152

153153
/**

0 commit comments

Comments
 (0)