diff --git a/Src/stm32f4xx_it.c b/Src/stm32f4xx_it.c index ceb5b6b..c18a418 100644 --- a/Src/stm32f4xx_it.c +++ b/Src/stm32f4xx_it.c @@ -35,6 +35,7 @@ extern "C" { } #include "globals_cpp.h" +#include "ll_memcpydma.h" extern "C" { @@ -427,7 +428,7 @@ void DMA2_Stream2_IRQHandler(void) void DMA2_Stream3_IRQHandler(void) { /* USER CODE BEGIN DMA2_Stream3_IRQn 0 */ - HandleMemcpyDmaIrq(); + f4ll::LL_MemcpyDma::Instance().DmaTransferCompleted(); /* USER CODE END DMA2_Stream3_IRQn 0 */ diff --git a/app/globals.c b/app/globals.c index 540cb61..edf988c 100644 --- a/app/globals.c +++ b/app/globals.c @@ -12,5 +12,5 @@ USARTSTATUS g_uartStatuses[USARTCOUNT]; CRCSTATUS g_crcStatus; DMAINFO g_ConsoleTxDmaInfo; -uint8_t g_statsBuf[128]; +uint8_t g_statsBuf[256]; diff --git a/app/globals.h b/app/globals.h index 526fd13..439f19c 100644 --- a/app/globals.h +++ b/app/globals.h @@ -19,6 +19,6 @@ extern USARTSTATUS g_uartStatuses[USARTCOUNT]; extern CRCSTATUS g_crcStatus; extern DMAINFO g_ConsoleTxDmaInfo; -extern uint8_t g_statsBuf[128]; +extern uint8_t g_statsBuf[256]; #endif /* GLOBALS_H_ */ diff --git a/app/globals_cpp.cpp b/app/globals_cpp.cpp index 6f0e59e..81e55f9 100644 --- a/app/globals_cpp.cpp +++ b/app/globals_cpp.cpp @@ -7,7 +7,7 @@ #include "globals.h" #include "ll_hsusart.h" +#include "ll_memcpydma.h" f4ll::LL_HsUsart *g_usarts[4]; - diff --git a/app/ll_testbed.cpp b/app/ll_testbed.cpp index d588b62..309846b 100644 --- a/app/ll_testbed.cpp +++ b/app/ll_testbed.cpp @@ -8,10 +8,12 @@ #include #include "ll_hsusart.h" #include "ll_crchandler.h" +#include "ll_memcpydma.h" extern "C" { #include "main.h" #include "globals.h" #include "strutil.h" + #include "config.h" } #include "globals_cpp.h" @@ -59,9 +61,9 @@ extern "C" void MainLoop() "Megszentsegtelenithetetlensegeskedeseitekert\r\n" "--------------------------------------------\r\n\0\0\0"; + f4ll::LL_MemcpyDma::Init(MEMCPY_DMA_ENGINE, MEMCPY_DMA_STREAM); f4ll::LL_CrcHandler::Init(DMA2, LL_DMA_STREAM_4); - f4ll::LL_CrcHandler::Slot<2> slt; f4ll::LL_HsUsart u1{ USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7 }; f4ll::LL_HsUsart u2{ USART2, DMA1, LL_DMA_STREAM_5, LL_DMA_STREAM_6 }; f4ll::LL_HsUsart u3{ USART3, DMA1, LL_DMA_STREAM_1, LL_DMA_STREAM_3 }; @@ -101,25 +103,26 @@ extern "C" void MainLoop() for(auto u : usarts) { if(!u->IsTxBusy() && send) { //DIAG_ENTER_BUSY(); - u->PostPacket(text2Send, sizeof(text2Send) - 1 - (rand() & randmask)); + auto len = sizeof(text2Send) - 1 - (rand() & randmask); + f4ll::LL_MemcpyDma::Instance().Copy(u->GetTxPacketBuffer(), text2Send, len); + u->PostPacket(nullptr, len); //DIAG_EXIT_BUSY(); } for(uint16_t rIdx = 0; rIdx < 2; ++rIdx) - if(u->IsRxBusy((bool)rIdx) || u->IsRxFailed(rIdx)) { + if(u->IsRxBusy((bool)rIdx) || u->IsRxFailed(rIdx)) u->RxProcessed((bool)rIdx); - } } if(tick - lastStatsTick > STATS_DELAY_MS) { _PrintStats((char*)g_statsBuf, statId, *usarts[statId], UART4, &g_ConsoleTxDmaInfo); lastStatsTick += STATS_DELAY_MS; ++statId; - if(statId >= USARTCOUNT) + if(statId >= sizeof(usarts) / sizeof(usarts[0])) statId = 0; } - uint32_t ein = LL_GPIO_ReadInputPort(KEY1_GPIO_Port); - if(!(ein & KEY1_Pin)) { - void (*fptr)(void) = (void (*)(void))(void*)0xa0000000; - fptr(); - } +// uint32_t ein = LL_GPIO_ReadInputPort(KEY1_GPIO_Port); +// if(!(ein & KEY1_Pin)) { +// void (*fptr)(void) = (void (*)(void))(void*)0xa0000000; +// fptr(); +// } } } diff --git a/lib/ll_memcpydma.cpp b/lib/ll_memcpydma.cpp index 7ea564b..64c52c3 100644 --- a/lib/ll_memcpydma.cpp +++ b/lib/ll_memcpydma.cpp @@ -15,4 +15,23 @@ LL_MemcpyDma::LL_MemcpyDma(DMA_TypeDef *dma, uint32_t stream) LL_DMA_EnableIT_TC(dma, stream); } +void* LL_MemcpyDma::Copy(void *dst, void const *src, uint16_t length) +{ + LL_DMA_SetM2MSrcAddress(GetDma(), GetStream(), (uint32_t)src); + LL_DMA_SetM2MDstAddress(GetDma(), GetStream(), (uint32_t)dst); + LL_DMA_SetDataLength(GetDma(), GetStream(), (length+3)/4 ); + m_busy = 1; + LL_DMA_EnableStream(GetDma(), GetStream()); + while(m_busy); + return dst; +} + +void LL_MemcpyDma::DmaTransferCompleted() +{ + if(*GetIsReg() & GetTcMask()) { // DMA transfer complete + *GetIcfReg() = GetTcMask(); + LL_DMA_DisableStream(GetDma(), GetStream()); + m_busy = 0; + } +} } /* namespace f4ll */ diff --git a/lib/ll_memcpydma.h b/lib/ll_memcpydma.h index 23dd0b1..c00ee1d 100644 --- a/lib/ll_memcpydma.h +++ b/lib/ll_memcpydma.h @@ -8,15 +8,19 @@ #ifndef LL_MEMCPY_DMA_H_ #define LL_MEMCPY_DMA_H_ #include "ll_dmahelper.h" +#include "singleton.h" namespace f4ll { -class LL_MemcpyDma : private LL_DmaHelper +class LL_MemcpyDma : public Singleton, private LL_DmaHelper { + friend class Singleton; public: + void* Copy(void *dst, void const *src, uint16_t length); + void DmaTransferCompleted(); +private: LL_MemcpyDma(DMA_TypeDef *dma, uint32_t stream); - void Copy(void *dst, void const *src, uint16_t length); - + bool volatile m_busy = false; }; } /* namespace f4ll */ diff --git a/lib/singleton.h b/lib/singleton.h index 8cd9886..b64c345 100644 --- a/lib/singleton.h +++ b/lib/singleton.h @@ -10,8 +10,7 @@ public: static T &Init(Args &&... args) { static T instance{ std::forward(args)... }; - if(!m_instance) - m_instance = &instance; + m_instance = &instance; return instance; }