More elegant fsl::Task implementation

This commit is contained in:
Attila Body 2021-11-09 00:31:53 +01:00
parent 7eedbfdf9b
commit 0111f3d210
9 changed files with 301 additions and 19 deletions

View file

@ -16,7 +16,7 @@
namespace f4ll_cpp {
template<unsigned int bufSize> class SerialConsole : protected UartBase
template<size_t bufSize> class SerialConsole : protected UartBase
{
public:
struct Buffer {
@ -52,7 +52,7 @@ private:
void *m_callbackUserParam;
};
template<unsigned int bufSize> SerialConsole<bufSize>::SerialConsole(
template<size_t bufSize> SerialConsole<bufSize>::SerialConsole(
USART_TypeDef *uart, DMA_TypeDef *dma, uint32_t stream_rx, uint32_t stream_tx,
ISerialConsoleCallback *callback, void *callbackUserParam
)
@ -63,13 +63,13 @@ template<unsigned int bufSize> SerialConsole<bufSize>::SerialConsole(
SetupReceive(m_rxBuffers[m_activeRxBuffer].buffer, bufSize);
}
template<unsigned int bufSize> void SerialConsole<bufSize>::SetupTransmit(void *buffer, uint16_t length)
template<size_t bufSize> void SerialConsole<bufSize>::SetupTransmit(void *buffer, uint16_t length)
{
m_txBuffer.busy = true;
UartBase::SetupTransmit(buffer, length);
}
template<unsigned int bufSize> void SerialConsole<bufSize>::HandleRxDmaIrq()
template<size_t bufSize> void SerialConsole<bufSize>::HandleRxDmaIrq()
{
if(*m_rxDma.GetIsReg() & m_rxDma.GetTcMask()) {
*m_rxDma.GetIfcReg() = m_rxDma.GetTcMask();
@ -87,7 +87,7 @@ template<unsigned int bufSize> void SerialConsole<bufSize>::HandleRxDmaIrq()
SetupReceive(m_rxBuffers[m_activeRxBuffer].buffer, bufSize);
}
template<unsigned int bufSize> void SerialConsole<bufSize>::HandleTxDmaIrq()
template<size_t bufSize> void SerialConsole<bufSize>::HandleTxDmaIrq()
{
if(*m_txDma.GetIsReg() & m_txDma.GetTcMask()) { // DMA transfer complete
*m_txDma.GetIfcReg() = m_txDma.GetTcMask();
@ -102,7 +102,7 @@ template<unsigned int bufSize> void SerialConsole<bufSize>::HandleTxDmaIrq()
}
}
template<unsigned int bufSize> void SerialConsole<bufSize>::HandleUsartIrq()
template<size_t bufSize> void SerialConsole<bufSize>::HandleUsartIrq()
{
if(LL_USART_IsActiveFlag_IDLE(m_uart) && LL_USART_IsEnabledIT_IDLE(m_uart)) { // receiver idle
// we assume that new line marker will arrive without an idle cycle even if it is CRLF
@ -136,7 +136,7 @@ template<unsigned int bufSize> void SerialConsole<bufSize>::HandleUsartIrq()
}
}
template<unsigned int bufSize> void SerialConsole<bufSize>::Send(char const *buffer, uint8_t length)
template<size_t bufSize> void SerialConsole<bufSize>::Send(char const *buffer, uint8_t length)
{
if(!length) {
auto computedLength = strlen(buffer);
@ -150,7 +150,7 @@ template<unsigned int bufSize> void SerialConsole<bufSize>::Send(char const *buf
}
}
template<unsigned int bufSize> void SerialConsole<bufSize>::SendLine(char const *buffer, uint8_t length)
template<size_t bufSize> void SerialConsole<bufSize>::SendLine(char const *buffer, uint8_t length)
{
if(!length) {
auto computedLength = strlen(buffer);