LL_DmaHelper (c++)

This commit is contained in:
Attila Body 2019-10-25 14:47:46 +02:00
parent f0ddd19150
commit 663d68baf1
5 changed files with 81 additions and 9 deletions

View file

@ -22,7 +22,7 @@ TARGET = f407ve_hs_uart
DEBUG = 1 DEBUG = 1
# optimization # optimization
OPT = -Og OPT = -Og
CXXSTD = -std=c++17
####################################### #######################################
# paths # paths
@ -172,7 +172,7 @@ CC_INCLUDES = \
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(COMMON_DEFS) $(C_DEFS) $(COMMON_INCLUDES) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections CFLAGS = $(MCU) $(COMMON_DEFS) $(C_DEFS) $(COMMON_INCLUDES) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CXXFLAGS = $(MCU) $(COMMON_DEFS) $(CC_DEFS) $(COMMON_INCLUDES) $(CC_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections CXXFLAGS = $(MCU) $(COMMON_DEFS) $(CC_DEFS) $(COMMON_INCLUDES) $(CC_INCLUDES) $(OPT) $(CXXSTD) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2 CFLAGS += -g -gdwarf-2

View file

@ -1,6 +1,6 @@
#ifndef __PLATFORM_DMA_LL_H_INCLUDED #ifndef __PLATFORM_DMA_LL_H_INCLUDED
#define __PLATFORM_DMA_LL_H_INCLUDED #define __PLATFORM_DMA_LL_H_INCLUDED
#include "dma.h" #include "stm32f4xx_ll_dma.h"
#endif // __PLATFORM_DMA_LL_H_INCLUDED #endif // __PLATFORM_DMA_LL_H_INCLUDED

View file

@ -25,18 +25,18 @@ volatile uint32_t* GetIcfReg(DMA_TypeDef *dma, uint32_t stream)
uint32_t GetFeMask(uint32_t stream) uint32_t GetFeMask(uint32_t stream)
{ {
static const uint32_t masks[8] = { static const uint32_t feMasks[8] = {
DMA_LISR_FEIF0, DMA_LISR_FEIF1, DMA_LISR_FEIF2, DMA_LISR_FEIF3, DMA_HISR_FEIF4, DMA_HISR_FEIF5, DMA_HISR_FEIF6, DMA_HISR_FEIF7 DMA_LISR_FEIF0, DMA_LISR_FEIF1, DMA_LISR_FEIF2, DMA_LISR_FEIF3, DMA_HISR_FEIF4, DMA_HISR_FEIF5, DMA_HISR_FEIF6, DMA_HISR_FEIF7
}; };
return masks[stream]; return feMasks[stream];
} }
uint32_t GetDmeMask(uint32_t stream) uint32_t GetDmeMask(uint32_t stream)
{ {
static const uint32_t teMasks[8] = { static const uint32_t dmeMasks[8] = {
DMA_LISR_DMEIF0, DMA_LISR_DMEIF1, DMA_LISR_DMEIF2, DMA_LISR_DMEIF3, DMA_HISR_DMEIF4, DMA_HISR_DMEIF5, DMA_HISR_DMEIF6, DMA_HISR_DMEIF7 DMA_LISR_DMEIF0, DMA_LISR_DMEIF1, DMA_LISR_DMEIF2, DMA_LISR_DMEIF3, DMA_HISR_DMEIF4, DMA_HISR_DMEIF5, DMA_HISR_DMEIF6, DMA_HISR_DMEIF7
}; };
return teMasks[stream]; return dmeMasks[stream];
} }
uint32_t GetTeMask(uint32_t stream) uint32_t GetTeMask(uint32_t stream)
@ -49,10 +49,10 @@ uint32_t GetTeMask(uint32_t stream)
uint32_t GetHtMask(uint32_t stream) uint32_t GetHtMask(uint32_t stream)
{ {
static const uint32_t teMasks[8] = { static const uint32_t htMasks[8] = {
DMA_LISR_HTIF0, DMA_LISR_HTIF1, DMA_LISR_HTIF2, DMA_LISR_HTIF3, DMA_HISR_HTIF4, DMA_HISR_HTIF5, DMA_HISR_HTIF6, DMA_HISR_HTIF7 DMA_LISR_HTIF0, DMA_LISR_HTIF1, DMA_LISR_HTIF2, DMA_LISR_HTIF3, DMA_HISR_HTIF4, DMA_HISR_HTIF5, DMA_HISR_HTIF6, DMA_HISR_HTIF7
}; };
return teMasks[stream]; return htMasks[stream];
} }
uint32_t GetTcMask(uint32_t stream) uint32_t GetTcMask(uint32_t stream)

26
lib/ll_dmahelper.cpp Normal file
View file

@ -0,0 +1,26 @@
/*
* ll_dmahelper.cpp
*
* Created on: Oct 25, 2019
* Author: abody
*/
#include <ll_dmahelper.h>
namespace f4ll {
static const uint32_t m_FEMasks[8] = {DMA_LISR_FEIF0, DMA_LISR_FEIF1, DMA_LISR_FEIF2, DMA_LISR_FEIF3, DMA_HISR_FEIF4, DMA_HISR_FEIF5, DMA_HISR_FEIF6, DMA_HISR_FEIF7};
static const uint32_t m_DMEMasks[8] = {DMA_LISR_DMEIF0, DMA_LISR_DMEIF1, DMA_LISR_DMEIF2, DMA_LISR_DMEIF3, DMA_HISR_DMEIF4, DMA_HISR_DMEIF5, DMA_HISR_DMEIF6, DMA_HISR_DMEIF7};
static const uint32_t m_TEMasks[8] = {DMA_LISR_TEIF0, DMA_LISR_TEIF1, DMA_LISR_TEIF2, DMA_LISR_TEIF3, DMA_HISR_TEIF4, DMA_HISR_TEIF5, DMA_HISR_TEIF6, DMA_HISR_TEIF7};
static const uint32_t m_HTMasks[8] = {DMA_LISR_HTIF0, DMA_LISR_HTIF1, DMA_LISR_HTIF2, DMA_LISR_HTIF3, DMA_HISR_HTIF4, DMA_HISR_HTIF5, DMA_HISR_HTIF6, DMA_HISR_HTIF7};
static const uint32_t m_TCMasks[8] = {DMA_LISR_TCIF0, DMA_LISR_TCIF1, DMA_LISR_TCIF2, DMA_LISR_TCIF3, DMA_HISR_TCIF4, DMA_HISR_TCIF5, DMA_HISR_TCIF6, DMA_HISR_TCIF7};
LL_DmaHelper::LL_DmaHelper(DMA_TypeDef *dma, uint32_t stream)
: m_dma(dma)
, m_stream(stream)
, m_isReg((dma == DMA1) ? ((m_stream < LL_DMA_STREAM_4) ? &DMA1->LISR : &DMA1->HISR) : ((m_stream < LL_DMA_STREAM_4) ? &DMA2->LISR : &DMA2->HISR))
, m_ifcReg((dma == DMA1) ? ((m_stream < LL_DMA_STREAM_4) ? &DMA1->LIFCR : &DMA1->HIFCR) : ((m_stream < LL_DMA_STREAM_4) ? &DMA2->LIFCR : &DMA2->HIFCR))
{
}
} /* namespace f4ll */

46
lib/ll_dmahelper.h Normal file
View file

@ -0,0 +1,46 @@
/*
* ll_dmahelper.h
*
* Created on: Oct 25, 2019
* Author: abody
*/
#ifndef LL_DMAHELPER_H_
#define LL_DMAHELPER_H_
#include <inttypes.h>
#include <platform/dma_ll.h>
namespace f4ll {
class LL_DmaHelper {
public:
LL_DmaHelper(DMA_TypeDef *dma, uint32_t stream);
~LL_DmaHelper() = delete;
inline DMA_TypeDef* GetDMA() { return m_dma; }
inline uint32_t GetStream() { return m_stream; }
inline volatile uint32_t* GetIsReg() { return m_isReg; }
inline volatile uint32_t* GetIcfReg() { return m_ifcReg; }
inline uint32_t GetFeMask() { return m_FEMasks[m_stream]; }
inline uint32_t GetDmeMask() { return m_DMEMasks[m_stream]; }
inline uint32_t GetTeMask() { return m_TEMasks[m_stream]; }
inline uint32_t GetHtMask() { return m_HTMasks[m_stream]; }
inline uint32_t GetTcMask() { return m_TCMasks[m_stream]; }
private:
DMA_TypeDef *m_dma;
uint32_t m_stream;
volatile uint32_t *m_isReg;
volatile uint32_t *m_ifcReg;
static const uint32_t m_FEMasks[8];
static const uint32_t m_DMEMasks[8];
static const uint32_t m_TEMasks[8];
static const uint32_t m_HTMasks[8];
static const uint32_t m_TCMasks[8];
};
} /* namespace f4ll */
#endif /* LL_DMAHELPER_H_ */