mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-20 09:17:23 +01:00
[ion] Fix USART communication: wait for transmission done in writeLine
This commit is contained in:
@@ -10,6 +10,7 @@ char readChar();
|
||||
// The lines are NULL-terminated
|
||||
void writeLine(const char * line);
|
||||
void readLine(char * line, int maxLineLength);
|
||||
bool transmissionDone();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
class SR : Register32 {
|
||||
public:
|
||||
REGS_BOOL_FIELD(RXNE, 5);
|
||||
REGS_BOOL_FIELD(TC, 6);
|
||||
REGS_BOOL_FIELD(TXE, 7);
|
||||
};
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -13,5 +13,10 @@ void writeChar(char c) {
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
bool transmissionDone() {
|
||||
// Always true because we flush after each writeChar
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user