Skip to content

Commit

Permalink
[sam] Fix inconsistent macros for SAME70 "B"-variant
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Apr 5, 2022
1 parent 9ef4ed1 commit db44fa5
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 31 deletions.
15 changes: 10 additions & 5 deletions src/modm/platform/uart/sam/uart.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

%% set name="{}{}".format(type.capitalize(), id)
%% set reg=name.upper()
%% if type == "usart" and target.family == "e" and target.variant == "b"
%% set reg_suffix="_USART"
%% else
%% set reg_suffix=""
%% endif

namespace
{
Expand All @@ -34,7 +39,7 @@ MODM_ISR({{ peripheral | upper }}{{ id }})

if({{ name }}::isTransmitReady()) {
if(txBuffer.isEmpty()) {
{{ name }}::Regs()->{{ prefix }}_IDR = {{ prefix }}_IDR_TXRDY;
{{ name }}::Regs()->{{ prefix }}_IDR = {{ prefix }}_IDR_TXRDY_Msk;
} else {
{{ name }}::Regs()->{{ prefix }}_THR = txBuffer.get();
txBuffer.pop();
Expand Down Expand Up @@ -80,7 +85,7 @@ bool
return false;
}
// Enable tx interrupt
Regs()->{{ prefix }}_IER = {{ prefix }}_IER_TXRDY;
Regs()->{{ prefix }}_IER = {{ prefix }}_IER_TXRDY_Msk;
}
return true;
}
Expand Down Expand Up @@ -112,17 +117,17 @@ void
void
{{ name }}::setParity(Parity parity)
{
Regs()->{{ prefix }}_MR = (Regs()->{{ prefix }}_MR & ~{{ prefix }}_MR_PAR_Msk) | (uint32_t)parity;
Regs()->{{ prefix }}_MR = (Regs()->{{ prefix }}_MR & ~{{ prefix }}_MR{{reg_suffix}}_PAR_Msk) | (uint32_t)parity;
}

