From cb4e165071ad56c4cf881f5221f02eeefde5de53 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Thu, 24 May 2018 12:49:23 -0400 Subject: command: Prefer uint8_t* for buffers; prefer uint8_fast_t for lengths Prefer using 'uint8_t' buffers as it is too easy to run into C sign extension problems with 'char' buffers. Prefer using 'uint_fast8_t' for buffer lengths as gcc does a better job compiling them on 32bit mcus. Signed-off-by: Kevin O'Connor --- src/generic/serial_irq.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/generic/serial_irq.c') diff --git a/src/generic/serial_irq.c b/src/generic/serial_irq.c index 79eaad7f..7c7842ea 100644 --- a/src/generic/serial_irq.c +++ b/src/generic/serial_irq.c @@ -14,10 +14,8 @@ #include "sched.h" // sched_wake_tasks #include "serial_irq.h" // serial_enable_tx_irq -static char receive_buf[192]; -static uint8_t receive_pos; -static char transmit_buf[96]; -static uint8_t transmit_pos, transmit_max; +static uint8_t receive_buf[192], receive_pos; +static uint8_t transmit_buf[96], transmit_pos, transmit_max; DECL_CONSTANT(SERIAL_BAUD, CONFIG_SERIAL_BAUD); @@ -73,9 +71,8 @@ console_pop_input(uint_fast8_t len) void console_task(void) { - uint_fast8_t rpos = readb(&receive_pos); - uint8_t pop_count; - int8_t ret = command_find_block(receive_buf, rpos, &pop_count); + uint_fast8_t rpos = readb(&receive_pos), pop_count; + int_fast8_t ret = command_find_block(receive_buf, rpos, &pop_count); if (ret > 0) command_dispatch(receive_buf, pop_count); if (ret) @@ -110,8 +107,8 @@ console_sendf(const struct command_encoder *ce, va_list args) } // Generate message - char *buf = &transmit_buf[tmax]; - uint8_t msglen = command_encodef(buf, ce, args); + uint8_t *buf = &transmit_buf[tmax]; + uint_fast8_t msglen = command_encodef(buf, ce, args); command_add_frame(buf, msglen); // Start message transmit -- cgit v1.2.3-70-g09d2