diff --git a/.gitmodules b/.gitmodules index a79bb1a..52e3854 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,9 @@ [submodule "proto"] path = proto url = git@git.lan:oliver/cls-proto.git +[submodule "lib/TinyFrame"] + path = lib/TinyFrame + url = https://github.com/MightyPork/TinyFrame.git +[submodule "Application/MLZR_Comm"] + path = Application/MLZR_Comm + url = git@git.lan:ODDIY/MLZR_Comm.git diff --git a/Application/CMakeLists.txt b/Application/CMakeLists.txt index e956b22..16a2cae 100644 --- a/Application/CMakeLists.txt +++ b/Application/CMakeLists.txt @@ -3,4 +3,5 @@ add_subdirectory(CLS) add_subdirectory(CLS_BSP) add_subdirectory(BSP) add_subdirectory(ram_loader) +add_subdirectory(MLZR_Comm) add_subdirectory(Vehicle) \ No newline at end of file diff --git a/Application/MLZR_Comm b/Application/MLZR_Comm new file mode 160000 index 0000000..48a98f4 --- /dev/null +++ b/Application/MLZR_Comm @@ -0,0 +1 @@ +Subproject commit 48a98f4c82bf0e90d0fa4e02d6f587db58bbad26 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d45705..d66f74f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,7 +143,7 @@ target_sources(${CMAKE_PROJECT_NAME} PUBLIC ${sources_SRCS}) target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tasks CLS CLS_BSP BSP EE24 INA219 ulog ram_loader Vehicle) #target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC PROTOS) -target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC uart_driver) +target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC mlzr_comm TinyFrame uart_driver) #target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC lwrb) target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index d944e5d..3cc45d4 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -162,6 +162,7 @@ void AddHeadlightMessages(); #include "CLS_BSP.h" #include "CLSAddress.h" +#include "mlzr_comm.h" /* USER CODE END Header_StartDefaultTask */ void StartDefaultTask(void *argument) { @@ -171,6 +172,9 @@ void StartDefaultTask(void *argument) BSP_EE24_Init(); BSP_INA_Init(); + MLZR_INIT(); + + retSD = f_mount(&SDFatFS,SDPath,0); retSD = f_open(&SDFile, "counter.bin", FA_READ); diff --git a/Core/Src/stm32h7xx_it.c b/Core/Src/stm32h7xx_it.c index 7286b0d..a804376 100644 --- a/Core/Src/stm32h7xx_it.c +++ b/Core/Src/stm32h7xx_it.c @@ -22,6 +22,7 @@ #include "stm32h7xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include "AsyncComm.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -41,7 +42,8 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ - +extern uart_desc_t uart_duplex; +extern uart_desc_t uart_half; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ @@ -233,7 +235,7 @@ void DMA1_Stream0_IRQHandler(void) /* USER CODE END DMA1_Stream0_IRQn 0 */ /* USER CODE BEGIN DMA1_Stream0_IRQn 1 */ - + usart_dma_irq_handler(&uart_duplex); /* USER CODE END DMA1_Stream0_IRQn 1 */ } @@ -247,7 +249,7 @@ void DMA1_Stream1_IRQHandler(void) /* USER CODE END DMA1_Stream1_IRQn 0 */ /* USER CODE BEGIN DMA1_Stream1_IRQn 1 */ - + usart_dma_irq_handler_tx(&uart_duplex); /* USER CODE END DMA1_Stream1_IRQn 1 */ } @@ -261,7 +263,7 @@ void DMA1_Stream2_IRQHandler(void) /* USER CODE END DMA1_Stream2_IRQn 0 */ /* USER CODE BEGIN DMA1_Stream2_IRQn 1 */ - + usart_dma_irq_handler(&uart_half); /* USER CODE END DMA1_Stream2_IRQn 1 */ } @@ -275,7 +277,7 @@ void DMA1_Stream3_IRQHandler(void) /* USER CODE END DMA1_Stream3_IRQn 0 */ /* USER CODE BEGIN DMA1_Stream3_IRQn 1 */ - + usart_dma_irq_handler_tx(&uart_half); /* USER CODE END DMA1_Stream3_IRQn 1 */ } @@ -400,7 +402,7 @@ void USART1_IRQHandler(void) /* USER CODE END USART1_IRQn 0 */ /* USER CODE BEGIN USART1_IRQn 1 */ - + usart_irq_handler(&uart_duplex); /* USER CODE END USART1_IRQn 1 */ } @@ -413,7 +415,7 @@ void USART3_IRQHandler(void) /* USER CODE END USART3_IRQn 0 */ /* USER CODE BEGIN USART3_IRQn 1 */ - + usart_irq_handler(&uart_half); /* USER CODE END USART3_IRQn 1 */ } diff --git a/Core/Src/usart.c b/Core/Src/usart.c index 0fa6db4..9655318 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -157,7 +157,7 @@ void MX_USART1_UART_Init(void) /* USER CODE END USART1_Init 1 */ USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 1000000; + USART_InitStruct.BaudRate = 2000000; USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; USART_InitStruct.StopBits = LL_USART_STOPBITS_1; USART_InitStruct.Parity = LL_USART_PARITY_NONE; @@ -273,7 +273,7 @@ void MX_USART3_UART_Init(void) /* USER CODE END USART3_Init 1 */ USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1; - USART_InitStruct.BaudRate = 1000000; + USART_InitStruct.BaudRate = 2000000; USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B; USART_InitStruct.StopBits = LL_USART_STOPBITS_1; USART_InitStruct.Parity = LL_USART_PARITY_NONE; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 0acd65e..dcbaede 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,5 +4,10 @@ add_subdirectory(nanopb) add_subdirectory(ulog) add_subdirectory(ina219) + add_library(EE24 STATIC "ee24/ee24.c") -target_include_directories(EE24 PUBLIC "ee24") \ No newline at end of file +target_include_directories(EE24 PUBLIC "ee24") + + +add_library(TinyFrame STATIC "TinyFrame/TinyFrame.c") +target_include_directories(TinyFrame PUBLIC "./TinyFrame" "./TinyFrameConf") diff --git a/lib/TinyFrame b/lib/TinyFrame new file mode 160000 index 0000000..a29167a --- /dev/null +++ b/lib/TinyFrame @@ -0,0 +1 @@ +Subproject commit a29167a69f052975b0e0134a73b4d31d03afa8fa diff --git a/lib/TinyFrameConf/TF_Config.h b/lib/TinyFrameConf/TF_Config.h new file mode 100644 index 0000000..1f84b06 --- /dev/null +++ b/lib/TinyFrameConf/TF_Config.h @@ -0,0 +1,81 @@ +// +// TinyFrame configuration file. +// +// Rename to TF_Config.h +// + +#ifndef TF_CONFIG_H +#define TF_CONFIG_H + +#include +#include // used by the TF_Error() macro defined below +//#include // when using with esphttpd + +//----------------------------- FRAME FORMAT --------------------------------- +// The format can be adjusted to fit your particular application needs + +// If the connection is reliable, you can disable the SOF byte and checksums. +// That can save up to 9 bytes of overhead. + +// ,-----+-----+-----+------+------------+- - - -+-------------, +// | SOF | ID | LEN | TYPE | HEAD_CKSUM | DATA | DATA_CKSUM | +// | 0-1 | 1-4 | 1-4 | 1-4 | 0-4 | ... | 0-4 | <- size (bytes) +// '-----+-----+-----+------+------------+- - - -+-------------' + +// !!! BOTH PEERS MUST USE THE SAME SETTINGS !!! + +// Adjust sizes as desired (1,2,4) +#define TF_ID_BYTES 2 +#define TF_LEN_BYTES 2 +#define TF_TYPE_BYTES 2 + +// Checksum type. Options: +// TF_CKSUM_NONE, TF_CKSUM_XOR, TF_CKSUM_CRC8, TF_CKSUM_CRC16, TF_CKSUM_CRC32 +// TF_CKSUM_CUSTOM8, TF_CKSUM_CUSTOM16, TF_CKSUM_CUSTOM32 +// Custom checksums require you to implement checksum functions (see TinyFrame.h) +#define TF_CKSUM_TYPE TF_CKSUM_CRC16 + +// Use a SOF byte to mark the start of a frame +#define TF_USE_SOF_BYTE 1 +// Value of the SOF byte (if TF_USE_SOF_BYTE == 1) +#define TF_SOF_BYTE 0x01 + +//----------------------- PLATFORM COMPATIBILITY ---------------------------- + +// used for timeout tick counters - should be large enough for all used timeouts +typedef uint16_t TF_TICKS; + +// used in loops iterating over listeners +typedef uint8_t TF_COUNT; + +//----------------------------- PARAMETERS ---------------------------------- + +// Maximum received payload size (static buffer) +// Larger payloads will be rejected. +#define TF_MAX_PAYLOAD_RX 1024 +// Size of the sending buffer. Larger payloads will be split to pieces and sent +// in multiple calls to the write function. This can be lowered to reduce RAM usage. +#define TF_SENDBUF_LEN 1024 + +// --- Listener counts - determine sizes of the static slot tables --- + +// Frame ID listeners (wait for response / multi-part message) +#define TF_MAX_ID_LST 50 +// Frame Type listeners (wait for frame with a specific first payload byte) +#define TF_MAX_TYPE_LST 5 +// Generic listeners (fallback if no other listener catches it) +#define TF_MAX_GEN_LST 5 + +// Timeout for receiving & parsing a frame +// ticks = number of calls to TF_Tick() +#define TF_PARSER_TIMEOUT_TICKS 10 + +// Whether to use mutex - requires you to implement TF_ClaimTx() and TF_ReleaseTx() +#define TF_USE_MUTEX 1 + +// Error reporting function. To disable debug, change to empty define +#define TF_Error(format, ...) printf("[TF] " format "\n", ##__VA_ARGS__) + +//------------------------- End of user config ------------------------------ + +#endif //TF_CONFIG_H