From 68e1accde711a721aacb60c777ee10d83bbbc498 Mon Sep 17 00:00:00 2001 From: anschrammh Date: Mon, 27 Nov 2023 08:37:08 +0100 Subject: [PATCH] Added the possibility to enable the watchdog timer in case something goes sideways using the app_config.h file (enabled by default) --- src/W800_SDK_v1.00.10/app/app_config.h | 10 ++++++++-- .../watch_peripherals/watch_peripherals.c | 16 ++++++++++++++++ .../watch_peripherals/watch_peripherals.h | 6 ++++++ src/W800_SDK_v1.00.10/app/gfx/gfx_task.c | 7 ++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/W800_SDK_v1.00.10/app/app_config.h b/src/W800_SDK_v1.00.10/app/app_config.h index b7d8d40..391edee 100644 --- a/src/W800_SDK_v1.00.10/app/app_config.h +++ b/src/W800_SDK_v1.00.10/app/app_config.h @@ -102,7 +102,7 @@ #define VIBRATION_MOTOR_PWM_CHANNEL (0) /** - * @brief BLE advertised device name + * @brief Define the BLE advertised device name * */ #if HARDWARE_PLATFORM == SMART_WATCH_BREADBOARD @@ -111,6 +111,12 @@ #define BLE_DEVICE_NAME "MDBT42Q_PCBDEV" #else #define BLE_DEVICE_NAME "MDBT42Q_W800SW" -#endif +#endif + +/** + * @brief Define if the watchdog timer should be enabled or not + * + */ +#define WATCHDOG_TIMER_ENABLE (1) #endif //APP_CONFIG_H \ No newline at end of file diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c index 6d72582..259c0e1 100644 --- a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c +++ b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.c @@ -5,6 +5,7 @@ #include "wm_adc.h" #include "wm_timer.h" #include "wm_pwm.h" +#include "wm_watchdog.h" #include "i2c.h" #include "BMP280.h" #include "bma456w.h" @@ -17,6 +18,9 @@ #define BATTERY_CONTROLLER_STATUS_DETECTION_POLICY INTERRUPT_POLICY +/* Watchdog configured timeout value is milliseconds */ +#define WATCHDOG_TIMEOUT_MS (2000) + /* Battery voltage and ADC */ static int8_t _adc_offset = 0; @@ -285,6 +289,18 @@ void watch_peripherals_init(int8_t adcOffset) /* Let's init the I2C interface */ i2c_init(I2C_SDA, I2C_SCL, I2C_CLOCK_SPEED); + + /* Let's init the watchdog timer in case the software freezes */ +#if WATCHDOG_TIMER_ENABLE + tls_watchdog_init(WATCHDOG_TIMEOUT_MS * 1000); +#endif +} + +void watch_peripherals_feed_watchdog(void) +{ +#if WATCHDOG_TIMER_ENABLE + tls_watchdog_clr(); +#endif } void watch_peripherals_register_battery_controller_status_change_cb(BatteryControllerStatusChangeCb_t BatteryControllerStatusChangeCb) diff --git a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h index 2945b26..87f049b 100644 --- a/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h +++ b/src/W800_SDK_v1.00.10/app/app_drivers/watch_peripherals/watch_peripherals.h @@ -43,6 +43,12 @@ const char *battery_controller_status_2_str(battery_controller_status_e status); */ void watch_peripherals_init(int8_t adcOffset); +/** + * @brief Feeds the watchdog timer to prevent the watch from reseting. + * + */ +void watch_peripherals_feed_watchdog(void); + /** * @brief Registers the user provided callback function to notify the battery controller status change event * @note This function should be as short as possible, do not call LVGL functions in it. diff --git a/src/W800_SDK_v1.00.10/app/gfx/gfx_task.c b/src/W800_SDK_v1.00.10/app/gfx/gfx_task.c index 7b32c03..4bb64d2 100644 --- a/src/W800_SDK_v1.00.10/app/gfx/gfx_task.c +++ b/src/W800_SDK_v1.00.10/app/gfx/gfx_task.c @@ -724,7 +724,7 @@ void gfx_task(void *param) /* Initialize lvgl screens */ watch_face_init(&watchFace); menu_screen_init(&menuScreen); - menu_screen_register_on_menu_item_click_cb(&menuScreen, &(watch_peripherals_vibrate_on_item_click)); + menu_screen_register_user_feedback_cb(&menuScreen, &(watch_peripherals_vibrate_on_item_click)); compass_screen_init(&compassScreen); compass_screen_register_on_state_change_cb(&compassScreen, &(compass_screen_on_state_change_cb)); @@ -736,12 +736,14 @@ void gfx_task(void *param) music_player_screen_init(&musicPlayerScreen); music_player_screen_register_music_playback_control_cb(&musicPlayerScreen, &(sendMusicPlaybackBLECommandCb)); music_player_screen_register_music_player_time_ref_ms_cb(&musicPlayerScreen, &(elapsed_ms)); + music_player_screen_register_user_feedback_cb(&musicPlayerScreen, &(watch_peripherals_vibrate_on_item_click)); notification_screen_init(¬ificationScreen); notification_screen_register_on_state_change_cb(¬ificationScreen, &(notification_on_state_change_cb)); settings_screen_init(&settingsScreen); settings_screen_register_on_state_change_cb(&settingsScreen, &(settings_screen_on_state_change_cb)); + settings_screen_register_user_feedback_cb(&settingsScreen, &(watch_peripherals_vibrate_on_item_click)); settings_screen_register_API_interface(&settingsScreen, &settingsScreenAPIInterface); watch_face_register_date_time_cb(&watchFace, &(date_time_cb)); @@ -924,6 +926,9 @@ void gfx_task(void *param) _perform_deferred_display_wake_up_set_timestamp(); } } + + /* Let's feed the watchdog timer */ + watch_peripherals_feed_watchdog(); } }