aboutsummaryrefslogtreecommitdiffstats
path: root/src/pru
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2018-05-24 12:49:23 -0400
committerKevin O'Connor <kevin@koconnor.net>2018-05-28 10:43:39 -0400
commitcb4e165071ad56c4cf881f5221f02eeefde5de53 (patch)
tree0d88bd5e3ebaf53526cda428eebf3d7ad61876bf /src/pru
parent2a55741ea883e6a9958a64c3463b4c3d60c21b63 (diff)
downloadkutter-cb4e165071ad56c4cf881f5221f02eeefde5de53.tar.gz
kutter-cb4e165071ad56c4cf881f5221f02eeefde5de53.tar.xz
kutter-cb4e165071ad56c4cf881f5221f02eeefde5de53.zip
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>
Diffstat (limited to 'src/pru')
-rw-r--r--src/pru/internal.h4
-rw-r--r--src/pru/pru0.c20
2 files changed, 12 insertions, 12 deletions
diff --git a/src/pru/internal.h b/src/pru/internal.h
index abbc9e40..dc125cd3 100644
--- a/src/pru/internal.h
+++ b/src/pru/internal.h
@@ -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
diff --git a/src/pru/pru0.c b/src/pru/pru0.c
index 58f15175..2a136e9e 100644
--- a/src/pru/pru0.c
+++ b/src/pru/pru0.c
@@ -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));
}