big refactoring and features added
This commit is contained in:
68
App/Devices/uart_transport.c
Normal file
68
App/Devices/uart_transport.c
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* @file uart_transport.c
|
||||
* @brief USART1 transmit helpers used by the application core.
|
||||
*/
|
||||
|
||||
#include "uart_transport.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
static volatile uint8_t g_dma_busy = 0u;
|
||||
|
||||
void uart_transport_init(void)
|
||||
{
|
||||
LL_DMA_DisableStream(DMA2, LL_DMA_STREAM_7);
|
||||
LL_DMA_ClearFlag_TC7(DMA2);
|
||||
LL_DMA_ClearFlag_TE7(DMA2);
|
||||
LL_USART_EnableDMAReq_TX(USART1);
|
||||
LL_DMA_EnableIT_TC(DMA2, LL_DMA_STREAM_7);
|
||||
LL_DMA_EnableIT_TE(DMA2, LL_DMA_STREAM_7);
|
||||
g_dma_busy = 0u;
|
||||
}
|
||||
|
||||
void uart_transport_reset(void)
|
||||
{
|
||||
g_dma_busy = 0u;
|
||||
}
|
||||
|
||||
void uart_transport_send_blocking(const uint8_t *data, uint16_t size)
|
||||
{
|
||||
uint16_t index;
|
||||
|
||||
for (index = 0u; index < size; ++index)
|
||||
{
|
||||
while (!LL_USART_IsActiveFlag_TXE(USART1))
|
||||
{
|
||||
}
|
||||
LL_USART_TransmitData8(USART1, data[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void uart_transport_send_dma(const uint8_t *data, uint16_t size)
|
||||
{
|
||||
while (g_dma_busy != 0u)
|
||||
{
|
||||
}
|
||||
|
||||
LL_DMA_DisableStream(DMA2, LL_DMA_STREAM_7);
|
||||
LL_DMA_ClearFlag_TC7(DMA2);
|
||||
LL_DMA_ClearFlag_TE7(DMA2);
|
||||
LL_DMA_ConfigAddresses(DMA2,
|
||||
LL_DMA_STREAM_7,
|
||||
(uint32_t)data,
|
||||
LL_USART_DMA_GetRegAddr(USART1, LL_USART_DMA_REG_DATA_TRANSMIT),
|
||||
LL_DMA_GetDataTransferDirection(DMA2, LL_DMA_STREAM_7));
|
||||
LL_DMA_SetDataLength(DMA2, LL_DMA_STREAM_7, size);
|
||||
g_dma_busy = 1u;
|
||||
LL_DMA_EnableStream(DMA2, LL_DMA_STREAM_7);
|
||||
}
|
||||
|
||||
void uart_transport_mark_dma_complete(void)
|
||||
{
|
||||
g_dma_busy = 0u;
|
||||
}
|
||||
|
||||
bool uart_transport_is_dma_busy(void)
|
||||
{
|
||||
return g_dma_busy != 0u;
|
||||
}
|
||||
Reference in New Issue
Block a user