diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-01-14 10:40:46 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-01-14 11:32:27 -0500 |
commit | ed715ec43770e197f639c31736e1ea9ed6202996 (patch) | |
tree | efbbbb14deb75fff47daaed178fce8ff06804ca8 | |
parent | 9a44a20a9d25f7e5d38ff943fbbd51d0f305ce3f (diff) | |
download | kutter-ed715ec43770e197f639c31736e1ea9ed6202996.tar.gz kutter-ed715ec43770e197f639c31736e1ea9ed6202996.tar.xz kutter-ed715ec43770e197f639c31736e1ea9ed6202996.zip |
command: No need to disable irqs in sendf reentrant check
As long as the code is careful when writing the in_sendf variable it
should be safe to update it without having to disable irqs.
Also, make sure in_sendf is cleared on shutdown.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | src/avr/serial.c | 1 | ||||
-rw-r--r-- | src/command.c | 28 | ||||
-rw-r--r-- | src/sam3x8e/serial.c | 1 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/avr/serial.c b/src/avr/serial.c index 6bd88598..8c0da553 100644 --- a/src/avr/serial.c +++ b/src/avr/serial.c @@ -141,6 +141,7 @@ console_get_output(uint8_t len) void console_push_output(uint8_t len) { + barrier(); writeb(&transmit_max, readb(&transmit_max) + len); enable_tx_irq(); } diff --git a/src/command.c b/src/command.c index 069dfe57..2d00aaf4 100644 --- a/src/command.c +++ b/src/command.c @@ -4,12 +4,9 @@ // // This file may be distributed under the terms of the GNU GPLv3 license. -#include <ctype.h> // isspace #include <stdarg.h> // va_start -#include <stdio.h> // vsnprintf -#include <stdlib.h> // strtod -#include <string.h> // strcasecmp -#include "board/irq.h" // irq_disable +#include <string.h> // memcpy +#include "board/io.h" // readb #include "board/misc.h" // crc16_ccitt #include "board/pgm.h" // READP #include "command.h" // output_P @@ -110,20 +107,17 @@ error: shutdown("Command parser error"); } +static uint8_t in_sendf; + // Encode a message and transmit it void _sendf(uint8_t parserid, ...) { - static uint8_t in_sendf; - irqstatus_t flag = irq_save(); - if (in_sendf) { + if (readb(&in_sendf)) // This sendf call was made from an irq handler while the main // code was already in sendf - just drop this sendf request. - irq_restore(flag); return; - } - in_sendf = 1; - irq_restore(flag); + writeb(&in_sendf, 1); const struct command_encoder *cp = &command_encoders[parserid]; uint8_t max_size = READP(cp->max_size); @@ -194,12 +188,19 @@ _sendf(uint8_t parserid, ...) *p++ = MESSAGE_SYNC; console_push_output(msglen); done: - in_sendf = 0; + writeb(&in_sendf, 0); return; error: shutdown("Message encode error"); } +static void +sendf_shutdown(void) +{ + writeb(&in_sendf, 0); +} +DECL_SHUTDOWN(sendf_shutdown); + /**************************************************************** * Command routing @@ -306,6 +307,5 @@ command_task(void) func(args); } console_pop_input(msglen); - return; } DECL_TASK(command_task); diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c index d07fc734..35a7d35c 100644 --- a/src/sam3x8e/serial.c +++ b/src/sam3x8e/serial.c @@ -146,6 +146,7 @@ console_get_output(uint8_t len) void console_push_output(uint8_t len) { + barrier(); writeb(&transmit_max, readb(&transmit_max) + len); enable_tx_irq(); } |