heap scan, stack overflow check debug_scan_heap_stack_size
authorkyz <kongyuzhong@google.com>
Thu, 25 Jun 2026 06:50:16 +0000 (14:50 +0800)
committerkyz <kongyuzhong@google.com>
Thu, 25 Jun 2026 06:50:16 +0000 (14:50 +0800)
Aging_app/freertos/inc/FreeRTOSConfig.h
Aging_app/freertos/src/main.c
Aging_app/freertos/src/task_lists.c

index 2eac637c0ac0fc3f123b1ba45408bf6c2596f21f..5183ad223659e085f5918d42683b959beef7221d 100644 (file)
@@ -76,15 +76,15 @@ PRIORITY THAN THIS! (higher priorities are lower numeric values. */
 /* Hook function related definitions. */
 #define configUSE_IDLE_HOOK                         0
 #define configUSE_TICK_HOOK                         0
-#define configUSE_MALLOC_FAILED_HOOK                0
-#define configCHECK_FOR_STACK_OVERFLOW              0
+#define configUSE_MALLOC_FAILED_HOOK                1
+#define configCHECK_FOR_STACK_OVERFLOW              2
 #define configUSE_DAEMON_TASK_STARTUP_HOOK          0
 
 /* Run time and task stats gathering related definitions. */
 #define configGENERATE_RUN_TIME_STATS               0
 #define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS()    
 #define portGET_RUN_TIME_COUNTER_VALUE()            xTaskGetTickCount()
-#define configUSE_TRACE_FACILITY                    0
+#define configUSE_TRACE_FACILITY                    1
 #define configUSE_STATS_FORMATTING_FUNCTIONS        1
 
 /* Co-routine related definitions. */
index 4ab3148ba9e47f21a4b367e73c521d8a6580cc79..2aba25324147265227093efb58692b1dafdd60ad 100644 (file)
@@ -187,3 +187,23 @@ void TempCallBackTask(void)
 {
        Temp_Now = Adc_Collect_Temp();
 }
+
+//-----------------------------------
+// freertos/src/heap_stats.c
+
+#include "FreeRTOS.h"
+#include "task.h"
+#include <stdio.h>
+
+/* Õ»Òç³ö¹³×Óº¯Êý */
+void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
+{
+    /* ¿ÉÒÔÌí¼ÓÆäËû´¦ÀíÂß¼­£¬È縴λϵͳ */
+    for( ;; );
+}
+
+/* mallocʧ°Ü¹³×Óº¯Êý */
+void vApplicationMallocFailedHook( void )
+{
+    for( ;; );
+}
index 02d8052d112fecc80a89b496b540fb0f61800ec8..eb57aabeff1288ec5400f7f53f03684d2f6e6b9e 100644 (file)
@@ -86,6 +86,10 @@ static void queueHeartBeatTask(void *parames)
        
        for( ;; )
        {
+        {
+            void mem_scan( void );
+            mem_scan();
+        }
                xSemaphoreTake(xSemaphoreTx, portMAX_DELAY);
                //strcpy((char *)uart0TxBuff, "$CMSGH,<"__DEVICES_ID__">,$#");
                sprintf((char *)uart0TxBuff, "$CMSGH,<%s>,$#", g_devinfo.serial);
@@ -919,9 +923,42 @@ void Tasks_Create(void)
     xTaskCreate(queueCommandTask, "Command", configMINIMAL_STACK_SIZE+128, NULL, 1, &Command_Handler);
     xTaskCreate(queueGatherTask1, "Gather1", configMINIMAL_STACK_SIZE+128, NULL, 1, &Gather_Handler1);
        xTaskCreate(queueGatherTask2, "Gather2", configMINIMAL_STACK_SIZE+128, NULL, 1, &Gather_Handler2);
-    xTaskCreate(queueSendTask, "Senddata", configMINIMAL_STACK_SIZE, NULL, 1, &Send_Handler);
-       xTaskCreate(queueHeartBeatTask, "Heartbeat", configMINIMAL_STACK_SIZE, NULL, 1, &HeartBeat_Handler);
-    xTaskCreate(queueUserDaemonTask, "UserDaemon", configMINIMAL_STACK_SIZE, NULL, 1, &UserDaemon_Handler);
+    xTaskCreate(queueSendTask, "Senddata", configMINIMAL_STACK_SIZE+32, NULL, 1, &Send_Handler);
+       xTaskCreate(queueHeartBeatTask, "Heartbeat", configMINIMAL_STACK_SIZE+32, NULL, 1, &HeartBeat_Handler);
+    xTaskCreate(queueUserDaemonTask, "UserDaemon", configMINIMAL_STACK_SIZE+32, NULL, 1, &UserDaemon_Handler);
        xTaskCreate(parameterTask, "Parameter", configMINIMAL_STACK_SIZE+128, NULL, 1, &Parameter_Handler);
 }
 
+// freertos/src/task_mem_stats.c
+
+#include "FreeRTOS.h"
+#include "task.h"
+//#include "heap_4.h"  /* Èç¹ûʹÓÃÆäËûheap·½°¸£¬°üº¬¶ÔÓ¦µÄÍ·Îļþ */
+#include <stdio.h>
+
+volatile size_t xFreeHeapSize;
+volatile size_t xMinimumEverFreeHeapSize;
+UBaseType_t uxHighWaterMark[10];
+/* ÄÚ´æÍ³¼ÆÈÎÎñ */
+void mem_scan( void )
+{
+        /* »ñÈ¡¶ÑÄÚ´æÐÅÏ¢ */
+        xFreeHeapSize = xPortGetFreeHeapSize();
+        xMinimumEverFreeHeapSize = xPortGetMinimumEverFreeHeapSize();
+
+        uxHighWaterMark[0] = uxTaskGetStackHighWaterMark(Command_Handler);
+        uxHighWaterMark[1] = uxTaskGetStackHighWaterMark(Gather_Handler1);
+        uxHighWaterMark[2] = uxTaskGetStackHighWaterMark(Gather_Handler2);
+        uxHighWaterMark[3] = uxTaskGetStackHighWaterMark(Send_Handler);
+        uxHighWaterMark[4] = uxTaskGetStackHighWaterMark(HeartBeat_Handler);
+        uxHighWaterMark[5] = uxTaskGetStackHighWaterMark(UserDaemon_Handler);
+        
+        /* ´òÓ¡ÄÚ´æÐÅÏ¢ */
+        //printf("========================================\r\n");
+        //printf("ÄÚ´æÍ³¼ÆÐÅÏ¢ (ÿ5Ãë)\r\n");
+        //printf("----------------------------------------\r\n");
+        //printf("µ±Ç°¿ÕÏжÑÄÚ´æ: %u bytes\r\n", (unsigned int)xFreeHeapSize);
+        //printf("ÀúÊ·×îС¿ÕÏжÑ: %u bytes\r\n", (unsigned int)xMinimumEverFreeHeapSize);
+        //printf("ÒÑʹÓöÑÄÚ´æ: %u bytes\r\n", 
+        //       (unsigned int)(configTOTAL_HEAP_SIZE - xFreeHeapSize));
+}