Added flushing test

This commit is contained in:
BlackMark 2019-08-03 18:46:23 +02:00
parent 2ba032c103
commit 823921dcd8
2 changed files with 27 additions and 16 deletions

View File

@ -11,13 +11,12 @@
void newUartUsage()
{
using namespace uart;
Uart<Hardware1<Mode::ASYNCHRONOUS, Config<>, Driven::INTERRUPT>> serial1;
Uart<Hardware1<Mode::ASYNCHRONOUS, Config<115200>, Driven::INTERRUPT>> serial1;
serial1.init();
sei();
serial1 << F("Hello World from RAM. ") << F("Hello World from flash\r\n");
serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
while (true) {
while (false) {
uint8_t received = 0;
while (!serial1.peek())
@ -36,15 +35,15 @@ void newUartUsage()
}
}
_delay_ms(1000);
serial1.flushTx();
}
void newUartUsage2()
{
using namespace uart;
using config = Config<9600, DataBits::EIGHT, Parity::NONE, StopBits::ONE>;
using uart0 = Hardware0<Mode::ASYNCHRONOUS, config, Driven::BLOCKING>;
using config = Config<115200, DataBits::EIGHT, Parity::NONE, StopBits::ONE>;
using uart0 = Hardware0<Mode::ASYNCHRONOUS, config, Driven::INTERRUPT>;
Uart<uart0> serial;
serial.init();
@ -57,9 +56,8 @@ void newUartUsage2()
void newUartStreamOverloads()
{
using namespace uart;
Uart1<Config<115200>> serial;
Uart<Hardware1<Mode::ASYNCHRONOUS, Config<115200>, Driven::BLOCKING>> serial;
serial.init();
sei();
bool bVal = true;
char chVal = 'c';
@ -108,7 +106,7 @@ void newUartStreamOverloads()
serial.txNumber<decltype(number), 16>(number);
serial << F("\r\n");
_delay_ms(1000);
serial.flushTx();
}
/*
@ -189,7 +187,7 @@ void spiTest()
*/
static inline void initUart(const uint32_t baudRate)
{
UBRR1 = static_cast<uint16_t>((F_CPU / (16 * baudRate)) - 1);
UBRR1 = static_cast<uint16_t>((F_CPU + 8 * baudRate) / (16 * baudRate) - 1);
UCSR1C = (1 << UCSZ11) | (1 << UCSZ10);
UCSR1B = (1 << RXEN1) | (1 << TXEN1);
}
@ -216,24 +214,37 @@ static inline void txString(const detail::FlashString *str)
txUart(ch);
}
static inline void flushTx()
{
while (!(UCSR1A & (1 << UDRE1)))
;
while (!(UCSR1A & (1 << TXC1)))
;
UCSR1A |= (1 << TXC1);
}
void optimalUartTest()
{
auto ramString = "Hello World from RAM. ";
auto flashString = F("Hello World from flash\r\n");
initUart(9600);
initUart(115200);
txString(ramString);
txString(flashString);
_delay_ms(1000);
flushTx();
}
int main()
{
// newUartUsage();
sei();
newUartUsage();
optimalUartTest();
newUartStreamOverloads();
// optimalUartTest();
txString(F("\r\n"));
flushTx();
// spiTest();

@ -1 +1 @@
Subproject commit b6c1c3b51b44b3d7cb32e7f5f0222ecc155f8294
Subproject commit 8153696309a72ee551a37b17e4eb8ddcda62d0de