[Feature][ZXW-33]merge ZXW 0428 version

Change-Id: I11f167edfea428d9fab198ff00ff1364932d1b0b
diff --git a/ap/app/zte_comm/rtc-service/rtc-service.c b/ap/app/zte_comm/rtc-service/rtc-service.c
index cae1f7e..c5baf65 100755
--- a/ap/app/zte_comm/rtc-service/rtc-service.c
+++ b/ap/app/zte_comm/rtc-service/rtc-service.c
@@ -301,7 +301,36 @@
  *******************************************/
 static int handle_get_time(MSG_BUF *pmsg_buf)
 {
+	struct rtc_time rtc_tm = {0};
+	int ret = 0;
+	RTC_DATA_BUF * buf = pmsg_buf->aucDataBuf;
+	
 	slog(RTC_PRINT, SLOG_DEBUG, "rtc-service: handle_get_time NOOPS.\n");
+
+	if(buf->cpu == RTC_CPU_CAP)
+	{
+		int cmd = RTC_MSG_GET_TIME;
+		RTC_DATA_BUF  sendbuf = {0};
+		unsigned long cur_sec =0;
+		
+		ret = ioctl(g_rtc_fd, RTC_RD_TIME, &rtc_tm);
+		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_get_time tm_year:%d, tm_mon:%d, tm_hour:%d, tm_min:%d, tm_yday:%d, tm_mday:%d, tm_wday:%d.\n",
+		rtc_tm.tm_year, rtc_tm.tm_mon, rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_yday, rtc_tm.tm_mday, rtc_tm.tm_wday);
+		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_get_time src_id:0x%x, buf->cpu:%d.\n",buf->srcModule,buf->cpu);
+		
+		cur_sec = mktime(&rtc_tm);
+		sendbuf.srcModule = buf->srcModule;
+		sendbuf.cpu = RTC_CPU_AP;
+		sendbuf.ulSec = cur_sec;
+	
+		slog(RTC_PRINT, SLOG_NORMAL, "[rtc] handle_get_time: send to cap cmd:0x%x, srcMod:0x%x, cur_sec:%lu \n", cmd, sendbuf.srcModule, sendbuf.ulSec);
+		ret = send_soc_msg(FAR_PS, MODULE_ID_RTC_SERVICE, cmd, sizeof(RTC_DATA_BUF), (void *)&sendbuf);
+		if (ret != 0)
+		{
+			slog(RTC_PRINT, SLOG_ERR, "rtc-service: ipc_send_message unexpected,ret:%d\n",ret);;
+		}
+	}
+	
 	return 0;
 }
 
@@ -369,7 +398,7 @@
 	memcpy(&pAlarm->rtc_tm, &rtc_tm, sizeof(rtc_tm));
 
 	pAlarm->rtc_id = buf->module;
-	pAlarm->module_id = pmsg_buf->src_id;
+	pAlarm->module_id = buf->srcModule;
 	pAlarm->interval = buf->ulSec ;   //  count down time
 	pAlarm->remain_time = buf->ulSec; // remain count down time
 	pAlarm->wakeup = buf->wakeup;
