Added platforms and components (befinnings of f4ll_cpp)

This commit is contained in:
Attila Body 2020-01-31 15:19:04 +01:00
parent 482d3b8248
commit 7481a66667
8 changed files with 267 additions and 0 deletions

View file

@ -62,6 +62,8 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F4xx/Include"/> <listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F4xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy"/> <listOptionValue builtIn="false" value="../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../App"/> <listOptionValue builtIn="false" value="../App"/>
<listOptionValue builtIn="false" value="../platforms/firmware"/>
<listOptionValue builtIn="false" value="../components"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1413855680" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1413855680" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/> <listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/>
@ -100,6 +102,8 @@
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Src"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Src"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="components"/>
<entry excluding="test" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="platforms"/>
</sourceEntries> </sourceEntries>
</configuration> </configuration>
</storageModule> </storageModule>
@ -166,6 +170,8 @@
<listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F4xx/Include"/> <listOptionValue builtIn="false" value="../Drivers/CMSIS/Device/ST/STM32F4xx/Include"/>
<listOptionValue builtIn="false" value="../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy"/> <listOptionValue builtIn="false" value="../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy"/>
<listOptionValue builtIn="false" value="../App"/> <listOptionValue builtIn="false" value="../App"/>
<listOptionValue builtIn="false" value="../platforms/firmware"/>
<listOptionValue builtIn="false" value="../components"/>
</option> </option>
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1891229407" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols"> <option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols.1891229407" name="Define symbols (-D)" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.cpp.compiler.option.definedsymbols" useByScannerDiscovery="false" valueType="definedSymbols">
<listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/> <listOptionValue builtIn="false" value="USE_FULL_LL_DRIVER"/>
@ -204,6 +210,8 @@
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Drivers"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Src"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Src"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/> <entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Startup"/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="components"/>
<entry excluding="test" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="platforms"/>
</sourceEntries> </sourceEntries>
</configuration> </configuration>
</storageModule> </storageModule>

View file

@ -0,0 +1,82 @@
/*
* dma_helper.c
*
* Created on: Sep 18, 2019
* Author: abody
*/
#include <f4ll_cpp/dmahelper.h>
#ifndef MOCKABLE
#define MOCKABLE(x) x
#endif
DmaHelper::DmaHelper(DMA_TypeDef *dma, uint32_t stream)
{
m_dma = dma;
m_stream = stream;
m_isReg = GetIsReg(dma, stream);
m_ifcReg = GetIfcReg(dma, stream);
m_feMask = GetFeMask(stream);
m_dmeMask = GetDmeMask(stream);
m_teMask = GetTeMask(stream);
m_htMask = GetHtMask(stream);
m_tcMask = GetTcMask(stream);
}
volatile uint32_t* DmaHelper::GetIsReg(DMA_TypeDef *dma, uint32_t stream)
{
if(dma == DMA1)
return (stream < LL_DMA_STREAM_4) ? &DMA1->LISR : &DMA1->HISR;
else
return (stream < LL_DMA_STREAM_4) ? &DMA2->LISR : &DMA2->HISR;
}
volatile uint32_t* DmaHelper::GetIfcReg(DMA_TypeDef *dma, uint32_t stream)
{
if(dma == DMA1)
return (stream < LL_DMA_STREAM_4) ? &DMA1->LIFCR : &DMA1->HIFCR;
else
return (stream < LL_DMA_STREAM_4) ? &DMA2->LIFCR : &DMA2->HIFCR;
}
uint32_t DmaHelper::GetFeMask(uint32_t stream)
{
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
};
return feMasks[stream];
}
uint32_t DmaHelper::GetDmeMask(uint32_t stream)
{
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
};
return dmeMasks[stream];
}
uint32_t DmaHelper::GetTeMask(uint32_t stream)
{
static const uint32_t 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
};
return teMasks[stream];
}
uint32_t DmaHelper::GetHtMask(uint32_t stream)
{
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
};
return htMasks[stream];
}
uint32_t DmaHelper::GetTcMask(uint32_t stream)
{
static const uint32_t 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
};
return tcMasks[stream];
}

View file

@ -0,0 +1,52 @@
/*
* dma_helper.h
*
* Created on: Sep 18, 2019
* Author: abody
*/
#ifndef DMA_HELPER_H_
#define DMA_HELPER_H_
#include <inttypes.h>
#include <platform/dma_ll.h>
#ifndef DECLARE_MOCK
#define DECLARE_MOCK(x)
#endif
class DmaHelper {
public:
DmaHelper(DMA_TypeDef *dma, uint32_t stream);
volatile uint32_t* GetIsReg(DMA_TypeDef *dma, uint32_t stream);
volatile uint32_t* GetIfcReg(DMA_TypeDef *dma, uint32_t stream);
uint32_t GetDmeMask(uint32_t stream);
uint32_t GetTeMask(uint32_t stream);
uint32_t GetHtMask(uint32_t stream);
uint32_t GetTcMask(uint32_t stream);
uint32_t GetFeMask(uint32_t stream);
private:
DMA_TypeDef *m_dma;
uint32_t m_stream;
volatile uint32_t *m_isReg;
volatile uint32_t *m_ifcReg;
uint32_t m_feMask;
uint32_t m_dmeMask;
uint32_t m_teMask;
uint32_t m_htMask;
uint32_t m_tcMask;
};
#ifdef UNITTEST
DECLARE_MOCK(Dma_GetIsReg);
DECLARE_MOCK(Dma_GetIfcReg);
DECLARE_MOCK(Dma_GetDmeMask);
DECLARE_MOCK(Dma_GetTeMask);
DECLARE_MOCK(Dma_GetHtMask);
DECLARE_MOCK(Dma_GetTcMask);
DECLARE_MOCK(Dma_GetFeMask);
DECLARE_MOCK(Dma_Init);
#endif
#endif /* DMA_HELPER_H_ */

