Merge #1081 into sdk602patch0626 from refs/changes/1081/head 1082/target/1 1084/target/1
author彭磊 <1624952103@qq.com>
Wed, 2 Oct 2024 23:36:39 +0000 (23:36 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Wed, 2 Oct 2024 23:36:39 +0000 (23:36 +0000)
设置睡眠存储runtime,优化加锁逻辑

* refs/changes/1081/head: (1 commits squashed)

  - 设置睡眠存储runtime,优化加锁逻辑
    降低gsensor功耗(10uA左右)

Signed-off-by: aliyun6865282430 <1624952103@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1081
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/utils/custom_runtime.c
code/sdk/drivers/peripheral/utils/custom_runtime.h

index 8604031..056eb75 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: SLEPPNOTIFY24-06-26 19:36:48
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-09-30 11:47:04
+ * @LastEditTime: 2024-10-02 17:56:07
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
  * @Description:
  *
@@ -44,6 +44,7 @@
 #include "power_display_service.h"
 #include "MainModel.h"
 #include "cywee_service.h"
+#include "custom_runtime.h"
 
 extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char date_separator, char time_separator, date_format_t format);
 extern "C" int get_sleep_time_from_config_model(void);
@@ -92,14 +93,6 @@ namespace OHOS
 
     bool save_nap_data(NAP_T *data)
     {
-        errcode_t ret;
-        ret = osal_mutex_lock(&sleep_mutex);
-        if (ret != ERRCODE_SUCC) 
-        {
-            PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret);
-            return false;
-        }
-        
         struct stat info;
         char dir_path[64] = {0};
         char file_path[64] = {0};
@@ -111,7 +104,6 @@ namespace OHOS
         {
             if (mkdir("user/userdata/sleep", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
             {
-                osal_mutex_unlock(&sleep_mutex);
                 return false; // Failed to create folder
             }
         }
@@ -121,7 +113,6 @@ namespace OHOS
             if (mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mkdir  fail %s", dir_path);
-                osal_mutex_unlock(&sleep_mutex);
                 return false; // Failed to create folder
             }
         }
@@ -135,7 +126,6 @@ namespace OHOS
         if (fp == NULL)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data fopen fail");
-            osal_mutex_unlock(&sleep_mutex);
             return false;
         }
 
@@ -169,8 +159,6 @@ namespace OHOS
 
         fclose(fp);
 
-        osal_mutex_unlock(&sleep_mutex);
-
         return true;
     }
 
@@ -178,7 +166,19 @@ namespace OHOS
     {
         memset(&nap_data, 0, sizeof(NAP_T));
         memcpy_s(&nap_data, sizeof(NAP_T), data, sizeof(NAP_T));
+
+        //睡眠存储加锁与设runtime状态统一在外面处理
+        uapi_dev_runtime_set_sleep_storage_status(1);
+        errcode_t ret = osal_mutex_lock(&sleep_mutex);
+        if (ret != ERRCODE_SUCC) 
+        {
+            PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret);
+            uapi_dev_runtime_set_sleep_storage_status(0);
+            return;
+        }
         save_nap_data(&nap_data);
+        osal_mutex_unlock(&sleep_mutex);
+        uapi_dev_runtime_set_sleep_storage_status(0);
     }
 
     uint32_t read_sleep_nap_data(char *data, uint32_t size, FILE *fp)
@@ -296,7 +296,6 @@ namespace OHOS
         if (fp == NULL)
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
-            osal_mutex_unlock(&sleep_mutex);
             return false;
         }
 
@@ -375,7 +374,6 @@ namespace OHOS
             if(fp == NULL)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
-                osal_mutex_unlock(&sleep_mutex);
                 return false;
             }
             // if(data->wake_up_timestamp != 0)
@@ -424,8 +422,6 @@ namespace OHOS
         }
         fclose(fp);
 
-       osal_mutex_unlock(&sleep_mutex);
-
         return true;
     }
 
@@ -509,7 +505,18 @@ namespace OHOS
     {
         memset(&sleep_data, 0, sizeof(SLEEP_T));
         memcpy_s(&sleep_data, sizeof(SLEEP_T), data, sizeof(SLEEP_T));
+        //睡眠存储加锁与设runtime状态统一在外面处理
+        uapi_dev_runtime_set_sleep_storage_status(1);
+        errcode_t ret = osal_mutex_lock(&sleep_mutex);
+        if (ret != ERRCODE_SUCC) 
+        {
+            PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret);
+            uapi_dev_runtime_set_sleep_storage_status(0);
+            return;
+        }
         save_sleep_data(&sleep_data);
+        osal_mutex_unlock(&sleep_mutex);
+        uapi_dev_runtime_set_sleep_storage_status(0);
         // 刷新model里面的数据
         // SleepModel::GetInstance().update_sleep(&sleep_data);
     }
index 455a5e1..9b86a82 100644 (file)
@@ -1225,6 +1225,13 @@ int cywee_main_dml(void)
     // for(int i = 0 ; i < 80 ; i++)
     //     printf("%d",buffer[i]);
     // printf("\n");
+       
+    //降功耗
+       memset(&scl, 0, sizeof(scl));
+       scl.iData[0] = 1;
+       scl.iData[1] = 2;
+       CWM_SettingControl(SCL_SENS_CALI_CONFIG, &scl);
+       
     CWM_LibPostInit(CWM_AP_SensorListen);
     //CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__);
 
index b59b374..35e0d6a 100644 (file)
@@ -92,6 +92,7 @@ typedef struct
     uint8_t lock_flag_training;//训练
     uint8_t lock_flag_heartrate;//心率
     uint8_t lock_flag_blood;//血氧
+    uint8_t lock_flag_sleep;//睡眠
 
 } runtime_status_t;
 
@@ -472,6 +473,11 @@ uint8_t uapi_dev_runtime_get_rwlock_status(void)
         //血氧存储
         g_runtime.rwlock_status = 1;
     }
+    if(g_runtime.lock_flag_sleep)
+    {
+        //睡眠存储
+        g_runtime.rwlock_status = 1;
+    }
     return g_runtime.rwlock_status;
 }
 //设置运动存储
@@ -501,6 +507,15 @@ uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void)
 {
     return g_runtime.lock_flag_blood;
 }
+//设置睡眠存储
+void uapi_dev_runtime_set_sleep_storage_status(uint8_t status)
+{
+    g_runtime.lock_flag_sleep = status;
+}
+uint8_t uapi_dev_runtime_get_sleep_storage_status(void)
+{
+    return g_runtime.lock_flag_sleep;
+}
 //后续还需要补充。。。
 
 // 设置被动心率检测状态
index 358c2d3..6e71c8f 100644 (file)
@@ -141,6 +141,13 @@ uint8_t uapi_dev_runtime_get_heartrate_storage_status(void);
 void uapi_dev_runtime_set_bloodoxygen_storage_status(uint8_t status);
 uint8_t uapi_dev_runtime_get_bloodoxygen_storage_status(void);
 
+/*
+    睡眠存储
+    0 未存储
+    1 正在存储
+*/
+void uapi_dev_runtime_set_sleep_storage_status(uint8_t status);
+uint8_t uapi_dev_runtime_get_sleep_storage_status(void);
 
 /*运动识别*/
 void uapi_dev_runtime_set_motion_recognition_status(uint8_t status);