diff --git a/ion/include/ion/console.h b/ion/include/ion/console.h index 1e5092862..ddfc0deef 100644 --- a/ion/include/ion/console.h +++ b/ion/include/ion/console.h @@ -10,6 +10,7 @@ char readChar(); // The lines are NULL-terminated void writeLine(const char * line); void readLine(char * line, int maxLineLength); +bool transmissionDone(); } } diff --git a/ion/src/device/shared/drivers/console.cpp b/ion/src/device/shared/drivers/console.cpp index 97ce27331..3c83e0ea2 100644 --- a/ion/src/device/shared/drivers/console.cpp +++ b/ion/src/device/shared/drivers/console.cpp @@ -18,9 +18,14 @@ char readChar() { } void writeChar(char c) { + Config::Port.TDR()->set(c); + // Wait until the write is done while (Config::Port.SR()->getTXE() == 0) { } - Config::Port.TDR()->set(c); +} + +bool transmissionDone() { + return Config::Port.SR()->getTC() == 1; } } diff --git a/ion/src/device/shared/regs/usart.h b/ion/src/device/shared/regs/usart.h index 58b5a35cc..1501716e0 100644 --- a/ion/src/device/shared/regs/usart.h +++ b/ion/src/device/shared/regs/usart.h @@ -13,6 +13,7 @@ public: class SR : Register32 { public: REGS_BOOL_FIELD(RXNE, 5); + REGS_BOOL_FIELD(TC, 6); REGS_BOOL_FIELD(TXE, 7); }; diff --git a/ion/src/shared/console_line.cpp b/ion/src/shared/console_line.cpp index 7574ee7f3..7aa81d016 100644 --- a/ion/src/shared/console_line.cpp +++ b/ion/src/shared/console_line.cpp @@ -5,6 +5,7 @@ namespace Console { char readChar(); void writeChar(char c); +bool transmissionDone(); void writeLine(const char * line) { while (*line != 0) { @@ -12,6 +13,8 @@ void writeLine(const char * line) { } writeChar('\r'); writeChar('\n'); + while (!transmissionDone()) { + } } void readLine(char * line, int maxLineLength) { diff --git a/ion/src/shared/console_stdio.cpp b/ion/src/shared/console_stdio.cpp index fda0fa3ab..e77659f71 100644 --- a/ion/src/shared/console_stdio.cpp +++ b/ion/src/shared/console_stdio.cpp @@ -13,5 +13,10 @@ void writeChar(char c) { fflush(stdout); } +bool transmissionDone() { + // Always true because we flush after each writeChar + return true; +} + } }