Code compiles

This commit is contained in:
Attila Body 2019-09-29 17:51:32 +02:00
parent 7a74273ca7
commit 2aa08f20a0
118 changed files with 119250 additions and 34 deletions

83
app/application.c Normal file
View file

@ -0,0 +1,83 @@
#include <string.h>
#include "application.h"
#include "globals.h"
#include "strutil.h"
#include "diag.h"
#include "usart_handler.h"
#include "crc_handler.h"
#include "console_handler.h"
#define PACKAGE_DELAY_MS 0
#define STATS_DELAY_MS 1000
// UART DMA RX TX
// 1 2 2 7
// 2 1 5 6
// 3 1 1 3
// 5 1 0 7
// 6 2 1 6
// console UART
// 4 1 2 4
void MainLoop()
{
static uint8_t const text2Send[] = "------------------------------------------------\r\n| Megszentsegtelenithetetlensegeskedeseitekert |\r\n------------------------------------------------\r\n";
struct initdata_t {
USART_TypeDef* uart;
DMA_TypeDef* dma;
uint32_t stream_rx;
uint32_t stream_tx;
} static const initdata[] = {
{ USART1, DMA2, LL_DMA_STREAM_2, LL_DMA_STREAM_7 },
{ USART2, DMA1, LL_DMA_STREAM_5, LL_DMA_STREAM_6 },
{ USART3, DMA1, LL_DMA_STREAM_1, LL_DMA_STREAM_3 },
{ UART5, DMA1, LL_DMA_STREAM_0, LL_DMA_STREAM_7 },
{ USART6, DMA2, LL_DMA_STREAM_1, LL_DMA_STREAM_6 },
};
uint32_t lastStatsTick = 0;
uint32_t prevSentTick = 0;
uint8_t statId = 0;
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx) {
struct initdata_t const *id = &initdata[idx];
InitUartStatus(&g_uartStatuses[idx], id->uart, id->dma, id->stream_rx, id->stream_tx,
&g_crcStatus, idx + UARTCOUNT, idx);
memcpy(GetTxBuffer(&g_uartStatuses[idx]), text2Send, sizeof(text2Send) -1);
}
InitCrcStatus(&g_crcStatus, DMA2, LL_DMA_STREAM_4);
InitDmaInfo(&g_ConsoleTxDmaInfo, DMA1, LL_DMA_STREAM_3);
LL_DMA_EnableIT_TC(g_ConsoleTxDmaInfo.dma, g_ConsoleTxDmaInfo.stream);
LL_DMA_EnableIT_TE(g_ConsoleTxDmaInfo.dma, g_ConsoleTxDmaInfo.stream);
LL_SYSTICK_EnableIT();
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx)
SetupReceive(&g_uartStatuses[idx]);
for(;;) {
uint8_t send = PACKAGE_DELAY_MS ? (g_tickCount - prevSentTick > PACKAGE_DELAY_MS) : 1;
if(send)
prevSentTick += PACKAGE_DELAY_MS;
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx) {
if(!g_uartStatuses[idx].txBuffer.busy && send) {
PostPacket(&g_uartStatuses[idx], NULL, sizeof(text2Send) -1, &g_crcStatus);
}
for(uint16_t rIdx = 0; rIdx < 2; ++rIdx)
if(g_uartStatuses[idx].rxBuffers[rIdx].busy || g_uartStatuses[idx].rxBuffers[rIdx].error)
ConsumePacket(&g_uartStatuses[idx], rIdx, &g_crcStatus);
}
if(g_tickCount - lastStatsTick > STATS_DELAY_MS) {
PrintStats((char*)g_statsBuf, statId, &g_uartStatuses[statId].stats, USART3, &g_ConsoleTxDmaInfo);
lastStatsTick += STATS_DELAY_MS;
++statId;
if(statId >= UARTCOUNT)
statId = 0;
}
}
}

17
app/application.h Normal file
View file

@ -0,0 +1,17 @@
/*
* app.h
*
* Created on: Aug 29, 2019
* Author: abody
*/
#ifndef APP_H_
#define APP_H_
#include <inttypes.h>
#include "main.h"
#include <stats.h>
void MainLoop();
#endif /* APP_H_ */

19
app/config.h Normal file
View file

@ -0,0 +1,19 @@
/*
* config.h
*
* Created on: Sep 24, 2019
* Author: abody
*/
#ifndef CONFIG_H_
#define CONFIG_H_
#define UARTCOUNT 5
#define CRCTASKCOUNT (UARTCOUNT * 2)
#define USART1_OFFSET 0
#define USART2_OFFSET 1
#define USART3_OFFSET 2
#define USART5_OFFSET 3
#define USART6_OFFSET 4
#endif /* CONFIG_H_ */

8
app/diag.c Normal file
View file

@ -0,0 +1,8 @@
/*
* diag.c
*
* Created on: Sep 16, 2019
* Author: abody
*/

53
app/diag.h Normal file
View file

