Compare commits

..

9 Commits

8 changed files with 74 additions and 36 deletions

3
.gitmodules vendored
View File

@@ -7,3 +7,6 @@
[submodule "uart/flash"] [submodule "uart/flash"]
path = uart/flash path = uart/flash
url = git@git.blackmark.me:avr/flash.git url = git@git.blackmark.me:avr/flash.git
[submodule "uart/util"]
path = uart/util
url = git@git.blackmark.me:avr/util.git

View File

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

Submodule uart/io updated: 986ceef65d...80de36ee7e

View File

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

View File

@@ -28,9 +28,10 @@
<ResetRule>0</ResetRule> <ResetRule>0</ResetRule>
<eraseonlaunchrule>0</eraseonlaunchrule> <eraseonlaunchrule>0</eraseonlaunchrule>
<EraseKey /> <EraseKey />
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool> <avrtool>
</avrtool>
<avrtoolserialnumber>J41800099437</avrtoolserialnumber> <avrtoolserialnumber>J41800099437</avrtoolserialnumber>
<avrdeviceexpectedsignature>0x1E9705</avrdeviceexpectedsignature> <avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
<com_atmel_avrdbg_tool_jtagicemkii> <com_atmel_avrdbg_tool_jtagicemkii>
<ToolOptions> <ToolOptions>
<InterfaceProperties> <InterfaceProperties>
@@ -43,7 +44,7 @@
<ToolName>JTAGICE mkII</ToolName> <ToolName>JTAGICE mkII</ToolName>
</com_atmel_avrdbg_tool_jtagicemkii> </com_atmel_avrdbg_tool_jtagicemkii>
<avrtoolinterface>ISP</avrtoolinterface> <avrtoolinterface>ISP</avrtoolinterface>
<avrtoolinterfaceclock>5000000</avrtoolinterfaceclock> <avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
<AAFDebugger> <AAFDebugger>
<AAFDebugFiles> <AAFDebugFiles>
<DebugFile> <DebugFile>
@@ -87,7 +88,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<ToolchainSettings> <ToolchainSettings>
<AvrGccCpp> <AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega1284p"</avrgcc.common.Device> <avrgcc.common.Device>-mmcu=atmega1284p</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches> <avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex> <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss> <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
@@ -145,7 +146,7 @@
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<ToolchainSettings> <ToolchainSettings>
<AvrGccCpp> <AvrGccCpp>
<avrgcc.common.Device>-mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega1284p"</avrgcc.common.Device> <avrgcc.common.Device>-mmcu=atmega1284p</avrgcc.common.Device>
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches> <avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex> <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss> <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
@@ -233,13 +234,20 @@
<Compile Include="uart\uart.hpp"> <Compile Include="uart\uart.hpp">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
<Compile Include="uart\utils.hpp"> <Compile Include="util\func.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="util\type.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="util\util.hpp">
<SubType>compile</SubType> <SubType>compile</SubType>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="io" /> <Folder Include="io" />
<Folder Include="flash" /> <Folder Include="flash" />
<Folder Include="util" />
<Folder Include="uart" /> <Folder Include="uart" />
</ItemGroup> </ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" /> <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />

1
uart/util Submodule

Submodule uart/util added at 81b3ae244c