From fc124c14d41a7226575fcc22abf7b1cb851deab4 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Mon, 27 Jul 2015 13:01:43 +0200 Subject: [PATCH] serial-arm.c: allow sending arbitrarily long messages. On ARM we use only the 16 byte hardware buffer for sending and receiving over the serial line, which is often too short for debugging messages. This implementation works fine and still neither blocks nor introduces delays for short messages. Costs 72 bytes binary size, mostly because it's the first usage of delay_us(): SIZES ARM... lpc1114 FLASH : 1656 bytes 6% RAM : 136 bytes 4% EEPROM : 0 bytes 0% --- serial-arm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/serial-arm.c b/serial-arm.c index d0e72da..d4758d2 100644 --- a/serial-arm.c +++ b/serial-arm.c @@ -15,6 +15,7 @@ #include "arduino.h" #include "mbed-LPC11xx.h" +#include "delay.h" #ifdef XONXOFF #error XON/XOFF protocol not yet implemented for ARM. \ @@ -161,9 +162,15 @@ uint8_t serial_popchar(void) { /** Send one character. - If the queue is full, too bad. Do NOT block. + If the queue is full, we wait as long as sending a character takes + (87 microseconds at 115200 baud) and send then blindly. This way we can + send arbitrarily long messages without slowing down short messages or even + blocking. */ void serial_writechar(uint8_t data) { + if ( ! (LPC_UART->LSR & (0x01 << 5))) // Queue full? + delay_us((1000000 / BAUD * 10) + 1); + LPC_UART->THR = data; }