Add double speed test and change to atmega328p

This commit is contained in:
BlackMark 2020-04-12 23:59:18 +02:00
parent 414ebbebff
commit 24d17688c0
5 changed files with 52 additions and 41 deletions

View File

@ -1,4 +1,4 @@
#pragma once
#define F_CPU 20000000
#define F_CPU 16'000'000
#include <util/delay.h>

View File

@ -8,44 +8,63 @@
#include "io/io.hpp"
#include "uart/uart.hpp"
#define UART1_INT_VECTORS
#include "uart/hardware1.hpp"
#define UART0_INT_VECTORS
#include "uart/hardware0.hpp"
void doubleSpeedTest()
{
using namespace uart;
Uart<Hardware0<Config<115200>, Driven::INTERRUPT, Mode::ASYNCHRONOUS>> serial;
serial.init();
uint8_t counter = 100;
uint8_t data;
while (counter) {
if (serial.rxByte(data)) {
serial.txByte(data);
--counter;
}
}
serial.flushTx();
}
void newUartUsage()
{
using namespace uart;
Uart<Hardware1<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial1;
serial1.init();
Uart<Hardware0<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
serial.init();
serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
serial << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
while (false) {
uint8_t received = 0;
while (!serial1.peek())
while (!serial.peek())
;
{
serial1 << F("Peeked: ");
serial1.txByte(received);
serial1 << F("\r\n");
serial << F("Peeked: ");
serial.txByte(received);
serial << F("\r\n");
}
if (serial1.rxByte(received)) {
serial1 << F("Received: ");
serial1.txByte(received);
serial1 << F("\r\n");
if (serial.rxByte(received)) {
serial << F("Received: ");
serial.txByte(received);
serial << F("\r\n");
}
}
serial1.flushTx();
serial.flushTx();
}
void newUartUsage2()
{
using namespace uart;
Uart<Hardware1<Config<115200>, Driven::INTERRUPT>> serial1;
Uart<Hardware0<Config<115200>, Driven::INTERRUPT>> serial1;
auto ramString = "Hello World from RAM. ";
auto flashString = F("Hello World from flash\r\n");
@ -61,7 +80,7 @@ void newUartUsage2()
void newUartStreamOverloads()
{
using namespace uart;
Uart<Hardware1<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
Uart<Hardware0<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
serial.init();
bool bVal = true;
@ -191,17 +210,18 @@ void spiTest()
static inline void initUart(const uint32_t baudRate)
{
UBRR1 = static_cast<uint16_t>((F_CPU + 8 * baudRate) / (16 * baudRate) - 1);
UCSR1C = (1 << UCSZ11) | (1 << UCSZ10);
UCSR1B = (1 << RXEN1) | (1 << TXEN1);
UBRR0 = static_cast<uint16_t>((F_CPU + 8 * baudRate) / (16 * baudRate) - 1);
UCSR0A = 0;
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
}
static inline void txUart(uint8_t byte)
{
while (!(UCSR1A & (1 << UDRE1)))
while (!(UCSR0A & (1 << UDRE0)))
;
UDR1 = byte;
UDR0 = byte;
}
static inline void txString(const char *str)
@ -220,11 +240,11 @@ static inline void txString(const detail::FlashString *str)
static inline void flushTx()
{
while (!(UCSR1A & (1 << UDRE1)))
while (!(UCSR0A & (1 << UDRE0)))
;
while (!(UCSR1A & (1 << TXC1)))
while (!(UCSR0A & (1 << TXC0)))
;
UCSR1A |= (1 << TXC1);
UCSR0A |= (1 << TXC0);
}
void optimalUartTest()
@ -244,6 +264,8 @@ int main()
{
sei();
doubleSpeedTest();
newUartUsage2();
optimalUartTest();
newUartStreamOverloads();

@ -1 +1 @@
Subproject commit 068a179cef0d1eebe17771270fa82cc3d693c9a5
Subproject commit ce31ef017f738baaca6f0cbf99dac9d59b5e6811

@ -1 +1 @@
Subproject commit 41b9ef74f9138e6eb8559a961d951049db1d7c67
Subproject commit 04b6782ec457fb22759a097892b863a3ec6eaab4

View File

@ -5,7 +5,7 @@
<ProjectVersion>7.0</ProjectVersion>
<ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
<avrdevice>ATmega1284P</avrdevice>
<avrdevice>ATmega328P</avrdevice>
<avrdeviceseries>none</avrdeviceseries>
<OutputType>Executable</OutputType>
<Language>CPP</Language>
@ -30,7 +30,7 @@
<EraseKey />
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
<avrtoolserialnumber>J41800099437</avrtoolserialnumber>
<avrdeviceexpectedsignature>0x1E9705</avrdeviceexpectedsignature>
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
<com_atmel_avrdbg_tool_jtagicemkii>
<ToolOptions>
<InterfaceProperties>
@ -43,20 +43,9 @@
<ToolName>JTAGICE mkII</ToolName>
</com_atmel_avrdbg_tool_jtagicemkii>
<avrtoolinterface>ISP</avrtoolinterface>
<avrtoolinterfaceclock>5000000</avrtoolinterfaceclock>
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
<AAFDebugger>
<AAFDebugFiles>
<DebugFile>
<path>\Debug\uart.lss</path>
<AAFSetting>
<Label>Lss Files</Label>
<Extention>.lss</Extention>
<Regex>^\s*(?&lt;address&gt;[a-f0-9]*):\s*.*$</Regex>
<DebugEnabled>true</DebugEnabled>
<RegexGroups>address</RegexGroups>
<DebuggerExpression>$pc</DebuggerExpression>
</AAFSetting>
</DebugFile>
</AAFDebugFiles>
</AAFDebugger>
<AsfFrameworkConfig>