irq: Prefer irq_disable/enable instead of irq_save/restore in cmds/tasks

Task and command handlers always run with irqs enabled, so it is not
necessary to save/restore the irq state when disabling irqs in these
handlers.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2016-06-08 20:51:00 -04:00
parent 4fcf5a31f5
commit 9dd101c26f
4 changed files with 13 additions and 13 deletions

View File

@ -6,7 +6,7 @@
#include "basecmd.h" // alloc_oid #include "basecmd.h" // alloc_oid
#include "board/gpio.h" // struct gpio_adc #include "board/gpio.h" // struct gpio_adc
#include "board/irq.h" // irq_save #include "board/irq.h" // irq_disable
#include "command.h" // DECL_COMMAND #include "command.h" // DECL_COMMAND
#include "sched.h" // DECL_TASK #include "sched.h" // DECL_TASK
@ -90,15 +90,15 @@ analog_in_task(void)
foreach_oid(oid, a, command_config_analog_in) { foreach_oid(oid, a, command_config_analog_in) {
if (a->state != a->sample_count) if (a->state != a->sample_count)
continue; continue;
uint8_t flag = irq_save(); irq_disable();
if (a->state != a->sample_count) { if (a->state != a->sample_count) {
irq_restore(flag); irq_enable();
continue; continue;
} }
uint16_t value = a->value; uint16_t value = a->value;
uint32_t next_begin_time = a->next_begin_time; uint32_t next_begin_time = a->next_begin_time;
a->state++; a->state++;
irq_restore(flag); irq_enable();
sendf("analog_in_state oid=%c next_clock=%u value=%hu" sendf("analog_in_state oid=%c next_clock=%u value=%hu"
, oid, next_begin_time, value); , oid, next_begin_time, value);
} }

View File

@ -7,7 +7,7 @@
#include <stddef.h> // offsetof #include <stddef.h> // offsetof
#include "basecmd.h" // alloc_oid #include "basecmd.h" // alloc_oid
#include "board/gpio.h" // struct gpio #include "board/gpio.h" // struct gpio
#include "board/irq.h" // irq_save #include "board/irq.h" // irq_disable
#include "command.h" // DECL_COMMAND #include "command.h" // DECL_COMMAND
#include "sched.h" // struct timer #include "sched.h" // struct timer
#include "stepper.h" // stepper_stop #include "stepper.h" // stepper_stop
@ -73,11 +73,11 @@ DECL_COMMAND(command_end_stop_home,
static void static void
end_stop_report(uint8_t oid, struct end_stop *e) end_stop_report(uint8_t oid, struct end_stop *e)
{ {
uint8_t flag = irq_save(); irq_disable();
uint32_t position = stepper_get_position(e->stepper); uint32_t position = stepper_get_position(e->stepper);
uint8_t eflags = e->flags; uint8_t eflags = e->flags;
e->flags &= ~ESF_REPORT; e->flags &= ~ESF_REPORT;
irq_restore(flag); irq_enable();
sendf("end_stop_state oid=%c homing=%c pin=%c pos=%i" sendf("end_stop_state oid=%c homing=%c pin=%c pos=%i"
, oid, !!(eflags & ESF_HOMING), gpio_in_read(e->pin) , oid, !!(eflags & ESF_HOMING), gpio_in_read(e->pin)

View File

@ -6,7 +6,7 @@
#include "basecmd.h" // alloc_oid #include "basecmd.h" // alloc_oid
#include "board/gpio.h" // struct gpio_out #include "board/gpio.h" // struct gpio_out
#include "board/irq.h" // irq_save #include "board/irq.h" // irq_disable
#include "command.h" // DECL_COMMAND #include "command.h" // DECL_COMMAND
#include "sched.h" // sched_timer #include "sched.h" // sched_timer
@ -188,7 +188,7 @@ command_schedule_soft_pwm_out(uint32_t *args)
if (s->max_duration) if (s->max_duration)
next_flags |= SPF_NEXT_CHECK_END; next_flags |= SPF_NEXT_CHECK_END;
} }
uint8_t flag = irq_save(); irq_disable();
if (s->flags & SPF_CHECK_END && sched_is_before(s->end_time, time)) if (s->flags & SPF_CHECK_END && sched_is_before(s->end_time, time))
shutdown("next soft pwm extends existing pwm"); shutdown("next soft pwm extends existing pwm");
s->end_time = time; s->end_time = time;
@ -204,7 +204,7 @@ command_schedule_soft_pwm_out(uint32_t *args)
s->timer.func = soft_pwm_load_event; s->timer.func = soft_pwm_load_event;
sched_timer(&s->timer); sched_timer(&s->timer);
} }
irq_restore(flag); irq_enable();
} }
DECL_COMMAND(command_schedule_soft_pwm_out, DECL_COMMAND(command_schedule_soft_pwm_out,
"schedule_soft_pwm_out oid=%c clock=%u value=%c"); "schedule_soft_pwm_out oid=%c clock=%u value=%c");

View File

@ -8,7 +8,7 @@
#include "autoconf.h" // CONFIG_* #include "autoconf.h" // CONFIG_*
#include "basecmd.h" // alloc_oid #include "basecmd.h" // alloc_oid
#include "board/gpio.h" // gpio_out_write #include "board/gpio.h" // gpio_out_write
#include "board/irq.h" // irq_save #include "board/irq.h" // irq_disable
#include "command.h" // DECL_COMMAND #include "command.h" // DECL_COMMAND
#include "sched.h" // struct timer #include "sched.h" // struct timer
#include "stepper.h" // command_config_stepper #include "stepper.h" // command_config_stepper
@ -113,7 +113,7 @@ command_queue_step(uint32_t *args)
m->next = NULL; m->next = NULL;
m->flags = 0; m->flags = 0;
uint8_t flag = irq_save(); irq_disable();
if (!!(s->flags & SF_LAST_DIR) != !!(s->flags & SF_NEXT_DIR)) { if (!!(s->flags & SF_LAST_DIR) != !!(s->flags & SF_NEXT_DIR)) {
s->flags ^= SF_LAST_DIR; s->flags ^= SF_LAST_DIR;
m->flags |= MF_DIR; m->flags |= MF_DIR;
@ -129,7 +129,7 @@ command_queue_step(uint32_t *args)
stepper_load_next(s); stepper_load_next(s);
sched_timer(&s->time); sched_timer(&s->time);
} }
irq_restore(flag); irq_enable();
} }
DECL_COMMAND(command_queue_step, DECL_COMMAND(command_queue_step,
"queue_step oid=%c interval=%u count=%hu add=%hi"); "queue_step oid=%c interval=%u count=%hu add=%hi");