@ -0,0 +1,53 @@
/*
* diag.h
*
* Created on: Sep 16, 2019
* Author: abody
*/
#ifndef DIAG_H_
#define DIAG_H_
#ifdef _ENABLE_DIAG
#define DIAG_RX_BUFFER_SWITCH(x) \
if(x) { \
LL_GPIO_SetOutputPin(LED0_GPIO_Port, LED0_Pin); \
LL_GPIO_ResetOutputPin(LED1_GPIO_Port, LED1_Pin); \
} else { \
LL_GPIO_ResetOutputPin(LED0_GPIO_Port, LED0_Pin); \
LL_GPIO_SetOutputPin(LED1_GPIO_Port, LED1_Pin); \
}
#define DIAG_CRC_CALC_START() LL_GPIO_SetOutputPin(DIAG0_GPIO_Port, DIAG0_Pin)
#define DIAG_CRC_CALC_END() LL_GPIO_ResetOutputPin(DIAG0_GPIO_Port, DIAG0_Pin)//; LL_GPIO_TogglePin(DIAG3_GPIO_Port, DIAG3_Pin)
#define DIAG_INTERRUPT_IN() LL_GPIO_SetOutputPin(DIAG1_GPIO_Port, DIAG1_Pin)
#define DIAG_INTERRUPT_OUT() LL_GPIO_ResetOutputPin(DIAG1_GPIO_Port, DIAG1_Pin)
#else // _ENABLE_DIAG
#ifndef DIAG_RX_BUFFER_SWITCH
# define DIAG_RX_BUFFER_SWITCH(x)
#endif
#ifndef DIAG_CRC_CALC_START
# define DIAG_CRC_CALC_START()
#endif
#ifndef DIAG_CRC_CALC_END
# define DIAG_CRC_CALC_END()
#endif
#ifndef DIAG_INTERRUPT_IN
# define DIAG_INTERRUPT_IN()
#endif
#ifndef DIAG_INTERRUPT_OUT
# define DIAG_INTERRUPT_OUT()
#endif
#ifndef DIAG_ERROR_EVENT
# define DIAG_ERROR_EVENT()
#endif
#endif // _ENABLE_DIAG
#endif /* DIAG_H_ */

18
app/globals.c Normal file
View file

@ -0,0 +1,18 @@
/*
* globals.c
*
* Created on: Aug 29, 2019
* Author: abody
*/
#include "globals.h"
uint32_t g_tickCount = 0;
UARTSTATUS g_uartStatuses[UARTCOUNT];
struct crcstatus_t g_crcStatus;
DMAINFO g_ConsoleTxDmaInfo;
uint8_t g_statsBuf[128];

26
app/globals.h Normal file
View file

@ -0,0 +1,26 @@
/*
* globals.h
*
* Created on: Aug 29, 2019
* Author: abody
*/
#ifndef GLOBALS_H_
#define GLOBALS_H_
#include <inttypes.h>
#include "config.h"
#include "usart_handler.h"
#include "dma_helper.h"
#include "crc_handler.h"
extern uint32_t g_tickCount;
extern UARTSTATUS g_uartStatuses[UARTCOUNT];
extern struct crcstatus_t g_crcStatus;
extern DMAINFO g_ConsoleTxDmaInfo;
extern uint8_t g_statsBuf[128];
#endif /* GLOBALS_H_ */

66
app/stats.h Normal file
View file

@ -0,0 +1,66 @@
/*
* stats.h
*
* Created on: Sep 16, 2019
* Author: abody
*/
#ifndef STATS_H_
#define STATS_H_
#ifndef DIAG_ERROR_EVENT
# define DIAG_ERROR_EVENT()
#endif
typedef struct {
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;
} STATS;
#ifndef STATS_DISABLED
static inline void StatsIncOverrun(STATS *s) {
++s->overrun;
}
static inline void StatsIncHdrError(STATS *s, uint32_t hdr) {
DIAG_ERROR_EVENT();
++s->hdrError;
}
static inline void StatsIncPayloadError(STATS *s, uint32_t pep1, uint32_t pep2) {
DIAG_ERROR_EVENT();
++s->payloadErrror;
s->pep1 = pep1;
s->pep2 = pep2;
}
static inline void StatsIncDmaError(STATS *s) {
++s->dmaError;
}
static inline void StatsIncRcvd(STATS *s) {
++s->rcvd;
}
static inline void StatsIncPremature_hdr(STATS *s) {
++s->premature_hdr;
}
static inline void StatsIncPremature_payload(STATS *s) {
++s->premature_payload;
}
static inline void StatsIncSent(STATS *s) {
++s->sent;
}
static inline void StatsAddSkiped(STATS *s, uint8_t cnt) {
s->skiped += s->rcvd > 2 ? cnt : 0;
}
#else // STATS_DISABLED
#define StatsIncSent(x)
#endif // STATS_DISABLED
#endif /* STATS_H_ */