Compare commits
43 Commits
fe9e67036e
...
example
| Author | SHA1 | Date | |
|---|---|---|---|
| d1452b6dc0 | |||
| e760cf541c | |||
| 6b90c1779f | |||
| 8bb1bd7397 | |||
| 24d17688c0 | |||
| 414ebbebff | |||
| 717a69c231 | |||
| f0abf335e5 | |||
| 991a67bd86 | |||
| 4d31f20714 | |||
| 85e6510cd5 | |||
| 2eefa7fd7f | |||
| dd3e69daa3 | |||
| cc5b375b44 | |||
| fcdce7cc1d | |||
| 0354bc3020 | |||
| c74f1afcac | |||
| 823921dcd8 | |||
| 2ba032c103 | |||
| dafb7ee059 | |||
| 9b4b0cac67 | |||
| 2d54e4ea45 | |||
| d32e2a13e6 | |||
| 5047b661af | |||
| 408ab83afb | |||
| e891e1019f | |||
| 4a25398c1e | |||
| 48e312d076 | |||
| 59a83a304b | |||
| 011776a709 | |||
| d952794c55 | |||
| 9809b34bca | |||
| e71d103602 | |||
| d8aee7498d | |||
| 5cd2b963fa | |||
| ab1d55ee6f | |||
| b66c33506c | |||
| 2cb62d4fac | |||
| 98bd0e1238 | |||
| f1de6c3701 | |||
| 0ec71af448 | |||
| 8fa18f8e88 | |||
| 5ba8cc4ec3 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -2,4 +2,10 @@
|
|||||||
Release
|
Release
|
||||||
Debug
|
Debug
|
||||||
*.componentinfo.xml
|
*.componentinfo.xml
|
||||||
avrdude.bat
|
*.elf
|
||||||
|
*.o
|
||||||
|
*.hex
|
||||||
|
*.srec
|
||||||
|
*.eeprom
|
||||||
|
*.lss
|
||||||
|
*.map
|
||||||
|
|||||||
12
.gitmodules
vendored
Normal file
12
.gitmodules
vendored
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[submodule "uart/io"]
|
||||||
|
path = uart/io
|
||||||
|
url = git@git.blackmark.me:avr/io.git
|
||||||
|
[submodule "uart/uart"]
|
||||||
|
path = uart/uart
|
||||||
|
url = git@git.blackmark.me:avr/uart.git
|
||||||
|
[submodule "uart/flash"]
|
||||||
|
path = uart/flash
|
||||||
|
url = git@git.blackmark.me:avr/flash.git
|
||||||
|
[submodule "uart/util"]
|
||||||
|
path = uart/util
|
||||||
|
url = git@git.blackmark.me:avr/util.git
|
||||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 BlackMark
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is furnished
|
||||||
|
to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice (including the next
|
||||||
|
paragraph) shall be included in all copies or substantial portions of the
|
||||||
|
Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
|
||||||
|
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
|
||||||
|
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
50
config.hpp
50
config.hpp
@@ -1,50 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
|
|
||||||
enum class DataBits {
|
|
||||||
FIVE,
|
|
||||||
SIX,
|
|
||||||
SEVEN,
|
|
||||||
EIGHT,
|
|
||||||
NINE,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class StopBits {
|
|
||||||
ONE,
|
|
||||||
TWO,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Parity {
|
|
||||||
NONE,
|
|
||||||
ODD,
|
|
||||||
EVEN,
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <DataBits dataBits>
|
|
||||||
struct choose_data_type {
|
|
||||||
using type = uint8_t;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct choose_data_type<DataBits::NINE> {
|
|
||||||
using type = uint16_t;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <uint32_t baudRate = 9600, DataBits dataBits = DataBits::EIGHT, Parity parity = Parity::NONE,
|
|
||||||
StopBits stopBits = StopBits::ONE>
|
|
||||||
struct Config {
|
|
||||||
static constexpr auto BAUD_RATE = baudRate;
|
|
||||||
static constexpr auto DATA_BITS = dataBits;
|
|
||||||
static constexpr auto PARITY = parity;
|
|
||||||
static constexpr auto STOP_BITS = stopBits;
|
|
||||||
using data_t = typename detail::choose_data_type<DATA_BITS>::type;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace uart
|
|
||||||
217
hardware.hpp
217
hardware.hpp
@@ -1,217 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "../clock.h"
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define FORCE_INLINE __attribute__((always_inline))
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
|
|
||||||
enum class Mode {
|
|
||||||
ASYNCHRONOUS,
|
|
||||||
ASYNCHRONOUS_2X,
|
|
||||||
SYNCHRONOUS_MASTER,
|
|
||||||
SYNCHRONOUS_SLAVE,
|
|
||||||
SPI,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Driven {
|
|
||||||
INTERRUPT,
|
|
||||||
BLOCKING,
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <class Registers, typename CtrlFlagsA, typename CtrlFlagsB, typename CtrlFlagsC, class cfg, Mode mode,
|
|
||||||
Driven driven>
|
|
||||||
class Hardware {
|
|
||||||
public:
|
|
||||||
static void init() FORCE_INLINE
|
|
||||||
{
|
|
||||||
constexpr auto baudVal = calcBaud();
|
|
||||||
|
|
||||||
*Registers::BAUD_REG_H = static_cast<uint8_t>(baudVal >> 8);
|
|
||||||
*Registers::BAUD_REG_L = static_cast<uint8_t>(baudVal);
|
|
||||||
|
|
||||||
constexpr auto dataBitsVal = calcDataBits();
|
|
||||||
constexpr auto parityVal = calcParity();
|
|
||||||
constexpr auto stopBitsVal = calcStopBits();
|
|
||||||
constexpr auto modeVal = calcMode();
|
|
||||||
constexpr auto enableRx = calcRxState<true>();
|
|
||||||
constexpr auto enableTx = calcTxState<true>();
|
|
||||||
constexpr auto interruptVal = calcInterrupt();
|
|
||||||
|
|
||||||
constexpr uint8_t controlRegB = dataBitsVal.regBVal | enableRx | enableTx | interruptVal;
|
|
||||||
constexpr uint8_t controlRegC = dataBitsVal.regCVal | parityVal | stopBitsVal | modeVal;
|
|
||||||
|
|
||||||
*Registers::CTRL_STAT_REG_B = controlRegB;
|
|
||||||
*Registers::CTRL_STAT_REG_C = controlRegC;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rxByteBlocking(typename cfg::data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::RECEIVE_COMPLETE)) {
|
|
||||||
byte = *Registers::IO_REG;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static typename cfg::data_t rxByteInterrupt() FORCE_INLINE
|
|
||||||
{
|
|
||||||
return *Registers::IO_REG;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByteBlocking(const typename cfg::data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
while (!(*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::DATA_REG_EMPTY)))
|
|
||||||
;
|
|
||||||
|
|
||||||
*Registers::IO_REG = byte;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByteInterrupt(volatile const typename cfg::data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
*Registers::IO_REG = byte;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peekBlocking() FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (*Registers::CTRL_STAT_REG_A & (1 << CtrlFlagsA::RECEIVE_COMPLETE)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void enableDataRegEmptyInt() FORCE_INLINE
|
|
||||||
{
|
|
||||||
*Registers::CTRL_STAT_REG_B |= (1 << CtrlFlagsB::DATA_REG_EMPTY_INT_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void disableDataRegEmptyInt() FORCE_INLINE
|
|
||||||
{
|
|
||||||
*Registers::CTRL_STAT_REG_B &= ~(1 << CtrlFlagsB::DATA_REG_EMPTY_INT_ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
struct DataBitsVal {
|
|
||||||
uint8_t regCVal = 0;
|
|
||||||
uint8_t regBVal = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto calcBaud()
|
|
||||||
{
|
|
||||||
// The actual formula is (F_CPU / (16 * baudRate)) - 1, but this one has the advantage of rounding correctly
|
|
||||||
constexpr auto baudVal = (F_CPU + 8 * cfg::BAUD_RATE) / (16 * cfg::BAUD_RATE) - 1;
|
|
||||||
return baudVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto calcDataBits()
|
|
||||||
{
|
|
||||||
DataBitsVal dataBitsVal;
|
|
||||||
|
|
||||||
switch (cfg::DATA_BITS) {
|
|
||||||
case DataBits::FIVE:
|
|
||||||
dataBitsVal.regCVal = 0;
|
|
||||||
break;
|
|
||||||
case DataBits::SIX:
|
|
||||||
dataBitsVal.regCVal = (1 << CtrlFlagsC::CHAR_SIZE_0);
|
|
||||||
break;
|
|
||||||
case DataBits::SEVEN:
|
|
||||||
dataBitsVal.regCVal = (1 << CtrlFlagsC::CHAR_SIZE_1);
|
|
||||||
break;
|
|
||||||
case DataBits::EIGHT:
|
|
||||||
dataBitsVal.regCVal = (1 << CtrlFlagsC::CHAR_SIZE_1) | (1 << CtrlFlagsC::CHAR_SIZE_0);
|
|
||||||
break;
|
|
||||||
case DataBits::NINE:
|
|
||||||
dataBitsVal.regCVal = (1 << CtrlFlagsC::CHAR_SIZE_1) | (1 << CtrlFlagsC::CHAR_SIZE_0);
|
|
||||||
dataBitsVal.regBVal = (1 << CtrlFlagsB::CHAR_SIZE_2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dataBitsVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto calcParity()
|
|
||||||
{
|
|
||||||
uint8_t parityVal = 0;
|
|
||||||
|
|
||||||
if (cfg::PARITY == Parity::EVEN)
|
|
||||||
parityVal = (1 << CtrlFlagsC::PARITY_MODE_1);
|
|
||||||
else if (cfg::PARITY == Parity::ODD)
|
|
||||||
parityVal = (1 << CtrlFlagsC::PARITY_MODE_1) | (1 << CtrlFlagsC::PARITY_MODE_0);
|
|
||||||
|
|
||||||
return parityVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto calcStopBits()
|
|
||||||
{
|
|
||||||
uint8_t stopBitsVal = 0;
|
|
||||||
|
|
||||||
if (cfg::STOP_BITS == StopBits::TWO)
|
|
||||||
stopBitsVal = (1 << CtrlFlagsC::STOP_BIT_SEL);
|
|
||||||
|
|
||||||
return stopBitsVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto calcMode()
|
|
||||||
{
|
|
||||||
static_assert(mode != Mode::SPI, "SPI mode can not be used with uart");
|
|
||||||
|
|
||||||
uint8_t modeVal = 0;
|
|
||||||
|
|
||||||
if (mode == Mode::SYNCHRONOUS_MASTER || mode == Mode::SYNCHRONOUS_SLAVE) {
|
|
||||||
modeVal = (1 << CtrlFlagsC::MODE_SEL_0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return modeVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <bool enable>
|
|
||||||
static constexpr auto calcRxState()
|
|
||||||
{
|
|
||||||
uint8_t enableVal = 0;
|
|
||||||
|
|
||||||
if (enable)
|
|
||||||
enableVal = (1 << CtrlFlagsB::RX_ENABLE);
|
|
||||||
|
|
||||||
return enableVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <bool enable>
|
|
||||||
static constexpr auto calcTxState()
|
|
||||||
{
|
|
||||||
uint8_t enableVal = 0;
|
|
||||||
|
|
||||||
if (enable)
|
|
||||||
enableVal = (1 << CtrlFlagsB::TX_ENABLE);
|
|
||||||
|
|
||||||
return enableVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
static constexpr auto calcInterrupt()
|
|
||||||
{
|
|
||||||
uint8_t interruptVal = 0;
|
|
||||||
|
|
||||||
if (driven == Driven::INTERRUPT)
|
|
||||||
interruptVal |= (1 << CtrlFlagsB::DATA_REG_EMPTY_INT_ENABLE) | (1 << CtrlFlagsB::RX_INT_ENABLE);
|
|
||||||
|
|
||||||
return interruptVal;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename data_t, uint8_t Size>
|
|
||||||
struct RingBuffer {
|
|
||||||
uint8_t head;
|
|
||||||
uint8_t tail;
|
|
||||||
data_t buf[Size];
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
} // namespace uart
|
|
||||||
|
|
||||||
#undef FORCE_INLINE
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#include "hardware0.hpp"
|
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
#if defined(__AVR_ATmega1284P__)
|
|
||||||
|
|
||||||
void (*fnRx0IntHandler)() = nullptr;
|
|
||||||
void (*fnDataReg0EmptyIntHandler)() = nullptr;
|
|
||||||
|
|
||||||
ISR(USART0_RX_vect)
|
|
||||||
{
|
|
||||||
if (fnRx0IntHandler)
|
|
||||||
fnRx0IntHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
ISR(USART0_UDRE_vect)
|
|
||||||
{
|
|
||||||
if (fnDataReg0EmptyIntHandler)
|
|
||||||
fnDataReg0EmptyIntHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "This chip is not supported"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace uart
|
|
||||||
210
hardware0.hpp
210
hardware0.hpp
@@ -1,210 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <avr/io.h>
|
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "hardware.hpp"
|
|
||||||
|
|
||||||
#define FORCE_INLINE __attribute__((always_inline))
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
#if defined(__AVR_ATmega1284P__)
|
|
||||||
|
|
||||||
struct Registers0 {
|
|
||||||
static constexpr volatile auto *IO_REG = &UDR0;
|
|
||||||
static constexpr volatile auto *CTRL_STAT_REG_A = &UCSR0A;
|
|
||||||
static constexpr volatile auto *CTRL_STAT_REG_B = &UCSR0B;
|
|
||||||
static constexpr volatile auto *CTRL_STAT_REG_C = &UCSR0C;
|
|
||||||
static constexpr volatile auto *BAUD_REG_L = &UBRR0L;
|
|
||||||
static constexpr volatile auto *BAUD_REG_H = &UBRR0H;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ControlFlagsA0 {
|
|
||||||
MULTI_PROC_COMM_MODE = MPCM0,
|
|
||||||
SPEED_2X = U2X0,
|
|
||||||
PARITY_ERROR = UPE0,
|
|
||||||
DATA_OVER_RUN = DOR0,
|
|
||||||
FRAME_ERROR = FE0,
|
|
||||||
DATA_REG_EMPTY = UDRE0,
|
|
||||||
TRANSMIT_COMPLETE = TXC0,
|
|
||||||
RECEIVE_COMPLETE = RXC0,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ControlFlagsB0 {
|
|
||||||
TX_DATA_BIT_8 = TXB80,
|
|
||||||
RX_DATA_BIT_8 = RXB80,
|
|
||||||
CHAR_SIZE_2 = UCSZ02,
|
|
||||||
TX_ENABLE = TXEN0,
|
|
||||||
RX_ENABLE = RXEN0,
|
|
||||||
DATA_REG_EMPTY_INT_ENABLE = UDRIE0,
|
|
||||||
TX_INT_ENABLE = TXCIE0,
|
|
||||||
RX_INT_ENABLE = RXCIE0,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ControlFlagsC0 {
|
|
||||||
CLK_POLARITY = UCPOL0,
|
|
||||||
CHAR_SIZE_0 = UCSZ00,
|
|
||||||
CHAR_SIZE_1 = UCSZ01,
|
|
||||||
STOP_BIT_SEL = USBS0,
|
|
||||||
PARITY_MODE_0 = UPM00,
|
|
||||||
PARITY_MODE_1 = UPM01,
|
|
||||||
MODE_SEL_0 = UMSEL00,
|
|
||||||
MODE_SEL_1 = UMSEL01,
|
|
||||||
};
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
constexpr int operator<<(const int &lhs, const ControlFlagsA0 &rhs) { return lhs << static_cast<int>(rhs); }
|
|
||||||
constexpr int operator<<(const int &lhs, const ControlFlagsB0 &rhs) { return lhs << static_cast<int>(rhs); }
|
|
||||||
constexpr int operator<<(const int &lhs, const ControlFlagsC0 &rhs) { return lhs << static_cast<int>(rhs); }
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
extern void (*fnRx0IntHandler)();
|
|
||||||
extern void (*fnDataReg0EmptyIntHandler)();
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "This chip is not supported"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <Mode mode = Mode::ASYNCHRONOUS, class cfg = Config<>, Driven driven = Driven::INTERRUPT>
|
|
||||||
class Hardware0 {
|
|
||||||
public:
|
|
||||||
using data_t = typename cfg::data_t;
|
|
||||||
static constexpr auto DATA_BITS = cfg::DATA_BITS;
|
|
||||||
|
|
||||||
static void init() FORCE_INLINE
|
|
||||||
{
|
|
||||||
HardwareImpl::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByte(data_t byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
HardwareImpl::txByteBlocking(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rxByte(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
return HardwareImpl::rxByteBlocking(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
static_cast<void>(byte);
|
|
||||||
static_assert(driven == Driven::BLOCKING, "Peek with data is not supported in blocking mode");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek() FORCE_INLINE
|
|
||||||
{
|
|
||||||
return HardwareImpl::peekBlocking();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
|
|
||||||
detail::ControlFlagsC0, cfg, mode, driven>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <Mode mode, class cfg>
|
|
||||||
class Hardware0<mode, cfg, Driven::INTERRUPT> {
|
|
||||||
public:
|
|
||||||
using data_t = typename cfg::data_t;
|
|
||||||
static constexpr auto DATA_BITS = cfg::DATA_BITS;
|
|
||||||
|
|
||||||
static void init() FORCE_INLINE
|
|
||||||
{
|
|
||||||
detail::fnRx0IntHandler = rxIntHandler;
|
|
||||||
detail::fnDataReg0EmptyIntHandler = dataRegEmptyIntHandler;
|
|
||||||
|
|
||||||
HardwareImpl::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByte(const data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
uint8_t tmpHead = (sm_txBuf.head + 1) % TX_BUFFER_SIZE;
|
|
||||||
while (tmpHead == sm_txBuf.tail)
|
|
||||||
;
|
|
||||||
|
|
||||||
sm_txBuf.buf[tmpHead] = byte;
|
|
||||||
sm_txBuf.head = tmpHead;
|
|
||||||
|
|
||||||
HardwareImpl::enableDataRegEmptyInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rxByte(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (sm_rxBuf.head == sm_rxBuf.tail)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
|
|
||||||
byte = sm_rxBuf.buf[tmpTail];
|
|
||||||
sm_rxBuf.tail = tmpTail;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (sm_rxBuf.head == sm_rxBuf.tail)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
|
|
||||||
byte = sm_rxBuf.buf[tmpTail];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek() FORCE_INLINE
|
|
||||||
{
|
|
||||||
return (sm_rxBuf.head != sm_rxBuf.tail);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
using HardwareImpl = detail::Hardware<detail::Registers0, detail::ControlFlagsA0, detail::ControlFlagsB0,
|
|
||||||
detail::ControlFlagsC0, cfg, mode, Driven::INTERRUPT>;
|
|
||||||
|
|
||||||
static constexpr auto TX_BUFFER_SIZE = 16;
|
|
||||||
static constexpr auto RX_BUFFER_SIZE = 16;
|
|
||||||
|
|
||||||
static volatile detail::RingBuffer<data_t, TX_BUFFER_SIZE> sm_txBuf;
|
|
||||||
static volatile detail::RingBuffer<data_t, RX_BUFFER_SIZE> sm_rxBuf;
|
|
||||||
|
|
||||||
static void rxIntHandler()
|
|
||||||
{
|
|
||||||
uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE;
|
|
||||||
|
|
||||||
if (tmpHead != sm_rxBuf.tail) {
|
|
||||||
sm_rxBuf.head = tmpHead;
|
|
||||||
sm_rxBuf.buf[tmpHead] = HardwareImpl::rxByteInterrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dataRegEmptyIntHandler() FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (sm_txBuf.head != sm_txBuf.tail) {
|
|
||||||
uint8_t tmpTail = (sm_txBuf.tail + 1) % TX_BUFFER_SIZE;
|
|
||||||
sm_txBuf.tail = tmpTail;
|
|
||||||
HardwareImpl::txByteInterrupt(sm_txBuf.buf[tmpTail]);
|
|
||||||
} else
|
|
||||||
HardwareImpl::disableDataRegEmptyInt();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <Mode mode, class cfg>
|
|
||||||
volatile detail::RingBuffer<typename Hardware0<mode, cfg, Driven::INTERRUPT>::data_t,
|
|
||||||
Hardware0<mode, cfg, Driven::INTERRUPT>::TX_BUFFER_SIZE>
|
|
||||||
Hardware0<mode, cfg, Driven::INTERRUPT>::sm_txBuf = {0, 0, {0}};
|
|
||||||
|
|
||||||
template <Mode mode, class cfg>
|
|
||||||
volatile detail::RingBuffer<typename Hardware0<mode, cfg, Driven::INTERRUPT>::data_t,
|
|
||||||
Hardware0<mode, cfg, Driven::INTERRUPT>::RX_BUFFER_SIZE>
|
|
||||||
Hardware0<mode, cfg, Driven::INTERRUPT>::sm_rxBuf = {0, 0, {0}};
|
|
||||||
|
|
||||||
} // namespace uart
|
|
||||||
|
|
||||||
#undef FORCE_INLINE
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#include "hardware1.hpp"
|
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
#if defined(__AVR_ATmega1284P__)
|
|
||||||
|
|
||||||
void (*fnRx1IntHandler)() = nullptr;
|
|
||||||
void (*fnDataReg1EmptyIntHandler)() = nullptr;
|
|
||||||
|
|
||||||
ISR(USART1_RX_vect)
|
|
||||||
{
|
|
||||||
if (fnRx1IntHandler)
|
|
||||||
fnRx1IntHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
ISR(USART1_UDRE_vect)
|
|
||||||
{
|
|
||||||
if (fnDataReg1EmptyIntHandler)
|
|
||||||
fnDataReg1EmptyIntHandler();
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "This chip is not supported"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
} // namespace uart
|
|
||||||
216
hardware1.hpp
216
hardware1.hpp
@@ -1,216 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include <avr/io.h>
|
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "hardware.hpp"
|
|
||||||
|
|
||||||
#define FORCE_INLINE __attribute__((always_inline))
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
#if defined(__AVR_ATmega1284P__)
|
|
||||||
|
|
||||||
struct Registers1 {
|
|
||||||
static constexpr volatile auto *IO_REG = &UDR1;
|
|
||||||
static constexpr volatile auto *CTRL_STAT_REG_A = &UCSR1A;
|
|
||||||
static constexpr volatile auto *CTRL_STAT_REG_B = &UCSR1B;
|
|
||||||
static constexpr volatile auto *CTRL_STAT_REG_C = &UCSR1C;
|
|
||||||
static constexpr volatile auto *BAUD_REG_L = &UBRR1L;
|
|
||||||
static constexpr volatile auto *BAUD_REG_H = &UBRR1H;
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ControlFlagsA1 {
|
|
||||||
MULTI_PROC_COMM_MODE = MPCM1,
|
|
||||||
SPEED_2X = U2X1,
|
|
||||||
PARITY_ERROR = UPE1,
|
|
||||||
DATA_OVER_RUN = DOR1,
|
|
||||||
FRAME_ERROR = FE1,
|
|
||||||
DATA_REG_EMPTY = UDRE1,
|
|
||||||
TRANSMIT_COMPLETE = TXC1,
|
|
||||||
RECEIVE_COMPLETE = RXC1,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ControlFlagsB1 {
|
|
||||||
TX_DATA_BIT_8 = TXB81,
|
|
||||||
RX_DATA_BIT_8 = RXB81,
|
|
||||||
CHAR_SIZE_2 = UCSZ12,
|
|
||||||
TX_ENABLE = TXEN1,
|
|
||||||
RX_ENABLE = RXEN1,
|
|
||||||
DATA_REG_EMPTY_INT_ENABLE = UDRIE1,
|
|
||||||
TX_INT_ENABLE = TXCIE1,
|
|
||||||
RX_INT_ENABLE = RXCIE1,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class ControlFlagsC1 {
|
|
||||||
CLK_POLARITY = UCPOL1,
|
|
||||||
CHAR_SIZE_0 = UCSZ10,
|
|
||||||
CHAR_SIZE_1 = UCSZ11,
|
|
||||||
STOP_BIT_SEL = USBS1,
|
|
||||||
PARITY_MODE_0 = UPM10,
|
|
||||||
PARITY_MODE_1 = UPM11,
|
|
||||||
MODE_SEL_0 = UMSEL10,
|
|
||||||
MODE_SEL_1 = UMSEL11,
|
|
||||||
};
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
constexpr int operator<<(const int &lhs, const ControlFlagsA1 &rhs) { return lhs << static_cast<int>(rhs); }
|
|
||||||
constexpr int operator<<(const int &lhs, const ControlFlagsB1 &rhs) { return lhs << static_cast<int>(rhs); }
|
|
||||||
constexpr int operator<<(const int &lhs, const ControlFlagsC1 &rhs) { return lhs << static_cast<int>(rhs); }
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
extern void (*fnRx1IntHandler)();
|
|
||||||
extern void (*fnDataReg1EmptyIntHandler)();
|
|
||||||
|
|
||||||
#define HAS_UART1
|
|
||||||
|
|
||||||
#else
|
|
||||||
#error "This chip is not supported"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
#ifdef HAS_UART1
|
|
||||||
|
|
||||||
template <Mode mode = Mode::ASYNCHRONOUS, class cfg = Config<>, Driven driven = Driven::INTERRUPT>
|
|
||||||
class Hardware1 {
|
|
||||||
public:
|
|
||||||
using data_t = typename cfg::data_t;
|
|
||||||
static constexpr auto DATA_BITS = cfg::DATA_BITS;
|
|
||||||
|
|
||||||
static void init() FORCE_INLINE
|
|
||||||
{
|
|
||||||
HardwareImpl::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByte(const data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
HardwareImpl::txByteBlocking(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rxByte(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
return HardwareImpl::rxByteBlocking(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
static_cast<void>(byte);
|
|
||||||
static_assert(driven != Driven::BLOCKING, "Peek with data is not supported in blocking mode");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek() FORCE_INLINE
|
|
||||||
{
|
|
||||||
return HardwareImpl::peekBlocking();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
|
|
||||||
detail::ControlFlagsC1, cfg, mode, driven>;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <Mode mode, class cfg>
|
|
||||||
class Hardware1<mode, cfg, Driven::INTERRUPT> {
|
|
||||||
public:
|
|
||||||
using data_t = typename cfg::data_t;
|
|
||||||
static constexpr auto DATA_BITS = cfg::DATA_BITS;
|
|
||||||
|
|
||||||
static void init() FORCE_INLINE
|
|
||||||
{
|
|
||||||
detail::fnRx1IntHandler = rxIntHandler;
|
|
||||||
detail::fnDataReg1EmptyIntHandler = dataRegEmptyIntHandler;
|
|
||||||
|
|
||||||
HardwareImpl::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByte(const data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
uint8_t tmpHead = (sm_txBuf.head + 1) % TX_BUFFER_SIZE;
|
|
||||||
while (tmpHead == sm_txBuf.tail)
|
|
||||||
;
|
|
||||||
|
|
||||||
sm_txBuf.buf[tmpHead] = byte;
|
|
||||||
sm_txBuf.head = tmpHead;
|
|
||||||
|
|
||||||
HardwareImpl::enableDataRegEmptyInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rxByte(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (sm_rxBuf.head == sm_rxBuf.tail)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
|
|
||||||
byte = sm_rxBuf.buf[tmpTail];
|
|
||||||
sm_rxBuf.tail = tmpTail;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek(data_t &byte) FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (sm_rxBuf.head == sm_rxBuf.tail)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE;
|
|
||||||
byte = sm_rxBuf.buf[tmpTail];
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek() FORCE_INLINE
|
|
||||||
{
|
|
||||||
return (sm_rxBuf.head != sm_rxBuf.tail);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
|
|
||||||
detail::ControlFlagsC1, cfg, mode, Driven::INTERRUPT>;
|
|
||||||
|
|
||||||
static constexpr auto TX_BUFFER_SIZE = 16;
|
|
||||||
static constexpr auto RX_BUFFER_SIZE = 16;
|
|
||||||
|
|
||||||
static volatile detail::RingBuffer<data_t, TX_BUFFER_SIZE> sm_txBuf;
|
|
||||||
static volatile detail::RingBuffer<data_t, RX_BUFFER_SIZE> sm_rxBuf;
|
|
||||||
|
|
||||||
static void rxIntHandler()
|
|
||||||
{
|
|
||||||
uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE;
|
|
||||||
|
|
||||||
if (tmpHead != sm_rxBuf.tail) {
|
|
||||||
sm_rxBuf.head = tmpHead;
|
|
||||||
sm_rxBuf.buf[tmpHead] = HardwareImpl::rxByteInterrupt();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void dataRegEmptyIntHandler() FORCE_INLINE
|
|
||||||
{
|
|
||||||
if (sm_txBuf.head != sm_txBuf.tail) {
|
|
||||||
uint8_t tmpTail = (sm_txBuf.tail + 1) % TX_BUFFER_SIZE;
|
|
||||||
sm_txBuf.tail = tmpTail;
|
|
||||||
HardwareImpl::txByteInterrupt(sm_txBuf.buf[tmpTail]);
|
|
||||||
} else
|
|
||||||
HardwareImpl::disableDataRegEmptyInt();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <Mode mode, class cfg>
|
|
||||||
volatile detail::RingBuffer<typename Hardware1<mode, cfg, Driven::INTERRUPT>::data_t,
|
|
||||||
Hardware1<mode, cfg, Driven::INTERRUPT>::TX_BUFFER_SIZE>
|
|
||||||
Hardware1<mode, cfg, Driven::INTERRUPT>::sm_txBuf = {0, 0, {0}};
|
|
||||||
|
|
||||||
template <Mode mode, class cfg>
|
|
||||||
volatile detail::RingBuffer<typename Hardware1<mode, cfg, Driven::INTERRUPT>::data_t,
|
|
||||||
Hardware1<mode, cfg, Driven::INTERRUPT>::RX_BUFFER_SIZE>
|
|
||||||
Hardware1<mode, cfg, Driven::INTERRUPT>::sm_rxBuf = {0, 0, {0}};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace uart
|
|
||||||
|
|
||||||
#undef FORCE_INLINE
|
|
||||||
21
software.hpp
21
software.hpp
@@ -1,21 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "utils.hpp"
|
|
||||||
|
|
||||||
#include "../io/io.hpp"
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
|
|
||||||
template <io::P rxPin, io::P txPin, class cfg = Config<>>
|
|
||||||
class Software {
|
|
||||||
static_assert(util::always_false_v<cfg>, "Not implemented");
|
|
||||||
|
|
||||||
public:
|
|
||||||
using data_t = typename cfg::data_t;
|
|
||||||
static constexpr auto DATA_BITS = cfg::DATA_BITS;
|
|
||||||
|
|
||||||
static void init() {}
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace uart
|
|
||||||
22
uart.atsln
Normal file
22
uart.atsln
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Atmel Studio Solution File, Format Version 11.00
|
||||||
|
VisualStudioVersion = 14.0.23107.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "uart", "uart\uart.cppproj", "{DCE6C7E3-EE26-4D79-826B-08594B9AD897}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|AVR = Debug|AVR
|
||||||
|
Release|AVR = Release|AVR
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.ActiveCfg = Debug|AVR
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Debug|AVR.Build.0 = Debug|AVR
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.ActiveCfg = Release|AVR
|
||||||
|
{DCE6C7E3-EE26-4D79-826B-08594B9AD897}.Release|AVR.Build.0 = Release|AVR
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
345
uart.hpp
345
uart.hpp
@@ -1,345 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
#include "hardware0.hpp"
|
|
||||||
#include "hardware1.hpp"
|
|
||||||
#include "software.hpp"
|
|
||||||
#include "utils.hpp"
|
|
||||||
|
|
||||||
#include "../flash/flash.hpp"
|
|
||||||
|
|
||||||
#define FORCE_INLINE __attribute__((always_inline))
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <typename T, T limit, size_t Base>
|
|
||||||
static constexpr size_t cntDigits()
|
|
||||||
{
|
|
||||||
T num = limit;
|
|
||||||
size_t cnt = 0;
|
|
||||||
|
|
||||||
if (num < 0) {
|
|
||||||
num = -num;
|
|
||||||
++cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
num /= 10;
|
|
||||||
++cnt;
|
|
||||||
} while (num > 0);
|
|
||||||
|
|
||||||
return cnt;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, size_t Base>
|
|
||||||
static constexpr size_t maxNumDigits()
|
|
||||||
{
|
|
||||||
T minDigits = cntDigits<T, util::NumericLimits<T>::min(), Base>();
|
|
||||||
T maxDigits = cntDigits<T, util::NumericLimits<T>::max(), Base>();
|
|
||||||
|
|
||||||
return (minDigits < maxDigits) ? maxDigits : minDigits;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <class Driver>
|
|
||||||
class Uart {
|
|
||||||
public:
|
|
||||||
using data_t = typename Driver::data_t;
|
|
||||||
|
|
||||||
// Constructing a uart object does not initialize the driver to allow different specializations with the same
|
|
||||||
// back-end to exists at the same time
|
|
||||||
// Note that init must be called every time when switching specializations with the same back-end
|
|
||||||
Uart() = default;
|
|
||||||
|
|
||||||
// Moving and copying uart objects is not supported
|
|
||||||
Uart(const Uart &) = delete;
|
|
||||||
Uart(Uart &&) = delete;
|
|
||||||
Uart &operator=(const Uart &) = delete;
|
|
||||||
Uart &operator=(Uart &&) = delete;
|
|
||||||
|
|
||||||
// Before using the uart init must be called
|
|
||||||
static void init()
|
|
||||||
{
|
|
||||||
Driver::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txByte(const data_t &byte)
|
|
||||||
{
|
|
||||||
Driver::txByte(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool rxByte(data_t &byte)
|
|
||||||
{
|
|
||||||
return Driver::rxByte(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek(data_t &byte)
|
|
||||||
{
|
|
||||||
return Driver::peek(byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool peek()
|
|
||||||
{
|
|
||||||
return Driver::peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txString(const char *str)
|
|
||||||
{
|
|
||||||
static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");
|
|
||||||
|
|
||||||
while (char ch = *str++)
|
|
||||||
txByte(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void txString(const ::detail::FlashString *str)
|
|
||||||
{
|
|
||||||
static_assert(Driver::DATA_BITS == DataBits::EIGHT, "Strings are only supported with 8 data bits");
|
|
||||||
|
|
||||||
const char *strIt = reinterpret_cast<const char *>(str);
|
|
||||||
|
|
||||||
while (char ch = pgm_read_byte(strIt++))
|
|
||||||
txByte(ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, size_t Base = 10>
|
|
||||||
static inline void txNumber(const T &val)
|
|
||||||
{
|
|
||||||
static_assert(util::is_integral_v<T>, "Only supported on integral types");
|
|
||||||
|
|
||||||
constexpr size_t numDigits = detail::maxNumDigits<T, Base>();
|
|
||||||
data_t buffer[numDigits];
|
|
||||||
data_t *bufEnd = buffer + numDigits - 1;
|
|
||||||
|
|
||||||
T digits = val;
|
|
||||||
|
|
||||||
if (digits < 0) {
|
|
||||||
digits = -digits;
|
|
||||||
txByte('-');
|
|
||||||
}
|
|
||||||
|
|
||||||
do {
|
|
||||||
data_t lastDigit = digits % Base;
|
|
||||||
*bufEnd-- = '0' + lastDigit;
|
|
||||||
digits /= Base;
|
|
||||||
} while (digits > 0);
|
|
||||||
|
|
||||||
for (data_t *buf = bufEnd + 1; buf < buffer + numDigits; ++buf)
|
|
||||||
txByte(*buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Output stream overloads
|
|
||||||
|
|
||||||
Uart &operator<<(const char *str)
|
|
||||||
{
|
|
||||||
txString(str);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const ::detail::FlashString *str)
|
|
||||||
{
|
|
||||||
txString(str);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const char &val)
|
|
||||||
{
|
|
||||||
txByte(val);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const unsigned char &val)
|
|
||||||
{
|
|
||||||
txNumber(val);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const short &val)
|
|
||||||
{
|
|
||||||
txNumber(val);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(unsigned short) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const int &val)
|
|
||||||
{
|
|
||||||
txNumber(val);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const unsigned int &val)
|
|
||||||
{
|
|
||||||
txNumber(val);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(long) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(unsigned long) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(long long) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(unsigned long long) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(float) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(double) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(long double) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
Uart &operator<<(const bool &val)
|
|
||||||
{
|
|
||||||
txString(val ? F("true") : F("false"));
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator<<(const void *) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
|
||||||
// Input stream overloads
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(char &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(unsigned char &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(short &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(unsigned short &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(int &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(unsigned int &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(long &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(unsigned long &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(long long &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(unsigned long long &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(float &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(double &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(long double &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(bool &) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename... Ts>
|
|
||||||
Uart &operator>>(const void *&) const
|
|
||||||
{
|
|
||||||
static_assert(util::always_false_v<Ts...>, "Not implemented");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename cfg = Config<>>
|
|
||||||
using Uart0 = Uart<Hardware0<Mode::ASYNCHRONOUS, cfg>>;
|
|
||||||
|
|
||||||
#ifdef HAS_UART1
|
|
||||||
template <typename cfg = Config<>>
|
|
||||||
using Uart1 = Uart<Hardware1<Mode::ASYNCHRONOUS, cfg>>;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace uart
|
|
||||||
|
|
||||||
#undef FORCE_INLINE
|
|
||||||
#undef HAS_UART1
|
|
||||||
4
uart/clock.hpp
Normal file
4
uart/clock.hpp
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define F_CPU 16'000'000
|
||||||
|
#include <util/delay.h>
|
||||||
1
uart/flash
Submodule
1
uart/flash
Submodule
Submodule uart/flash added at 6edb2e5a21
1
uart/io
Submodule
1
uart/io
Submodule
Submodule uart/io added at 80de36ee7e
283
uart/main.cpp
Normal file
283
uart/main.cpp
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
#include "clock.hpp"
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "flash/flash.hpp"
|
||||||
|
#include "io/io.hpp"
|
||||||
|
#include "uart/uart.hpp"
|
||||||
|
|
||||||
|
using uart0_interface_t =
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
using namespace uart;
|
||||||
|
Uart<Hardware0<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
|
||||||
|
serial.init();
|
||||||
|
|
||||||
|
serial << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
|
||||||
|
|
||||||
|
while (false) {
|
||||||
|
uint8_t received = 0;
|
||||||
|
|
||||||
|
while (!serial.peek())
|
||||||
|
;
|
||||||
|
|
||||||
|
{
|
||||||
|
serial << F("Peeked: ");
|
||||||
|
serial.txByte(received);
|
||||||
|
serial << F("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (serial.rxByte(received)) {
|
||||||
|
serial << F("Received: ");
|
||||||
|
serial.txByte(received);
|
||||||
|
serial << F("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
serial.flushTx();
|
||||||
|
}
|
||||||
|
|
||||||
|
void newUartUsage2()
|
||||||
|
{
|
||||||
|
uart1_interface_t serial1;
|
||||||
|
|
||||||
|
auto ramString = "Hello World from RAM. ";
|
||||||
|
auto flashString = F("Hello World from flash\r\n");
|
||||||
|
|
||||||
|
serial1.init();
|
||||||
|
|
||||||
|
serial1 << ramString;
|
||||||
|
serial1 << flashString;
|
||||||
|
|
||||||
|
serial1.flushTx();
|
||||||
|
}
|
||||||
|
|
||||||
|
void newUartStreamOverloads()
|
||||||
|
{
|
||||||
|
using namespace uart;
|
||||||
|
Uart<Hardware0<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
|
||||||
|
serial.init();
|
||||||
|
|
||||||
|
bool bVal = true;
|
||||||
|
char chVal = 'c';
|
||||||
|
signed char schVal = 's';
|
||||||
|
unsigned char uchVal = 'u';
|
||||||
|
short shVal = -12345;
|
||||||
|
unsigned short ushVal = 64123;
|
||||||
|
int iVal = -14321;
|
||||||
|
unsigned int uiVal = 32146;
|
||||||
|
long lVal = -571474496;
|
||||||
|
unsigned long ulVal = 2718958144;
|
||||||
|
long long llVal = -45197516864960;
|
||||||
|
unsigned long long ullVal = 4611685969606738496;
|
||||||
|
|
||||||
|
serial << F("Stream overload test:") << F("\r\n");
|
||||||
|
|
||||||
|
serial << F("bool : ") << bVal << F("\r\n");
|
||||||
|
serial << F("char : ") << chVal << F("\r\n");
|
||||||
|
serial << F("signed char : ") << schVal << F("\r\n");
|
||||||
|
serial << F("unsigned char : ") << uchVal << F("\r\n");
|
||||||
|
serial << F("short : ") << shVal << F("\r\n");
|
||||||
|
serial << F("unsigned short : ") << ushVal << F("\r\n");
|
||||||
|
serial << F("int : ") << iVal << F("\r\n");
|
||||||
|
serial << F("unsigned int : ") << uiVal << F("\r\n");
|
||||||
|
serial << F("long : ") << lVal << F("\r\n");
|
||||||
|
serial << F("unsigned long : ") << ulVal << F("\r\n");
|
||||||
|
serial << F("long long : ") << llVal << F("\r\n");
|
||||||
|
serial << F("unsigned long long : ") << ullVal << F("\r\n");
|
||||||
|
serial << F("const void : ") << &bVal << F("\r\n");
|
||||||
|
|
||||||
|
auto number = 0xBADF00D;
|
||||||
|
|
||||||
|
serial << F("Binary : 0b");
|
||||||
|
serial.txNumber<decltype(number), 2>(number);
|
||||||
|
serial << F("\r\n");
|
||||||
|
|
||||||
|
serial << F("Octal : 0");
|
||||||
|
serial.txNumber<decltype(number), 8>(number);
|
||||||
|
serial << F("\r\n");
|
||||||
|
|
||||||
|
serial << F("Decimal : ");
|
||||||
|
serial.txNumber<decltype(number), 10>(number);
|
||||||
|
serial << F("\r\n");
|
||||||
|
|
||||||
|
serial << F("Hex : 0x");
|
||||||
|
serial.txNumber<decltype(number), 16>(number);
|
||||||
|
serial << F("\r\n");
|
||||||
|
|
||||||
|
serial.flushTx();
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace spi {
|
||||||
|
|
||||||
|
enum class Cpol {
|
||||||
|
MODE_0,
|
||||||
|
MODE_1,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Cpha {
|
||||||
|
MODE_0,
|
||||||
|
MODE_1,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class DataOrder {
|
||||||
|
MSB,
|
||||||
|
LSB,
|
||||||
|
};
|
||||||
|
|
||||||
|
template <Cpol cpol, Cpha cpha, DataOrder dataOrder>
|
||||||
|
struct Config {
|
||||||
|
static constexpr auto CPOL_MODE = cpol;
|
||||||
|
static constexpr auto CPHA_MODE = cpha;
|
||||||
|
static constexpr auto DATA_ORDER = dataOrder;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class Driver>
|
||||||
|
struct spi {
|
||||||
|
spi()
|
||||||
|
{
|
||||||
|
Driver::init();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace spi
|
||||||
|
|
||||||
|
namespace uart {
|
||||||
|
|
||||||
|
template <class Config>
|
||||||
|
class Hardware0<Config, Driven::INTERRUPT, Mode::SPI> {
|
||||||
|
public:
|
||||||
|
static void init()
|
||||||
|
{
|
||||||
|
UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00);
|
||||||
|
|
||||||
|
if (DATA_ORDER == spi::DataOrder::MSB)
|
||||||
|
UCSR0C &= ~(1 << UCSZ01);
|
||||||
|
else
|
||||||
|
UCSR0C |= (1 << UCSZ01);
|
||||||
|
|
||||||
|
if (CPOL_MODE == spi::Cpol::MODE_0)
|
||||||
|
UCSR0C &= ~(1 << UCPOL0);
|
||||||
|
else
|
||||||
|
UCSR0C |= (1 << UCPOL0);
|
||||||
|
|
||||||
|
if (CPHA_MODE == spi::Cpha::MODE_0)
|
||||||
|
UCSR0C &= ~(1 << UCSZ00);
|
||||||
|
else
|
||||||
|
UCSR0C |= (1 << UCSZ00);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static constexpr auto CPOL_MODE = Config::CPOL_MODE;
|
||||||
|
static constexpr auto CPHA_MODE = Config::CPHA_MODE;
|
||||||
|
static constexpr auto DATA_ORDER = Config::DATA_ORDER;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace uart
|
||||||
|
|
||||||
|
void spiTest()
|
||||||
|
{
|
||||||
|
using config = spi::Config<spi::Cpol::MODE_0, spi::Cpha::MODE_0, spi::DataOrder::MSB>;
|
||||||
|
using uartspi = uart::Hardware0<config, uart::Driven::INTERRUPT, uart::Mode::SPI>;
|
||||||
|
|
||||||
|
spi::spi<uartspi> uartSpi;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void initUart(const uint32_t baudRate)
|
||||||
|
{
|
||||||
|
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 (!(UCSR0A & (1 << UDRE0)))
|
||||||
|
;
|
||||||
|
|
||||||
|
UDR0 = byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void txString(const char *str)
|
||||||
|
{
|
||||||
|
while (char ch = *str++)
|
||||||
|
txUart(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void txString(const detail::FlashString *str)
|
||||||
|
{
|
||||||
|
const char *strIt = reinterpret_cast<const char *>(str);
|
||||||
|
|
||||||
|
while (char ch = pgm_read_byte(strIt++))
|
||||||
|
txUart(ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void flushTx()
|
||||||
|
{
|
||||||
|
while (!(UCSR0A & (1 << UDRE0)))
|
||||||
|
;
|
||||||
|
while (!(UCSR0A & (1 << TXC0)))
|
||||||
|
;
|
||||||
|
UCSR0A |= (1 << TXC0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void optimalUartTest()
|
||||||
|
{
|
||||||
|
auto ramString = "Hello World from RAM. ";
|
||||||
|
auto flashString = F("Hello World from flash\r\n");
|
||||||
|
|
||||||
|
initUart(115200);
|
||||||
|
|
||||||
|
txString(ramString);
|
||||||
|
txString(flashString);
|
||||||
|
|
||||||
|
flushTx();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
sei();
|
||||||
|
|
||||||
|
doubleSpeedTest();
|
||||||
|
|
||||||
|
newUartUsage2();
|
||||||
|
optimalUartTest();
|
||||||
|
newUartStreamOverloads();
|
||||||
|
|
||||||
|
txString(F("\r\n"));
|
||||||
|
flushTx();
|
||||||
|
|
||||||
|
spiTest();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
1
uart/uart
Submodule
1
uart/uart
Submodule
Submodule uart/uart added at 119de32445
254
uart/uart.cppproj
Normal file
254
uart/uart.cppproj
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
|
||||||
|
<PropertyGroup>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectVersion>7.0</ProjectVersion>
|
||||||
|
<ToolchainName>com.Atmel.AVRGCC8.CPP</ToolchainName>
|
||||||
|
<ProjectGuid>dce6c7e3-ee26-4d79-826b-08594b9ad897</ProjectGuid>
|
||||||
|
<avrdevice>ATmega1284P</avrdevice>
|
||||||
|
<avrdeviceseries>none</avrdeviceseries>
|
||||||
|
<OutputType>Executable</OutputType>
|
||||||
|
<Language>CPP</Language>
|
||||||
|
<OutputFileName>$(MSBuildProjectName)</OutputFileName>
|
||||||
|
<OutputFileExtension>.elf</OutputFileExtension>
|
||||||
|
<OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
|
||||||
|
<AssemblyName>uart</AssemblyName>
|
||||||
|
<Name>uart</Name>
|
||||||
|
<RootNamespace>uart</RootNamespace>
|
||||||
|
<ToolchainFlavour>avr-g++-9.1.0</ToolchainFlavour>
|
||||||
|
<KeepTimersRunning>true</KeepTimersRunning>
|
||||||
|
<OverrideVtor>false</OverrideVtor>
|
||||||
|
<CacheFlash>true</CacheFlash>
|
||||||
|
<ProgFlashFromRam>true</ProgFlashFromRam>
|
||||||
|
<RamSnippetAddress>0x20000000</RamSnippetAddress>
|
||||||
|
<UncachedRange />
|
||||||
|
<preserveEEPROM>true</preserveEEPROM>
|
||||||
|
<OverrideVtorValue>exception_table</OverrideVtorValue>
|
||||||
|
<BootSegment>2</BootSegment>
|
||||||
|
<ResetRule>0</ResetRule>
|
||||||
|
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||||
|
<EraseKey />
|
||||||
|
<avrtool>
|
||||||
|
</avrtool>
|
||||||
|
<avrtoolserialnumber>J41800099437</avrtoolserialnumber>
|
||||||
|
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
|
||||||
|
<com_atmel_avrdbg_tool_jtagicemkii>
|
||||||
|
<ToolOptions>
|
||||||
|
<InterfaceProperties>
|
||||||
|
<IspClock>0</IspClock>
|
||||||
|
</InterfaceProperties>
|
||||||
|
<InterfaceName>ISP</InterfaceName>
|
||||||
|
</ToolOptions>
|
||||||
|
<ToolType>com.atmel.avrdbg.tool.jtagicemkii</ToolType>
|
||||||
|
<ToolNumber>070000004699</ToolNumber>
|
||||||
|
<ToolName>JTAGICE mkII</ToolName>
|
||||||
|
</com_atmel_avrdbg_tool_jtagicemkii>
|
||||||
|
<avrtoolinterface>ISP</avrtoolinterface>
|
||||||
|
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
||||||
|
<AAFDebugger>
|
||||||
|
<AAFDebugFiles>
|
||||||
|
<DebugFile>
|
||||||
|
<path>\Debug\uart.lss</path>
|
||||||
|
<AAFSetting>
|
||||||
|
<Label>Lss Files</Label>
|
||||||
|
<Extention>.lss</Extention>
|
||||||
|
<Regex>^\s*(?<address>[a-f0-9]*):\s*.*$</Regex>
|
||||||
|
<DebugEnabled>true</DebugEnabled>
|
||||||
|
<RegexGroups>address</RegexGroups>
|
||||||
|
<DebuggerExpression>$pc</DebuggerExpression>
|
||||||
|
</AAFSetting>
|
||||||
|
</DebugFile>
|
||||||
|
</AAFDebugFiles>
|
||||||
|
</AAFDebugger>
|
||||||
|
<AsfFrameworkConfig>
|
||||||
|
<framework-data xmlns="">
|
||||||
|
<options />
|
||||||
|
<configurations />
|
||||||
|
<files />
|
||||||
|
<documentation help="" />
|
||||||
|
<offline-documentation help="" />
|
||||||
|
<dependencies>
|
||||||
|
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.46.0" />
|
||||||
|
</dependencies>
|
||||||
|
</framework-data>
|
||||||
|
</AsfFrameworkConfig>
|
||||||
|
<com_atmel_avrdbg_tool_atmelice>
|
||||||
|
<ToolOptions>
|
||||||
|
<InterfaceProperties>
|
||||||
|
<IspClock>125000</IspClock>
|
||||||
|
<JtagDbgClock>5000000</JtagDbgClock>
|
||||||
|
</InterfaceProperties>
|
||||||
|
<InterfaceName>ISP</InterfaceName>
|
||||||
|
</ToolOptions>
|
||||||
|
<ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
|
||||||
|
<ToolNumber>J41800099437</ToolNumber>
|
||||||
|
<ToolName>Atmel-ICE</ToolName>
|
||||||
|
</com_atmel_avrdbg_tool_atmelice>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
|
<ToolchainSettings>
|
||||||
|
<AvrGccCpp>
|
||||||
|
<avrgcc.common.Device>-mmcu=atmega1284p</avrgcc.common.Device>
|
||||||
|
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||||
|
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
|
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||||
|
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||||
|
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||||
|
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||||
|
<avrgcc.compiler.symbols.DefSymbols>
|
||||||
|
<ListValues>
|
||||||
|
<Value>NDEBUG</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcc.compiler.directories.IncludePaths>
|
||||||
|
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||||
|
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
|
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||||
|
<avrgcc.compiler.warnings.ExtraWarnings>True</avrgcc.compiler.warnings.ExtraWarnings>
|
||||||
|
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
|
||||||
|
<avrgcc.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -std=c11</avrgcc.compiler.miscellaneous.OtherFlags>
|
||||||
|
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||||
|
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||||
|
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||||
|
<ListValues>
|
||||||
|
<Value>NDEBUG</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||||
|
<avrgcccpp.compiler.directories.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.compiler.directories.IncludePaths>
|
||||||
|
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
|
||||||
|
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
|
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||||
|
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
|
||||||
|
<avrgcccpp.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -Wextra -std=c++17</avrgcccpp.compiler.miscellaneous.OtherFlags>
|
||||||
|
<avrgcccpp.linker.libraries.Libraries>
|
||||||
|
<ListValues>
|
||||||
|
<Value>libm</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.linker.libraries.Libraries>
|
||||||
|
<avrgcccpp.assembler.general.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.assembler.general.IncludePaths>
|
||||||
|
</AvrGccCpp>
|
||||||
|
</ToolchainSettings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
|
<ToolchainSettings>
|
||||||
|
<AvrGccCpp>
|
||||||
|
<avrgcc.common.Device>-mmcu=atmega1284p</avrgcc.common.Device>
|
||||||
|
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||||
|
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||||
|
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||||
|
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||||
|
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||||
|
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||||
|
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||||
|
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||||
|
<avrgcc.compiler.symbols.DefSymbols>
|
||||||
|
<ListValues>
|
||||||
|
<Value>DEBUG</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcc.compiler.symbols.DefSymbols>
|
||||||
|
<avrgcc.compiler.directories.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcc.compiler.directories.IncludePaths>
|
||||||
|
<avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
|
||||||
|
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
|
<avrgcc.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcc.compiler.optimization.DebugLevel>
|
||||||
|
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||||
|
<avrgcc.compiler.warnings.ExtraWarnings>True</avrgcc.compiler.warnings.ExtraWarnings>
|
||||||
|
<avrgcc.compiler.warnings.Pedantic>True</avrgcc.compiler.warnings.Pedantic>
|
||||||
|
<avrgcc.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -std=c11</avrgcc.compiler.miscellaneous.OtherFlags>
|
||||||
|
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||||
|
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||||
|
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||||
|
<ListValues>
|
||||||
|
<Value>DEBUG</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||||
|
<avrgcccpp.compiler.directories.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.compiler.directories.IncludePaths>
|
||||||
|
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||||
|
<avrgcccpp.compiler.optimization.DebugLevel>Maximum (-g3)</avrgcccpp.compiler.optimization.DebugLevel>
|
||||||
|
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||||
|
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
|
||||||
|
<avrgcccpp.compiler.miscellaneous.OtherFlags>-fno-threadsafe-statics -Wextra -std=c++17</avrgcccpp.compiler.miscellaneous.OtherFlags>
|
||||||
|
<avrgcccpp.linker.libraries.Libraries>
|
||||||
|
<ListValues>
|
||||||
|
<Value>libm</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.linker.libraries.Libraries>
|
||||||
|
<avrgcccpp.assembler.general.IncludePaths>
|
||||||
|
<ListValues>
|
||||||
|
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||||
|
</ListValues>
|
||||||
|
</avrgcccpp.assembler.general.IncludePaths>
|
||||||
|
<avrgcccpp.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcccpp.assembler.debugging.DebugLevel>
|
||||||
|
</AvrGccCpp>
|
||||||
|
</ToolchainSettings>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="clock.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="flash\flash.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="io\io.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="main.cpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\config.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\hardware.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\hardware0.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\hardware1.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\software.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="uart\uart.hpp">
|
||||||
|
<SubType>compile</SubType>
|
||||||
|
</Compile>
|
||||||
|
<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>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="io" />
|
||||||
|
<Folder Include="flash" />
|
||||||
|
<Folder Include="util" />
|
||||||
|
<Folder Include="uart" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||||
|
</Project>
|
||||||
1
uart/util
Submodule
1
uart/util
Submodule
Submodule uart/util added at 81b3ae244c
142
utils.hpp
142
utils.hpp
@@ -1,142 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
// Fix for limits.h not exposing LLONG_MIN, LLONG_MIN, and ULLONG_MAX to C++ context
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#define __STDC_VERSION__ 201112L
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
|
|
||||||
namespace uart {
|
|
||||||
namespace util {
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
template <bool Val> struct set_bool { static constexpr auto value = Val; };
|
|
||||||
|
|
||||||
struct true_type : set_bool<true> {};
|
|
||||||
struct false_type : set_bool<false> {};
|
|
||||||
|
|
||||||
template <typename...> struct always_false : false_type {};
|
|
||||||
|
|
||||||
template <typename... Ts> static constexpr auto always_false_v = always_false<Ts...>::value;
|
|
||||||
|
|
||||||
template <typename T> struct is_integral : false_type {};
|
|
||||||
template <> struct is_integral<bool> : true_type {};
|
|
||||||
template <> struct is_integral<char> : true_type {};
|
|
||||||
template <> struct is_integral<signed char> : true_type {};
|
|
||||||
template <> struct is_integral<unsigned char> : true_type {};
|
|
||||||
template <> struct is_integral<short> : true_type {};
|
|
||||||
template <> struct is_integral<int> : true_type {};
|
|
||||||
template <> struct is_integral<long int> : true_type {};
|
|
||||||
template <> struct is_integral<long long int> : true_type {};
|
|
||||||
template <> struct is_integral<unsigned short> : true_type {};
|
|
||||||
template <> struct is_integral<unsigned int> : true_type {};
|
|
||||||
template <> struct is_integral<unsigned long int> : true_type {};
|
|
||||||
template <> struct is_integral<unsigned long long int> : true_type {};
|
|
||||||
|
|
||||||
template <typename T> static constexpr auto is_integral_v = is_integral<T>::value;
|
|
||||||
|
|
||||||
template <typename T, typename U> struct is_same : false_type {};
|
|
||||||
template <typename T> struct is_same<T, T> : true_type {};
|
|
||||||
|
|
||||||
template <typename T, typename U> static constexpr auto is_same_v = is_same<T, U>::value;
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
struct NumericLimits {
|
|
||||||
static constexpr T min() { return T(); }
|
|
||||||
static constexpr T max() { return T(); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<bool> {
|
|
||||||
static constexpr bool min() { return false; }
|
|
||||||
static constexpr bool max() { return true; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<char> {
|
|
||||||
static constexpr char min() { return CHAR_MIN; }
|
|
||||||
static constexpr char max() { return CHAR_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<signed char> {
|
|
||||||
static constexpr signed char min() { return SCHAR_MIN; }
|
|
||||||
static constexpr signed char max() { return SCHAR_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<unsigned char> {
|
|
||||||
static constexpr unsigned char min() { return 0; }
|
|
||||||
static constexpr unsigned char max() { return UCHAR_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<short> {
|
|
||||||
static constexpr short min() { return SHRT_MIN; }
|
|
||||||
static constexpr short max() { return SHRT_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<int> {
|
|
||||||
static constexpr int min() { return INT_MIN; }
|
|
||||||
static constexpr int max() { return INT_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<long> {
|
|
||||||
static constexpr long int min() { return LONG_MIN; }
|
|
||||||
static constexpr long int max() { return LONG_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<long long int> {
|
|
||||||
static constexpr long long int min() { return LLONG_MIN; }
|
|
||||||
static constexpr long long int max() { return LLONG_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<unsigned short> {
|
|
||||||
static constexpr unsigned short min() { return 0; }
|
|
||||||
static constexpr unsigned short max() { return USHRT_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<unsigned int> {
|
|
||||||
static constexpr unsigned int min() { return 0; }
|
|
||||||
static constexpr unsigned int max() { return UINT_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<unsigned long int> {
|
|
||||||
static constexpr unsigned long int min() { return 0; }
|
|
||||||
static constexpr unsigned long int max() { return ULONG_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<unsigned long long int> {
|
|
||||||
static constexpr unsigned long long int min() { return 0; }
|
|
||||||
static constexpr unsigned long long int max() { return ULLONG_MAX; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<float> {
|
|
||||||
template <typename... Ts> static constexpr float min() { static_assert(always_false_v<Ts...>, "Not implemented"); return 0; }
|
|
||||||
template <typename... Ts> static constexpr float max() { static_assert(always_false_v<Ts...>, "Not implemented"); return 0; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<double> {
|
|
||||||
template <typename... Ts> static constexpr double min() { static_assert(always_false_v<Ts...>, "Not implemented"); return 0; }
|
|
||||||
template <typename... Ts> static constexpr double max() { static_assert(always_false_v<Ts...>, "Not implemented"); return 0; }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
struct NumericLimits<long double> {
|
|
||||||
template <typename... Ts> static constexpr long double min() { static_assert(always_false_v<Ts...>, "Not implemented"); return 0; }
|
|
||||||
template <typename... Ts> static constexpr long double max() { static_assert(always_false_v<Ts...>, "Not implemented"); return 0; }
|
|
||||||
};
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
} // namespace util
|
|
||||||
} // namespace uart
|
|
||||||
Reference in New Issue
Block a user