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 <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2018-05-24 12:49:23 -04:00
parent 2a55741ea8
commit cb4e165071
11 changed files with 71 additions and 78 deletions

View File

@@ -25,7 +25,7 @@
// Layout of shared memory
struct shared_response_buffer {
uint32_t count;
char data[MESSAGE_MAX];
uint8_t data[MESSAGE_MAX];
};
struct shared_mem {
uint32_t signal;
@@ -36,7 +36,7 @@ struct shared_mem {
const struct command_parser *command_index;
uint32_t command_index_size;
const struct command_parser *shutdown_handler;
char read_data[512];
uint8_t read_data[512];
};
#define SIGNAL_PRU0_WAITING 0xefefefef

View File

@@ -32,7 +32,7 @@ static uint16_t transport_dst;
#define CHAN_PORT 30
#define RPMSG_HDR_SIZE 16
static char transmit_buf[RPMSG_BUF_SIZE - RPMSG_HDR_SIZE];
static uint8_t transmit_buf[RPMSG_BUF_SIZE - RPMSG_HDR_SIZE];
static int transmit_pos;
// Transmit all pending message blocks
@@ -48,7 +48,7 @@ flush_messages(void)
// Generate a message block and queue it for transmission
static void
build_message(char *msg, int msglen)
build_message(uint8_t *msg, int msglen)
{
if (transmit_pos + msglen > sizeof(transmit_buf))
flush_messages();
@@ -105,13 +105,13 @@ send_pru1_shutdown(void)
// Dispatch all the commands in a message block
static void
do_dispatch(char *buf, uint32_t msglen)
do_dispatch(uint8_t *buf, uint32_t msglen)
{
char *p = &buf[MESSAGE_HEADER_SIZE];
char *msgend = &buf[msglen-MESSAGE_TRAILER_SIZE];
uint8_t *p = &buf[MESSAGE_HEADER_SIZE];
uint8_t *msgend = &buf[msglen-MESSAGE_TRAILER_SIZE];
while (p < msgend) {
// Parse command
uint8_t cmdid = *p++;
uint_fast8_t cmdid = *p++;
const struct command_parser *cp = &SHARED_MEM->command_index[cmdid];
if (!cmdid || cmdid >= SHARED_MEM->command_index_size
|| cp->num_args > ARRAY_SIZE(SHARED_MEM->next_command_args)) {
@@ -131,7 +131,7 @@ check_can_read(void)
{
// Read data
uint16_t dst, len;
char *p = SHARED_MEM->read_data;
uint8_t *p = SHARED_MEM->read_data;
int16_t ret = pru_rpmsg_receive(&transport, &transport_dst, &dst, p, &len);
if (ret)
return ret == PRU_RPMSG_NO_BUF_AVAILABLE;
@@ -144,8 +144,8 @@ check_can_read(void)
// Parse data into message blocks
for (;;) {
uint8_t pop_count, msglen = len > MESSAGE_MAX ? MESSAGE_MAX : len;
int8_t ret = command_find_block(p, msglen, &pop_count);
uint_fast8_t pop_count, msglen = len > MESSAGE_MAX ? MESSAGE_MAX : len;
int_fast8_t ret = command_find_block(p, msglen, &pop_count);
if (!ret)
break;
if (ret > 0)
@@ -210,7 +210,7 @@ sched_shutdown(uint_fast8_t reason)
void
console_sendf(const struct command_encoder *ce, va_list args)
{
char buf[MESSAGE_MIN];
uint8_t buf[MESSAGE_MIN];
build_message(buf, sizeof(buf));
}