Compare commits

...

3 Commits

5 changed files with 96 additions and 92 deletions

View File

@@ -338,7 +338,7 @@ class InterruptHardware {
} }
protected: protected:
static void rxIntHandler() static void rxIntHandler() FORCE_INLINE
{ {
auto data = HardwareImpl::rxByteInterrupt(); auto data = HardwareImpl::rxByteInterrupt();

View File

@@ -1,35 +0,0 @@
#include "hardware0.hpp"
#include <avr/interrupt.h>
namespace uart {
namespace detail {
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__)
#if defined(__AVR_ATmega328P__)
#define USART0_RX_vect USART_RX_vect
#define USART0_UDRE_vect USART_UDRE_vect
#endif
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

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef UART_HARDWARE_0_HPP
#define UART_HARDWARE_0_HPP
#include <stdint.h> #include <stdint.h>
@@ -22,24 +23,18 @@ The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are no
constexpr auto *foo = ptr; constexpr auto *foo = ptr;
Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site
For this to work we need to temporarily disable the _SFR_MEM8 macro so that the register macro just gives the address For this the sfr_defs.h provides a macro which returns the address of a register
*/ */
#undef _SFR_MEM8
#define _SFR_MEM8
struct Registers0 { struct Registers0 {
static constexpr uintptr_t IO_REG_ADDR = UDR0; static constexpr uintptr_t IO_REG_ADDR = _SFR_ADDR(UDR0);
static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = UCSR0A; static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = _SFR_ADDR(UCSR0A);
static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = UCSR0B; static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = _SFR_ADDR(UCSR0B);
static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = UCSR0C; static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = _SFR_ADDR(UCSR0C);
static constexpr uintptr_t BAUD_REG_L_ADDR = UBRR0L; static constexpr uintptr_t BAUD_REG_L_ADDR = _SFR_ADDR(UBRR0L);
static constexpr uintptr_t BAUD_REG_H_ADDR = UBRR0H; static constexpr uintptr_t BAUD_REG_H_ADDR = _SFR_ADDR(UBRR0H);
}; };
#undef _SFR_MEM8
#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr)
enum class ControlFlagsA0 { enum class ControlFlagsA0 {
MULTI_PROC_COMM_MODE = MPCM0, MULTI_PROC_COMM_MODE = MPCM0,
SPEED_2X = U2X0, SPEED_2X = U2X0,
@@ -120,3 +115,45 @@ class Hardware0<cfg, Driven::INTERRUPT, mode>
} // namespace uart } // namespace uart
#undef FORCE_INLINE #undef FORCE_INLINE
#endif
//////////////////////////////////////////////////////////////////////////
#ifndef UART0_NO_INT_VECTORS
#include <avr/interrupt.h>
namespace uart {
namespace detail {
#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__)
#if defined(__AVR_ATmega328P__)
#define USART0_RX_vect USART_RX_vect
#define USART0_UDRE_vect USART_UDRE_vect
#endif
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
#endif

View File

@@ -1,28 +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();
}
#endif
} // namespace detail
} // namespace uart

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef UART_HARDWARE_1_HPP
#define UART_HARDWARE_1_HPP
#include <stdint.h> #include <stdint.h>
@@ -22,24 +23,18 @@ The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are no
constexpr auto *foo = ptr; constexpr auto *foo = ptr;
Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site Workaround is to store the the address of the ptr in a uintptr_t and reinterpret_cast it at call site
For this to work we need to temporarily disable the _SFR_MEM8 macro so that the register macro just gives the address For this the sfr_defs.h provides a macro which returns the address of a register
*/ */
#undef _SFR_MEM8
#define _SFR_MEM8
struct Registers1 { struct Registers1 {
static constexpr uintptr_t IO_REG_ADDR = UDR1; static constexpr uintptr_t IO_REG_ADDR = _SFR_ADDR(UDR1);
static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = UCSR1A; static constexpr uintptr_t CTRL_STAT_REG_A_ADDR = _SFR_ADDR(UCSR1A);
static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = UCSR1B; static constexpr uintptr_t CTRL_STAT_REG_B_ADDR = _SFR_ADDR(UCSR1B);
static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = UCSR1C; static constexpr uintptr_t CTRL_STAT_REG_C_ADDR = _SFR_ADDR(UCSR1C);
static constexpr uintptr_t BAUD_REG_L_ADDR = UBRR1L; static constexpr uintptr_t BAUD_REG_L_ADDR = _SFR_ADDR(UBRR1L);
static constexpr uintptr_t BAUD_REG_H_ADDR = UBRR1H; static constexpr uintptr_t BAUD_REG_H_ADDR = _SFR_ADDR(UBRR1H);
}; };
#undef _SFR_MEM8
#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr)
enum class ControlFlagsA1 { enum class ControlFlagsA1 {
MULTI_PROC_COMM_MODE = MPCM1, MULTI_PROC_COMM_MODE = MPCM1,
SPEED_2X = U2X1, SPEED_2X = U2X1,
@@ -124,3 +119,38 @@ class Hardware1<cfg, Driven::INTERRUPT, mode>
} // namespace uart } // namespace uart
#undef FORCE_INLINE #undef FORCE_INLINE
#endif
//////////////////////////////////////////////////////////////////////////
#ifndef UART1_NO_INT_VECTORS
#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();
}
#endif
} // namespace detail
} // namespace uart
#endif