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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-05-26 08:34:31 -04:00
parent b9940f0e0d
commit ca9756413f
4 changed files with 17 additions and 16 deletions

View File

@ -7,6 +7,7 @@
#include "basecmd.h" // oid_lookup #include "basecmd.h" // oid_lookup
#include "board/irq.h" // irq_save #include "board/irq.h" // irq_save
#include "board/misc.h" // alloc_maxsize #include "board/misc.h" // alloc_maxsize
#include "board/pgm.h" // READP
#include "command.h" // DECL_COMMAND #include "command.h" // DECL_COMMAND
#include "sched.h" // sched_clear_shutdown #include "sched.h" // sched_clear_shutdown

View File

@ -72,7 +72,7 @@ static char *
parsef(char *p, char *maxend, const struct command_parser *cp, uint32_t *args) parsef(char *p, char *maxend, const struct command_parser *cp, uint32_t *args)
{ {
if (sched_is_shutdown() && !(READP(cp->flags) & HF_IN_SHUTDOWN)) { 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; return NULL;
} }
uint8_t num_params = READP(cp->num_params); uint8_t num_params = READP(cp->num_params);

View File

@ -8,6 +8,7 @@
#include "autoconf.h" // CONFIG_* #include "autoconf.h" // CONFIG_*
#include "board/irq.h" // irq_save #include "board/irq.h" // irq_save
#include "board/misc.h" // timer_from_us #include "board/misc.h" // timer_from_us
#include "board/pgm.h" // READP
#include "command.h" // shutdown #include "command.h" // shutdown
#include "sched.h" // sched_check_periodic #include "sched.h" // sched_check_periodic
#include "stepper.h" // stepper_event #include "stepper.h" // stepper_event
@ -181,8 +182,7 @@ DECL_SHUTDOWN(sched_timer_shutdown);
* Shutdown processing * Shutdown processing
****************************************************************/ ****************************************************************/
static uint16_t shutdown_reason; static uint_fast8_t shutdown_status, shutdown_reason;
static uint8_t shutdown_status;
// Return true if the machine is in an emergency stop state // Return true if the machine is in an emergency stop state
uint8_t uint8_t
@ -191,12 +191,6 @@ sched_is_shutdown(void)
return !!shutdown_status; return !!shutdown_status;
} }
uint16_t
sched_shutdown_reason(void)
{
return shutdown_reason;
}
// Transition out of shutdown state // Transition out of shutdown state
void void
sched_clear_shutdown(void) sched_clear_shutdown(void)
@ -226,9 +220,16 @@ run_shutdown(void)
sendf("shutdown clock=%u static_string_id=%hu", cur, shutdown_reason); 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 // Shutdown the machine if not already in the process of shutting down
void void
sched_try_shutdown(unsigned int reason) sched_try_shutdown(uint_fast8_t reason)
{ {
if (shutdown_status != 2) if (shutdown_status != 2)
sched_shutdown(reason); sched_shutdown(reason);
@ -238,7 +239,7 @@ static jmp_buf shutdown_jmp;
// Force the machine to immediately run the shutdown handlers // Force the machine to immediately run the shutdown handlers
void void
sched_shutdown(unsigned int reason) sched_shutdown(uint_fast8_t reason)
{ {
irq_disable(); irq_disable();
if (!shutdown_status) if (!shutdown_status)

View File

@ -1,8 +1,7 @@
#ifndef __SCHED_H #ifndef __SCHED_H
#define __SCHED_H #define __SCHED_H
#include <stdint.h> #include <stdint.h> // uint32_t
#include "board/pgm.h" // PSTR
#include "compiler.h" // __section #include "compiler.h" // __section
// Declare an init function (called at firmware startup) // 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); void sched_del_timer(struct timer *del);
unsigned int sched_timer_dispatch(void); unsigned int sched_timer_dispatch(void);
uint8_t sched_is_shutdown(void); uint8_t sched_is_shutdown(void);
uint16_t sched_shutdown_reason(void);
void sched_clear_shutdown(void); void sched_clear_shutdown(void);
void sched_try_shutdown(unsigned int reason); void sched_try_shutdown(uint_fast8_t reason);
void sched_shutdown(unsigned int reason) __noreturn; void sched_shutdown(uint_fast8_t reason) __noreturn;
void sched_report_shutdown(void);
void sched_main(void); void sched_main(void);
// Compiler glue for DECL_X macros above. // Compiler glue for DECL_X macros above.