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
%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
%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
#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)
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();
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;
}
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)
{
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;
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");
--- /dev/null
+/*
+ * 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;
+};