tmp 3
This commit is contained in:
parent
3253c9413e
commit
a4e25d702b
14 changed files with 398 additions and 399 deletions
|
@ -24,16 +24,16 @@ private:
|
|||
console_handler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t streamRx, uint32_t streamTx);
|
||||
|
||||
// LL_UsartCore pure virtual function implementations
|
||||
virtual void ReceiverIdle(void);
|
||||
virtual void TransmissionComplete(void);
|
||||
virtual void FramingError(void);
|
||||
virtual void Overrun(void);
|
||||
virtual void RxDmaTransferComplete(void);
|
||||
virtual void RxDmaHalfTransfer(void);
|
||||
virtual void RxDmaError(dma_helper::DmaErrorType reason);
|
||||
virtual void TxDmaTransferComplete(void);
|
||||
virtual void TxDmaHalfTransfer(void);
|
||||
virtual void TxDmaError(dma_helper::DmaErrorType reason);
|
||||
virtual void receiver_idle(void);
|
||||
virtual void transmission_complete(void);
|
||||
virtual void framing_error(void);
|
||||
virtual void overrun(void);
|
||||
virtual void rx_dma_transfer_complete(void);
|
||||
virtual void rx_dma_half_transfer(void);
|
||||
virtual void rx_dma_error(dma_helper::dma_error_type reason);
|
||||
virtual void tx_dma_transfer_complete(void);
|
||||
virtual void tx_dma_half_transfer(void);
|
||||
virtual void tx_dma_error(dma_helper::dma_error_type reason);
|
||||
|
||||
char m_buffer[128];
|
||||
uint16_t m_used = 0;
|
||||
|
|
|
@ -1,96 +1,90 @@
|
|||
/*
|
||||
* ll_crchandler.h
|
||||
* ll_crc_handler.h
|
||||
*
|
||||
* Created on: Oct 26, 2019
|
||||
* Author: compi
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifndef LL_CRCHANDLER_H_
|
||||
#define LL_CRCHANDLER_H_
|
||||
#include <f4ll/dma_helper.h>
|
||||
#include <f4ll/singleton.h>
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
|
||||
extern "C" void _HandleCrcDmaIrq(void);
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class CrcHandler : public singleton<CrcHandler>
|
||||
class crc_handler : public singleton<crc_handler>
|
||||
{
|
||||
friend class singleton<CrcHandler>;
|
||||
friend class singleton<crc_handler>;
|
||||
|
||||
public:
|
||||
struct ICallback
|
||||
struct icallback
|
||||
{
|
||||
virtual void CrcSucceeded(uintptr_t callbackParam, uint32_t crc, uint8_t task) = 0;
|
||||
virtual void CrcFailed(uintptr_t callbackParam, uint32_t crc, uint8_t task) = 0;
|
||||
virtual void crc_succeeded(uintptr_t callback_param, uint32_t crc, uint8_t task) = 0;
|
||||
virtual void crc_failed(uintptr_t callback_param, uint32_t crc, uint8_t task) = 0;
|
||||
};
|
||||
|
||||
class SlotBase
|
||||
class slot_base
|
||||
{
|
||||
friend class CrcHandler;
|
||||
friend class crc_handler;
|
||||
|
||||
public:
|
||||
struct CrcTask
|
||||
struct crc_task
|
||||
{
|
||||
void const *m_address; // changed to nullptr when execution starts
|
||||
uint16_t m_wordCount;
|
||||
ICallback *m_callback;
|
||||
uintptr_t m_callbackParam;
|
||||
uint16_t m_word_count;
|
||||
icallback *m_callback;
|
||||
uintptr_t m_callback_param;
|
||||
};
|
||||
|
||||
private:
|
||||
SlotBase volatile *m_next = nullptr;
|
||||
uint8_t m_taskCount;
|
||||
slot_base volatile *m_next = nullptr;
|
||||
uint8_t m_task_count;
|
||||
|
||||
virtual CrcTask volatile &operator[](int index) volatile = 0;
|
||||
virtual crc_task volatile &operator[](int index) volatile = 0;
|
||||
|
||||
protected:
|
||||
SlotBase(unsigned int taskCount)
|
||||
: m_taskCount(taskCount)
|
||||
slot_base(unsigned int task_count)
|
||||
: m_task_count(task_count)
|
||||
{
|
||||
}
|
||||
SlotBase() = delete;
|
||||
SlotBase(SlotBase const &other) = delete;
|
||||
slot_base() = delete;
|
||||
slot_base(slot_base const &other) = delete;
|
||||
};
|
||||
|
||||
template <uint8_t n> class Slot : public SlotBase
|
||||
template <uint8_t n> class slot : public slot_base
|
||||
{
|
||||
public:
|
||||
Slot()
|
||||
: SlotBase(n)
|
||||
slot()
|
||||
: slot_base(n)
|
||||
{
|
||||
}
|
||||
virtual CrcTask volatile &operator[](int index) volatile { return m_tasks[index]; }
|
||||
virtual crc_task volatile &operator[](int index) volatile { return m_tasks[index]; }
|
||||
|
||||
private:
|
||||
Slot::CrcTask m_tasks[n];
|
||||
slot::crc_task m_tasks[n];
|
||||
};
|
||||
|
||||
void AttachSlot(SlotBase &slot);
|
||||
bool Enqueue(SlotBase &slot, uint8_t task, void const *address, uint16_t len, ICallback *cb, uintptr_t cbParam);
|
||||
uint32_t Compute(SlotBase &slot, uint8_t task, void const *address, uint16_t len);
|
||||
void attach_slot(slot_base &slot);
|
||||
bool enqueue(slot_base &slot, uint8_t task, void const *address, uint16_t len, icallback *cb, uintptr_t cb_param);
|
||||
uint32_t compute(slot_base &slot, uint8_t task, void const *address, uint16_t len);
|
||||
|
||||
bool IsActive(SlotBase &slot, uint8_t task) const;
|
||||
bool IsQueued(SlotBase &slot, uint8_t task) const;
|
||||
bool IsRunning(SlotBase &slot, uint8_t task) const;
|
||||
bool is_active(slot_base &slot, uint8_t task) const;
|
||||
bool is_queued(slot_base &slot, uint8_t task) const;
|
||||
bool is_running(slot_base &slot, uint8_t task) const;
|
||||
|
||||
void DmaTransferCompleted(void);
|
||||
void dma_transfer_completed(void);
|
||||
|
||||
private:
|
||||
CrcHandler(DMA_TypeDef *dma, uint32_t stream);
|
||||
crc_handler(DMA_TypeDef *dma, uint32_t stream);
|
||||
|
||||
friend void ::_HandleCrcDmaIrq(void);
|
||||
void StartNextTask(void);
|
||||
void WaitResults(SlotBase &slot, uint8_t task) const;
|
||||
void start_next_task(void);
|
||||
void wait_results(slot_base &slot, uint8_t task) const;
|
||||
|
||||
dma_helper m_dma;
|
||||
SlotBase volatile *m_firstSlot = nullptr;
|
||||
SlotBase volatile *m_activeSlot = nullptr;
|
||||
slot_base volatile *m_first_slot = nullptr;
|
||||
slot_base volatile *m_active_slot = nullptr;
|
||||
int volatile m_activeTask;
|
||||
};
|
||||
|
||||
} // namespace f4ll
|
||||
|
||||
#endif /* LL_CRCHANDLER_H_ */
|
||||
|
|
|
@ -19,40 +19,35 @@ public:
|
|||
dma_helper(DMA_TypeDef *dma, uint32_t stream);
|
||||
dma_helper(dma_helper const &base) = default;
|
||||
|
||||
inline DMA_TypeDef *GetDma() const { return m_dma; }
|
||||
inline uint32_t GetStream() const { return m_stream; }
|
||||
inline volatile uint32_t *GetIsReg() const { return m_isReg; }
|
||||
inline volatile uint32_t *GetIfcReg() const { return m_ifcReg; }
|
||||
inline uint32_t GetFeMask() const { return m_FEMasks[m_stream]; }
|
||||
inline uint32_t GetDmeMask() const { return m_DMEMasks[m_stream]; }
|
||||
inline uint32_t GetTeMask() const { return m_TEMasks[m_stream]; }
|
||||
inline uint32_t GetHtMask() const { return m_HTMasks[m_stream]; }
|
||||
inline uint32_t GetTcMask() const { return m_TCMasks[m_stream]; }
|
||||
inline DMA_TypeDef *get_dma() const { return m_dma; }
|
||||
inline uint32_t get_stream() const { return m_stream; }
|
||||
inline volatile uint32_t *get_is_reg() const { return m_is_reg; }
|
||||
inline volatile uint32_t *get_ifc_reg() const { return m_ifc_reg; }
|
||||
inline uint32_t get_fe_mask() const { return m_fe_masks[m_stream]; }
|
||||
inline uint32_t get_dme_mask() const { return m_dme_masks[m_stream]; }
|
||||
inline uint32_t get_te_mask() const { return m_te_masks[m_stream]; }
|
||||
inline uint32_t get_ht_mask() const { return m_ht_masks[m_stream]; }
|
||||
inline uint32_t get_tc_mask() const { return m_tc_masks[m_stream]; }
|
||||
|
||||
inline bool IsEnabledIt_HT() { return LL_DMA_IsEnabledIT_HT(m_dma, m_stream) != 0; }
|
||||
inline bool IsEnabledIt_TE() { return LL_DMA_IsEnabledIT_TE(m_dma, m_stream) != 0; }
|
||||
inline bool IsEnabledIt_TC() { return LL_DMA_IsEnabledIT_TC(m_dma, m_stream) != 0; }
|
||||
inline bool IsEnabledIt_DME() { return LL_DMA_IsEnabledIT_DME(m_dma, m_stream) != 0; }
|
||||
inline bool IsEnabledIt_FE() { return LL_DMA_IsEnabledIT_FE(m_dma, m_stream) != 0; }
|
||||
inline bool is_enabled_it_ht() { return LL_DMA_IsEnabledIT_HT(m_dma, m_stream) != 0; }
|
||||
inline bool is_enabled_it_te() { return LL_DMA_IsEnabledIT_TE(m_dma, m_stream) != 0; }
|
||||
inline bool is_enabled_it_tc() { return LL_DMA_IsEnabledIT_TC(m_dma, m_stream) != 0; }
|
||||
inline bool is_enabled_it_dme() { return LL_DMA_IsEnabledIT_DME(m_dma, m_stream) != 0; }
|
||||
inline bool is_enabled_it_fe() { return LL_DMA_IsEnabledIT_FE(m_dma, m_stream) != 0; }
|
||||
|
||||
enum class DmaErrorType
|
||||
{
|
||||
Transfer,
|
||||
DirectMode,
|
||||
Fifo
|
||||
};
|
||||
enum class dma_error_type { transfer, direct_mode, fifo };
|
||||
|
||||
private:
|
||||
DMA_TypeDef *m_dma;
|
||||
uint32_t m_stream;
|
||||
volatile uint32_t *m_isReg;
|
||||
volatile uint32_t *m_ifcReg;
|
||||
volatile uint32_t *m_is_reg;
|
||||
volatile uint32_t *m_ifc_reg;
|
||||
|
||||
static const uint32_t m_FEMasks[8];
|
||||
static const uint32_t m_DMEMasks[8];
|
||||
static const uint32_t m_TEMasks[8];
|
||||
static const uint32_t m_HTMasks[8];
|
||||
static const uint32_t m_TCMasks[8];
|
||||
static const uint32_t m_fe_masks[8];
|
||||
static const uint32_t m_dme_masks[8];
|
||||
static const uint32_t m_te_masks[8];
|
||||
static const uint32_t m_ht_masks[8];
|
||||
static const uint32_t m_tc_masks[8];
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
|
|
@ -4,27 +4,24 @@
|
|||
* Created on: Nov 4, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#ifndef LL_MEMCPY_DMA_H_
|
||||
#define LL_MEMCPY_DMA_H_
|
||||
#include <f4ll/dma_helper.h>
|
||||
#include <f4ll/singleton.h>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class MemcpyDma : public singleton<MemcpyDma>, private dma_helper
|
||||
class memcpy_dma : public singleton<memcpy_dma>, private dma_helper
|
||||
{
|
||||
friend class singleton<MemcpyDma>;
|
||||
friend class singleton<memcpy_dma>;
|
||||
|
||||
public:
|
||||
void *Copy(void *dst, void const *src, uint16_t length);
|
||||
void DmaTransferCompleted();
|
||||
void *copy(void *dst, void const *src, uint16_t length);
|
||||
void dma_transfer_completed();
|
||||
|
||||
private:
|
||||
MemcpyDma(DMA_TypeDef *dma, uint32_t stream);
|
||||
memcpy_dma(DMA_TypeDef *dma, uint32_t stream);
|
||||
bool volatile m_busy = false;
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_MEMCPY_DMA_H_ */
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace f4ll {
|
|||
|
||||
struct DMAINFO;
|
||||
|
||||
class PacketUsart : public CrcHandler::ICallback, public usart_core
|
||||
class PacketUsart : public crc_handler::icallback, public usart_core
|
||||
{
|
||||
// friend class UsartCore;
|
||||
public:
|
||||
|
@ -56,9 +56,9 @@ public:
|
|||
virtual bool PacketReceived(PacketUsart *caller, uintptr_t userParam, Packet const &packet) = 0;
|
||||
};
|
||||
|
||||
// CRCHandler::ICallback interface functions
|
||||
virtual void CrcSucceeded(uintptr_t callbackParam, uint32_t crc, uint8_t task);
|
||||
virtual void CrcFailed(uintptr_t callbackParam, uint32_t crc, uint8_t task);
|
||||
// crc_handler::ICallback interface functions
|
||||
virtual void crc_succeeded(uintptr_t callbackParam, uint32_t crc, uint8_t task);
|
||||
virtual void crc_failed(uintptr_t callbackParam, uint32_t crc, uint8_t task);
|
||||
|
||||
void PostPacket(uint8_t const *payload, uint8_t length, bool waitForCrcQueue = true);
|
||||
void SetupReceive(void);
|
||||
|
@ -83,16 +83,16 @@ private:
|
|||
void SwitchRxBuffers(void);
|
||||
|
||||
// UsartCore pure virtual function implementations
|
||||
virtual void ReceiverIdle(void);
|
||||
virtual void TransmissionComplete(void);
|
||||
virtual void FramingError(void);
|
||||
virtual void Overrun(void);
|
||||
virtual void RxDmaTransferComplete(void);
|
||||
virtual void RxDmaHalfTransfer(void);
|
||||
virtual void RxDmaError(dma_helper::DmaErrorType reason);
|
||||
virtual void TxDmaTransferComplete(void);
|
||||
virtual void TxDmaHalfTransfer(void);
|
||||
virtual void TxDmaError(dma_helper::DmaErrorType reason);
|
||||
virtual void receiver_idle(void);
|
||||
virtual void transmission_complete(void);
|
||||
virtual void framing_error(void);
|
||||
virtual void overrun(void);
|
||||
virtual void rx_dma_transfer_complete(void);
|
||||
virtual void rx_dma_half_transfer(void);
|
||||
virtual void rx_dma_error(dma_helper::dma_error_type reason);
|
||||
virtual void tx_dma_transfer_complete(void);
|
||||
virtual void tx_dma_half_transfer(void);
|
||||
virtual void tx_dma_error(dma_helper::dma_error_type reason);
|
||||
|
||||
struct Buffer
|
||||
{
|
||||
|
@ -111,7 +111,7 @@ private:
|
|||
Stats m_stats;
|
||||
bool m_rxBufferSelector = false;
|
||||
|
||||
CrcHandler::Slot<2> m_crcSlot;
|
||||
crc_handler::slot<2> m_crcSlot;
|
||||
IHsUsartCallback *m_userCallback = nullptr;
|
||||
uintptr_t m_userCallbackParam = 0;
|
||||
Buffer m_txBuffer;
|
||||
|
|
|
@ -16,37 +16,37 @@ namespace f4ll {
|
|||
class usart_core
|
||||
{
|
||||
public:
|
||||
static inline void HandleUsartIrq(usart_core *_this) { _this->UsartIsr(); }
|
||||
static inline void HandleRxDmaIrq(usart_core *_this) { _this->RxDmaIsr(); }
|
||||
static inline void HandleTxDmaIrq(usart_core *_this) { _this->TxDmaIsr(); }
|
||||
static inline void usart_isr(usart_core *_this) { _this->usart_isr(); }
|
||||
static inline void rx_dma_isr(usart_core *_this) { _this->rx_dma_isr(); }
|
||||
static inline void tx_dma_isr(usart_core *_this) { _this->tx_dma_isr(); }
|
||||
|
||||
void SetupTransmit(void const *buffer, uint16_t length);
|
||||
void SetupReceive(void *buffer, uint16_t length);
|
||||
void setup_transmit(void const *buffer, uint16_t length);
|
||||
void setup_receive(void *buffer, uint16_t length);
|
||||
|
||||
protected:
|
||||
usart_core(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t streamRx, uint32_t streamTx);
|
||||
usart_core(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t stream_rx, uint32_t stream_tx);
|
||||
|
||||
USART_TypeDef *m_usart;
|
||||
dma_helper m_rxDma;
|
||||
dma_helper m_txDma;
|
||||
dma_helper m_rx_dma;
|
||||
dma_helper m_tx_dma;
|
||||
|
||||
private:
|
||||
virtual void ReceiverIdle(void) = 0;
|
||||
virtual void TransmissionComplete(void) = 0;
|
||||
virtual void FramingError(void) = 0;
|
||||
virtual void Overrun(void) = 0;
|
||||
virtual void receiver_idle(void) = 0;
|
||||
virtual void transmission_complete(void) = 0;
|
||||
virtual void framing_error(void) = 0;
|
||||
virtual void overrun(void) = 0;
|
||||
|
||||
virtual void RxDmaTransferComplete(void) = 0;
|
||||
virtual void RxDmaHalfTransfer(void) = 0;
|
||||
virtual void RxDmaError(dma_helper::DmaErrorType reason) = 0;
|
||||
virtual void rx_dma_transfer_complete(void) = 0;
|
||||
virtual void rx_dma_half_transfer(void) = 0;
|
||||
virtual void rx_dma_error(dma_helper::dma_error_type reason) = 0;
|
||||
|
||||
virtual void TxDmaTransferComplete(void) = 0;
|
||||
virtual void TxDmaHalfTransfer(void) = 0;
|
||||
virtual void TxDmaError(dma_helper::DmaErrorType reason) = 0;
|
||||
virtual void tx_dma_transfer_complete(void) = 0;
|
||||
virtual void tx_dma_half_transfer(void) = 0;
|
||||
virtual void tx_dma_error(dma_helper::dma_error_type reason) = 0;
|
||||
|
||||
void UsartIsr();
|
||||
void RxDmaIsr();
|
||||
void TxDmaIsr();
|
||||
void usart_isr();
|
||||
void rx_dma_isr();
|
||||
void tx_dma_isr();
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue