initial commit
This commit is contained in:
commit
9f225a2c9d
113 changed files with 116214 additions and 0 deletions
109
application/application.c
Normal file
109
application/application.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
#include <f4ll_c/consolehandler.h>
|
||||
#include <f4ll_c/crcscheduler.h>
|
||||
#include <f4ll_c/memcpydma.h>
|
||||
#include <f4ll_c/packetusart.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "application.h"
|
||||
#include "globals.h"
|
||||
#include "f4ll_c/strutil.h"
|
||||
#include "diag.h"
|
||||
|
||||
#ifndef USE_CPLUSPLUS
|
||||
|
||||
#define PACKAGE_DELAY_MS 0
|
||||
#define STATS_DELAY_MS 1000
|
||||
|
||||
// USART DMA RX TX
|
||||
// 1 2 2 7
|
||||
// 2 1 5 6
|
||||
// 3 1 1 3
|
||||
// 6 2 1 6
|
||||
// console USART
|
||||
// 4 1 2 4
|
||||
|
||||
void MainLoop()
|
||||
{
|
||||
uint8_t const text2Send[] __attribute__((aligned(4))) =
|
||||
"Megszentsegtelenithetetlensegeskedeseitekert\r\n"
|
||||
"--------------------------------------------\r\n\0\0\0";
|
||||
|
||||
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 },
|
||||
{ USART6, DMA2, LL_DMA_STREAM_1, LL_DMA_STREAM_6 },
|
||||
};
|
||||
|
||||
uint32_t lastStatsTick = 0;
|
||||
uint32_t prevSentTick = 0;
|
||||
uint8_t statId = 0;
|
||||
|
||||
uint32_t tmp = sizeof(text2Send) - 1;
|
||||
uint32_t randmask = 0x80000000;
|
||||
do
|
||||
if(randmask & tmp)
|
||||
break;
|
||||
while((randmask = randmask >> 1));
|
||||
randmask -= 1;
|
||||
|
||||
Crc_InitStatus(&g_crcStatus, DMA2, LL_DMA_STREAM_4);
|
||||
|
||||
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx) {
|
||||
struct initdata_t const *id = &initdata[idx];
|
||||
Pku_Init(&g_uartStatuses[idx], id->uart, id->dma, id->stream_rx, id->stream_tx, &g_crcStatus, NULL, NULL);
|
||||
memcpy(Pku_GetTxBuffer(&g_uartStatuses[idx]), text2Send, sizeof(text2Send) -1);
|
||||
}
|
||||
|
||||
Dma_Init(&g_ConsoleTxDmaInfo, CONSOLE_DMA_ENGINE, CONSOLE_TX_DMA_STREAM);
|
||||
LL_DMA_EnableIT_TC(g_ConsoleTxDmaInfo.dma, g_ConsoleTxDmaInfo.stream);
|
||||
|
||||
Mcd_Init(MEMCPY_DMA_ENGINE, MEMCPY_DMA_STREAM);
|
||||
|
||||
lastStatsTick = HAL_GetTick();
|
||||
|
||||
for(uint16_t idx = 0; idx < sizeof(g_uartStatuses) / sizeof(g_uartStatuses[0]); ++idx)
|
||||
Pku_SetupReceive(&g_uartStatuses[idx]);
|
||||
|
||||
for(;;) {
|
||||
uint32_t tick = HAL_GetTick();
|
||||
uint8_t send = PACKAGE_DELAY_MS ? (tick - 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) {
|
||||
uint16_t len = sizeof(text2Send) - 1 - (rand() & randmask);
|
||||
DIAG_ENTER_BUSY();
|
||||
Mcd_Copy(Pku_GetTxBuffer(&g_uartStatuses[idx]), text2Send, len);
|
||||
Pku_Post(&g_uartStatuses[idx], NULL, len, &g_crcStatus, 1);
|
||||
DIAG_EXIT_BUSY();
|
||||
}
|
||||
for(uint16_t rIdx = 0; rIdx < 2; ++rIdx)
|
||||
if(g_uartStatuses[idx].rxBuffers[rIdx].busy || g_uartStatuses[idx].rxBuffers[rIdx].error) {
|
||||
DIAG_ENTER_BUSY();
|
||||
Pku_ConsumePacket(&g_uartStatuses[idx], rIdx);
|
||||
DIAG_EXIT_BUSY();
|
||||
}
|
||||
}
|
||||
if(tick - lastStatsTick > STATS_DELAY_MS) {
|
||||
Con_PrintStats((char*)g_statsBuf, statId, &g_uartStatuses[statId].stats, UART4, &g_ConsoleTxDmaInfo);
|
||||
lastStatsTick += STATS_DELAY_MS;
|
||||
++statId;
|
||||
if(statId >= USARTCOUNT)
|
||||
statId = 0;
|
||||
}
|
||||
uint32_t ein = LL_GPIO_ReadInputPort(KEY1_GPIO_Port);
|
||||
if(!(ein & KEY1_Pin)) {
|
||||
void (*fptr)(void) = (void (*)(void))(void*)0xa0000000;
|
||||
fptr();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // USE_CPLUSPLUS
|
23
application/application.h
Normal file
23
application/application.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* app.h
|
||||
*
|
||||
* Created on: Aug 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef APP_H_
|
||||
#define APP_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "main.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void MainLoop();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C" {
|
||||
#endif // __cplusplus
|
||||
#endif /* APP_H_ */
|
27
application/config.h
Normal file
27
application/config.h
Normal file
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* config.h
|
||||
*
|
||||
* Created on: Sep 24, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#define USARTCOUNT 4
|
||||
#define CRCTASKCOUNT (USARTCOUNT * 2)
|
||||
#define USART1_OFFSET 0
|
||||
#define USART2_OFFSET 1
|
||||
#define USART3_OFFSET 2
|
||||
#define USART6_OFFSET 3
|
||||
|
||||
#define CONSOLE_DMA_ENGINE DMA1
|
||||
#define CONSOLE_TX_DMA_STREAM LL_DMA_STREAM_4
|
||||
|
||||
#define CRC_DMA_ENGINE DMA2
|
||||
#define CRC_DMA_STREAM LL_DMA_STREAM_4
|
||||
|
||||
#define MEMCPY_DMA_ENGINE DMA2
|
||||
#define MEMCPY_DMA_STREAM LL_DMA_STREAM_3
|
||||
|
||||
#endif /* CONFIG_H_ */
|
8
application/diag.c
Normal file
8
application/diag.c
Normal file
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* diag.c
|
||||
*
|
||||
* Created on: Sep 16, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
|
63
application/diag.h
Normal file
63
application/diag.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* 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_INTERRUPT_IN() LL_GPIO_SetOutputPin(DBG0_GPIO_Port, DBG0_Pin)
|
||||
#define DIAG_INTERRUPT_OUT() LL_GPIO_ResetOutputPin(DBG0_GPIO_Port, DBG0_Pin)
|
||||
#define DIAG_CRC_CALC_START() LL_GPIO_SetOutputPin(DBG1_GPIO_Port, DBG1_Pin)
|
||||
#define DIAG_CRC_CALC_END() LL_GPIO_ResetOutputPin(DBG1_GPIO_Port, DBG1_Pin)
|
||||
//#define DIAG_ERROR_EVENT() LL_GPIO_TogglePin(DBG2_GPIO_Port, DBG2_Pin)
|
||||
#define DIAG_ENTER_BUSY() LL_GPIO_SetOutputPin(DBG2_GPIO_Port, DBG2_Pin)
|
||||
#define DIAG_EXIT_BUSY() LL_GPIO_ResetOutputPin(DBG2_GPIO_Port, DBG2_Pin)
|
||||
|
||||
#endif // _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
|
||||
|
||||
#ifndef DIAG_ENTER_BUSY
|
||||
# define DIAG_ENTER_BUSY()
|
||||
#endif
|
||||
|
||||
#ifndef DIAG_EXIT_BUSY
|
||||
# define DIAG_EXIT_BUSY()
|
||||
#endif
|
||||
|
||||
#endif /* DIAG_H_ */
|
16
application/globals.c
Normal file
16
application/globals.c
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* globals.c
|
||||
*
|
||||
* Created on: Aug 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
struct usartstatus_t g_uartStatuses[USARTCOUNT];
|
||||
|
||||
struct crcstatus_t g_crcStatus;
|
||||
|
||||
DMAINFO g_ConsoleTxDmaInfo;
|
||||
uint8_t g_statsBuf[256];
|
||||
|
24
application/globals.h
Normal file
24
application/globals.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* globals.h
|
||||
*
|
||||
* Created on: Aug 29, 2019
|
||||
* Author: abody
|
||||
*/
|
||||
|
||||
#ifndef GLOBALS_H_
|
||||
#define GLOBALS_H_
|
||||
|
||||
#include <f4ll_c/crcscheduler.h>
|
||||
#include <f4ll_c/dmahelper.h>
|
||||
#include <f4ll_c/packetusart.h>
|
||||
#include <inttypes.h>
|
||||
#include "config.h"
|
||||
|
||||
extern struct usartstatus_t g_uartStatuses[USARTCOUNT];
|
||||
|
||||
extern struct crcstatus_t g_crcStatus;
|
||||
|
||||
extern DMAINFO g_ConsoleTxDmaInfo;
|
||||
extern uint8_t g_statsBuf[256];
|
||||
|
||||
#endif /* GLOBALS_H_ */
|
6
application/platform/crc_ll.h
Normal file
6
application/platform/crc_ll.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __PLATFORM_CRC_LL_H_INCLUDED
|
||||
#define __PLATFORM_CRC_LL_H_INCLUDED
|
||||
|
||||
#include "crc.h"
|
||||
|
||||
#endif // __PLATFORM_CRC_LL_H_INCLUDED
|
6
application/platform/dma_ll.h
Normal file
6
application/platform/dma_ll.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __PLATFORM_DMA_LL_H_INCLUDED
|
||||
#define __PLATFORM_DMA_LL_H_INCLUDED
|
||||
|
||||
#include "stm32f4xx_ll_dma.h"
|
||||
|
||||
#endif // __PLATFORM_DMA_LL_H_INCLUDED
|
6
application/platform/usart_ll.h
Normal file
6
application/platform/usart_ll.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef __PLATFORM_USART_LL_H_INCLUDED
|
||||
#define __PLATFORM_USART_LL_H_INCLUDED
|
||||
|
||||
#include "usart.h"
|
||||
|
||||
#endif // __PLATFORM_USART_LL_H_INCLUDED
|
Loading…
Add table
Add a link
Reference in a new issue