aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/avr/serial.c6
-rw-r--r--src/avr/usbserial.c19
-rw-r--r--src/command.c10
-rw-r--r--src/command.h4
-rw-r--r--src/pru/internal.h3
-rw-r--r--src/pru/main.c5
-rw-r--r--src/sam3x8e/serial.c6
7 files changed, 24 insertions, 29 deletions
diff --git a/src/avr/serial.c b/src/avr/serial.c
index 8b9dd14a..5fcf54d6 100644
--- a/src/avr/serial.c
+++ b/src/avr/serial.c
@@ -1,6 +1,6 @@
// AVR serial port code.
//
-// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
@@ -8,7 +8,7 @@
#include <string.h> // memmove
#include "autoconf.h" // CONFIG_SERIAL_BAUD
#include "board/io.h" // readb
-#include "board/misc.h" // console_get_input
+#include "board/misc.h" // console_sendf
#include "command.h" // DECL_CONSTANT
#include "irq.h" // irq_save
#include "pgm.h" // READP
@@ -161,7 +161,7 @@ console_sendf(const struct command_encoder *ce, va_list args)
// Generate message
char *buf = &transmit_buf[tmax];
- uint8_t msglen = command_encodef(buf, max_size, ce, args);
+ uint8_t msglen = command_encodef(buf, ce, args);
command_add_frame(buf, msglen);
// Start message transmit
diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c
index cc7bb12c..ac60e087 100644
--- a/src/avr/usbserial.c
+++ b/src/avr/usbserial.c
@@ -1,20 +1,17 @@
// Wrappers for AVR usb serial.
//
-// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
-#include <avr/interrupt.h> // USART0_RX_vect
#include <string.h> // memmove
#include "../lib/pjrc_usb_serial/usb_serial.h"
+#include "board/misc.h" // console_sendf
#include "command.h" // command_dispatch
-#include "pgm.h" // READP
#include "sched.h" // DECL_INIT
-#define USBSERIAL_BUFFER_SIZE 64
-static char receive_buf[USBSERIAL_BUFFER_SIZE];
+static char receive_buf[MESSAGE_MAX];
static uint8_t receive_pos;
-static char transmit_buf[USBSERIAL_BUFFER_SIZE];
void
usbserial_init(void)
@@ -68,13 +65,11 @@ void
console_sendf(const struct command_encoder *ce, va_list args)
{
// Generate message
- uint8_t max_size = READP(ce->max_size);
- if (max_size > sizeof(transmit_buf))
- return;
- uint8_t msglen = command_encodef(transmit_buf, max_size, ce, args);
- command_add_frame(transmit_buf, msglen);
+ static char buf[MESSAGE_MAX];
+ uint8_t msglen = command_encodef(buf, ce, args);
+ command_add_frame(buf, msglen);
// Transmit message
- usb_serial_write((void*)transmit_buf, msglen);
+ usb_serial_write((void*)buf, msglen);
usb_serial_flush_output();
}
diff --git a/src/command.c b/src/command.c
index 3e5ef4c9..8780ae8a 100644
--- a/src/command.c
+++ b/src/command.c
@@ -94,14 +94,14 @@ error:
// Encode a message
uint8_t
-command_encodef(char *buf, uint8_t buf_len
- , const struct command_encoder *ce, va_list args)
+command_encodef(char *buf, const struct command_encoder *ce, va_list args)
{
- if (buf_len <= MESSAGE_MIN)
+ uint8_t max_size = READP(ce->max_size);
+ if (max_size <= MESSAGE_MIN)
// Ack/Nak message
- return buf_len;
+ return max_size;
char *p = &buf[MESSAGE_HEADER_SIZE];
- char *maxend = &p[buf_len - MESSAGE_MIN];
+ char *maxend = &p[max_size - MESSAGE_MIN];
uint8_t num_params = READP(ce->num_params);
const uint8_t *param_types = READP(ce->param_types);
*p++ = READP(ce->msg_id);
diff --git a/src/command.h b/src/command.h
index 91d7cd80..e493c3ee 100644
--- a/src/command.h
+++ b/src/command.h
@@ -63,8 +63,8 @@ enum {
// command.c
char *command_parsef(char *p, char *maxend
, const struct command_parser *cp, uint32_t *args);
-uint8_t command_encodef(char *buf, uint8_t buf_len
- , const struct command_encoder *ce, va_list args);
+uint8_t command_encodef(char *buf, const struct command_encoder *ce
+ , va_list args);
void command_sendf(const struct command_encoder *ce, ...);
void command_add_frame(char *buf, uint8_t msglen);
int8_t command_find_block(char *buf, uint8_t buf_len, uint8_t *pop_count);
diff --git a/src/pru/internal.h b/src/pru/internal.h
index 980c1d61..abbc9e40 100644
--- a/src/pru/internal.h
+++ b/src/pru/internal.h
@@ -3,6 +3,7 @@
// Local definitions for PRU code
#include <stdint.h> // uint32_t
+#include "command.h" // MESSAGE_MAX
#define IEP_EVENT 7
#define KICK_ARM_EVENT 16
@@ -24,7 +25,7 @@
// Layout of shared memory
struct shared_response_buffer {
uint32_t count;
- char data[64];
+ char data[MESSAGE_MAX];
};
struct shared_mem {
uint32_t signal;
diff --git a/src/pru/main.c b/src/pru/main.c
index 45eb8274..6eed82e3 100644
--- a/src/pru/main.c
+++ b/src/pru/main.c
@@ -135,14 +135,13 @@ void
console_sendf(const struct command_encoder *ce, va_list args)
{
// Verify space for message
- uint32_t max_size = ce->max_size;
uint32_t send_push_pos = SHARED_MEM->send_push_pos;
struct shared_response_buffer *s = &SHARED_MEM->send_data[send_push_pos];
- if (max_size > sizeof(s->data) || readl(&s->count))
+ if (readl(&s->count))
return;
// Generate message
- uint32_t msglen = command_encodef(s->data, max_size, ce, args);
+ uint32_t msglen = command_encodef(s->data, ce, args);
// Signal PRU0 to transmit message
writel(&s->count, msglen);
diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c
index 7741d6f8..f4a65aa0 100644
--- a/src/sam3x8e/serial.c
+++ b/src/sam3x8e/serial.c
@@ -1,6 +1,6 @@
// sam3x8e serial port
//
-// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2016,2017 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
@@ -9,7 +9,7 @@
#include "board/gpio.h" // gpio_peripheral
#include "board/io.h" // readl
#include "board/irq.h" // irq_save
-#include "board/misc.h" // console_get_input
+#include "board/misc.h" // console_sendf
#include "command.h" // DECL_CONSTANT
#include "sam3x8e.h" // UART
#include "sched.h" // DECL_INIT
@@ -152,7 +152,7 @@ console_sendf(const struct command_encoder *ce, va_list args)
// Generate message
char *buf = &transmit_buf[tmax];
- uint32_t msglen = command_encodef(buf, max_size, ce, args);
+ uint32_t msglen = command_encodef(buf, ce, args);
command_add_frame(buf, msglen);
// Start message transmit