defining the mock function pointer using the __attribute__((section(...))) trick
This commit is contained in:
parent
4754b65041
commit
833d604b2f
2 changed files with 19 additions and 33 deletions
32
dmahelper.c
32
dmahelper.c
|
@ -6,22 +6,7 @@
|
|||
*/
|
||||
#include <f4ll_c/dmahelper.h>
|
||||
|
||||
#ifndef DEFINE_MOCKPTR
|
||||
#define DEFINE_MOCKPTR(...)
|
||||
#endif
|
||||
|
||||
#ifdef UNITTEST
|
||||
DEFINE_MOCKPTR(volatile uint32_t*, Dma_GetIsReg, DMA_TypeDef*, uint32_t)
|
||||
DEFINE_MOCKPTR(volatile uint32_t*, Dma_GetIfcReg, DMA_TypeDef*, uint32_t)
|
||||
DEFINE_MOCKPTR(uint32_t, Dma_GetDmeMask, uint32_t)
|
||||
DEFINE_MOCKPTR(uint32_t, Dma_GetTeMask, uint32_t)
|
||||
DEFINE_MOCKPTR(uint32_t, Dma_GetHtMask, uint32_t)
|
||||
DEFINE_MOCKPTR(uint32_t, Dma_GetTcMask, uint32_t)
|
||||
DEFINE_MOCKPTR(uint32_t, Dma_GetFeMask, uint32_t)
|
||||
DEFINE_MOCKPTR(void, Dma_Init, struct dmainfo_t*, DMA_TypeDef*, uint32_t)
|
||||
#endif // UNITTEST
|
||||
|
||||
volatile uint32_t* MOCKABLE(Dma_GetIsReg)(DMA_TypeDef *dma, uint32_t stream)
|
||||
volatile uint32_t* MOCKME(Dma_GetIsReg)(DMA_TypeDef *dma, uint32_t stream)
|
||||
{
|
||||
if(dma == DMA1)
|
||||
return (stream < LL_DMA_STREAM_4) ? &DMA1->LISR : &DMA1->HISR;
|
||||
|
@ -29,7 +14,8 @@ volatile uint32_t* MOCKABLE(Dma_GetIsReg)(DMA_TypeDef *dma, uint32_t stream)
|
|||
return (stream < LL_DMA_STREAM_4) ? &DMA2->LISR : &DMA2->HISR;
|
||||
}
|
||||
|
||||
volatile uint32_t* MOCKABLE(Dma_GetIfcReg)(DMA_TypeDef *dma, uint32_t stream)
|
||||
|
||||
volatile uint32_t* MOCKME(Dma_GetIfcReg)(DMA_TypeDef *dma, uint32_t stream)
|
||||
{
|
||||
if(dma == DMA1)
|
||||
return (stream < LL_DMA_STREAM_4) ? &DMA1->LIFCR : &DMA1->HIFCR;
|
||||
|
@ -37,7 +23,7 @@ volatile uint32_t* MOCKABLE(Dma_GetIfcReg)(DMA_TypeDef *dma, uint32_t stream)
|
|||
return (stream < LL_DMA_STREAM_4) ? &DMA2->LIFCR : &DMA2->HIFCR;
|
||||
}
|
||||
|
||||
uint32_t MOCKABLE(Dma_GetFeMask)(uint32_t stream)
|
||||
uint32_t MOCKME(Dma_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
|
||||
|
@ -45,7 +31,7 @@ uint32_t MOCKABLE(Dma_GetFeMask)(uint32_t stream)
|
|||
return feMasks[stream];
|
||||
}
|
||||
|
||||
uint32_t MOCKABLE(Dma_GetDmeMask)(uint32_t stream)
|
||||
uint32_t MOCKME(Dma_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
|
||||
|
@ -53,7 +39,7 @@ uint32_t MOCKABLE(Dma_GetDmeMask)(uint32_t stream)
|
|||
return dmeMasks[stream];
|
||||
}
|
||||
|
||||
uint32_t MOCKABLE(Dma_GetTeMask)(uint32_t stream)
|
||||
uint32_t MOCKME(Dma_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
|
||||
|
@ -61,7 +47,7 @@ uint32_t MOCKABLE(Dma_GetTeMask)(uint32_t stream)
|
|||
return teMasks[stream];
|
||||
}
|
||||
|
||||
uint32_t MOCKABLE(Dma_GetHtMask)(uint32_t stream)
|
||||
uint32_t MOCKME(Dma_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
|
||||
|
@ -69,7 +55,7 @@ uint32_t MOCKABLE(Dma_GetHtMask)(uint32_t stream)
|
|||
return htMasks[stream];
|
||||
}
|
||||
|
||||
uint32_t MOCKABLE(Dma_GetTcMask)(uint32_t stream)
|
||||
uint32_t MOCKME(Dma_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
|
||||
|
@ -78,7 +64,7 @@ uint32_t MOCKABLE(Dma_GetTcMask)(uint32_t stream)
|
|||
return tcMasks[stream];
|
||||
}
|
||||
|
||||
void MOCKABLE(Dma_Init)(struct dmainfo_t *info, DMA_TypeDef *dma, uint32_t stream)
|
||||
void MOCKME(Dma_Init)(struct dmainfo_t *info, DMA_TypeDef *dma, uint32_t stream)
|
||||
{
|
||||
info->dma = dma;
|
||||
info->stream = stream;
|
||||
|
|
20
dmahelper.h
20
dmahelper.h
|
@ -13,8 +13,8 @@
|
|||
#ifndef DECLARE_MOCKPTR
|
||||
#define DECLARE_MOCKPTR(...)
|
||||
#endif
|
||||
#ifndef MOCKABLE
|
||||
#define MOCKABLE(x) x
|
||||
#ifndef MAKE_MOCKABLE
|
||||
#define MAKE_MOCKABLE(x) x
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -44,14 +44,14 @@ DECLARE_MOCKPTR(uint32_t, Dma_GetFeMask, uint32_t)
|
|||
DECLARE_MOCKPTR(void, Dma_Init, struct dmainfo_t*, DMA_TypeDef*, uint32_t)
|
||||
#endif // UNITTEST
|
||||
|
||||
volatile uint32_t* MOCKABLE(Dma_GetIsReg)(DMA_TypeDef *dma, uint32_t stream);
|
||||
volatile uint32_t* MOCKABLE(Dma_GetIfcReg)(DMA_TypeDef *dma, uint32_t stream);
|
||||
uint32_t MOCKABLE(Dma_GetDmeMask)(uint32_t stream);
|
||||
uint32_t MOCKABLE(Dma_GetTeMask)(uint32_t stream);
|
||||
uint32_t MOCKABLE(Dma_GetHtMask)(uint32_t stream);
|
||||
uint32_t MOCKABLE(Dma_GetTcMask)(uint32_t stream);
|
||||
uint32_t MOCKABLE(Dma_GetFeMask)(uint32_t stream);
|
||||
void MOCKABLE(Dma_Init)(struct dmainfo_t *info, DMA_TypeDef *dma, uint32_t stream);
|
||||
volatile uint32_t* MAKE_MOCKABLE(Dma_GetIsReg)(DMA_TypeDef *dma, uint32_t stream);
|
||||
volatile uint32_t* MAKE_MOCKABLE(Dma_GetIfcReg)(DMA_TypeDef *dma, uint32_t stream);
|
||||
uint32_t MAKE_MOCKABLE(Dma_GetDmeMask)(uint32_t stream);
|
||||
uint32_t MAKE_MOCKABLE(Dma_GetTeMask)(uint32_t stream);
|
||||
uint32_t MAKE_MOCKABLE(Dma_GetHtMask)(uint32_t stream);
|
||||
uint32_t MAKE_MOCKABLE(Dma_GetTcMask)(uint32_t stream);
|
||||
uint32_t MAKE_MOCKABLE(Dma_GetFeMask)(uint32_t stream);
|
||||
void MAKE_MOCKABLE(Dma_Init)(struct dmainfo_t *info, DMA_TypeDef *dma, uint32_t stream);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue