Reorganizing project
This commit is contained in:
parent
2d6567b1b2
commit
76ba80db36
51 changed files with 139 additions and 266 deletions
1
components/f4ll/inc/f4ll
Symbolic link
1
components/f4ll/inc/f4ll
Symbolic link
|
@ -0,0 +1 @@
|
|||
.
|
43
components/f4ll/inc/ll_consolehandler.h
Normal file
43
components/f4ll/inc/ll_consolehandler.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* ll_consolehandler.h
|
||||
*
|
||||
* Created on: Nov 7, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_CONSOLEHANDLER_H_
|
||||
#define LL_CONSOLEHANDLER_H_
|
||||
|
||||
#include "f4ll/ll_hsusart.h"
|
||||
#include "singleton.h"
|
||||
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class LL_ConsoleHandler: public LL_UsartCore, public Singleton<LL_ConsoleHandler>
|
||||
{
|
||||
friend class Singleton<LL_ConsoleHandler>;
|
||||
|
||||
public:
|
||||
// LL_UsartCore pure virtual function implementations
|
||||
virtual void ReceiverIdle(void);
|
||||
virtual void TransmissionComplete(void);
|
||||
virtual void RxDmaTransferComplete(void);
|
||||
virtual void RxDmaHalfTransfer(void);
|
||||
virtual void RxDmaError(LL_DmaHelper::DmaErrorType reason);
|
||||
virtual void TxDmaTransferComplete(void);
|
||||
virtual void TxDmaHalfTransfer(void);
|
||||
virtual void TxDmaError(LL_DmaHelper::DmaErrorType reason);
|
||||
|
||||
void PrintStats(uint8_t id, LL_HsUsart &usart);
|
||||
|
||||
private:
|
||||
LL_ConsoleHandler(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t streamRx, uint32_t streamTx);
|
||||
|
||||
char m_buffer[128];
|
||||
uint16_t m_used = 0;
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_CONSOLEHANDLER_H_ */
|
89
components/f4ll/inc/ll_crchandler.h
Normal file
89
components/f4ll/inc/ll_crchandler.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* ll_crchandler.h
|
||||
*
|
||||
* Created on: Oct 26, 2019
|
||||
* Author: compi
|
||||
*/
|
||||
|
||||
#ifndef LL_CRCHANDLER_H_
|
||||
#define LL_CRCHANDLER_H_
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
#include "f4ll/ll_dmahelper.h"
|
||||
#include "singleton.h"
|
||||
|
||||
extern "C" void _HandleCrcDmaIrq(void);
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class LL_CrcHandler : public Singleton<LL_CrcHandler>
|
||||
{
|
||||
friend class Singleton<LL_CrcHandler>;
|
||||
|
||||
public:
|
||||
struct ICallback
|
||||
{
|
||||
virtual void CrcSucceeded(uintptr_t callbackParam, uint32_t crc, int prio) = 0;
|
||||
virtual void CrcFailed(uintptr_t callbackParam, uint32_t crc, int prio) = 0;
|
||||
};
|
||||
|
||||
class SlotBase
|
||||
{
|
||||
friend class LL_CrcHandler;
|
||||
public:
|
||||
struct CrcTask {
|
||||
void const * volatile m_address; // changed to nullptr when execution starts
|
||||
uint16_t volatile m_wordCount;
|
||||
LL_CrcHandler::ICallback *m_callback;
|
||||
uintptr_t m_callbackParam;
|
||||
};
|
||||
|
||||
private:
|
||||
SlotBase *m_next = nullptr;
|
||||
uint8_t m_taskCount;
|
||||
virtual CrcTask& operator[](int index) = 0;
|
||||
|
||||
protected:
|
||||
SlotBase(unsigned int taskCount) : m_taskCount(taskCount) {}
|
||||
SlotBase() = delete;
|
||||
SlotBase(SlotBase const &other) = delete;
|
||||
};
|
||||
|
||||
// DON't try this at home! we "extend" LL_CrcHandler::m_tasks this way
|
||||
template <uint8_t n> class Slot : public SlotBase
|
||||
{
|
||||
public:
|
||||
Slot() : SlotBase(n) {}
|
||||
virtual CrcTask& operator[](int index) { return m_tasks[index]; }
|
||||
|
||||
private:
|
||||
Slot::CrcTask m_tasks[n];
|
||||
};
|
||||
|
||||
void AttachSlot(SlotBase &slot);
|
||||
bool Enqueue(SlotBase &slot, uint8_t prio, void const *address, uint16_t len, ICallback *cb, uintptr_t cbParam);
|
||||
uint32_t Compute(SlotBase &slot, uint8_t prio, void const *address, uint16_t len);
|
||||
|
||||
bool IsActive(SlotBase &slot, uint8_t prio) const;
|
||||
bool IsQueued(SlotBase &slot, uint8_t prio) const;
|
||||
bool IsRunning(SlotBase &slot, uint8_t prio) const;
|
||||
|
||||
void DmaTransferCompleted(void);
|
||||
|
||||
private:
|
||||
LL_CrcHandler(DMA_TypeDef *dma, uint32_t stream);
|
||||
|
||||
friend void ::_HandleCrcDmaIrq(void);
|
||||
void StartNextTask(void);
|
||||
void WaitResults(SlotBase &slot, uint8_t prio) const;
|
||||
|
||||
LL_DmaHelper m_dma;
|
||||
SlotBase * volatile m_firstSlot = nullptr;
|
||||
SlotBase * volatile m_activeSlot = nullptr;
|
||||
int volatile m_activePrio;
|
||||
};
|
||||
|
||||
|
||||
} // namespace f4ll
|
||||
|
||||
#endif /* LL_CRCHANDLER_H_ */
|
58
components/f4ll/inc/ll_dmahelper.h
Normal file
58
components/f4ll/inc/ll_dmahelper.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* ll_dmahelper.h
|
||||
*
|
||||
* Created on: Oct 25, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_DMAHELPER_H_
|
||||
#define LL_DMAHELPER_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class LL_DmaHelper {
|
||||
public:
|
||||
LL_DmaHelper(DMA_TypeDef *dma, uint32_t stream);
|
||||
LL_DmaHelper(LL_DmaHelper 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 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; }
|
||||
|
||||
enum class DmaErrorType {
|
||||
Transfer,
|
||||
DirectMode,
|
||||
Fifo
|
||||
};
|
||||
|
||||
private:
|
||||
DMA_TypeDef *m_dma;
|
||||
uint32_t m_stream;
|
||||
volatile uint32_t *m_isReg;
|
||||
volatile uint32_t *m_ifcReg;
|
||||
|
||||
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];
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_DMAHELPER_H_ */
|
111
components/f4ll/inc/ll_hsusart.h
Normal file
111
components/f4ll/inc/ll_hsusart.h
Normal file
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* ll_HsUsart.h
|
||||
*
|
||||
* Created on: Oct 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_HSUSART_H_
|
||||
#define LL_HSUSART_H_
|
||||
#include <platform/usart_ll.h>
|
||||
#include "f4ll/ll_usartcore.h"
|
||||
#include "f4ll/ll_crchandler.h"
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
struct DMAINFO;
|
||||
|
||||
class LL_HsUsart : public LL_CrcHandler::ICallback, public LL_UsartCore
|
||||
{
|
||||
public:
|
||||
LL_HsUsart(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t stream_rx, uint32_t stream_tx);
|
||||
|
||||
struct PacketHeader { // !!! size should be multiple of 4 !!!
|
||||
uint8_t startByte;
|
||||
uint8_t serial;
|
||||
uint8_t payloadLength;
|
||||
uint8_t hash;
|
||||
};
|
||||
|
||||
struct Packet {
|
||||
PacketHeader header;
|
||||
uint8_t payload[256+sizeof(uint32_t)]; // extra room for crc32
|
||||
} __attribute__((aligned));
|
||||
|
||||
struct Stats {
|
||||
uint32_t overrun = 0;
|
||||
uint32_t hdrError = 0;
|
||||
uint32_t payloadErrror = 0;
|
||||
uint32_t pep1 = 0;
|
||||
uint32_t pep2 = 0;
|
||||
uint32_t rxDmaError = 0;
|
||||
uint32_t txDmaError = 0;
|
||||
uint32_t rcvd = 0;
|
||||
uint32_t premature_hdr = 0;
|
||||
uint32_t premature_payload = 0;
|
||||
uint32_t sent = 0;
|
||||
uint32_t skiped = 0;
|
||||
};
|
||||
|
||||
struct IHsUsartCallback {
|
||||
virtual bool PacketReceived(LL_HsUsart *caller, uintptr_t userParam, Packet const &packet) = 0;
|
||||
};
|
||||
|
||||
// LL_CRCHandler::ICallback interface functions
|
||||
virtual void CrcSucceeded(uintptr_t callbackParam, uint32_t crc, int prio);
|
||||
virtual void CrcFailed(uintptr_t callbackParam, uint32_t crc, int prio);
|
||||
|
||||
// LL_UsartCore pure virtual function implementations
|
||||
virtual void ReceiverIdle(void);
|
||||
virtual void TransmissionComplete(void);
|
||||
virtual void RxDmaTransferComplete(void);
|
||||
virtual void RxDmaHalfTransfer(void);
|
||||
virtual void RxDmaError(LL_DmaHelper::DmaErrorType reason);
|
||||
virtual void TxDmaTransferComplete(void);
|
||||
virtual void TxDmaHalfTransfer(void);
|
||||
virtual void TxDmaError(LL_DmaHelper::DmaErrorType reason);
|
||||
|
||||
void PostPacket(uint8_t const *payload, uint8_t length, bool waitForCrcQueue = true);
|
||||
void SetupReceive(void);
|
||||
|
||||
void RxProcessed(bool second);
|
||||
uint8_t* GetTxPacketBuffer(void);
|
||||
USART_TypeDef* GetUsart(void);
|
||||
Stats const & GetStats(void);
|
||||
bool IsTxBusy(void);
|
||||
bool IsTxFailed(void);
|
||||
bool IsRxBusy(bool second);
|
||||
bool IsRxFailed(bool second);
|
||||
|
||||
void SetCallback(IHsUsartCallback* callback, uintptr_t callbackParam);
|
||||
|
||||
private:
|
||||
void BuildHeader(Packet &packet, uint8_t serialNo, uint8_t length);
|
||||
bool CheckHeader(PacketHeader &header);
|
||||
void SwitchRxBuffers(void);
|
||||
|
||||
struct Buffer {
|
||||
Packet packet;
|
||||
//transfer area ends here
|
||||
volatile bool busy = 0;
|
||||
volatile bool error = 0;
|
||||
uint16_t requestedLength = 0;
|
||||
uint32_t errorInfo = 0;
|
||||
};
|
||||
|
||||
static const uint8_t STARTMARKER = 0x95;
|
||||
|
||||
uint8_t m_rxSerialNo = -1;
|
||||
uint8_t m_txSerialNo = -1;
|
||||
Stats m_stats;
|
||||
bool m_rxBufferSelector = false;
|
||||
|
||||
LL_CrcHandler::Slot<2> m_crcSlot;
|
||||
IHsUsartCallback *m_userCallback = nullptr;
|
||||
uintptr_t m_userCallbackParam = 0;
|
||||
Buffer m_txBuffer;
|
||||
Buffer m_rxBuffers[2];
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* LL_HSUSART_H_ */
|
28
components/f4ll/inc/ll_memcpydma.h
Normal file
28
components/f4ll/inc/ll_memcpydma.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* llmemcpydma.h
|
||||
*
|
||||
* Created on: Nov 4, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_MEMCPY_DMA_H_
|
||||
#define LL_MEMCPY_DMA_H_
|
||||
#include "f4ll/ll_dmahelper.h"
|
||||
#include "singleton.h"
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
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);
|
||||
bool volatile m_busy = false;
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_MEMCPY_DMA_H_ */
|
51
components/f4ll/inc/ll_usartcore.h
Normal file
51
components/f4ll/inc/ll_usartcore.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* ll_dmadrivenusartcore.h
|
||||
*
|
||||
* Created on: Nov 4, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef LL_USARTCORE_H_
|
||||
#define LL_USARTCORE_H_
|
||||
#include <platform/usart_ll.h>
|
||||
|
||||
#include "f4ll/ll_dmahelper.h"
|
||||
|
||||
namespace f4ll {
|
||||
|
||||
class LL_UsartCore
|
||||
{
|
||||
public:
|
||||
static inline void HandleUsartIrq(LL_UsartCore *_this) { _this->UsartIsr(); }
|
||||
static inline void HandleRxDmaIrq(LL_UsartCore *_this) { _this->RxDmaIsr(); }
|
||||
static inline void HandleTxDmaIrq(LL_UsartCore *_this) { _this->TxDmaIsr(); }
|
||||
|
||||
protected:
|
||||
LL_UsartCore(USART_TypeDef *usart, DMA_TypeDef *dma, uint32_t streamRx, uint32_t streamTx);
|
||||
|
||||
virtual void ReceiverIdle() = 0;
|
||||
virtual void TransmissionComplete() = 0;
|
||||
|
||||
virtual void RxDmaTransferComplete() = 0;
|
||||
virtual void RxDmaHalfTransfer() = 0;
|
||||
virtual void RxDmaError(LL_DmaHelper::DmaErrorType reason) = 0;
|
||||
|
||||
virtual void TxDmaTransferComplete() = 0;
|
||||
virtual void TxDmaHalfTransfer() = 0;
|
||||
virtual void TxDmaError(LL_DmaHelper::DmaErrorType reason) = 0;
|
||||
|
||||
void SetupTransmit(void const *buffer, uint16_t length);
|
||||
void SetupReceive(void *buffer, uint16_t length);
|
||||
|
||||
void UsartIsr();
|
||||
void RxDmaIsr();
|
||||
void TxDmaIsr();
|
||||
|
||||
USART_TypeDef *m_usart;
|
||||
LL_DmaHelper m_rxDma;
|
||||
LL_DmaHelper m_txDma;
|
||||
};
|
||||
|
||||
} /* namespace f4ll */
|
||||
|
||||
#endif /* LL_USARTCORE_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue