-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_log.c
88 lines (79 loc) · 2.43 KB
/
app_log.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* @Descripttion:
* @version:
* @Author: JiaLu
* @Date: 2021-03-19 22:48:20
* @LastEditors: JiaLu
* @LastEditTime: 2021-04-10 18:04:38
*/
#include "app_log.h"
#include "bsp_led.h"
#include "FreeRTOS.h"
#include "task.h"
#include "cmsis_os.h"
#include "bsp_uart.h"
#include "tim.h"
#include "string.h"
LightControl state = kLightOff;
void StartLogTask(void *argument)
{
uint16_t cnt_ms = 0;
uint32_t test_cnt = 0;
UartRxData uart_rx;
BspUartInit();
TickType_t last_time = xTaskGetTickCount();
for(;;)
{
// vTaskDelayUntil(&last_time,10);
vTaskDelay(10);
cnt_ms++;
if(cnt_ms >99)
cnt_ms = 0;
#if PRINTF_TASK_LOG
if(cnt_ms == 0)
{
uint8_t *cpu_run_info;
cpu_run_info = pvPortMalloc(TASK_LOG_NUM);
if(cpu_run_info != NULL)
{
memset(cpu_run_info,0,TASK_LOG_NUM); //信息缓冲区清零
vTaskList((char *)cpu_run_info); //获取任务运行时间信息
APP_LOG_DEBUG("---------------------------------------------\r\n");
APP_LOG_DEBUG("任务名 \t\t任务状态 优先级 剩余栈 任务序号\r\n");
APP_LOG_DEBUG("%s", cpu_run_info);
APP_LOG_DEBUG("---------------------------------------------\r\n");
memset(cpu_run_info,0,TASK_LOG_NUM); //信息缓冲区清零
vTaskGetRunTimeStats((char *)cpu_run_info);
APP_LOG_DEBUG("任务名 \t\t运行计数 使用率\r\n");
APP_LOG_DEBUG("%s", cpu_run_info);
APP_LOG_DEBUG("---------------------------------------------\r\n");
APP_LOG_DEBUG("当前未分配堆大小: %dByte\r\n",xPortGetFreeHeapSize());
APP_LOG_DEBUG("未分配内存堆历史最小值 :%dByte\r\n\n",xPortGetMinimumEverFreeHeapSize());
vPortFree(cpu_run_info);
}
}
#endif
if(BspGetUart2RxData(&uart_rx))
{
APP_LOG_DEBUG("串口2接收数据时间:%dms\r\n",uart_rx.rx_last_time);
APP_LOG_DEBUG("串口2接收时间周期:%dms\r\n",uart_rx.rx_time_difference);
APP_LOG_DEBUG("串口2接收数据长度:%dByte\r\n",uart_rx.rx_data_len);
uart_rx.rx_data[uart_rx.rx_data_len] = 0;
APP_LOG_DEBUG("串口2接收数据:%s\r\n",uart_rx.rx_data);
}
LedSetState( state);
LedTaskCycle();
}
}
uint32_t RUN_Time=0;
extern TIM_HandleTypeDef htim6;
void configureTimerForRunTimeStats(void)
{
RUN_Time=0;
MX_TIM6_Init();
HAL_TIM_Base_Start_IT(&htim6);
}
unsigned long getRunTimeCounterValue(void)
{
return RUN_Time;
}