1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 04:52:59 +01:00

Merge pull request #17433 from chrysn-pull-requests/irq_enable-considered-harmful

core: Warn about using irq_enable
This commit is contained in:
Kaspar Schleiser 2021-12-21 22:23:17 +01:00 committed by GitHub
commit debb2d5fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -53,7 +53,12 @@ MAYBE_INLINE unsigned irq_disable(void);
* interpreted as a boolean value. The actual value is only
* significant for irq_restore().
*
* @see irq_restore
* @warning This function is here primarily for internal use, and for
* compatibility with the Arduino environment (which lacks the
* "disable / restore" concept. Enabling interrupts when a different
* component disabled them can easily cause unintended behavior there.
*
* Use @ref irq_restore instead.
*/
MAYBE_INLINE unsigned irq_enable(void);
@ -63,7 +68,6 @@ MAYBE_INLINE unsigned irq_enable(void);
*
* @param[in] state state to restore
*
* @see irq_enable
* @see irq_disable
*/
MAYBE_INLINE void irq_restore(unsigned state);

View File

@ -168,12 +168,12 @@ int motor_set(const motor_driver_t motor_driver, uint8_t motor_id, \
int32_t pwm_duty_cycle_abs = pwm_duty_cycle;
pwm_duty_cycle_abs *= (pwm_duty_cycle < 0) ? -1 : 1;
irq_disable();
unsigned irqstate = irq_disable();
gpio_write(dev->gpio_dir0, gpio_dir0_value);
gpio_write(dev->gpio_dir1_or_brake, gpio_dir1_or_brake_value);
pwm_set(motor_driver_conf->pwm_dev, dev->pwm_channel, \
(uint16_t)pwm_duty_cycle_abs);
irq_enable();
irq_restore(irqstate);
motor_driver_cb_t cb = motor_driver_conf->cb;
if (cb) {
@ -233,11 +233,11 @@ int motor_brake(const motor_driver_t motor_driver, uint8_t motor_id)
goto motor_brake_err;
}
irq_disable();
unsigned irqstate = irq_disable();
gpio_write(dev->gpio_dir0, gpio_dir0_value);
gpio_write(dev->gpio_dir1_or_brake, gpio_dir1_or_brake_value);
pwm_set(motor_driver_conf->pwm_dev, dev->pwm_channel, 0);
irq_enable();
irq_restore(irqstate);
return 0;