diff --git a/.cproject b/.cproject index 48966ba..1410f48 100644 --- a/.cproject +++ b/.cproject @@ -62,6 +62,8 @@ + + @@ -100,6 +102,8 @@ + + @@ -166,6 +170,8 @@ + + @@ -204,6 +210,8 @@ + + diff --git a/components/f4ll_cpp/dmahelper.cpp b/components/f4ll_cpp/dmahelper.cpp new file mode 100644 index 0000000..71e6fa1 --- /dev/null +++ b/components/f4ll_cpp/dmahelper.cpp @@ -0,0 +1,82 @@ +/* + * dma_helper.c + * + * Created on: Sep 18, 2019 + * Author: abody + */ +#include +#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]; +} + diff --git a/components/f4ll_cpp/dmahelper.h b/components/f4ll_cpp/dmahelper.h new file mode 100644 index 0000000..038872b --- /dev/null +++ b/components/f4ll_cpp/dmahelper.h @@ -0,0 +1,52 @@ +/* + * dma_helper.h + * + * Created on: Sep 18, 2019 + * Author: abody + */ + +#ifndef DMA_HELPER_H_ +#define DMA_HELPER_H_ +#include +#include + +#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_ */ diff --git a/platforms/firmware/component.mk b/platforms/firmware/component.mk new file mode 100644 index 0000000..c7741b4 --- /dev/null +++ b/platforms/firmware/component.mk @@ -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 diff --git a/platforms/firmware/platform/crc_ll.h b/platforms/firmware/platform/crc_ll.h new file mode 100644 index 0000000..f10b7bc --- /dev/null +++ b/platforms/firmware/platform/crc_ll.h @@ -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 diff --git a/platforms/firmware/platform/dma_ll.h b/platforms/firmware/platform/dma_ll.h new file mode 100644 index 0000000..f17125a --- /dev/null +++ b/platforms/firmware/platform/dma_ll.h @@ -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 diff --git a/platforms/firmware/platform/mockme.h b/platforms/firmware/platform/mockme.h new file mode 100644 index 0000000..6b98cca --- /dev/null +++ b/platforms/firmware/platform/mockme.h @@ -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 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 fn ## _ ## decor ## _mockguard(&test_ ## fn, fn ## _ ## decor) + +#define ACTIVATE_MOCK_RV(fn, decor, ret) \ + fn##_##decor##_callcount = 0; \ + fn##_##decor##_retval = ret; \ + mockme::mockguard fn##_##decor##_mockguard(&test_ ## fn, fn##_##decor) + +#endif // __cplusplus + +#endif /* PLATFORM_MOCKME_H_ */ diff --git a/platforms/firmware/platform/usart_ll.h b/platforms/firmware/platform/usart_ll.h new file mode 100644 index 0000000..52354de --- /dev/null +++ b/platforms/firmware/platform/usart_ll.h @@ -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