From f798a3fb24182b466be892ac10e7b477f2e76381 Mon Sep 17 00:00:00 2001 From: SnickerSun Date: Tue, 10 Sep 2024 18:55:51 +0800 Subject: [PATCH] =?utf8?q?=E5=9C=A8recovery=E5=92=8C=E5=90=84=E7=A7=8Drebo?= =?utf8?q?ot=E5=89=8D=E5=A2=9E=E5=8A=A0=20=E4=BF=9D=E5=AD=98=E6=97=B6?= =?utf8?q?=E9=97=B4=E5=88=B0calendar=EF=BC=8C=E5=87=8F=E5=B0=91ota?= =?utf8?q?=E5=8D=87=E7=BA=A7=E9=80=A0=E6=88=90=E7=9A=84=E6=97=B6=E9=97=B4?= =?utf8?q?=E5=81=8F=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../brandy/brandy_recovery/app_os_init.c | 8 +++ .../application/brandy/brandy_recovery/main.c | 16 +++++- .../brandy/brandy_standard/thread_pri_init.c | 8 +++ .../msg_center/src/ota/msg_center_ota.cpp | 3 +- .../target_config/brandy/target_config.py | 2 +- .../drivers/peripheral/utils/custom_utils.c | 56 ++++++++++--------- .../diag_dfx_cmd/diag_update/diag_update.c | 2 + .../utils/update/storage/upg_storage.c | 2 + 8 files changed, 68 insertions(+), 29 deletions(-) diff --git a/code/sdk/application/brandy/brandy_recovery/app_os_init.c b/code/sdk/application/brandy/brandy_recovery/app_os_init.c index 70c760679..b9fce367d 100755 --- a/code/sdk/application/brandy/brandy_recovery/app_os_init.c +++ b/code/sdk/application/brandy/brandy_recovery/app_os_init.c @@ -211,5 +211,13 @@ static void app_main(const void *unused) printf("--------------------------\r\n"); printf("no need upgrade, this branch will never enter\r\n"); } + /*******重启前保存时间到Calendar******/ + #ifndef MSEC_PER_SEC + #define MSEC_PER_SEC 1000L + #endif + uint64_t time_sec = get_local_timestamp(); + time_sec = time_sec * MSEC_PER_SEC; + uapi_calendar_set_timestamp(time_sec); + /***********************************/ upg_reboot(); } diff --git a/code/sdk/application/brandy/brandy_recovery/main.c b/code/sdk/application/brandy/brandy_recovery/main.c index 8ab629fa6..c825f24dc 100755 --- a/code/sdk/application/brandy/brandy_recovery/main.c +++ b/code/sdk/application/brandy/brandy_recovery/main.c @@ -55,7 +55,10 @@ #include "xlt_memory.h" #endif #endif - +#include "calendar.h" +#ifndef MSEC_PER_SEC +#define MSEC_PER_SEC 1000L +#endif #define WDT_TIMEOUT_S 30 #define IMG_NUM_MAX 2 #define IMG_SEC 0 @@ -225,6 +228,17 @@ static void board_init(uint32_t flash_id, uint32_t flash_unique_id) pio_func_init(); gpio_func_init(); +/********启动时获取Canedar时间并同步到设备*****/ + uapi_calendar_init(); + calendar_t date; + uapi_calendar_get_datetime(&date); + print_time(&date); + uint64_t sec; + uapi_calendar_get_timestamp(&sec); + printf("callendar timestamp = %lld \r\n", sec); + sec = sec / MSEC_PER_SEC; + sync_time(sec, uapi_get_timezone()); +/**********************************/ } static void chip_xip_init(void) diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index a7b4c29b3..5af185110 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -352,6 +352,14 @@ static void upg_check_upgrade(void) } else { PRINT("upgrade success\r\n"); } + /*******重启前保存时间到Calendar******/ + #ifndef MSEC_PER_SEC + #define MSEC_PER_SEC 1000L + #endif + uint64_t time_sec = get_local_timestamp(); + time_sec = time_sec * MSEC_PER_SEC; + uapi_calendar_set_timestamp(time_sec); + /***********************************/ upg_reboot(); } #endif diff --git a/code/sdk/application/wearable/service/msg_center/src/ota/msg_center_ota.cpp b/code/sdk/application/wearable/service/msg_center/src/ota/msg_center_ota.cpp index 7ae4e61b3..256c5c160 100644 --- a/code/sdk/application/wearable/service/msg_center/src/ota/msg_center_ota.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/ota/msg_center_ota.cpp @@ -22,7 +22,7 @@ #ifdef SUPPORT_AUTO_OTA #include "auto_ota_service.h" #endif - +#include "custom_utils.h" #ifdef __cplusplus extern "C" { #endif @@ -186,6 +186,7 @@ errcode_t msg_center_ota_rec_upg_start(uint8_t cmd_id, uint8_t type, void *usr_d } WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "upg start success!!!!\r\n"); + uapi_calendar_store_date(); upg_reboot(); return ERRCODE_SUCC; } diff --git a/code/sdk/build/config/target_config/brandy/target_config.py b/code/sdk/build/config/target_config/brandy/target_config.py index 83bd831a1..79496f144 100755 --- a/code/sdk/build/config/target_config/brandy/target_config.py +++ b/code/sdk/build/config/target_config/brandy/target_config.py @@ -140,7 +140,7 @@ target_template = { 'ram_component_set': ['std_common_lib', 'mem', 'cpu', 'lpc', 'dma', 'xip_os', 'ipc', 'watchdog', 'uart', 'otp', 'efuse_v100', 'gpio_v100', 'spi', 'qspi', 'cpu_trace', 'time_set', 'security', - 'update_recovery', 'i2c', 'pmp_set', 'flash', 'button' + 'update_recovery', 'i2c', 'pmp_set', 'flash', 'button','calendar' ], 'bin_name': 'recovery', 'application': 'recovery', diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 0ee82b1d4..51b0176a1 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -163,11 +163,14 @@ extern void uapi_sys_shipmode(uint32_t arg); extern void cm_sync_all_config_to_disk(void); void uapi_poweroff_device(void) { - + //重启前要保存时间 + uapi_calendar_store_date(); uapi_sys_shipmode(0); } void uapi_reboot_device(void) { + //重启前要保存时间 + uapi_calendar_store_date(); mcu_os_sys_reset(NULL,NULL); } @@ -450,6 +453,7 @@ errcode_t uaip_cmd_update_request(void) } else { printf("uapi_upg_request_upgrade OK!!\r\n"); /* app中下载后直接开始升级流程,升级流程结束后重启 */ + uapi_calendar_store_date(); /* IOT设备重启 */ upg_reboot(); } @@ -2024,31 +2028,31 @@ uint32_t uapi_calendar_recover_date(void) #endif } -#include "chip_system_time.h" -void test_bandy_time(uint32_t timestamp) -{ - struct tm tm; - struct timeval tv; - // uint32_t time = 1716044461; // 2024-5-18 15:1:1 网站转换:2024-05-18 23:01:01 - printf("--------SYNC TIME----------\r\n"); - get_current_timestamp(); - get_current_time(&tv, &tm); - sync_time(timestamp, 8*4); - get_current_timestamp(); - get_current_time(&tv, &tm); - printf("--------SAVE TIME----------\r\n"); - get_current_timestamp(); - get_current_time(&tv, &tm); - save_time(); - get_current_timestamp(); - get_current_time(&tv, &tm); - printf("--------RESTORE TIME----------\r\n"); - get_current_timestamp(); - get_current_time(&tv, &tm); - restore_time(); - get_current_timestamp(); - get_current_time(&tv, &tm); -} +// #include "chip_system_time.h" +// void test_bandy_time(uint32_t timestamp) +// { +// struct tm tm; +// struct timeval tv; +// // uint32_t time = 1716044461; // 2024-5-18 15:1:1 网站转换:2024-05-18 23:01:01 +// printf("--------SYNC TIME----------\r\n"); +// get_current_timestamp(); +// get_current_time(&tv, &tm); +// sync_time(timestamp, 8*4); +// get_current_timestamp(); +// get_current_time(&tv, &tm); +// printf("--------SAVE TIME----------\r\n"); +// get_current_timestamp(); +// get_current_time(&tv, &tm); +// save_time(); +// get_current_timestamp(); +// get_current_time(&tv, &tm); +// printf("--------RESTORE TIME----------\r\n"); +// get_current_timestamp(); +// get_current_time(&tv, &tm); +// restore_time(); +// get_current_timestamp(); +// get_current_time(&tv, &tm); +// } void uapi_ppg_get_id(uint8_t *chip_id) { diff --git a/code/sdk/middleware/utils/dfx/diag_dfx_cmd/diag_update/diag_update.c b/code/sdk/middleware/utils/dfx/diag_dfx_cmd/diag_update/diag_update.c index 2f0f684dc..061dd066d 100755 --- a/code/sdk/middleware/utils/dfx/diag_dfx_cmd/diag_update/diag_update.c +++ b/code/sdk/middleware/utils/dfx/diag_dfx_cmd/diag_update/diag_update.c @@ -68,6 +68,8 @@ STATIC errcode_t diag_cmd_update_start(uint16_t cmd_id, void *cmd_param, uint16_ } else { uapi_diag_report_packet(cmd_id, option, (uint8_t *)&ret, (uint16_t)sizeof(errcode_t), true); printf("uapi_update_start_test OK!\r\n"); + /**重启前要保存时间*/ + uapi_calendar_store_date(); upg_reboot(); } } while (0); diff --git a/code/sdk/middleware/utils/update/storage/upg_storage.c b/code/sdk/middleware/utils/update/storage/upg_storage.c index dcc38a0e6..c4e02542a 100755 --- a/code/sdk/middleware/utils/update/storage/upg_storage.c +++ b/code/sdk/middleware/utils/update/storage/upg_storage.c @@ -305,6 +305,8 @@ errcode_t uapi_upg_request_upgrade(bool reset) } /* app中下载后直接开始升级流程,升级流程结束后重启 */ if (reset) { + /**重启前要保存时间*/ + uapi_calendar_store_date(); /* IOT设备重启 */ upg_reboot(); } -- 2.17.1