/*---------------------------------------------------------------------------- * Copyright (c) Fenda Technologies Co., Ltd. 2020. All rights reserved. * * Description: task_watchdog.c * * Author: saimen * * Create: 2022-7-16 *--------------------------------------------------------------------------*/ //lib #include #include //os #include "FreeRTOS.h" #include "task.h" //sdk #include "am_mcu_apollo.h" #include "am_util.h" //drv #include "watchdog_api.h" #include "rtc_api.h" //user #include "sys_config.h" //#include "sys_restart.h" #include "user_adapter.h" #include "task_watchdog.h" #define ENABLE_STATIC_PRINT false extern uint32_t am_util_stdio_printf(const char *pcFmt, ...); #define static_print_remind(...) am_util_stdio_printf(__VA_ARGS__) #if ENABLE_STATIC_PRINT #define static_print_info(...) am_util_stdio_printf(__VA_ARGS__) #else #define static_print_info(...) #endif static TaskHandle_t g_watchdog_task_handle = NULL; static uint32_t g_watchdog_last_feed_time = 0; uint8_t task_watchdog_get_timeout_status(void) { if((xTaskGetTickCount() - g_watchdog_last_feed_time) > (watchdog_api_get_rst_ms()/3)) { return true; } else { return false; } } void task_watchdog_suspend(void) { vTaskSuspend(g_watchdog_task_handle); } void task_watchdog_entry(void *pvParameters) { static uint32_t dog_task_restart_count = 0; uint32_t restart_reason = 0; uint32_t utc_timestamp = 0; char* p_ver = NULL; uint8_t mid_ver = 0; uint8_t last_ver = 0; static_print_remind("watch dog task, task ticks: %d \r\n", xTaskGetTickCount()); watchdog_api_init(); user_update_bootup_stat(DEVICE_BOOTUP_FINISH); utc_timestamp = rtc_api_get_utc_timestamp(); p_ver = (char*)user_get_mcu_sw_ver(); mid_ver = strtol(p_ver, &p_ver, 16); p_ver++; mid_ver = strtol(p_ver, &p_ver, 16); p_ver++; mid_ver = strtol(p_ver, &p_ver, 16); p_ver++; last_ver = strtol(p_ver, NULL, 16); static_print_remind("mid_ver -- last_ver: 1.0.%x.%x \r\n", mid_ver, last_ver); // log_api_record_error(utc_timestamp, EVT_DEVICE_MANAGE_ERROR, INFO1_ABOR_FW_VER, mid_ver, last_ver, NULL); // log_api_record_action(utc_timestamp, EVT_DEVICE_MANAGE, INFO1_ACT_FW_VER, mid_ver, last_ver, NULL); // restart_reason = sys_restart_get_reason(); // log_api_record_error(utc_timestamp, EVT_DEVICE_MANAGE_ERROR, INFO1_MCU_RST, restart_reason << 8, restart_reason, NULL); g_watchdog_last_feed_time = xTaskGetTickCount(); while (1) { static_print_info("dog_task: %d \r\n", dog_task_restart_count); dog_task_restart_count++; vTaskDelay(pdMS_TO_TICKS(watchdog_api_get_rst_ms()/3)); #if defined(AM_PART_APOLLO4) watchdog_api_feed(); #else am_hal_wdt_restart(); #endif g_watchdog_last_feed_time = xTaskGetTickCount(); } } void task_watchdog_init(uint16_t stack_depth, uint16_t priority) { xTaskCreate(task_watchdog_entry, "task_watchdog_entry", stack_depth, 0, priority, &g_watchdog_task_handle); }