Apply conf file and change thermal structure 67/197367/8
authorlokilee73 <changjoo.lee@samsung.com>
Thu, 10 Jan 2019 12:08:51 +0000 (21:08 +0900)
committerlokilee73 <changjoo.lee@samsung.com>
Tue, 15 Jan 2019 04:45:17 +0000 (13:45 +0900)
Firstly, thermal value depends on hardware.
So, we have to apply different temp table for each targets.

Secondly, change the name on temp table as products.
ex) Critical -> Limt
    Danger -> Shutdown

Lastly, change condition in thermal_get_temp_enum

Change-Id: If25be071e000dfaa1d5e68d205538cd2332d1d9b
Signed-off-by: lokilee73 <changjoo.lee@samsung.com>
CMakeLists.txt
conf/temperature.conf [new file with mode: 0644]
conf/wearable-temperature.conf [new file with mode: 0644]
packaging/deviced.spec
src/thermal/thermal.c
src/thermal/thermal.h [new file with mode: 0644]

index bd1b986..013b1f2 100644 (file)
@@ -246,6 +246,11 @@ IF(POWER_MODULE STREQUAL on)
        INSTALL_CONF(conf power)
 ENDIF()
 
+IF(THERMAL_MODULE STREQUAL on)
+       INSTALL_CONF(conf temperature)
+       INSTALL_CONF(conf wearable-temperature)
+ENDIF()
+
 # USB connection
 IF(USB_MODULE STREQUAL on)
        # USB (Manual setting)
diff --git a/conf/temperature.conf b/conf/temperature.conf
new file mode 100644 (file)
index 0000000..db8a158
--- /dev/null
@@ -0,0 +1,6 @@
+[THERMAL]
+#Level is Celsius
+Normal=70
+Warning=75
+Limit=80
+Shutdown=85
diff --git a/conf/wearable-temperature.conf b/conf/wearable-temperature.conf
new file mode 100644 (file)
index 0000000..ceb68b2
--- /dev/null
@@ -0,0 +1,6 @@
+[THERMAL]
+#Level is Celsius
+Normal=44
+Warning=46
+Limit=48
+Shutdown=53
index d2d988b..2606afa 100644 (file)
@@ -207,6 +207,7 @@ cat %{_sysconfdir}/deviced/wearable-display.conf >> %{_sysconfdir}/deviced/displ
 rm -rf %{_sysconfdir}/deviced/wearable-display.conf
 mkdir -p %{_libdir}/deviced
 mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so
+mv %{_sysconfdir}/deviced/wearable-temperature.conf %{_sysconfdir}/deviced/temperature.conf
 
 %post plugin-profile-tv
 mkdir -p %{_libdir}/deviced
@@ -272,6 +273,7 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so
 %license LICENSE.Apache-2.0
 %defattr(-,root,root,-)
 %config %{_sysconfdir}/deviced/mobile-display.conf
+%config %{_sysconfdir}/deviced/temperature.conf
 %{_libdir}/mobile-display.so
 
 %files plugin-profile-wearable
@@ -279,16 +281,19 @@ mv %{_libdir}/iot-display.so %{_libdir}/deviced/display.so
 %license LICENSE.Apache-2.0
 %defattr(-,root,root,-)
 %config %{_sysconfdir}/deviced/wearable-display.conf
+%config %{_sysconfdir}/deviced/wearable-temperature.conf
 %{_libdir}/wearable-display.so
 
 %files plugin-profile-tv
 %manifest deviced.manifest
 %license LICENSE.Apache-2.0
 %defattr(-,root,root,-)
+%config %{_sysconfdir}/deviced/temperature.conf
 %{_libdir}/tv-display.so
 
 %files plugin-profile-iot
 %manifest deviced.manifest
 %license LICENSE.Apache-2.0
 %defattr(-,root,root,-)
+%config %{_sysconfdir}/deviced/temperature.conf
 %{_libdir}/iot-display.so
index 6dd8b22..794b186 100644 (file)
 #include "core/log.h"
 #include "core/device-notifier.h"
 #include "core/devices.h"