%% if type == "usart"
void
{{ name }}::setWordLength(WordLength length)
{
if(length == WordLength::Bit9) {
Regs()->{{ prefix }}_MR |= {{ prefix }}_MR_MODE9;
Regs()->{{ prefix }}_MR |= {{ prefix }}_MR{{reg_suffix}}_MODE9_Msk;
} else {
Regs()->{{ prefix }}_MR &= ~{{ prefix }}_MR_MODE9;
Regs()->{{ prefix }}_MR &= ~{{ prefix }}_MR{{reg_suffix}}_MODE9_Msk;
Regs()->{{ prefix }}_MR =
(Regs()->{{ prefix }}_MR & ~{{ prefix }}_MR_CHRL_Msk)
| {{ prefix }}_MR_CHRL((uint32_t)length);
Expand Down
17 changes: 11 additions & 6 deletions src/modm/platform/uart/sam/uart.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

%% set name="{}{}".format(type.capitalize(), id)
%% set reg=name.upper()
%% if type == "usart" and target.family == "e" and target.variant == "b"
%% set reg_suffix="_USART"
%% else
%% set reg_suffix=""
%% endif

namespace modm::platform
{
Expand All @@ -35,7 +40,7 @@ namespace modm::platform
* @author Christopher Durand
* @ingroup modm_platform_{{type}} modm_platform_{{type}}_{{id}}
*/
class {{ name }} : public {{ type }}Base, public modm::Uart
class {{ name }} : public {{ type | capitalize }}Base, public modm::Uart
{
private:
// prevent name collision between ::Uart* from SAM header with modm::Uart
Expand Down Expand Up @@ -104,16 +109,16 @@ public:

%% if type == "usart"
// Use 8x oversampling (this affects baud rate generation)
Regs()->{{ prefix }}_MR = {{ prefix }}_MR_OVER;
Regs()->{{ prefix }}_MR = {{ prefix }}_MR{{reg_suffix}}_OVER;
%% endif

setParity(parity);
%% if type == "usart"
setWordLength(length);
%% endif
Regs()->{{ prefix }}_CR = {{ prefix }}_CR_RXEN | {{ prefix }}_CR_TXEN;
Regs()->{{ prefix }}_CR = {{ prefix }}_CR_RXEN_Msk | {{ prefix }}_CR_TXEN_Msk;
// Enable rx interrupt
Regs()->{{ prefix }}_IER = {{ prefix }}_IER_RXRDY;
Regs()->{{ prefix }}_IER = {{ prefix }}_IER_RXRDY_Msk;

// Enable the IRQ
NVIC_SetPriority({{ peripheral | upper }}{{ id }}_IRQn, irq_priority);
Expand All @@ -138,9 +143,9 @@ public:
static void setWordLength(WordLength length);
%% endif

static inline bool isTransmitReady() { return Regs()->{{ prefix }}_{{ sr }} & {{ prefix }}_{{ sr }}_TXRDY; }
static inline bool isTransmitReady() { return Regs()->{{ prefix }}_{{ sr }} & {{ prefix }}_{{ sr }}_TXRDY_Msk; }

static inline bool isReceiveReady() { return Regs()->{{ prefix }}_{{ sr }} & {{ prefix }}_{{ sr }}_RXRDY; }
static inline bool isReceiveReady() { return Regs()->{{ prefix }}_{{ sr }} & {{ prefix }}_{{ sr }}_RXRDY_Msk; }
};

} // namespace modm::platform
3 changes: 2 additions & 1 deletion src/modm/platform/uart/sam/uart/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def _get_properties(env, instance=None):
"peripheral" : "Uart",
"id" : instance,
"prefix" : "UART",
"sr" : "SR"
"sr" : "SR",
"target" : device.identifier
}


Expand Down
55 changes: 37 additions & 18 deletions src/modm/platform/uart/sam/uart_base.hpp.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Jeff McBride
* Copyright (c) 2022, Christopher Durand
*
* This file is part of the modm project.
*
Expand All @@ -8,6 +9,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#pragma once

#include "../device.hpp"
Expand All @@ -16,28 +18,45 @@ namespace modm::platform
{

/// @ingroup modm_platform_uart
class {{type}}Base
class {{type | capitalize}}Base
{
public:
enum class Parity : uint32_t
{
Disabled = US_MR_PAR_NO,
Even = US_MR_PAR_EVEN,
Odd = US_MR_PAR_ODD,
Space = US_MR_PAR_SPACE,
Mark = US_MR_PAR_MARK,
MultiDrop = US_MR_PAR_MULTIDROP
};
enum class Parity : uint32_t
{
%% if type == "usart"
%% if target.family == "e" and target.variant == "b"
Disabled = US_MR_USART_PAR_NO_Val,
Even = US_MR_USART_PAR_EVEN_Val,
Odd = US_MR_USART_PAR_ODD_Val,
Space = US_MR_USART_PAR_SPACE_Val,
Mark = US_MR_USART_PAR_MARK_Val,
MultiDrop = US_MR_USART_PAR_MULTIDROP_Val
%% else
Disabled = US_MR_PAR_NO,
Even = US_MR_PAR_EVEN,
Odd = US_MR_PAR_ODD,
Space = US_MR_PAR_SPACE,
Mark = US_MR_PAR_MARK,
MultiDrop = US_MR_PAR_MULTIDROP
%% endif
%% else
Disabled = UART_MR_PAR_NO,
Even = UART_MR_PAR_EVEN,
Odd = UART_MR_PAR_ODD,
Space = UART_MR_PAR_SPACE,
Mark = UART_MR_PAR_MARK
%% endif
};

%% if type == "usart"
enum class WordLength : uint32_t
{
Bit5 = 0,
Bit6,
Bit7,
Bit8,
Bit9
};
enum class WordLength : uint32_t
{
Bit5 = 0,
Bit6,
Bit7,
Bit8,
Bit9
};
%% endif
};

Expand Down
3 changes: 2 additions & 1 deletion src/modm/platform/uart/sam/usart/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def _get_properties(env, instance=None):
"peripheral" : peripheral,
"id" : instance,
"prefix" : "US",
"sr" : "CSR"
"sr" : "CSR",
"target" : device.identifier
}


Expand Down

0 comments on commit db44fa5

Please sign in to comment.