From ca9756413f2793279b5ba1c1ecf274ce734b2087 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Fri, 26 May 2017 08:34:31 -0400 Subject: [PATCH] sched: Allow shutdown_reason to be uint8 Store the shutdown_reason code in an 8-bit integer - this produces better code on AVR. Signed-off-by: Kevin O'Connor --- src/basecmd.c | 1 + src/command.c | 2 +- src/sched.c | 21 +++++++++++---------- src/sched.h | 9 ++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/basecmd.c b/src/basecmd.c index 840bbee1..600b8106 100644 --- a/src/basecmd.c +++ b/src/basecmd.c @@ -7,6 +7,7 @@ #include "basecmd.h" // oid_lookup #include "board/irq.h" // irq_save #include "board/misc.h" // alloc_maxsize +#include "board/pgm.h" // READP #include "command.h" // DECL_COMMAND #include "sched.h" // sched_clear_shutdown diff --git a/src/command.c b/src/command.c index f96cee62..522b0223 100644 --- a/src/command.c +++ b/src/command.c @@ -72,7 +72,7 @@ static char * parsef(char *p, char *maxend, const struct command_parser *cp, uint32_t *args) { if (sched_is_shutdown() && !(READP(cp->flags) & HF_IN_SHUTDOWN)) { - sendf("is_shutdown static_string_id=%hu", sched_shutdown_reason()); + sched_report_shutdown(); return NULL; } uint8_t num_params = READP(cp->num_params); diff --git a/src/sched.c b/src/sched.c index ed23df26..f82b0060 100644 --- a/src/sched.c +++ b/src/sched.c @@ -8,6 +8,7 @@ #include "autoconf.h" // CONFIG_* #include "board/irq.h" // irq_save #include "board/misc.h" // timer_from_us +#include "board/pgm.h" // READP #include "command.h" // shutdown #include "sched.h" // sched_check_periodic #include "stepper.h" // stepper_event @@ -181,8 +182,7 @@ DECL_SHUTDOWN(sched_timer_shutdown); * Shutdown processing ****************************************************************/ -static uint16_t shutdown_reason; -static uint8_t shutdown_status; +static uint_fast8_t shutdown_status, shutdown_reason; // Return true if the machine is in an emergency stop state uint8_t @@ -191,12 +191,6 @@ sched_is_shutdown(void) return !!shutdown_status; } -uint16_t -sched_shutdown_reason(void) -{ - return shutdown_reason; -} - // Transition out of shutdown state void sched_clear_shutdown(void) @@ -226,9 +220,16 @@ run_shutdown(void) sendf("shutdown clock=%u static_string_id=%hu", cur, shutdown_reason); } +// Report the last shutdown reason code +void +sched_report_shutdown(void) +{ + sendf("is_shutdown static_string_id=%hu", shutdown_reason); +} + // Shutdown the machine if not already in the process of shutting down void -sched_try_shutdown(unsigned int reason) +sched_try_shutdown(uint_fast8_t reason) { if (shutdown_status != 2) sched_shutdown(reason); @@ -238,7 +239,7 @@ static jmp_buf shutdown_jmp; // Force the machine to immediately run the shutdown handlers void -sched_shutdown(unsigned int reason) +sched_shutdown(uint_fast8_t reason) { irq_disable(); if (!shutdown_status) diff --git a/src/sched.h b/src/sched.h index d2d3471e..9d6411d0 100644 --- a/src/sched.h +++ b/src/sched.h @@ -1,8 +1,7 @@ #ifndef __SCHED_H #define __SCHED_H -#include -#include "board/pgm.h" // PSTR +#include // uint32_t #include "compiler.h" // __section // Declare an init function (called at firmware startup) @@ -27,10 +26,10 @@ void sched_add_timer(struct timer*); void sched_del_timer(struct timer *del); unsigned int sched_timer_dispatch(void); uint8_t sched_is_shutdown(void); -uint16_t sched_shutdown_reason(void); void sched_clear_shutdown(void); -void sched_try_shutdown(unsigned int reason); -void sched_shutdown(unsigned int reason) __noreturn; +void sched_try_shutdown(uint_fast8_t reason); +void sched_shutdown(uint_fast8_t reason) __noreturn; +void sched_report_shutdown(void); void sched_main(void); // Compiler glue for DECL_X macros above.