+#include "thermal.h"
+#include "core/config-parser.h"
 
 static struct thermal_device *thermal_dev;
 static int noti;
 
-/* Action types */
-#define RELEASE_ACTION                 "ReleaseAction"
-#define WARNING_ACTION                 "WarningAction"
-#define LIMIT_ACTION                   "LimitAction"
-#define SHUTDOWN_ACTION                "ShutdownAction"
+#define THERMAL_CONF_FILE      "/etc/deviced/temperature.conf"
 
-#define SIGNAL_OVERHEAT_TIME           "TimeUpdate"
-#define OVERHEAT_CALLBACK_TIME         1 //seconds
-#define OVERHEAT_POWEROFF_TIME         30
-
-#define SAMPLE_CNT             4
-
-enum thermal_enum_type {
-       NORMAL,
-       WARNING,
-       CRITICAL,
-       DANGER
-};
-
-static int ap_temp_table[DANGER + 1] = {
-/* [Lv] = {Celsius degree} */
-       44,
-       46,
-       48,
-       53,
+static struct thermal_config_info thermal_table = {
+       .normal   = TEMPERATURE_NORMAL,
+       .warning  = TEMPERATURE_WARNING,
+       .limit    = TEMPERATURE_LIMIT,
+       .shutdown = TEMPERATURE_SHUTDOWN
 };
 
 static int power_off(void)
@@ -206,18 +190,17 @@ static void thermal_action(int state)
                break;
 
        case WARNING:
-               thermal_remove_popup();
-               thermal_add_noti();
+               _I("State is WARNING");
                action = strdup(WARNING_ACTION);
                break;
 
-       case CRITICAL:
+       case LIMIT:
                thermal_remove_popup();
                thermal_add_noti();
                action = strdup(LIMIT_ACTION);
                break;
 
-       case DANGER:
+       case SHUTDOWN:
                thermal_remove_popup();
                thermal_remove_noti();
                thermal_overheat_popup();
@@ -229,21 +212,46 @@ static void thermal_action(int state)
        free(action);
 }
 
