pru: Only sleep the pru0 if the incoming queue is fully empty

It's possible for multiple blocks to be pending on the incoming
"rpmsg" stream.  Don't sleep unless the input is confirmed to be
empty.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-09-03 20:45:47 -04:00
parent 8d0ef49e8f
commit 7b7f57e01c
1 changed files with 7 additions and 5 deletions

View File

@ -101,7 +101,7 @@ do_dispatch(char *buf, uint32_t msglen)
} }
// See if there are commands from the host ready to be processed // See if there are commands from the host ready to be processed
static void static int
check_can_read(void) check_can_read(void)
{ {
// Read data // Read data
@ -109,12 +109,12 @@ check_can_read(void)
char *p = SHARED_MEM->read_data; char *p = SHARED_MEM->read_data;
int16_t ret = pru_rpmsg_receive(&transport, &transport_dst, &dst, p, &len); int16_t ret = pru_rpmsg_receive(&transport, &transport_dst, &dst, p, &len);
if (ret) if (ret)
return; return ret == PRU_RPMSG_NO_BUF_AVAILABLE;
// Check for force shutdown request // Check for force shutdown request
if (len == 15 && p[14] == '\n' && memcmp(p, "FORCE_SHUTDOWN\n", 15) == 0) { if (len == 15 && p[14] == '\n' && memcmp(p, "FORCE_SHUTDOWN\n", 15) == 0) {
send_pru1_shutdown(); send_pru1_shutdown();
return; return 0;
} }
// Parse data into message blocks // Parse data into message blocks
@ -128,6 +128,7 @@ check_can_read(void)
p += pop_count; p += pop_count;
len -= pop_count; len -= pop_count;
} }
return 0;
} }
// Main processing loop // Main processing loop
@ -135,10 +136,11 @@ static void
process_io(void) process_io(void)
{ {
for (;;) { for (;;) {
asm("slp 1");
CT_INTC.SECR0 = (1 << KICK_PRU0_FROM_ARM_EVENT) | (1 << KICK_PRU0_EVENT); CT_INTC.SECR0 = (1 << KICK_PRU0_FROM_ARM_EVENT) | (1 << KICK_PRU0_EVENT);
check_can_send(); check_can_send();
check_can_read(); int can_sleep = check_can_read();
if (can_sleep)
asm("slp 1");
} }
} }