From c9d34783d8d062e864765c01d8a167d460b4e4be Mon Sep 17 00:00:00 2001 From: Klagarge Date: Fri, 26 Apr 2024 13:15:48 +0200 Subject: [PATCH 1/2] fix token --- mac_receiver.c | 2 ++ mac_sender.c | 13 ++++++-- main.h | 2 +- tokenring_project.uvoptx | 63 ++++++++++++++++----------------------- tokenring_project.uvprojx | 2 +- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/mac_receiver.c b/mac_receiver.c index 63e8e09..ca2d104 100644 --- a/mac_receiver.c +++ b/mac_receiver.c @@ -23,6 +23,8 @@ void send_DATA_IND(Adresse source, Adresse destination, uint8_t* dataFramePtr) { } strPtr[dataFramePtr[2]] = '\0'; // null-terminate string queueMsg.anyPtr = strPtr; + //retCode = osMemoryPoolFree(memPool, dataFramePtr); + //CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); switch (destination.sapi) { case TIME_SAPI: diff --git a/mac_sender.c b/mac_sender.c index ee4a558..7c4fc9f 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -15,7 +15,8 @@ const osMessageQueueAttr_t queue_macData_attr = { void sendToken() { struct queueMsg_t queueMsg; - queueMsg.anyPtr = lastToken; + queueMsg.anyPtr = osMemoryPoolAlloc(memPool,osWaitForever); + memcpy(queueMsg.anyPtr, lastToken, TOKENSIZE-2); queueMsg.type = TO_PHY; osStatus_t retCode = osMessageQueuePut( queue_phyS_id, @@ -60,6 +61,7 @@ void MacSender(void *argument) { //---------------------------------------------------------------------- case TOKEN: { // Get token and save it + //lastToken = osMemoryPoolAlloc(memPool,osWaitForever); memcpy(lastToken, msg, TOKENSIZE-2); // update token @@ -70,7 +72,8 @@ void MacSender(void *argument) { // send to lcd queueMsg.type = TOKEN_LIST; - queueMsg.anyPtr = lastToken; + memcpy(queueMsg.anyPtr , lastToken, TOKENSIZE-2); + //queueMsg.anyPtr = lastToken; retCode = osMessageQueuePut( queue_lcd_id, &queueMsg, @@ -91,6 +94,8 @@ void MacSender(void *argument) { 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } else { + retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); sendToken(); } break; @@ -196,7 +201,8 @@ void MacSender(void *argument) { } gTokenInterface.station_list[gTokenInterface.myAddress] = (0x1 << TIME_SAPI) + (gTokenInterface.connected << CHAT_SAPI); lastToken[gTokenInterface.myAddress+1] = gTokenInterface.station_list[gTokenInterface.myAddress]; - + sendToken(); + /* queueMsg.type = TO_PHY; queueMsg.anyPtr = lastToken; @@ -206,6 +212,7 @@ void MacSender(void *argument) { osPriorityNormal, osWaitForever); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + */ break; } diff --git a/main.h b/main.h index 2cf9529..3c2ba57 100644 --- a/main.h +++ b/main.h @@ -16,7 +16,7 @@ //-------------------------------------------------------------------------------- // Constants to change the system behavior //-------------------------------------------------------------------------------- -#define DEBUG_MODE 1 // mode is physical line (0) or debug (1) +#define DEBUG_MODE 0 // mode is physical line (0) or debug (1) #define MYADDRESS 3 // your address choice (table number) #define MAX_BLOCK_SIZE 100 // size max for a frame diff --git a/tokenring_project.uvoptx b/tokenring_project.uvoptx index b18b2c9..d6555e7 100644 --- a/tokenring_project.uvoptx +++ b/tokenring_project.uvoptx @@ -159,7 +159,7 @@ 0 18 1 -
134311450
+
134312290
0 0 0 @@ -173,39 +173,7 @@ 1 0 - 264 - 1 -
134256144
- 0 - 0 - 0 - 0 - 0 - 1 - .\mac_sender.c - - \\tokenring_project\mac_sender.c\264 -
- - 2 - 0 - 86 - 1 -
134255102
- 0 - 0 - 0 - 0 - 0 - 1 - .\mac_sender.c - - \\tokenring_project\mac_sender.c\86 -
- - 3 - 0 - 199 + 106 1
0
0 @@ -219,7 +187,23 @@
- 4 + 2 + 0 + 107 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\mac_sender.c + + +
+ + 3 0 199 1 @@ -261,6 +245,11 @@ 1 memPool + + 5 + 1 + qPtr + @@ -294,7 +283,7 @@ 0 1 - 1 + 0 0 0 0 @@ -569,7 +558,7 @@ ::CMSIS - 0 + 1 0 0 1 diff --git a/tokenring_project.uvprojx b/tokenring_project.uvprojx index 6099233..0ad19f1 100644 --- a/tokenring_project.uvprojx +++ b/tokenring_project.uvprojx @@ -10,7 +10,7 @@ Target 1 0x4 ARM-ADS - 5060960::V5.06 update 7 (build 960)::C:\Program Files (x86)\ARM_Compiler_5.06u7 + 5060960::V5.06 update 7 (build 960)::..\..\Program Files (x86)\ARM_Compiler_5.06u7 0 From 0a13c2948cde02d3cf7f465889e5dff2c6b9844c Mon Sep 17 00:00:00 2001 From: Klagarge Date: Fri, 26 Apr 2024 16:19:18 +0200 Subject: [PATCH 2/2] fix memory leak --- .gitignore | 16 ++++ mac_sender.c | 26 +++---- tokenring_project.uvoptx | 155 +++++++++++++++++++++++++++----------- tokenring_project.uvprojx | 2 +- 4 files changed, 141 insertions(+), 58 deletions(-) diff --git a/.gitignore b/.gitignore index 3dfbc80..d60c37d 100644 --- a/.gitignore +++ b/.gitignore @@ -83,3 +83,19 @@ .vscode/settings.json .vscode/uv4.log .vscode/uv4.log.lock +RTE/CMSIS/RTX_Config.c.update@5.1.1 +RTE/CMSIS/RTX_Config.h.update@5.5.2 +RTE/Compiler/EventRecorderConf.h.update@1.1.0 +RTE/Device/STM32F746NGHx/RTE_Device.h.update@1.5.1 +RTE/Device/STM32F746NGHx/startup_stm32f746xx.s.update@1.2.2 +RTE/Device/STM32F746NGHx/stm32f7xx_hal_conf.h.update@1.2.7 +RTE/Device/STM32F746NGHx/system_stm32f7xx.c.update@1.2.2 +RTE/Hesso_pack/ext_buttons.c.base@1.0.0 +RTE/Hesso_pack/ext_buttons.h.base@1.0.0 +RTE/Hesso_pack/ext_keyboard.c.update@1.1.1 +RTE/Hesso_pack/ext_keyboard.h.update@1.1.1 +RTE/Hesso_pack/ext_led.c.base@1.0.0 +RTE/Hesso_pack/ext_led.h.base@1.0.0 +RTE/Hesso_pack/ext_uart.c.base@1.0.0 +RTE/Hesso_pack/ext_uart.h.base@1.0.0 +RTE/uGFX_library/gfxconf.h.update@2.0.0 diff --git a/mac_sender.c b/mac_sender.c index 7c4fc9f..f16ca14 100644 --- a/mac_sender.c +++ b/mac_sender.c @@ -61,6 +61,7 @@ void MacSender(void *argument) { //---------------------------------------------------------------------- case TOKEN: { // Get token and save it +// osDelay(300); //lastToken = osMemoryPoolAlloc(memPool,osWaitForever); memcpy(lastToken, msg, TOKENSIZE-2); @@ -73,13 +74,15 @@ void MacSender(void *argument) { // send to lcd queueMsg.type = TOKEN_LIST; memcpy(queueMsg.anyPtr , lastToken, TOKENSIZE-2); - //queueMsg.anyPtr = lastToken; retCode = osMessageQueuePut( queue_lcd_id, &queueMsg, osPriorityNormal, osWaitForever); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); + + retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); + CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); // Send one msg from internal queue if exist //if (osMemoryPoolGetCount(queue_macData_id) != 0) { // Message in Queue @@ -94,8 +97,6 @@ void MacSender(void *argument) { 0); CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); } else { - retCode = osMemoryPoolFree(memPool, queueMsg.anyPtr); - CheckRetCode(retCode, __LINE__, __FILE__, CONTINUE); sendToken(); } break; @@ -244,19 +245,17 @@ void MacSender(void *argument) { src.nothing = 0; length = strlen(queueMsg.anyPtr); - if(dst.addr != BROADCAST_ADDRESS) { + if(dst.addr == BROADCAST_ADDRESS) { + status.read = 1; + status.ack = 1; + stationStatus.raw = 0; + } else { + status.read = 0; + status.ack = 0; stationStatus.raw = gTokenInterface.station_list[dst.addr]; } - if( (stationStatus.chat == 1) || (dst.addr == BROADCAST_ADDRESS)) { - - if(dst.addr == BROADCAST_ADDRESS) { - status.read = 1; - status.ack = 1; - } else { - status.read = 0; - status.ack = 0; - } + if( (dst.addr == BROADCAST_ADDRESS) || (stationStatus.chat == 1)) { msg = osMemoryPoolAlloc(memPool, 0); if(msg == NULL) { @@ -281,7 +280,6 @@ void MacSender(void *argument) { assert(false); } memcpy(lastSentMsgPtr, msg, length+4); - // TODO test if station is online } queueMsg.anyPtr = msg; diff --git a/tokenring_project.uvoptx b/tokenring_project.uvoptx index d6555e7..e156d63 100644 --- a/tokenring_project.uvoptx +++ b/tokenring_project.uvoptx @@ -157,9 +157,41 @@ 0 0 - 18 + 108 1 -
134312290
+
134255386
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_sender.c + + \\tokenring_project\mac_sender.c\108 +
+ + 1 + 0 + 110 + 1 +
134255394
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_sender.c + + \\tokenring_project\mac_sender.c\110 +
+ + 2 + 0 + 116 + 1 +
134254758
0 0 0 @@ -168,45 +200,77 @@ 1 .\mac_receiver.c - \\tokenring_project\mac_receiver.c\18 -
- - 1 - 0 - 106 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\mac_sender.c - - -
- - 2 - 0 - 107 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - .\mac_sender.c - - + \\tokenring_project\mac_receiver.c\116
3 0 - 199 + 89 1 +
134255344
+ 0 + 0 + 0 + 0 + 0 + 1 + .\mac_sender.c + + \\tokenring_project\mac_sender.c\89 +
+ + 4 + 0 + 92 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\mac_sender.c + + +
+ + 5 + 0 + 109 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\mac_sender.c + + +
+ + 6 + 0 + 111 + 1 +
0
+ 0 + 0 + 0 + 0 + 0 + 0 + .\mac_sender.c + + +
+ + 7 + 0 + 199 + 0
0
0 0 @@ -223,32 +287,37 @@ 0 1 - sai + gTokenInterface 1 1 - gTokenInterface + t 2 1 - t + lastToken,0x10 3 1 - lastToken + memPool 4 1 - memPool + qPtr[0] 5 1 - qPtr + qPtr[1] + + + 6 + 1 + qPtr[2] @@ -558,7 +627,7 @@ ::CMSIS - 1 + 0 0 0 1 diff --git a/tokenring_project.uvprojx b/tokenring_project.uvprojx index 0ad19f1..6099233 100644 --- a/tokenring_project.uvprojx +++ b/tokenring_project.uvprojx @@ -10,7 +10,7 @@ Target 1 0x4 ARM-ADS - 5060960::V5.06 update 7 (build 960)::..\..\Program Files (x86)\ARM_Compiler_5.06u7 + 5060960::V5.06 update 7 (build 960)::C:\Program Files (x86)\ARM_Compiler_5.06u7 0