-static bool is_thermal_updated(int old_state, int new_state)
+/* Action Table
+--------------------------------------------------
+Current                Previous        Action
+--------------------------------------------------
+NORMAL         NORMAL          X
+               WARNING         X
+               LIMIT           ReleaseAction
+               SHUTDOWN        X
+--------------------------------------------------
+WARNING                NORMAL          print log
+               WARNING         X
+               LIMIT           X
+               SHUTDOWN        X
+--------------------------------------------------
+LIMIT          NORMAL          LimitAction
+               WARNING         LimitAction
+               LIMIT           X
+               SHUTDOWN        X
+--------------------------------------
+SHUTDOWN       NORMAL          ShutdownAction
+               WARNING         ShutdownAction
+               LIMIT           ShutdownAction
+               SHUTDOWN        X
+--------------------------------------------------
+*/
+static bool is_action_needed(int old_state, int new_state)
 {
        bool ret = false;
 
        if (new_state == NORMAL) {
-               if (old_state == WARNING || old_state == CRITICAL)
+               if (old_state == WARNING || old_state == LIMIT)
                        ret = true;
        } else if (new_state == WARNING) {
-               if (old_state == NORMAL || old_state == CRITICAL)
+               if (old_state == NORMAL)
                        ret = true;
-       } else if (new_state == CRITICAL) {
+       } else if (new_state == LIMIT) {
                if (old_state == NORMAL || old_state == WARNING)
                        ret = true;
-       } else if (new_state == DANGER) {
-               if (old_state != DANGER)
+       } else if (new_state == SHUTDOWN) {
+               if (old_state != SHUTDOWN)
                        ret = true;
        }
 
@@ -252,17 +260,18 @@ static bool is_thermal_updated(int old_state, int new_state)
 
 static int thermal_get_temp_enum(int temp)
 {
-       int i;
+       int ret = -1;
 
-       if (temp > ap_temp_table[DANGER])
-               return DANGER;
+       if (temp <= thermal_table.normal)
+               ret = NORMAL;
+       else if (temp >= thermal_table.shutdown)
+               ret = SHUTDOWN;
+       else if (temp >= thermal_table.limit)
+               ret = LIMIT;
+       else if (temp >= thermal_table.warning)
+               ret = WARNING;
 
-       for (i = 0; i < DANGER + 1; i++) {
-               if (temp <= ap_temp_table[i])
-                       break;
-       }
-
-       return i;
+       return ret;
 }
 
 static int thermal_get_average(int temp)
@@ -285,18 +294,18 @@ static void thermal_handler(struct thermal_info *info, void *data)
 {
        static int old_state = NORMAL;
        int avg_temp, new_state;
-       bool updated = false;
+       bool action_needed = false;
 
        avg_temp = thermal_get_average(info->temp);
        new_state = thermal_get_temp_enum(avg_temp);
-       if (new_state < NORMAL || new_state > DANGER) {
-               _E("Invalid thermal state : %d", new_state);
+       if (new_state == -1) {
+               _I("Keep current state : %d", old_state);
                return;
        }
 
-       updated = is_thermal_updated(old_state, new_state);
-       _I("Last updated(%d) old_state(%d) new_state(%d)", updated, old_state, new_state);
-       if (updated)
+       action_needed = is_action_needed(old_state, new_state);
+       _I("Action(%d) old_state(%d) new_state(%d)", action_needed, old_state, new_state);
+       if (action_needed)
                thermal_action(new_state);
 
        old_state = new_state;
@@ -350,10 +359,46 @@ static int booting_done(void *data)
        return done;
 }
 
+static int load_config(struct parse_result *result, void *user_data)
+{
+       struct thermal_config_info *info = user_data;
+       char *name;
+       char *value;
+
+       _D("%s,%s,%s", result->section, result->name, result->value);
+
+       if (!info)
+               return -EINVAL;
+
+       if (!MATCH(result->section, "THERMAL"))
+               return -EINVAL;
+
+       name = result->name;
+       value = result->value;
+       if (MATCH(name, "Normal"))
+               info->normal = atoi(value);
+       else if (MATCH(name, "Warning"))
+               info->warning = atoi(value);
+       else if (MATCH(name, "Limit"))
+               info->limit = atoi(value);
+       else if (MATCH(name, "Shutdown"))
+               info->shutdown = atoi(value);
+
+       return 0;
+}
+
 static void thermal_init(void *data)
 {
        int ret;
 
+       /* load thermal configuration file */
+       ret = config_parse(THERMAL_CONF_FILE, load_config, &thermal_table);
+       if (ret < 0)
+               _E("Failed to load power off config (%d)", ret);
+
+       _I("temperature conf %d %d %d %d", thermal_table.normal, thermal_table.warning,
+               thermal_table.limit, thermal_table.shutdown);
+
        ret = register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
        if (ret < 0)
                _E("Fail to register booting done Notifier");
diff --git a/src/thermal/thermal.h b/src/thermal/thermal.h
new file mode 100644 (file)
index 0000000..19b8d3b
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+/* Action types */
+#define RELEASE_ACTION                 "ReleaseAction"
+#define WARNING_ACTION                 "WarningAction"
+#define LIMIT_ACTION                   "LimitAction"
+#define SHUTDOWN_ACTION                "ShutdownAction"
+
+#define SIGNAL_OVERHEAT_TIME           "TimeUpdate"
+#define OVERHEAT_CALLBACK_TIME         1 //seconds
+#define OVERHEAT_POWEROFF_TIME         30
+
+#define SAMPLE_CNT             4
+
+#define TEMPERATURE_NORMAL             70
+#define TEMPERATURE_WARNING            75
+#define TEMPERATURE_LIMIT              80
+#define TEMPERATURE_SHUTDOWN           85
+
+enum thermal_enum_type {
+       NORMAL,
+       WARNING,
+       LIMIT,
+       SHUTDOWN
+};
+
+struct thermal_config_info {
+       int normal;
+       int warning;
+       int limit;
+       int shutdown;
+};