re-structured f4ll_c (introducing src, inc)
This commit is contained in:
parent
f2fe20b3a4
commit
b98e0657ca
15 changed files with 4 additions and 3 deletions
28
components/f4ll_c/inc/f4ll_c/consolehandler.h
Normal file
28
components/f4ll_c/inc/f4ll_c/consolehandler.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* interrupt.h
|
||||
*
|
||||
* Created on: Aug 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef CONSOLEHANDLER_H_
|
||||
#define CONSOLEHANDLER_H_
|
||||
|
||||
#include "usart.h"
|
||||
#include "f4ll_c/dmahelper.h"
|
||||
#include "f4ll_c/packetusart.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void Con_HandleTxDmaIrq(struct dmainfo_t *info, USART_TypeDef *usart);
|
||||
void Con_HandleUsartIrq(USART_TypeDef *usart);
|
||||
|
||||
void Con_PrintStats(char *buffer, uint8_t id, struct usart_stats *stats, USART_TypeDef *usart, struct dmainfo_t *dmaInfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONSOLEHANDLER_H_ */
|
83
components/f4ll_c/inc/f4ll_c/crcscheduler.h
Normal file
83
components/f4ll_c/inc/f4ll_c/crcscheduler.h
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* interrupt.h
|
||||
*
|
||||
* Created on: Aug 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef CRC_HANDLER_H_
|
||||
#define CRC_HANDLER_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef HAVE_CONFIG
|
||||
#include "config.h"
|
||||
#endif // HAVE_CONFIG
|
||||
|
||||
#include <platform/crc_ll.h>
|
||||
#include <f4ll_c/dmahelper.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct crcslottask_t {
|
||||
void * volatile address;
|
||||
uint16_t wordCount;
|
||||
void (*callback)(void*, uint32_t, uint8_t);
|
||||
void *callbackParam;
|
||||
};
|
||||
|
||||
struct crcslotlistitem_t {
|
||||
uint16_t count;
|
||||
struct crcslotlistitem_t *next;
|
||||
struct crcslottask_t *tasks;
|
||||
};
|
||||
|
||||
struct crcstatus_t {
|
||||
CRC_TypeDef *crcUnit;
|
||||
struct dmainfo_t dmaInfo;
|
||||
struct crcslotlistitem_t *activeSlot;
|
||||
uint8_t activeTask;
|
||||
struct crcslotlistitem_t *firstSlot;
|
||||
};
|
||||
|
||||
void Crc_InitStatus(struct crcstatus_t *status, CRC_TypeDef *crcUnit, DMA_TypeDef *dma, uint32_t stream);
|
||||
|
||||
uint8_t Crc_GetActiveTask(struct crcslotlistitem_t **slot_out, struct crcstatus_t volatile *status);
|
||||
|
||||
uint8_t Crc_IsSlotQueued(struct crcslotlistitem_t *slot, uint8_t task);
|
||||
|
||||
uint8_t Crc_IsSlotBusy(struct crcslotlistitem_t *slot, uint8_t task);
|
||||
|
||||
void Crc_WaitResults(struct crcstatus_t *status, struct crcslotlistitem_t *slot, uint8_t task);
|
||||
|
||||
void Crc_AttachTask(struct crcstatus_t *status, struct crcslotlistitem_t *slot, struct crcslottask_t *tasks, uint8_t taskCount);
|
||||
|
||||
uint8_t Crc_Enqueue(struct crcstatus_t *status, struct crcslotlistitem_t *slot, uint8_t task,
|
||||
void *address, uint16_t len, void (*callback)(void*, uint32_t, uint8_t), void* callbackParam);
|
||||
uint32_t Crc_Compute(struct crcstatus_t *status, struct crcslotlistitem_t *slot, uint8_t task, void *address, uint16_t len);
|
||||
void Crc_HandleDmaIrq(struct crcstatus_t *status);
|
||||
|
||||
// !!!PRIVATE!!! exposed only to make mocking possible
|
||||
void Crc_StartNextTask(struct crcstatus_t *status);
|
||||
|
||||
|
||||
#ifdef UNITTEST
|
||||
DECLARE_MOCK(Crc_InitStatus);
|
||||
DECLARE_MOCK(Crc_GetActiveTask);
|
||||
DECLARE_MOCK(Crc_IsSlotQueued);
|
||||
DECLARE_MOCK(Crc_IsSlotBusy);
|
||||
DECLARE_MOCK(Crc_WaitResults);
|
||||
DECLARE_MOCK(Crc_AttachTask);
|
||||
DECLARE_MOCK(Crc_Enqueue);
|
||||
DECLARE_MOCK(Crc_Compute);
|
||||
DECLARE_MOCK(Crc_HandleDmaIrq);
|
||||
DECLARE_MOCK(Crc_StartNextTask);
|
||||
#endif // UNITTEST
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CRC_HANDLER_H_ */
|
57
components/f4ll_c/inc/f4ll_c/dmahelper.h
Normal file
57
components/f4ll_c/inc/f4ll_c/dmahelper.h
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* dma_helper.h
|
||||
*
|
||||
* Created on: Sep 18, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef DMA_HELPER_H_
|
||||
#define DMA_HELPER_H_
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
|
||||
#ifndef DECLARE_MOCK
|
||||
#define DECLARE_MOCK(x)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct dmainfo_t {
|
||||
DMA_TypeDef *dma;
|
||||
uint32_t stream;
|
||||
volatile uint32_t *isReg;
|
||||
volatile uint32_t *ifcReg;
|
||||
uint32_t feMask;
|
||||
uint32_t dmeMask;
|
||||
uint32_t teMask;
|
||||
uint32_t htMask;
|
||||
uint32_t tcMask;
|
||||
};
|
||||
|
||||
volatile uint32_t* Dma_GetIsReg(DMA_TypeDef *dma, uint32_t stream);
|
||||
volatile uint32_t* Dma_GetIfcReg(DMA_TypeDef *dma, uint32_t stream);
|
||||
uint32_t Dma_GetDmeMask(uint32_t stream);
|
||||
uint32_t Dma_GetTeMask(uint32_t stream);
|
||||
uint32_t Dma_GetHtMask(uint32_t stream);
|
||||
uint32_t Dma_GetTcMask(uint32_t stream);
|
||||
uint32_t Dma_GetFeMask(uint32_t stream);
|
||||
void Dma_Init(struct dmainfo_t *info, DMA_TypeDef *dma, uint32_t stream);
|
||||
|
||||
#ifdef UNITTEST
|
||||
DECLARE_MOCK(Dma_GetIsReg);
|
||||
DECLARE_MOCK(Dma_GetIfcReg);
|
||||
DECLARE_MOCK(Dma_GetDmeMask);
|
||||
DECLARE_MOCK(Dma_GetTeMask);
|
||||
DECLARE_MOCK(Dma_GetHtMask);
|
||||
DECLARE_MOCK(Dma_GetTcMask);
|
||||
DECLARE_MOCK(Dma_GetFeMask);
|
||||
DECLARE_MOCK(Dma_Init);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* DMA_HELPER_H_ */
|
32
components/f4ll_c/inc/f4ll_c/memcpydma.h
Normal file
32
components/f4ll_c/inc/f4ll_c/memcpydma.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* memcpy_dma.h
|
||||
*
|
||||
* Created on: Oct 1, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef MEMCPY_DMA_H_
|
||||
#define MEMCPY_DMA_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <platform/dma_ll.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void Mcd_Init(DMA_TypeDef *dma, uint32_t stream);
|
||||
void * Mcd_Copy(void *dst, void const *src, size_t length);
|
||||
void Mcd_HandleDmaIrq(void);
|
||||
|
||||
#ifdef UNITTEST
|
||||
DECLARE_MOCK(Mcd_Init);
|
||||
DECLARE_MOCK(Mcd_Copy);
|
||||
DECLARE_MOCK(Mcd_HandleDmaIrq);
|
||||
#endif // UNITTEST
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MEMCPY_DMA_H_ */
|
125
components/f4ll_c/inc/f4ll_c/packetusart.h
Normal file
125
components/f4ll_c/inc/f4ll_c/packetusart.h
Normal file
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* usart_handler.h
|
||||
*
|
||||
* Created on: Sep 16, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef USART_HANDLER_H_
|
||||
#define USART_HANDLER_H_
|
||||
#include <inttypes.h>
|
||||
#include <platform/usart_ll.h>
|
||||
#include "f4ll_c/dmahelper.h"
|
||||
#include <f4ll_c/crcscheduler.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct usart_buffer_t;
|
||||
struct usartstatus_t;
|
||||
struct usartpacket_t;
|
||||
|
||||
typedef void (*pku_packetreceivedcallback_t)(void *userParam, struct usart_buffer_t *buffer);
|
||||
|
||||
void Pu_Init(
|
||||
struct usartstatus_t *st, USART_TypeDef *usart, DMA_TypeDef *dma,
|
||||
uint32_t stream_rx, uint32_t stream_tx,
|
||||
struct crcstatus_t *crcStatus,
|
||||
pku_packetreceivedcallback_t packetReceivedCallback, void * packetReceivedCallbackParam);
|
||||
|
||||
uint8_t* Pu_GetTxBuffer(struct usartstatus_t *status);
|
||||
|
||||
uint8_t Pu_Post(struct usartstatus_t *status, uint8_t const *payload, uint8_t length, struct crcstatus_t *crcStatus, uint8_t waitForCrcQueue);
|
||||
void Pu_SetupReceive(struct usartstatus_t *status);
|
||||
void Pu_SetupTransmit(USART_TypeDef *usart, DMA_TypeDef* dma, uint32_t stream, void *buffer, uint32_t length);
|
||||
void Pu_ConsumePacket(struct usartstatus_t *status, uint8_t packetIndex);
|
||||
|
||||
void Pu_HandleRxDmaIrq(struct usartstatus_t *status);
|
||||
void Pu_HandleTxDmaIrq(struct usartstatus_t *status);
|
||||
void Pu_HandleUsartIrq(struct usartstatus_t *status);
|
||||
|
||||
// !!!Private!!! exposed only to make unit testing possible
|
||||
void Pu_RxCrcComputedCallback(void *callbackParm, uint32_t calculatedCrc, uint8_t success);
|
||||
uint8_t Pu_CheckHeader(struct usartpacket_t *packet);
|
||||
|
||||
DECLARE_MOCK(Pu_Init);
|
||||
DECLARE_MOCK(Pu_GetTxBuffer);
|
||||
DECLARE_MOCK(Pu_Post);
|
||||
DECLARE_MOCK(Pu_SetupReceive);
|
||||
DECLARE_MOCK(Pu_SetupTransmit);
|
||||
DECLARE_MOCK(Pu_ConsumePacket);
|
||||
DECLARE_MOCK(Pu_ConsumePacket);
|
||||
DECLARE_MOCK(Pu_HandleRxDmaIrq);
|
||||
DECLARE_MOCK(Pu_HandleTxDmaIrq);
|
||||
DECLARE_MOCK(Pu_HandleUsartIrq);
|
||||
DECLARE_MOCK(Pu_RxCrcComputedCallback);
|
||||
DECLARE_MOCK(Pu_CheckHeader);
|
||||
|
||||
/******************************************************************************************
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
struct usart_stats {
|
||||
uint32_t overrun;
|
||||
uint32_t hdrError;
|
||||
uint32_t lastErrHdr;
|
||||
uint32_t payloadErrror;
|
||||
uint32_t pep1, pep2;
|
||||
uint32_t dmaError;
|
||||
uint32_t rcvd;
|
||||
uint32_t premature_hdr;
|
||||
uint32_t premature_payload;
|
||||
uint32_t sent;
|
||||
uint32_t skiped;
|
||||
};
|
||||
|
||||
struct usartpacketheader_t {
|
||||
uint8_t startByte;
|
||||
uint8_t serial;
|
||||
uint8_t payloadLength;
|
||||
uint8_t hash;
|
||||
};
|
||||
|
||||
struct usartpacket_t {
|
||||
struct usartpacketheader_t header;
|
||||
//!!! should start on word offset !!!
|
||||
uint8_t payload[256+sizeof(uint32_t)]; // extra room for crc32
|
||||
} __attribute__((aligned));
|
||||
|
||||
struct usart_buffer_t {
|
||||
struct usartpacket_t packet;
|
||||
//transfer area ends here
|
||||
volatile uint8_t busy;
|
||||
volatile uint8_t error;
|
||||
uint16_t requestedLength;
|
||||
uint32_t errorInfo;
|
||||
struct usartstatus_t *usartStatus;
|
||||
};
|
||||
|
||||
struct usartstatus_t {
|
||||
USART_TypeDef *usart;
|
||||
struct dmainfo_t rxDmaInfo;
|
||||
struct dmainfo_t txDmaInfo;
|
||||
struct crcstatus_t *crcStatus;
|
||||
struct crcslotlistitem_t crcSlot;
|
||||
struct crcslottask_t crcTasks[2];
|
||||
|
||||
uint8_t rxSerial;
|
||||
uint8_t txSerial;
|
||||
struct usart_stats stats;
|
||||
uint8_t activeRxBuf;
|
||||
pku_packetreceivedcallback_t packetReceivedCallback;
|
||||
void *packetReceivedCallbackParam;
|
||||
struct usart_buffer_t txBuffer;
|
||||
struct usart_buffer_t rxBuffers[2];
|
||||
};
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* UART_HANDLER_H_ */
|
31
components/f4ll_c/inc/f4ll_c/strutil.h
Normal file
31
components/f4ll_c/inc/f4ll_c/strutil.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* strutil.h
|
||||
*
|
||||
* Created on: Feb 11, 2017
|
||||
* Author: compi
|
||||
*/
|
||||
|
||||
#ifndef _STM32PLUS_STRUTIL_H_
|
||||
#define _STM32PLUS_STRUTIL_H_
|
||||
|
||||
#include <stddef.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
size_t strcpy_ex(char *dst, char const *src);
|
||||
size_t uitodec(char* buffer, uint32_t data);
|
||||
size_t uitohex(char* buffer, uint32_t data, uint8_t chars);
|
||||
size_t itodec(char* buffer, int data);
|
||||
size_t itohex(char* buffer, int data);
|
||||
void strrev(char *first, char *last);
|
||||
char tochr(const uint8_t in, const uint8_t upper);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _STM32PLUS_STRUTIL_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue