theCore C++ embedded framework
ecl::dma_wrap_base< Impl > Class Template Reference

Generic interface of the DMA on STM32 platforms. More...

#include </home/travis/build/forGGe/theCore/platform/stm32/family/export/stm32_dma_wrap_interface.hpp>

Public Member Functions

 dma_wrap_base ()=delete
 
 dma_wrap_base (dma_wrap_base &)=delete
 

Static Public Member Functions

static constexpr auto get_irqn ()
 Gets IRQ number of given DMA entity. More...
 
static void init ()
 Initializes DMA. More...
 
template<dma_data_sz Size = dma_data_sz::byte, dma_mode Mode = dma_mode::normal>
static void mem_to_periph (const uint8_t *src, size_t size, volatile uint16_t *periph)
 Prepares DMA transaction from the memory buffer to the given peripheral. More...
 
template<dma_data_sz Size = dma_data_sz::byte, dma_mode Mode = dma_mode::normal>
static void mem_to_periph (uint16_t filler, size_t cnt, volatile uint16_t *periph)
 Prepares DMA transaction that sends given data unit to the given peripheral. More...
 
template<dma_data_sz Size = dma_data_sz::byte, dma_mode Mode = dma_mode::normal>
static void periph_to_mem (volatile uint16_t *periph, uint8_t *dst, size_t size)
 Prepares DMA transaction from the peripheral to the given memory buffer. More...
 
template<dma_data_sz Size = dma_data_sz::byte, dma_mode Mode = dma_mode::normal>
static void periph_to_mem (volatile uint16_t *periph, size_t size)
 Prepares DMA transaction that reads data from peripheral without storing it. More...
 
template<bool EnableTC = true, bool EnableHT = true, bool EnableErr = true>
static void enable_events_irq ()
 Enables IRQ for the events from DMA entity. More...
 
template<bool DisableTC = true, bool DisableHT = true, bool DisableErr = true>
static void disable_events_irq ()
 Disables IRQ for the events from DMA entity. More...
 
static void enable ()
 Enables DMA transaction. More...
 
static void disable ()
 Disables DMA transaction. More...
 
static bool tc ()
 Checks if TC event occurred. More...
 
static bool ht ()
 Checks if HT event occurred. More...
 
static bool err ()
 Checks if TC event occurred. More...
 
static void clear_tc ()
 Clears TC event. More...
 
static void clear_ht ()
 Clears HT event. More...
 
static void clear_err ()
 Clears ERR event. More...
 
static auto bytes_left ()
 Checks how many bytes left to transmit via DMA entity. More...
 

Detailed Description

template<class Impl>
class ecl::dma_wrap_base< Impl >

Generic interface of the DMA on STM32 platforms.

The STM32 MCU family module must implement each method in its own headers. Depends on the family the entity behind the class may differ. E.g. in STM32F4 each DMA instance is unambiguously described by the pair of "stream" and "channel" in contrast to just "channel" in STM32L1. Template parameter allows to incapsulate additional methods into separate class required by the MCU family while keeping in it the scope of a base class and not exposing it in its body.

Template Parameters
ImplDesired additional implementation, defined by the platform.

Constructor & Destructor Documentation

◆ dma_wrap_base() [1/2]

template<class Impl>
ecl::dma_wrap_base< Impl >::dma_wrap_base ( )
delete

◆ dma_wrap_base() [2/2]

template<class Impl>
ecl::dma_wrap_base< Impl >::dma_wrap_base ( dma_wrap_base< Impl > &  )
delete

Member Function Documentation

◆ get_irqn()

template<class Derived >
constexpr auto ecl::dma_wrap_base< Derived >::get_irqn ( )
static

Gets IRQ number of given DMA entity.

◆ init()

template<class Derived >
void ecl::dma_wrap_base< Derived >::init ( )
static

Initializes DMA.

Precondition
DMA is not initialized.
Postcondition
DMA is initialized and ready to work.

◆ mem_to_periph() [1/2]

template<class Derived >
template<dma_data_sz Size, dma_mode Mode>
void ecl::dma_wrap_base< Derived >::mem_to_periph ( const uint8_t *  src,
size_t  size,
volatile uint16_t *  periph 
)
static

Prepares DMA transaction from the memory buffer to the given peripheral.

Precondition
DMA was initialized by calling init() method.
src != nullptr, periph != nullptr, size > 0
Postcondition
DMA is configured with given parameters and ready to go.

Transaction can be triggered by enable() call. DMA events can be enabled using enable_events_irq() routine. If circular mode is chosen then new DMA transaction will start automatically, without need of the explicit enable() call.

Template Parameters
SizeRequired size of a single data unit.
ModeMode of operation.
Parameters
[in]srcThe source memory buffer from which data will be read.
[in]sizeSize of the memory buffer buffer in bytes.
[in]periphThe valid peripheral address.

◆ mem_to_periph() [2/2]

template<class Derived >
template<dma_data_sz Size, dma_mode Mode>
void ecl::dma_wrap_base< Derived >::mem_to_periph ( uint16_t  filler,
size_t  cnt,
volatile uint16_t *  periph 
)
static

Prepares DMA transaction that sends given data unit to the given peripheral.

Precondition
DMA was initialized by calling init() method.
cnt > 0, periph != nullptr
Postcondition
DMA is configured with given parameters and ready to go.

Transaction can be triggered by enable() call. DMA events can be enabled using enable_events_irq() routine. If circular mode is chosen then new DMA transaction will start automatically, without need of the explicit enable() call.

Template Parameters
SizeRequired size of a single data unit.
ModeMode of operation.
Parameters
[in]fillerData unit to be transfered.
[in]cntAmount of data units to be transfered.
[in]periphThe valid peripheral address.

◆ periph_to_mem() [1/2]

template<class Derived >
template<dma_data_sz Size, dma_mode Mode>
void ecl::dma_wrap_base< Derived >::periph_to_mem ( volatile uint16_t *  periph,
uint8_t *  dst,
size_t  size 
)
static

Prepares DMA transaction from the peripheral to the given memory buffer.

Precondition
DMA was initialized by calling init() method.
size > 0, periph != nullptr, dst != nullptr
Postcondition
DMA is configured with given parameters and ready to go.

Transaction can be triggered by enable() call. DMA events can be enabled using enable_events_irq() routine. If circular mode is chosen then new DMA transaction will start automatically, without need of the explicit enable() call.

Template Parameters
SizeSize of a single data unit.
ModeMode of operation.
Parameters
[in]periphThe valid peripheral address.
[in]sizeSize of the memory buffer buffer in bytes.
[in]dstThe destination buffer.

◆ periph_to_mem() [2/2]

template<class Derived >
template<dma_data_sz Size, dma_mode Mode>
void ecl::dma_wrap_base< Derived >::periph_to_mem ( volatile uint16_t *  periph,
size_t  size 
)
static

Prepares DMA transaction that reads data from peripheral without storing it.

Precondition
DMA was initialized by calling init() method.
size > 0, periph != nullptr
Postcondition
DMA is configured with given parameters and ready to go.

Transaction can be triggered by enable() call. DMA events can be enabled using enable_events_irq() routine. If circular mode is chosen then new DMA transaction will start automatically, without need of the explicit enable() call.

Template Parameters
SizeSize of a single data unit.
ModeMode of operation.
Parameters
[in]periphThe valid peripheral address.
[in]sizeSize of the memory buffer buffer in bytes.

◆ enable_events_irq()

template<class Derived >
template<bool EnableTC, bool EnableHT, bool EnableErr>
void ecl::dma_wrap_base< Derived >::enable_events_irq ( )
static

Enables IRQ for the events from DMA entity.

Precondition
DMA was initialized by calling init() method.
Postcondition
DMA configured to trigger IRQ every time corresponding event occur.

Events will be generated by the DMA according to type of events requested. If enabled, events will be delivered via IRQ. To subscribe for it use IRQ descriptor returned by the get_irqn() routine. Use tc(), ht() and err() to check if event occurred or not.