@@ -480,9 +509,9 @@
 	list_for_each_entry_safe(pTmp, pTmp1, &rtc_timer_list, list) {
 		slog(RTC_PRINT, SLOG_DEBUG, "rtc-service: handle_alarm_del timer module:0x%x - 0x%x, src:0x%x - 0x%x.\n",
 		     buf->module, pTmp->rtc_id, buf->srcModule, pTmp->module_id);
-		if ((buf->module == pTmp->rtc_id) && (buf->srcModule == pTmp->module_id)) {
-        		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_alarm_del timer module:0x%x , src:0x%x \n",
-        		     buf->module, buf->srcModule );
+		if ((buf->module == pTmp->rtc_id) && (buf->srcModule == pTmp->module_id)&& (buf->cpu == pTmp->cpu)) {
+        		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_alarm_del timer module:0x%x , src:0x%x , cpu:%d \n",
+        		     buf->module, buf->srcModule, buf->cpu);
 			list_del(&pTmp->list);
 			free(pTmp);
 			break;
@@ -492,9 +521,9 @@
 	list_for_each_entry_safe(pTmp, pTmp1, &rtc_alarm_list, list) {
 		slog(RTC_PRINT, SLOG_DEBUG, "rtc-service: handle_alarm_del alarm module:0x%x - 0x%x, src:0x%x - 0x%x.\n",
 		     buf->module, pTmp->rtc_id, buf->srcModule, pTmp->module_id);
-		if ((buf->module == pTmp->rtc_id) && (buf->srcModule == pTmp->module_id)) {
-        		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_alarm_del alarm module:0x%x , src:0x%x \n",
-        		     buf->module, buf->srcModule );
+		if ((buf->module == pTmp->rtc_id) && (buf->srcModule == pTmp->module_id)&& (buf->cpu == pTmp->cpu)) {
+        		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_alarm_del alarm module:0x%x , src:0x%x , cpu:%d \n",
+        		     buf->module, buf->srcModule, buf->cpu);
 			wakeup = pTmp->wakeup;
 			list_del(&pTmp->list);
 			free(pTmp);
@@ -510,6 +539,24 @@
 	return 0;
 }
 
+void send_ok_del_rsp(MSG_BUF *pmsg_buf)
+{
+	RTC_DATA_BUF * buf = pmsg_buf->aucDataBuf;
+
+	if(buf->cpu == RTC_CPU_CAP)
+	{
+		int ret = 0;
+		RTC_DATA_BUF sendbuf = {0};
+		sendbuf.cpu = RTC_CPU_AP;
+		sendbuf.module = buf->module;
+		sendbuf.srcModule = buf->srcModule;
+		ret = send_soc_msg(FAR_PS, MODULE_ID_RTC_SERVICE, RTC_MSG_DEL_ALARM, sizeof(RTC_DATA_BUF), (void *)&sendbuf);
+		if (ret != 0) 
+		{
+			slog(RTC_PRINT, SLOG_ERR, "send_ok_del_rsp: failed,ret:%d\n",ret);
+		}
+	}
+}
 /********************************************
  *¹¦ÄÜ:¶¨Ê±Æ÷³¬Ê±´¦Àí
  *******************************************/
@@ -557,12 +604,29 @@
 	wakeup = pAlarm->wakeup;
 	list_del(&pAlarm->list);
 	buf.module = pAlarm->rtc_id;
+	buf.srcModule = pAlarm->module_id;
 	slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: handle_alarm_timeout: target:0x%x, rtc_id:0x%x, utc:%d \n", pAlarm->module_id, buf.module, pAlarm->is_utc);
-	ret = ipc_send_message2(MODULE_ID_RTC_SERVICE, pAlarm->module_id, RTC_MSG_ALARM_ELAPSED, sizeof(RTC_DATA_BUF), (unsigned char*)&buf, 0);
-	if (ret != 0) {
-		slog(RTC_PRINT, SLOG_ERR, "rtc-service: ipc_send_message unexpected\n");
+	if(pAlarm->cpu == RTC_CPU_AP)
+	{	
+		ret = ipc_send_message2(MODULE_ID_RTC_SERVICE, pAlarm->module_id, RTC_MSG_ALARM_ELAPSED, sizeof(RTC_DATA_BUF), (unsigned char*)&buf, 0);
+		if (ret != 0) {
+			slog(RTC_PRINT, SLOG_ERR, "rtc-service: ipc_send_message unexpected,ret:%d\n",ret);
+		}
 	}
+	else
+	{
+		buf.module = pAlarm->rtc_id;
+        buf.srcModule = pAlarm->module_id;
+        buf.cpu = RTC_CPU_AP;
+        buf.is_utc = pAlarm->is_utc;
 
+		slog(RTC_PRINT, SLOG_NORMAL, "[rtc] handle_alarm_timeout: send to cap cmd:0x%x, srcMod:0x%x, module:0x%x, utc:%d \n", cmd, buf.srcModule, buf.module, pAlarm->is_utc);
+        ret = send_soc_msg(FAR_PS, MODULE_ID_RTC_SERVICE, cmd, sizeof(RTC_DATA_BUF), (void *)&buf);
+        if (ret != 0)
+        {
+            slog(RTC_PRINT, SLOG_ERR, "rtc-service: ipc_send_message unexpected,ret:%d\n",ret);;
+        }
+	}
 	if (pAlarm->is_utc == 0) {
 		alarm_adjust_value(pAlarm->remain_time);
 		alarm_fix_value(&rtc_timer_list);
@@ -865,6 +929,7 @@
 		slog(RTC_PRINT, SLOG_NORMAL, "rtc-service: process_msg RTC_MSG_DEL_ALARM, src:0x%x.\n", pmsg_buf->src_id);
 		update_timer_remain(0);
 		handle_alarm_del(pmsg_buf);
+		send_ok_del_rsp(pmsg_buf);
 		alarm_restart(&rtc_timer_list);
 		alarm_restart(&rtc_alarm_list);
 		break;