blob: 931a5bd8a4d2f7e52db6e5199f4ab15cc071238f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*****************************************************************************
2* °æ±¾ËùÓÐ (C)ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾
3* Ä£¿éÃû £ºMMI
4* ÎļþÃû £ºmmi.c
5* Îļþ±êʶ £º
6* Ïà¹ØÎļþ £º
7* ʵÏÖ¹¦ÄÜ £º
8* ×÷Õß £º
9* °æ±¾ £ºV1.0
10* Íê³ÉÈÕÆÚ £º2014-6-20
11* ÆäËü˵Ã÷ £º
12*
13******************************************************************************/
14
15/*****************************************************************************
16 Í·Îļþ
17******************************************************************************/
18#include <wdt_common.h>
19
20/********************************************************************************
21 È«¾Ö±äÁ¿ÒýÓÃ
22**********************************************************************************/
23
24
25/********************************************************************************
26 È«¾Ö±äÁ¿¶¨Òå
27**********************************************************************************/
28int g_wdt_msgQue_Id = 0;
29
30SINT32 g_hightempvol = 0;
31SINT32 g_superhightempvol = 0;
32SINT32 g_lowtempvol = 0;
33SINT32 g_superlowtempvol = 0;
34UINT32 g_watchdog_flag = 0;
35
36/**********************************************************************************
37º¯Êý×÷ÓÃ:´´½¨½ø³ÌµÄÏûÏ¢¶ÓÁÐ
38***********************************************************************************/
39long wdt_create_msg_queue()
40{
41 int msgid = 0;
42 if ((msgid = msgget(MODULE_ID_WDT, IPC_CREAT | 0600)) == -1) {
43 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT [error]:Create MODULE_ID_WDT queue faild! msgid=%d\n", msgid);
44 return -1;
45 }
46 slog(MMI_PRINT, SLOG_DEBUG, "ZTE_WDT Creating mmi message queue success! MODULE_ID_WDT=0x%x\n", msgid);
47 return msgid;
48}
49
50int wdt_RecvMsgFromQueue(int msgQueueId, MSG_BUF *pstMsg, long MsgType)
51{
52 int iRet = -1;
53 long msgSize = sizeof(MSG_BUF) - sizeof(long);
54
55 if (NULL == pstMsg) {
56 return -1;
57 }
58
59 iRet = msgrcv(msgQueueId, pstMsg, msgSize, MsgType, MSG_NOERROR);
60 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT wdt_RecvMsgFromQueue : iRet : %ld, pstMsg->src_id:%ld, pstMsg->usMsgCmd:%ld \n", iRet, pstMsg->src_id, pstMsg->usMsgCmd);
61
62 if (iRet <= 0) {
63 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT wdt_RecvMsgFromQueue Failed : iRet : %ld, pstMsg->src_id:%ld, pstMsg->usMsgCmd:%ld \n", iRet, pstMsg->src_id, pstMsg->usMsgCmd);
64 return -1;
65 } else {
66 return 0;
67 }
68}
69
70static int wdt_ProcMsg(MSG_BUF *pstMsg)
71{
72 int i = 0;
73 if (NULL == pstMsg) {
74 return -1;
75 }
76 if ((pstMsg->usMsgCmd != MSG_CMD_MMICHECK_TIP_INFO) && (pstMsg->usMsgCmd != MSG_CMD_MMIGET_WIFI_DATA)) {
77 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT wdt_ProcMsg msg:src_id = 0x%04x,lMsgType = %d,usMsgCmd = 0x%08x,usDataLen = %d,data = %s\n", pstMsg->src_id, pstMsg->lMsgType, pstMsg->usMsgCmd, pstMsg->usDataLen, pstMsg->aucDataBuf);
78 }
79 switch (pstMsg->usMsgCmd) {
80 case RTC_MSG_ALARM_ELAPSED:
81 //οغÍι¹·
82 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT RTC_MSG_ALARM_ELAPSED\n");
83 set_wake_lock(WDT_GET_POWER_LOCK_ID);
84 wdt_feet();
85 wdt_temp_check_process();
86 wdt_rtc_add(WDT_INTERVAL_TIME);
87 set_wake_unlock(WDT_GET_POWER_LOCK_ID);
88 break;
89 }
90 return 0;
91}
92
93
94static void *wdt_handleMsgEntry(void *arg)
95{
96 long MsgType = 0;
97 MSG_BUF Msg;
98 prctl(PR_SET_NAME, "wdthandlemsg", 0, 0, 0);
99 while (1) {
100 memset((VOID *)(&Msg), 0, sizeof(MSG_BUF));//warning516
101 if (-1 != wdt_RecvMsgFromQueue(g_wdt_msgQue_Id, &Msg, MsgType)) {
102 wdt_ProcMsg(&Msg);
103 }
104 }
105}
106
107/**********************************************************************************
108º¯Êý×÷ÓÃ:MMIÈë¿Úº¯Êý ´´½¨ÏûÏ¢¶ÓÁÐ ¸÷¸öµÆ³õʼ»¯ ½ÓÊÕÏûÏ¢
109***********************************************************************************/
110VOID wdt_creatMsgThread()
111{
112 //pthread_t handlemsg_thread;
113
114 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT start wdt_creatMsgThread\n");
115
116 long MsgType = 0;
117 MSG_BUF Msg;
118 prctl(PR_SET_NAME, "zte_watchdog", 0, 0, 0);
119 while (1) {
120 memset((VOID *)(&Msg), 0, sizeof(MSG_BUF));
121 if (-1 != wdt_RecvMsgFromQueue(g_wdt_msgQue_Id, &Msg, MsgType)) {
122 wdt_ProcMsg(&Msg);
123 }
124 }
125
126}
127
128static VOID *wdt_creatTempCheckThread(VOID *arg)
129{
130 UINT32 voltagepower = 0;
131
132 prctl(PR_SET_NAME, "zte_tempvheck", 0, 0, 0);
133
134 while (1) {
135 set_wake_lock(WDT_GET_POWER_LOCK_ID);
136 wdt_temp_check_process();
137 set_wake_unlock(WDT_GET_POWER_LOCK_ID);
138 sleep(TEMPCHECK_INTERVAL_TIME);
139 }
140}
141
142static int get_nv()
143{
144 char nv_value[NV_NAME_LEN] = {0};
145
146 sc_cfg_get("mmi_temp_voltage_line", nv_value, sizeof(nv_value));
147 slog(MMI_PRINT, SLOG_ERR, "mmi_temp_voltage_line = %s\n", nv_value);
148 char *tmp = NULL;
149 char *substr = strtok_r(nv_value, "+", &tmp);
150 SINT32 temp[4] = {0};
151 int i = 0;
152 while (substr != NULL) {
153 temp[i] = atoi(substr);
154 i++;
155 substr = strtok_r(NULL, "+", &tmp);
156 }
157 g_superhightempvol = temp[0];
158 g_hightempvol = temp[1];
159 g_lowtempvol = temp[2];
160 g_superlowtempvol = temp[3];
161 slog(MMI_PRINT, SLOG_ERR, "g_mmi_temp = %d %d %d %d %d\n", i, g_superhightempvol, g_hightempvol, g_lowtempvol, g_superlowtempvol);
162 if(i != 4)
163 softap_assert("");
164 sc_cfg_get("mmi_use_protect", nv_value, sizeof(nv_value));
165
166 if (strstr(nv_value, "discharge_protect")) {
167 g_discharge_protect_wd = 1;
168 }
169
170 if (strstr(nv_value, "temp_protect")) {
171 g_temp_protect_wd = 1;
172 if (strstr(nv_value, "charge_protect")) {
173 g_charge_protect_wd = 1;
174 }
175 }
176
177 sc_cfg_get("watchdog_app", nv_value, sizeof(nv_value));
178 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT watchdog_app = %s\n", nv_value);
179
180 if (strcmp(nv_value, "1") == 0) {
181 g_watchdog_flag = 1;
182 }
183
184 return 0;
185}
186
187/**********************************************************************************
188º¯Êý×÷ÓÃ:MMIÈë¿Úº¯Êý ´´½¨ÏûÏ¢¶ÓÁÐ ¸÷¸öµÆ³õʼ»¯ ½ÓÊÕÏûÏ¢
189***********************************************************************************/
190int zte_watchdog_main(int argc, char * argv[])
191{
192 pthread_t temp_check_thread;
193 prctl(PR_SET_NAME, "mmi_watchdog", 0, 0, 0);
194 //³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿
195 loglevel_init();
196
197 //zdm½«nvÉèÖÃת»»³ÉÈ«¾Ö±äÁ¿½øÐй¦ÄÜ¿ØÖÆ
198 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT ######START######\n");
199
200 if ((g_wdt_msgQue_Id = wdt_create_msg_queue()) == -1) {
201 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT create g_mmi_msgQue_Id failed!!!\n");
202 assert(0);
203 }
204
205 get_nv();
206
207 if (!g_watchdog_flag && !g_temp_protect_wd) {
208 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT ######END######\n");
209 return -1;
210 }
211 if (g_watchdog_flag) {
212 wdt_init();
213 wdt_rtc_add(WDT_INTERVAL_TIME);
214 } else {
215 if (pthread_create(&temp_check_thread, NULL, &wdt_creatTempCheckThread, NULL) == -1) {
216 slog(MMI_PRINT, SLOG_ERR, "ZTE_WDT temp_check_thread creat error\n");
217 return -1;
218 }
219 }
220
221 wdt_creatMsgThread();
222 return 0;
223}
224