LL_MemcpyDma
This commit is contained in:
parent
4de62c7f74
commit
bdc796a8ce
8 changed files with 45 additions and 19 deletions
|
@ -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 */
|
||||
|
||||
|
|
|
@ -12,5 +12,5 @@ USARTSTATUS g_uartStatuses[USARTCOUNT];
|
|||
CRCSTATUS g_crcStatus;
|
||||
|
||||
DMAINFO g_ConsoleTxDmaInfo;
|
||||
uint8_t g_statsBuf[128];
|
||||
uint8_t g_statsBuf[256];
|
||||
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "globals.h"
|
||||
|
||||
#include "ll_hsusart.h"
|
||||
#include "ll_memcpydma.h"
|
||||
|
||||
f4ll::LL_HsUsart *g_usarts[4];
|
||||
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@
|
|||
#include <stdlib.h>
|
||||
#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();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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<LL_MemcpyDma>, private LL_DmaHelper
|
||||
{
|
||||
friend class Singleton<LL_MemcpyDma>;
|
||||
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 */
|
||||
|
|
|
@ -10,8 +10,7 @@ public:
|
|||
static T &Init(Args &&... args)
|
||||
{
|
||||
static T instance{ std::forward<Args>(args)... };
|
||||
if(!m_instance)
|
||||
m_instance = &instance;
|
||||
m_instance = &instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue