[ion] Fix USART communication: wait for transmission done in writeLine

This commit is contained in:
Léa Saviot
2019-03-22 16:36:25 +01:00
parent a656b80089
commit b413da0d91
5 changed files with 16 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ char readChar();
// The lines are NULL-terminated
void writeLine(const char * line);
void readLine(char * line, int maxLineLength);
bool transmissionDone();
}
}

View File

@@ -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;
}
}

View File

@@ -13,6 +13,7 @@ public:
class SR : Register32 {
public:
REGS_BOOL_FIELD(RXNE, 5);
REGS_BOOL_FIELD(TC, 6);
REGS_BOOL_FIELD(TXE, 7);
};

View File

@@ -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) {

View File

@@ -13,5 +13,10 @@ void writeChar(char c) {
fflush(stdout);
}
bool transmissionDone() {
// Always true because we flush after each writeChar
return true;
}
}
}