View file

@ -0,0 +1,10 @@
SELF_DIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
REL_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
ifeq ($(MKDBG), 1)
$(info >>> $(REL_DIR)/component.mk)
endif
#$(eval C_SOURCES += $(wildcard $(REL_DIR)/*.c))
$(eval COMMON_INCLUDES += -I$(REL_DIR))
ifeq ($(MKDBG), 1)
$(info <<<)
endif

View file

@ -0,0 +1,6 @@
#ifndef __PLATFORM_CRC_LL_H_INCLUDED
#define __PLATFORM_CRC_LL_H_INCLUDED
#include "crc.h"
#endif // __PLATFORM_CRC_LL_H_INCLUDED

View file

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

View file

@ -0,0 +1,97 @@
/*
* mockme.h
*
* Created on: Nov 25, 2019
* Author: abody
*/
#ifndef PLATFORM_MOCKME_H_
#define PLATFORM_MOCKME_H_
//#define TOSTR(x) #x
#ifdef __cplusplus
#define DECLARE_MOCK(F) \
extern decltype(F) F ## __, *test_ ## F
#else
#define DECLARE_MOCK(F) \
extern typeof(F) F ## __, *test_ ## F
#endif
#define MOCKABLE(F) __attribute__((section(\
".bss\n\t"\
".globl test_" #F "\n\t"\
".align 4\n\t"\
".type test_" #F ", @object\n\t"\
".size test_" #F ", 4\n"\
"test_" #F ":\n\t"\
".zero 4\n\t"\
".text\n\t"\
".p2align 4,,15\n\t"\
".globl " #F "\n\t"\
".type " #F ", @function\n"\
#F ":\n\t"\
".cfi_startproc\n\t"\
"push %edx\n\t"\
"push %edx\n\t"\
"push %eax\n\t"\
"movl test_" #F ", %eax\n\t"\
"leal " #F "__, %edx\n\t"\
"test %eax, %eax\n\t"\
"cmove %edx, %eax\n\t"\
"mov %eax, 8(%esp)\n\t"\
"pop %eax\n\t"\
"pop %edx\n\t"\
"ret\n\t"\
".cfi_endproc\n\t"\
".size " #F ", .-" #F "\n\t"\
".section .text"))) F ## __
#define DEFINE_MOCK_RET(rettype, fn, decor, ...) \
static int fn ## _ ## decor ## _callcount; \
static rettype fn ## _ ## decor ## _retval; \
static rettype fn ## _ ## decor(__VA_ARGS__) { \
++fn ## _ ## decor ## _callcount;
#define DEFINE_MOCK(fn, decor, ...) \
static int fn ## _ ## decor ## _callcount; \
static void fn ## _ ## decor(__VA_ARGS__) { \
++fn ## _ ## decor ## _callcount;
#define RETURN_MOCK(fn, decor, ret) \
fn##_##decor##_retval = ret; \
return ret; }
#define RETURN_MOCK_PREDEF(fn, decor) \
return fn##_##decor##_retval; }
#define LEAVE_MOCK }
#define DEFINE_MOCK_VAR(type, fn, decor, varname) type fn##_##decor##_##varname
#define MOCK_STORE(fn, decor, varname, value) fn##_##decor##_##varname = value
#define MOCK_VAR(fn, decor, varname) fn##_##decor##_##varname
#define MOCK_CALLCOUNT(fn, decor) fn ## _ ## decor ## _callcount
#ifdef __cplusplus
namespace mockme {
template <typename T> class mockguard {
T* m_guarded;
public:
mockguard(T* guarded, T testFunc) : m_guarded(guarded) { *m_guarded = testFunc; }
~mockguard() { *m_guarded = nullptr; }
};
} // namespace mockme
#define ACTIVATE_MOCK(fn, decor) \
fn ## _ ## decor ## _callcount = 0; \
mockme::mockguard<decltype(fn)*> fn ## _ ## decor ## _mockguard(&test_ ## fn, fn ## _ ## decor)
#define ACTIVATE_MOCK_RV(fn, decor, ret) \
fn##_##decor##_callcount = 0; \
fn##_##decor##_retval = ret; \
mockme::mockguard<decltype(fn)*> fn##_##decor##_mockguard(&test_ ## fn, fn##_##decor)
#endif // __cplusplus
#endif /* PLATFORM_MOCKME_H_ */

View file

@ -0,0 +1,6 @@
#ifndef __PLATFORM_USART_LL_H_INCLUDED
#define __PLATFORM_USART_LL_H_INCLUDED
#include "usart.h"
#endif // __PLATFORM_USART_LL_H_INCLUDED