Template Parameters
EnableTCSet if transfer complete event must be enabled.
EnableHTSet if half transfer event must be enabled.
EnableErrSet if error event must be enabled.
Note
Event IRQ allowance is not changed if relevant argument is not set. See example below
// Initial state of the IRQ allowance:
// TC - disabled, HT - disabled, ERR - disabled
dma_tx::template enable_events_irq<true, false, false>();
// New state of the IRQ allowance:
// TC - enabled, HT - disabled, ERR - disabled
dma_tx::template enable_events_irq<false, false, true>();
// New state of the IRQ allowance. Note that HT event state was not
// changed:
// TC - enabled, HT - disabled, ERR - enabled

◆ disable_events_irq()

template<class Derived >
template<bool DisableTC, bool DisableHT, bool DisableErr>
void ecl::dma_wrap_base< Derived >::disable_events_irq ( )
static

Disables IRQ for the events from DMA entity.

Precondition
DMA was initialized by calling init() method.
Postcondition
DMA configure to do not trigger IRQ for selected events.

IRQ previously enabled by enable_events_irq() can be disabled using this method..

Template Parameters
EnableTCSet if transfer complete event must be enabled.
EnableHTSet if half transfer event must be enabled.
EnableErrSet if error event must be enabled.
Note
Event IRQ allowance is not changed if relevant argument is not set. See example below
// Initial state of the IRQ allowance:
// TC - enabled, HT - enabled, ERR - enabled
dma_tx::template disable_events_irq<true, false, false>();
// New state of the IRQ allowance:
// TC - disabled, HT - enabled, ERR - enabled
dma_tx::template disable_events_irq<false, false, true>();
// New state of the IRQ allowance. Note that HT event state was not
// changed:
// TC - disabled, HT - enabled, ERR - disabled

◆ enable()

template<class Derived >
void ecl::dma_wrap_base< Derived >::enable ( )
static

Enables DMA transaction.

Precondition
DMA was configured by one of the periph_to_mem() or mem_to_periph() methods.
DMA was not yet started or already stopped previously by disable() call.
Postcondition
DMA transaction enabled and started.

By invoking this method one can lauch previously configured transaction. Use tc(), ht() and err() to check particular event state. Corresponding IRQ will be triggered if configured by enable_events_irq().

◆ disable()

template<class Derived >
void ecl::dma_wrap_base< Derived >::disable ( )
static

Disables DMA transaction.

Precondition
DMA was enabled by enable() and not yet disabled.
Postcondition
DMA transaction stopped and disabled.

If to call disable() before TC event occur then DMA will stop only after last data unit will be transfered.

◆ tc()

template<class Derived >
bool ecl::dma_wrap_base< Derived >::tc ( )
static

Checks if TC event occurred.

Precondition
DMA was initialized by calling init() method.
Returns
true if tranfer completed, false otherwise.

◆ ht()

template<class Derived >
bool ecl::dma_wrap_base< Derived >::ht ( )
static

Checks if HT event occurred.

Precondition
DMA was initialized by calling init() method.
Returns
true if tranfer is half-completed, false otherwise.

◆ err()

template<class Derived >
bool ecl::dma_wrap_base< Derived >::err ( )
static

Checks if TC event occurred.

Precondition
DMA was initialized by calling init() method.
Returns
true if error occurred during transaction, false otherwise.

◆ clear_tc()

template<class Derived >
void ecl::dma_wrap_base< Derived >::clear_tc ( )
static

Clears TC event.

Precondition
DMA was initialized by calling init() method.
Postcondition
tc() == false.

◆ clear_ht()

template<class Derived >
void ecl::dma_wrap_base< Derived >::clear_ht ( )
static

Clears HT event.

Precondition
DMA was initialized by calling init() method.
Postcondition
ht() == false.

◆ clear_err()

template<class Derived >
void ecl::dma_wrap_base< Derived >::clear_err ( )
static

Clears ERR event.

Precondition
DMA was initialized by calling init() method.
Postcondition
err() == false.

◆ bytes_left()

template<class Derived >
auto ecl::dma_wrap_base< Derived >::bytes_left ( )
static

Checks how many bytes left to transmit via DMA entity.

Precondition
DMA was initialized by calling init() method.

The documentation for this class was generated from the following files: