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>
This commit is contained in:
parent
9a44a20a9d
commit
ed715ec437
|
@ -141,6 +141,7 @@ console_get_output(uint8_t len)
|
||||||
void
|
void
|
||||||
console_push_output(uint8_t len)
|
console_push_output(uint8_t len)
|
||||||
{
|
{
|
||||||
|
barrier();
|
||||||
writeb(&transmit_max, readb(&transmit_max) + len);
|
writeb(&transmit_max, readb(&transmit_max) + len);
|
||||||
enable_tx_irq();
|
enable_tx_irq();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,9 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include <ctype.h> // isspace
|
|
||||||
#include <stdarg.h> // va_start
|
#include <stdarg.h> // va_start
|
||||||
#include <stdio.h> // vsnprintf
|
#include <string.h> // memcpy
|
||||||
#include <stdlib.h> // strtod
|
#include "board/io.h" // readb
|
||||||
#include <string.h> // strcasecmp
|
|
||||||
#include "board/irq.h" // irq_disable
|
|
||||||
#include "board/misc.h" // crc16_ccitt
|
#include "board/misc.h" // crc16_ccitt
|
||||||
#include "board/pgm.h" // READP
|
#include "board/pgm.h" // READP
|
||||||
#include "command.h" // output_P
|
#include "command.h" // output_P
|
||||||
|
@ -110,20 +107,17 @@ error:
|
||||||
shutdown("Command parser error");
|
shutdown("Command parser error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint8_t in_sendf;
|
||||||
|
|
||||||
// Encode a message and transmit it
|
// Encode a message and transmit it
|
||||||
void
|
void
|
||||||
_sendf(uint8_t parserid, ...)
|
_sendf(uint8_t parserid, ...)
|
||||||
{
|
{
|
||||||
static uint8_t in_sendf;
|
if (readb(&in_sendf))
|
||||||
irqstatus_t flag = irq_save();
|
|
||||||
if (in_sendf) {
|
|
||||||
// This sendf call was made from an irq handler while the main
|
// This sendf call was made from an irq handler while the main
|
||||||
// code was already in sendf - just drop this sendf request.
|
// code was already in sendf - just drop this sendf request.
|
||||||
irq_restore(flag);
|
|
||||||
return;
|
return;
|
||||||
}
|
writeb(&in_sendf, 1);
|
||||||
in_sendf = 1;
|
|
||||||
irq_restore(flag);
|
|
||||||
|
|
||||||
const struct command_encoder *cp = &command_encoders[parserid];
|
const struct command_encoder *cp = &command_encoders[parserid];
|
||||||
uint8_t max_size = READP(cp->max_size);
|
uint8_t max_size = READP(cp->max_size);
|
||||||
|
@ -194,12 +188,19 @@ _sendf(uint8_t parserid, ...)
|
||||||
*p++ = MESSAGE_SYNC;
|
*p++ = MESSAGE_SYNC;
|
||||||
console_push_output(msglen);
|
console_push_output(msglen);
|
||||||
done:
|
done:
|
||||||
in_sendf = 0;
|
writeb(&in_sendf, 0);
|
||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
shutdown("Message encode error");
|
shutdown("Message encode error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sendf_shutdown(void)
|
||||||
|
{
|
||||||
|
writeb(&in_sendf, 0);
|
||||||
|
}
|
||||||
|
DECL_SHUTDOWN(sendf_shutdown);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
* Command routing
|
* Command routing
|
||||||
|
@ -306,6 +307,5 @@ command_task(void)
|
||||||
func(args);
|
func(args);
|
||||||
}
|
}
|
||||||
console_pop_input(msglen);
|
console_pop_input(msglen);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
DECL_TASK(command_task);
|
DECL_TASK(command_task);
|
||||||
|
|
|
@ -146,6 +146,7 @@ console_get_output(uint8_t len)
|
||||||
void
|
void
|
||||||
console_push_output(uint8_t len)
|
console_push_output(uint8_t len)
|
||||||
{
|
{
|
||||||
|
barrier();
|
||||||
writeb(&transmit_max, readb(&transmit_max) + len);
|
writeb(&transmit_max, readb(&transmit_max) + len);
|
||||||
enable_tx_irq();
|
enable_tx_irq();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue