DateTime.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:71k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * DateTime.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * This file implements date/time related utilities for other applications
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2004
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * DateTime.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- * This file implements date/time related utilities for other applications
- *
- * Author:
- * -------
- * -------
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- /**
- * Copyright Notice
- * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
- * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
- * (It is illegal to remove this copyright notice from this software or any
- * portion of it)
- */
- /**************************************************************
- FILENAME : DateTime.c
- PURPOSE : Utility functions to enable date and time display on idle screen
- REMARKS : nil
- AUTHOR : Neeraj Sharma, Vijay Vaidya
- DATE : Aug' 28, 2002
- **************************************************************/
- #ifndef _MMI_DATETIME_C
- #define _MMI_DATETIME_C
- #include "MMI_features.h"
- /* Include: MMI header file */
- #include "Stdafx.h"
- #include "PixtelDataTypes.h"
- #include "DebugInitDef.h"
- #include "DateTimeType.h"
- #include "EventsGprot.h"
- #include "DateTimeGprot.h"
- #include "L4Dr.h"
- #include <time.h>
- #include "TimerEvents.h"
- #ifndef MMI_ON_WIN32
- #include "rtc_sw.h"
- #endif
- #include "NVRAMType.h"
- #include "NVRAMEnum.h"
- #include "NVRAMProt.h"
- #include "SimDetectionGexdcl.h"
- #include "SimDetectionGprot.h"
- #include "AlarmFrameworkProt.h"
- #include "SettingStructs.h"
- #include "ProtocolEvents.h"
- #ifdef __MMI_LCD_PARTIAL_ON__
- #include "IdleAppProt.h"
- #endif
- /* Include: PS header file */
- /*
- * Define
- */
- #define DT_UTC_BASE_YEAR 1970
- #define DT_MONTH_PER_YEAR 12
- #define DT_DAY_PER_YEAR 365
- #define DT_SEC_PER_DAY 86400
- #define DT_SEC_PER_HOUR 3600
- #define DT_SEC_PER_MIN 60
- #define MMI_DT_YEAR_BOUNDARY 30
- /*
- * Typedef
- */
- /*
- * Local Variable
- */
- #ifdef MMI_ON_WIN32
- const U8 gDaysInMonth[NUM_MONTHS] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- #define DT_DAYS_OF_WEEK 7
- #endif
- #ifdef MMI_ON_WIN32
- MYTIME MyTime = {0, 1, 1, 1, 1, 1, 0}; /* Variable used by Setting Application */
- S8 DateTimeStrings[2][30]; /* amitm5 to be removed as told by manju */
- static S8 NameOfMonth[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
- static S8 NameOfday[7][4] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
- #endif /* MMI_ON_WIN32 */
- /*
- * Local Function
- */
- static void DTResetTime(void);
- /*
- * Global Variable
- */
- /* extern U8 idleScreenFirst; */
- U8 CMDateTimeRequest = 0;
- U8 CMCallCount = 0;
- U8 CMCallBackCount = 0;
- extern U8 g_dst;
- DateTimeFuncPtr CMDateTimeCallBack[MAX_CM_CALLS];
- #ifndef __MTK_TARGET__
- extern MYTIME MyTime;
- #endif
- #ifndef MMI_ON_WIN32
- extern rtc_format_struct gclockData;
- #endif
- #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
- extern BOOL gIsInSleepMode;
- #endif
- /*
- * Global Function
- */
- extern FLOAT GetTimeZone(U8);
- extern U8 PhnsetGetHomeCity(void);
- #ifdef MMI_ON_WIN32
- extern kal_uint8 g_dst;
- /*****************************************************************************
- * FUNCTION
- * applib_dt_is_dst_enabled
- * DESCRIPTION
- * Tp check if daylight saving time is enabled
- * PARAMETERS
- * void
- * t time to be computed(?)
- * RETURNS
- * TURE if enabled; otherwise, false
- *****************************************************************************/
- kal_bool applib_dt_is_dst_enabled(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return (kal_bool) g_dst;
- }
- /*****************************************************************************
- * FUNCTION
- * MyMonth
- * DESCRIPTION
- * Fucntion to update year and month, this function is used in PC simulator only.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void MyMonth()
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (MyTime.nMonth == 12)
- {
- MyTime.nMonth = 1;
- MyTime.nYear++;
- }
- else
- {
- MyTime.nMonth++;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * DateTimerProc
- * DESCRIPTION
- * Fucntion to update and display date and time. This function is used in PC simulator only.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void DateTimerProc(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- //#ifdef MMI_ON_HARDWARE_P
- // L4GetClockTime();
- //#else
- S32 CompareDay = 28;
- S16 isLeapYear = 0;
- U8 nDateChanged = 0x0;
- U8 update_flag = 0;
- /********************************************************
- Patch for the demo:: Min_Change_flag has been added to support low power mode.
- (May be we should have timer for 60 seconds).
- **********************************************************/
- S32 Min_Change_flag = 0;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- StartTimer(TIMER_REAL_TIME_CLOCK, 1000, DateTimerProc); /* 072605 Calvin added */
- if (MyTime.nSec == 59)
- {
- MyTime.nSec = 0;
- Min_Change_flag = 1;
- update_flag = 1;
- if (MyTime.nMin == 59)
- {
- MyTime.nMin = 0;
- if (MyTime.nHour == 23)
- {
- MyTime.nHour = 0;
- nDateChanged = 0x1;
- update_flag = 1;
- if (MyTime.DayIndex == 6)
- {
- MyTime.DayIndex = 0;
- }
- else
- {
- MyTime.DayIndex++;
- }
- switch (MyTime.nMonth)
- {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- if (MyTime.nDay == 31)
- {
- MyTime.nDay = 1;
- MyMonth();
- }
- else
- {
- MyTime.nDay++;
- }
- break;
- case 4:
- case 6:
- case 9:
- case 11:
- if (MyTime.nDay == 30)
- {
- MyTime.nDay = 1;
- MyMonth();
- }
- else
- {
- MyTime.nDay++;
- }
- break;
- case 2: /* Check for leap year */
- if (((MyTime.nYear % 100) == 0) && ((MyTime.nYear % 400) == 0))
- {
- isLeapYear = 1;
- }
- else if ((MyTime.nYear % 4) == 0)
- {
- isLeapYear = 1;
- }
- else /* Not a leap year */
- {
- isLeapYear = 0;
- }
- if (isLeapYear)
- {
- CompareDay = 29;
- }
- else
- {
- CompareDay = 28;
- }
- /* (isLeapYear) ? CompareDay = 29 : CompareDay = 28; */
- if (MyTime.nDay == CompareDay)
- {
- MyTime.nDay = 1;
- MyMonth();
- }
- else
- {
- MyTime.nDay++;
- }
- break;
- default:
- break;
- }
- //Right now only for time...need to expand to accommodate year and month
- //update
- }
- else
- {
- MyTime.nHour++;
- }
- }
- else
- {
- MyTime.nMin++;
- }
- }
- else
- {
- MyTime.nSec++;
- }
- //sprintf(DateTimeStrings[0],"%s %02d %s %d",NameOfday[MyTime.DayIndex],MyTime.nDay,NameOfMonth[MyTime.nMonth-1],MyTime.nYear);
- //sprintf(DateTimeStrings[1],"%02d:%02d:%02d",MyTime.nHour,MyTime.nMin,MyTime.nSec);
- if (update_flag)
- { /* Lisen0522 */
- update_mainlcd_dt_display();
- update_sublcd_dt_display();
- }
- /* */
- }
- /*****************************************************************************
- * FUNCTION
- * InitTime
- * DESCRIPTION
- * Function to initialize golbal variables and local date and time.
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void InitTime(void)
- {
- #ifdef __MTK_TARGET__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __DAILY_WALLPAPER__
- memset(&gWallpaperChangeDate, 0xFF, sizeof(gWallpaperChangeDate)); /* Robin 1226 */
- #endif
- #elif MMI_ON_WIN32
- SYSTEMTIME systime;
- time_t ltime;
- S8 MyDay[4];
- S16 i;
- GetLocalTime(&systime);
- time(<ime);
- strncpy(MyDay, ctime(<ime), 3);
- /* stack corruption fixed Kuldeep for Network Simulator 2.0 */
- MyDay[3] = ' ';
- /* changes done by Kuldeep */
- for (i = 0; i < 7; i++)
- {
- if (strncmp(MyDay, NameOfday[i], 3) == 0)
- {
- break;
- }
- }
- MyTime.nYear = systime.wYear;
- MyTime.nMonth = (U8) systime.wMonth;
- MyTime.nDay = (U8) systime.wDay;
- MyTime.nHour = (U8) systime.wHour;
- MyTime.nMin = (U8) systime.wMinute;
- MyTime.nSec = (U8) systime.wSecond;
- MyTime.DayIndex = (U8) i;
- sprintf(
- DateTimeStrings[0],
- "%s %02d %s %d",
- NameOfday[MyTime.DayIndex],
- MyTime.nDay,
- NameOfMonth[MyTime.nMonth - 1],
- MyTime.nYear);
- //sprintf(DateTimeStrings[1],"%02d::%02d::%02d",MyTime.nHour,MyTime.nMin,MyTime.nSec);
- //sprintf(DateTimeStrings[1],"%02d:%02d",MyTime.nHour,MyTime.nMin);
- StartTimer(TIMER_REAL_TIME_CLOCK, 1000, DateTimerProc);
- #else
- MyTime.nYear += DT_MIN_YEAR;
- StartTimer(TIMER_REAL_TIME_CLOCK, 1000, DateTimerProc);
- #endif
- }
- /*****************************************************************************
- * FUNCTION
- * GetDateTime
- * DESCRIPTION
- * Function to get the current date and time.
- * PARAMETERS
- * t [IN/OUT] Variable to store the result.
- * RETURNS
- * void
- *****************************************************************************/
- void GetDateTime(MYTIME *t)
- {
- #ifdef __MTK_TARGET__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- t->nSec = gclockData.rtc_sec;
- t->nMin = gclockData.rtc_min;
- t->nHour = gclockData.rtc_hour;
- t->nDay = gclockData.rtc_day;
- t->nMonth = gclockData.rtc_mon;
- t->DayIndex = gclockData.rtc_wday;
- t->nYear = YEARFORMATE + gclockData.rtc_year;
- #else /* __MTK_TARGET__ */
- t->DayIndex = MyTime.DayIndex;
- t->nDay = MyTime.nDay;
- t->nHour = MyTime.nHour;
- t->nMin = MyTime.nMin;
- t->nSec = MyTime.nSec;
- t->nMonth = MyTime.nMonth;
- t->nYear = MyTime.nYear;
- #endif /* __MTK_TARGET__ */
- t->DayIndex = DOW(t->nYear, t->nMonth, t->nDay);
- }
- /*****************************************************************************
- * FUNCTION
- * DOW
- * DESCRIPTION
- * Function to compute current day of week.
- * PARAMETERS
- * y [IN] Year of the date to be computed. (example, 2004)
- * m [IN] Month of the date to be computed
- * d [IN] Day of the date to be computed
- * RETURNS
- * U8 index of day of week
- *****************************************************************************/
- U8 DOW(U16 y, U8 m, U8 d)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (m < 3)
- {
- m += 13;
- y--;
- }
- else
- {
- m++;
- }
- return (d + 26 * m / 10 + y + y / 4 - y / 100 + y / 400 + 6) % 7;
- }
- /*****************************************************************************
- * FUNCTION
- * IsLeapYear
- * DOW
- * DESCRIPTION
- * Function to find out if given year is a leap year
- * PARAMETERS
- * year [IN]
- * y(?) [IN] Year of the date to be computed (example, 2004)(?)
- * RETURNS
- * 1 if the year is leap; otherwise 0.
- *****************************************************************************/
- U16 IsLeapYear(U16 year)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if ((year % 400) == 0)
- {
- return 1;
- }
- else if ((year % 100) == 0)
- {
- return 0;
- }
- else if ((year % 4) == 0)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * GetTimeDifference
- * DESCRIPTION
- * Function to calculate the difference between 2 times.
- * PARAMETERS
- * t1 [IN] The target time
- * t2 [IN] The base time (t1 shall be greater than t2)
- * result [IN/OUT] Result of t1-t2
- * RETURNS
- * NULL if t1 < t2; otherwise, return result
- *****************************************************************************/
- MYTIME *GetTimeDifference(MYTIME *t1, MYTIME *t2, MYTIME *result)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* Validate year ..no need of validating for month .. */
- /* /Handled NULL changes by Kuldeep for Network Simulator 2.0 */
- if (NULL == t2)
- {
- return NULL;
- }
- /* /Handled NULL changes by Kuldeep */
- if (t1->nYear < t2->nYear)
- {
- return NULL;
- }
- else
- {
- DecrementTime2(*t1, *t2, result);
- return result;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * FindMaxTime
- * DESCRIPTION
- * Function to find the larger one between two times
- * PARAMETERS
- * t1 [IN] The first time to be compared.
- * t2 [IN] The second time to be compared.
- * RETURNS
- * 0 if t1 < t2; otherwise 1.
- *****************************************************************************/
- U16 FindMaxTime(MYTIME *t1, MYTIME *t2)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (t1->nYear == t2->nYear)
- {
- if (t1->nMonth == t2->nMonth)
- {
- if (t1->nDay == t2->nDay)
- {
- if (t1->nHour == t2->nHour)
- {
- if (t1->nMin == t2->nMin)
- {
- if (t1->nSec >= t2->nSec)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else if (t1->nMin > t2->nMin)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else if (t1->nHour > t2->nHour)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else if (t1->nDay > t2->nDay)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else if (t1->nMonth > t2->nMonth)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- else if (t1->nYear > t2->nYear)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * DecrementTime2
- * DESCRIPTION
- * Decrease a reference time by some time.
- * The difference between DecrementTime is the result may not be a "time"
- * Because it's just to get the "difference", the time may be 1 month, 0 day, 12 minutes
- * PARAMETERS
- * timeToDecrement [IN] Time to be decreased
- * decrement [IN] Time to decrease
- * Result [IN/OUT] Result of compuatation
- * RETURNS
- * void
- *****************************************************************************/
- void DecrementTime2(MYTIME timeToDecrement, MYTIME decrement, MYTIME *Result)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (decrement.nSec != 0)
- {
- if (timeToDecrement.nSec >= decrement.nSec)
- {
- Result->nSec = timeToDecrement.nSec - decrement.nSec;
- }
- else
- {
- Result->nSec = NUM_MIN_HR + timeToDecrement.nSec - decrement.nSec;
- decrement.nMin++;
- }
- }
- else
- {
- Result->nSec = timeToDecrement.nSec;
- }
- if (decrement.nMin != 0)
- {
- if (timeToDecrement.nMin >= decrement.nMin)
- {
- Result->nMin = timeToDecrement.nMin - decrement.nMin;
- }
- else
- {
- Result->nMin = NUM_MIN_HR + timeToDecrement.nMin - decrement.nMin;
- decrement.nHour++;
- }
- }
- else
- {
- Result->nMin = timeToDecrement.nMin;
- }
- if (decrement.nHour != 0)
- {
- if (timeToDecrement.nHour >= decrement.nHour)
- {
- Result->nHour = timeToDecrement.nHour - decrement.nHour;
- }
- else
- {
- Result->nHour = NUM_HRS_DAY + timeToDecrement.nHour - decrement.nHour;
- decrement.nDay++;
- }
- }
- else
- {
- Result->nHour = timeToDecrement.nHour;
- }
- if (decrement.nDay != 0)
- {
- if (timeToDecrement.nDay >= decrement.nDay)
- {
- Result->nDay = timeToDecrement.nDay - decrement.nDay;
- }
- else
- {
- U8 tmp_last_day;
- decrement.nMonth++;
- if (timeToDecrement.nMonth != JAN)
- {
- tmp_last_day = LastDayOfMonth((U8) (timeToDecrement.nMonth - 1), timeToDecrement.nYear);
- }
- else
- {
- tmp_last_day = 31;
- }
- if (tmp_last_day < (tmp_last_day + timeToDecrement.nDay - decrement.nDay))
- {
- if (DEC == timeToDecrement.nMonth)
- {
- tmp_last_day += 31;
- }
- else
- {
- tmp_last_day += LastDayOfMonth((U8) (timeToDecrement.nMonth), timeToDecrement.nYear);
- }
- decrement.nMonth++;
- }
- Result->nDay = tmp_last_day + timeToDecrement.nDay - decrement.nDay;
- }
- }
- else
- {
- Result->nDay = timeToDecrement.nDay;
- }
- if (decrement.nMonth != 0)
- {
- if (timeToDecrement.nMonth >= decrement.nMonth)
- {
- Result->nMonth = timeToDecrement.nMonth - decrement.nMonth;
- }
- else
- {
- Result->nMonth = NUM_MONTHS + timeToDecrement.nMonth - decrement.nMonth;
- decrement.nYear++;
- }
- }
- else
- {
- Result->nMonth = timeToDecrement.nMonth;
- }
- Result->nYear = timeToDecrement.nYear - decrement.nYear;
- Result->DayIndex = DOW(Result->nYear, Result->nMonth, Result->nDay);
- }
- /*****************************************************************************
- * FUNCTION
- * DecrementTime
- * DESCRIPTION
- * Decrease a reference time by some time
- * PARAMETERS
- * timeToDecrement [IN] Time to be decreased
- * decrement [IN] Time to decrease
- * Result [IN/OUT] Result of compuatation
- * RETURNS
- * void
- *****************************************************************************/
- void DecrementTime(MYTIME timeToDecrement, MYTIME decrement, MYTIME *Result)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (decrement.nSec != 0)
- {
- if (timeToDecrement.nSec >= decrement.nSec)
- {
- Result->nSec = timeToDecrement.nSec - decrement.nSec;
- }
- else
- {
- Result->nSec = NUM_MIN_HR + timeToDecrement.nSec - decrement.nSec;
- decrement.nMin++;
- }
- }
- else
- {
- Result->nSec = timeToDecrement.nSec;
- }
- if (decrement.nMin != 0)
- {
- if (timeToDecrement.nMin >= decrement.nMin)
- {
- Result->nMin = timeToDecrement.nMin - decrement.nMin;
- }
- else
- {
- Result->nMin = NUM_MIN_HR + timeToDecrement.nMin - decrement.nMin;
- decrement.nHour++;
- }
- }
- else
- {
- Result->nMin = timeToDecrement.nMin;
- }
- if (decrement.nHour != 0)
- {
- if (timeToDecrement.nHour >= decrement.nHour)
- {
- Result->nHour = timeToDecrement.nHour - decrement.nHour;
- }
- else
- {
- Result->nHour = NUM_HRS_DAY + timeToDecrement.nHour - decrement.nHour;
- decrement.nDay++;
- }
- }
- else
- {
- Result->nHour = timeToDecrement.nHour;
- }
- if (decrement.nDay != 0)
- {
- if (timeToDecrement.nDay > decrement.nDay)
- {
- Result->nDay = timeToDecrement.nDay - decrement.nDay;
- }
- else
- {
- decrement.nMonth++;
- if (timeToDecrement.nMonth != JAN)
- {
- Result->nDay = LastDayOfMonth(
- (U8) (timeToDecrement.nMonth - 1),
- timeToDecrement.nYear) + timeToDecrement.nDay - decrement.nDay;
- }
- else
- {
- Result->nDay = 31 + timeToDecrement.nDay - decrement.nDay;
- }
- }
- }
- else
- {
- Result->nDay = timeToDecrement.nDay;
- }
- if (decrement.nMonth != 0)
- {
- if (timeToDecrement.nMonth > decrement.nMonth)
- {
- Result->nMonth = timeToDecrement.nMonth - decrement.nMonth;
- }
- else
- {
- Result->nMonth = NUM_MONTHS + timeToDecrement.nMonth - decrement.nMonth;
- decrement.nYear++;
- }
- }
- else
- {
- Result->nMonth = timeToDecrement.nMonth;
- }
- Result->nYear = timeToDecrement.nYear - decrement.nYear;
- Result->DayIndex = DOW(Result->nYear, Result->nMonth, Result->nDay);
- }
- /*****************************************************************************
- * FUNCTION
- * DTGetRTCTime
- * DESCRIPTION
- * Get current RTC time of system.
- * PARAMETERS
- * t [IN/OUT] Variable to store current time.
- * RETURNS
- * void
- *****************************************************************************/
- void DTGetRTCTime(MYTIME *t)
- {
- #ifdef __MTK_TARGET__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- t_rtc rtc_time;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- RTC_GetTime(&rtc_time);
- t->nYear = rtc_time.rtc_year + YEARFORMATE;
- t->nMonth = rtc_time.rtc_mon;
- t->nDay = rtc_time.rtc_day;
- t->nHour = rtc_time.rtc_hour;
- t->nMin = rtc_time.rtc_min;
- t->nSec = rtc_time.rtc_sec;
- t->DayIndex = DOW(t->nYear, t->nMonth, t->nDay);
- #else /* __MTK_TARGET__ */
- GetDateTime(&(*t));
- #endif /* __MTK_TARGET__ */
- }
- /*****************************************************************************
- * FUNCTION
- * CompareTime
- * DESCRIPTION
- * Compare the equality between 2 times.
- * PARAMETERS
- * referenceTime [IN] Time to be compare in right-hand side
- * compareTime [IN] Time to be compare in left-hand side
- * diff [IN] Not yet used
- * RETURNS
- * TIME_LESS if referenceTime < compareTime
- * TIME_EQUAL if referenceTime = compareTime
- * TIME_GREATER if referenceTime > compareTime
- *****************************************************************************/
- TIME_EQUALITY CompareTime(MYTIME referenceTime, MYTIME compareTime, MYTIME *diff)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- TIME_EQUALITY toReturn;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (referenceTime.nYear == compareTime.nYear)
- {
- if (referenceTime.nMonth == compareTime.nMonth)
- {
- if (referenceTime.nDay == compareTime.nDay)
- {
- if (referenceTime.nHour == compareTime.nHour)
- {
- if (referenceTime.nMin == compareTime.nMin)
- {
- if (referenceTime.nSec == compareTime.nSec)
- {
- toReturn = TIME_EQUAL;
- }
- else
- {
- if (referenceTime.nSec < compareTime.nSec)
- {
- toReturn = TIME_LESS;
- }
- else
- {
- toReturn = TIME_GREATER;
- }
- }
- }
- else
- {
- if (referenceTime.nMin < compareTime.nMin)
- {
- toReturn = TIME_LESS;
- }
- else
- {
- toReturn = TIME_GREATER;
- }
- }
- }
- else
- {
- if (referenceTime.nHour < compareTime.nHour)
- {
- toReturn = TIME_LESS;
- }
- else
- {
- toReturn = TIME_GREATER;
- }
- }
- }
- else
- {
- if (referenceTime.nDay < compareTime.nDay)
- {
- toReturn = TIME_LESS;
- }
- else
- {
- toReturn = TIME_GREATER;
- }
- }
- }
- else
- {
- if (referenceTime.nMonth < compareTime.nMonth)
- {
- toReturn = TIME_LESS;
- }
- else
- {
- toReturn = TIME_GREATER;
- }
- }
- }
- else
- {
- if (referenceTime.nYear < compareTime.nYear)
- {
- toReturn = TIME_LESS;
- }
- else
- {
- toReturn = TIME_GREATER;
- }
- }
- return toReturn;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_is_valid
- * DESCRIPTION
- * To compute is the date/time is within reasonable range
- * PARAMETERS
- * t [?] [?] Time to be computed
- * RETURNS
- * TURE if date/time valid; otherwise, FALSE
- *****************************************************************************/
- U8 mmi_dt_is_valid(MYTIME *t)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* error handling */
- if (t->nYear > 2030 || t->nYear < YEARFORMATE)
- {
- return FALSE;
- }
- if (t->nMonth > 12)
- {
- return FALSE;
- }
- if (t->nMonth == 2)
- {
- if (t->nDay > (gDaysInMonth[t->nMonth - 1] + IsLeapYear(t->nYear)))
- {
- return FALSE;
- }
- }
- else
- {
- if (t->nDay > gDaysInMonth[t->nMonth - 1])
- {
- return FALSE;
- }
- }
- if (t->nHour > 23)
- {
- return FALSE;
- }
- if (t->nMin > 59)
- {
- return FALSE;
- }
- if (t->nSec > 59)
- {
- return FALSE;
- }
- return TRUE;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_conv_tz_to_mytime
- * DESCRIPTION
- * contert timezone to MYTIME structure
- * PARAMETERS
- * tz [IN] Time zone to be converted
- * RETURNS
- * result in MYTIME structure
- *****************************************************************************/
- MYTIME mmi_conv_tz_to_mytime(FLOAT tz)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYTIME result;
- S16 timezone = (S16) (tz * 4);
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(&result, 0, sizeof(MYTIME));
- result.nHour = (U8) (timezone / 4);
- result.nMin = (U8) ((timezone % 4) * 15);
- return result;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_utc_to_rtc
- * DESCRIPTION
- * compute utc time to rtc time
- * PARAMETERS
- * tz [IN] Time zone
- * utc [IN] Utc time
- * RETURNS
- * result of time
- *****************************************************************************/
- MYTIME mmi_dt_utc_to_rtc(FLOAT tz, MYTIME utc)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYTIME result;
- MYTIME incTime;
- U8 negative = FALSE;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (tz < 0)
- {
- negative = TRUE;
- tz = 0 - tz;
- }
- incTime = mmi_conv_tz_to_mytime(tz);
- if (negative)
- {
- DecrementTime(utc, incTime, &result);
- }
- else
- {
- IncrementTime(utc, incTime, &result);
- }
- return result;
- }
- /*****************************************************************************
- * FUNCTION
- * LastDayOfMonth
- * DESCRIPTION
- * Function to find the last day of specific month.
- * PARAMETERS
- * month [IN] Month
- * year [IN] Year
- * RETURNS
- * number of days
- *****************************************************************************/
- U8 LastDayOfMonth(U8 month, U16 year)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (month != FEB)
- {
- return gDaysInMonth[month - 1];
- }
- else
- {
- return gDaysInMonth[1] + IsLeapYear(year);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * IncrementTime
- * DESCRIPTION
- * Increase a reference time by some time
- * PARAMETERS
- * timeToIncrement [IN] Time to be increased
- * increment [IN]
- * Result [IN]
- * decrement(?) [IN] Time to increase(?)
- * RETURNS
- * result of computation(?)
- *****************************************************************************/
- void IncrementTime(MYTIME timeToIncrement, MYTIME increment, MYTIME *Result)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 NumOfDays;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- /* second */
- Result->nSec = (timeToIncrement.nSec + increment.nSec);
- /* minute */
- Result->nMin = (timeToIncrement.nMin + increment.nMin);
- if (Result->nSec >= NUM_MIN_HR)
- {
- Result->nSec -= NUM_MIN_HR;
- Result->nMin += 1;
- }
- /* hour */
- Result->nHour = (timeToIncrement.nHour + increment.nHour);
- if (Result->nMin >= NUM_MIN_HR)
- {
- Result->nMin -= NUM_MIN_HR;
- Result->nHour += 1;
- }
- /* day */
- Result->nDay = (timeToIncrement.nDay + increment.nDay);
- if (Result->nHour >= NUM_HRS_DAY)
- {
- Result->nHour -= NUM_HRS_DAY;
- Result->nDay += +1;
- }
- /* month, year */
- Result->nMonth = timeToIncrement.nMonth + increment.nMonth;
- Result->nYear = timeToIncrement.nYear + increment.nYear;
- if (Result->nMonth > NUM_MONTHS)
- {
- Result->nMonth -= NUM_MONTHS;
- Result->nYear++;
- }
- /* correct day */
- NumOfDays = LastDayOfMonth(timeToIncrement.nMonth, timeToIncrement.nYear);
- if (Result->nDay > NumOfDays)
- {
- Result->nDay -= NumOfDays;
- if (Result->nMonth != DEC)
- {
- Result->nMonth += 1;
- }
- else
- {
- Result->nMonth = JAN;
- Result->nYear += 1;
- }
- }
- Result->DayIndex = DOW(Result->nYear, Result->nMonth, Result->nDay);
- }
- /*****************************************************************************
- * FUNCTION
- * applib_dt_get_rtc_without_daylight_impact
- * DESCRIPTION
- *
- * PARAMETERS
- * t [?]
- * RETURNS
- * void
- *****************************************************************************/
- void applib_dt_get_rtc_without_daylight_impact(MYTIME *t)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- kal_uint8 dst;
- MYTIME decreaseDST;
- S16 error;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- DTGetRTCTime((MYTIME*)t);
- ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
- if (dst)
- {
- memset(&decreaseDST, 0, sizeof(MYTIME));
- decreaseDST.nHour = 1;
- DecrementTime(*t, decreaseDST, t);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * applib_dt_modify_dt_with_daylight_impact
- * DESCRIPTION
- *
- * PARAMETERS
- * t [?]
- * RETURNS
- * void
- *****************************************************************************/
- void applib_dt_modify_dt_with_daylight_impact(MYTIME *t)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- kal_uint8 dst;
- MYTIME increaseDST;
- S16 error;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
- if (dst)
- {
- memset(&increaseDST, 0, sizeof(MYTIME));
- increaseDST.nHour = 1;
- IncrementTime(*t, increaseDST, t);
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_mytime_2_utc_sec
- * DESCRIPTION
- * convert MYTIME format of time to seconds after 1970/1/1
- * PARAMETERS
- * currTime [?]
- * RETURNS
- * void
- *****************************************************************************/
- kal_int32 mmi_dt_mytime_2_utc_sec(MYTIME *currTime, kal_bool daylightSaving)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- kal_uint16 i;
- kal_uint32 no_of_days = 0;
- kal_int32 utc_time;
- kal_int32 is_leap;
- kal_uint8 dst;
- S16 error;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (currTime->nYear < DT_UTC_BASE_YEAR)
- {
- return 0;
- }
- /* year */
- for (i = DT_UTC_BASE_YEAR; i < currTime->nYear; i++)
- {
- no_of_days += (365 + IsLeapYear(i));
- }
- /* month */
- is_leap = IsLeapYear(currTime->nYear);
- for (i = 1; i < currTime->nMonth; i++)
- {
- no_of_days += LastDayOfMonth((kal_uint8) i, currTime->nYear);
- }
- /* day */
- no_of_days += (currTime->nDay - 1);
- /* sec */
- utc_time =
- (kal_uint32) no_of_days *DT_SEC_PER_DAY + (kal_uint32) (currTime->nHour * DT_SEC_PER_HOUR +
- currTime->nMin * DT_SEC_PER_MIN + currTime->nSec);
-
- ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
- if (dst && daylightSaving)
- {
- utc_time -= DT_SEC_PER_HOUR;
- }
-
- return utc_time;
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_utc_sec_2_mytime
- * DESCRIPTION
- * convert from UTC second to MYTIME struct
- * PARAMETERS
- * utc_sec [IN] Uct_sec
- * result [IN] Result of time
- * RETURNS
- * TRUE if success; otherwise, FALSE.
- *****************************************************************************/
- kal_uint8 mmi_dt_utc_sec_2_mytime(kal_int32 utc_sec, MYTIME *result, kal_bool daylightSaving)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- kal_int32 sec, day;
- kal_uint16 y;
- kal_uint8 m;
- kal_uint16 d;
- kal_uint8 dst;
- S16 error;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (utc_sec < 0)
- {
- return KAL_FALSE;
- }
- ReadValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
- if (dst && daylightSaving)
- {
- utc_sec += DT_SEC_PER_HOUR;
- }
- /* hour, min, sec */
- /* hour */
- sec = utc_sec % DT_SEC_PER_DAY;
- result->nHour = sec / DT_SEC_PER_HOUR;
- /* min */
- sec %= DT_SEC_PER_HOUR;
- result->nMin = sec / DT_SEC_PER_MIN;
- /* sec */
- result->nSec = sec % DT_SEC_PER_MIN;
- /* year, month, day */
- /* year */
- /* year */
- day = utc_sec / DT_SEC_PER_DAY;
- for (y = DT_UTC_BASE_YEAR; day > 0; y++)
- {
- d = (DT_DAY_PER_YEAR + IsLeapYear(y));
- if (day >= d)
- {
- day -= d;
- }
- else
- {
- break;
- }
- }
- result->nYear = y;
- for (m = 1; m < DT_MONTH_PER_YEAR; m++)
- {
- d = LastDayOfMonth(m, y);
- if (day >= d)
- {
- day -= d;
- }
- else
- {
- break;
- }
- }
- result->nMonth = m;
- result->nDay = (kal_uint8) (day + 1);
- return KAL_TRUE;
- }
- /*****************************************************************************
- * FUNCTION
- * applib_dt_get_week_number
- * DESCRIPTION
- * Compute the week number of a date
- * PARAMETERS
- * date [?]
- * RETURNS
- * void
- *****************************************************************************/
- U8 mmi_dt_get_week_number(MYTIME *date)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S32 i, no_of_days, week_num, numdays_inmonth, day_on_firstjan;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- no_of_days = date->nDay;
- for (i = date->nMonth - 1; i > 0; i--)
- {
- /* get the num of days in todays month */
- numdays_inmonth = LastDayOfMonth((U8) i, date->nYear);
- no_of_days += numdays_inmonth;
- }
- day_on_firstjan = DOW(date->nYear, 1, 1);
- /* Total no of days/ weekdays */
- no_of_days += day_on_firstjan;
- week_num = (no_of_days) / DT_DAYS_OF_WEEK;
- if ((no_of_days) % DT_DAYS_OF_WEEK > 0)
- {
- week_num += 1;
- }
- ASSERT(week_num <= CLNDR_MAX_WEEK_NUM);
- return week_num;
- }
- #endif /* MMI_ON_WIN32 */
- /*****************************************************************************
- * FUNCTION
- * CMGetExactTime
- * DESCRIPTION
- * Used by CM to get the Exact Time. Asyncronous Call. Callback is passeds
- * PARAMETERS
- * callback [IN] Callback function to be called when get time response comes back
- * RETURNS
- * void
- *****************************************************************************/
- void CMGetExactTime(DateTimeFuncPtr callback)
- {
- #ifdef __MTK_TARGET__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- {
- /* MYTIME curtime;
- DTGetRTCTime(&curtime);
- callback(&curtime); */
- PRINT_INFORMATION(("<<** CMGetExactTime ** >> CMCallCount = %d, CMCallBackCount = %dn", CMCallCount,
- CMCallBackCount));
- CMDateTimeRequest++;
- CMDateTimeCallBack[CMCallCount++] = callback;
- if (CMCallCount == MAX_CM_CALLS)
- {
- CMCallCount = 0;
- }
- L4GetClockTime(CMGetExactTimeCB);
- }
- #else /* __MTK_TARGET__ */
- {
- CMDateTimeRequest++;
- CMDateTimeCallBack[CMCallCount++] = callback;
- if (CMCallCount == MAX_CM_CALLS)
- {
- CMCallCount = 0;
- }
- StartTimer(CM_GET_TIME_CALLBACK, 1000, CMCallBackTimer);
- }
- #endif /* __MTK_TARGET__ */
- }
- /*****************************************************************************
- * FUNCTION
- * CMGetExactTimeCB
- * DESCRIPTION
- *
- * PARAMETERS
- * buf [?] [?]
- * RETURNS
- * void
- *****************************************************************************/
- void CMGetExactTimeCB(void *buf)
- {
- #ifdef __MTK_TARGET__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- mmi_eq_get_rtc_time_rsp_struct *local_data = (mmi_eq_get_rtc_time_rsp_struct*) buf;
- /* Lisen0522 */
- extern void update_mainlcd_dt_display(void);
- extern void update_sublcd_dt_display(void);
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- SetDateTime(&(local_data->rtctime[0].data_time));
- /* gclockData.rtc_wday = local_data->rtctime[0].data_time.rtc_wday;
- gclockData.rtc_year = local_data->rtctime[0].data_time.rtc_year,
- gclockData.rtc_mon = local_data->rtctime[0].data_time.rtc_mon,
- gclockData.rtc_day = local_data->rtctime[0].data_time.rtc_day,
- gclockData.rtc_hour = local_data->rtctime[0].data_time.rtc_hour,
- gclockData.rtc_min = local_data->rtctime[0].data_time.rtc_min,
- gclockData.rtc_sec = local_data->rtctime[0].data_time.rtc_sec; */
- PRINT_INFORMATION(("<<** CMGetExactTimeCB ** >>n"));
- if (CMDateTimeRequest > 0)
- {
- MYTIME curtime;
- PRINT_INFORMATION(("<<** CMGetExactTimeCB ** >> CMCallCount = %d, CMCallBackCount = %dn", CMCallCount,
- CMCallBackCount));
- GetDateTime(&curtime);
- CMDateTimeCallBack[CMCallBackCount++] (&curtime);
- if (CMCallBackCount == MAX_CM_CALLS)
- {
- CMCallBackCount = 0;
- }
- CMDateTimeRequest--;
- return;
- }
- /* Lisen0522 */
- update_mainlcd_dt_display();
- update_sublcd_dt_display();
- #endif /* __MTK_TARGET__ */
- }
- /*****************************************************************************
- * FUNCTION
- * CMCallBackTimer
- * DESCRIPTION
- * Used to simulate CM time function on widows. Calls CM Callback function as set by CM
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void CMCallBackTimer(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (CMDateTimeRequest)
- {
- MYTIME curtime;
- GetDateTime(&curtime);
- CMDateTimeCallBack[CMCallBackCount++] (&curtime);
- if (CMCallBackCount == MAX_CM_CALLS)
- {
- CMCallBackCount = 0;
- }
- CMDateTimeRequest--;
- }
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_get_tz
- * DESCRIPTION
- * Get current time zone of MMI
- * PARAMETERS
- * void
- * RETURNS
- * time zone of current home city.
- *****************************************************************************/
- FLOAT mmi_dt_get_tz(void)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return GetTimeZone(PhnsetGetHomeCity());
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_set_dst
- * DESCRIPTION
- *
- * PARAMETERS
- * dst [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_dt_set_dst(U8 dst)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- S16 error;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- WriteValue(NVRAM_SETTING_DT_DST, &dst, DS_BYTE, &error);
- g_dst = (U8) dst;
- }
- #if 0
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- /* under construction !*/
- #endif /* 0 */
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_set_rtc_dt
- * DESCRIPTION
- * This function is to send set time request to L4
- * Functionality:
- * PARAMETERS
- * t [?] [?]
- * a(?) [IN/OUT](?)
- * b(?) [IN](?)
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_dt_set_rtc_dt(MYTIME *t)
- {
- #ifdef __MTK_TARGET__
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYQUEUE msgStruct;
- RTCTIMEFORMAT *time;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- time = OslConstructDataPtr(sizeof(RTCTIMEFORMAT));
- time->info.alarm_format = 0;
- time->info.alarm_index = 0;
- time->info.type = 0;
- time->info.text[0] = ' ';
- time->info.recurr = 0;
- time->info.data_time.rtc_sec = 0;
- time->info.data_time.rtc_min = t->nMin;
- time->info.data_time.rtc_hour = t->nHour;
- time->rtc_type = RTC_TIME_CLOCK_IND;
- time->set_type = RTC_SETTING_TYPE_DATETIME;
- time->info.data_time.rtc_day = t->nDay;
- time->info.data_time.rtc_mon = t->nMonth;
- time->info.data_time.rtc_year = t->nYear - YEARFORMATE;
- time->info.data_time.rtc_wday = applib_dt_dow(t->nYear, t->nMonth, t->nDay);
- msgStruct.oslSrcId = MOD_MMI;
- msgStruct.oslDestId = MOD_L4C;
- msgStruct.oslMsgId = HW_SET_TIME_REQ;
- msgStruct.oslSapId = 0;
- msgStruct.oslDataPtr = (oslParaType*) time;
- msgStruct.oslPeerBuffPtr = NULL;
- OslMsgSendExtQueue(&msgStruct);
- #else /* __MTK_TARGET__ */
- MyTime = *t;
- #endif /* __MTK_TARGET__ */
- }
- #ifndef MMI_ON_WIN32
- /*****************************************************************************
- * FUNCTION
- * SetDateTime
- * DESCRIPTION
- * Function to set date and time information to global variable of MMI
- * PARAMETERS
- * t [IN] Struct variable that stores date and time information from PS
- * RETURNS
- * void
- *****************************************************************************/
- void SetDateTime(void *t)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- rtc_format_struct *local_data = (rtc_format_struct*) t;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- #ifdef __MTK_TARGET__
- gclockData.rtc_wday = local_data->rtc_wday;
- gclockData.rtc_year = local_data->rtc_year;
- gclockData.rtc_mon = local_data->rtc_mon;
- gclockData.rtc_day = local_data->rtc_day;
- gclockData.rtc_hour = local_data->rtc_hour;
- gclockData.rtc_min = local_data->rtc_min;
- gclockData.rtc_sec = local_data->rtc_sec;
- if (gclockData.rtc_year > MMI_DT_YEAR_BOUNDARY)
- {
- gclockData.rtc_year = 0; /* reset to 2000 */
- DTResetTime();
- }
- #else /* __MTK_TARGET__ */
- MyTime.DayIndex = local_data->rtc_wday;
- MyTime.nYear = local_data->rtc_year;
- MyTime.nMonth = local_data->rtc_mon;
- MyTime.nDay = local_data->rtc_day;
- MyTime.nHour = local_data->rtc_hour;
- MyTime.nMin = local_data->rtc_min;
- MyTime.nSec = local_data->rtc_sec;
- #endif /* __MTK_TARGET__ */
- }
- /*****************************************************************************
- * FUNCTION
- * DTResetTimeRsp
- * DESCRIPTION
- * Response handler of reset date/time.
- * PARAMETERS
- * rsp [?] [?]
- * RETURNS
- * void
- *****************************************************************************/
- void DTResetTimeRsp(void *rsp)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- AlmReInitialize();
- SetProtocolEventHandler(L4SetClockRSP, MSG_ID_MMI_EQ_SET_RTC_TIME_RSP);
- #endif /* MMI_ON_WIN32 */
- }
- /*****************************************************************************
- * FUNCTION
- * DTResetTime
- * DESCRIPTION
- * Reset Date/Time function when time reaches boundary
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- static void DTResetTime(void)
- {
- #ifndef MMI_ON_WIN32
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYQUEUE msgStruct;
- mmi_eq_set_rtc_time_req_struct *time;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- time = OslConstructDataPtr(sizeof(mmi_eq_set_rtc_time_req_struct));
- time->info.alarm_format = 0;
- time->info.alarm_index = 0;
- time->info.type = 0;
- time->info.text[0] = ' ';
- time->info.recurr = 0;
- time->rtc_type = RTC_TIME_CLOCK_IND;
- time->set_type = RTC_SETTING_TYPE_DATETIME;
- time->info.data_time.rtc_sec = 0;
- time->info.data_time.rtc_min = gclockData.rtc_min;
- time->info.data_time.rtc_hour = gclockData.rtc_hour;
- time->info.data_time.rtc_day = gclockData.rtc_day;
- time->info.data_time.rtc_mon = gclockData.rtc_mon;
- time->info.data_time.rtc_wday = gclockData.rtc_wday;
- time->info.data_time.rtc_year = gclockData.rtc_year;
- msgStruct.oslSrcId = MOD_MMI;
- msgStruct.oslDestId = MOD_L4C;
- msgStruct.oslMsgId = MSG_ID_MMI_EQ_SET_RTC_TIME_REQ;
- msgStruct.oslSapId = 0;
- msgStruct.oslDataPtr = (oslParaType*) time;
- msgStruct.oslPeerBuffPtr = NULL;
- OslMsgSendExtQueue(&msgStruct);
- SetProtocolEventHandler(DTResetTimeRsp, MSG_ID_MMI_EQ_SET_RTC_TIME_RSP);
- #endif /* MMI_ON_WIN32 */
- }
- /*****************************************************************************
- * FUNCTION
- * DateTimerIndication
- * DESCRIPTION
- * Handler of MSG_ID_MMI_EQ_CLOCK_TICK_IND.
- * 1. Update global variable in MMI.
- * 2. Update date/time display in IDLE screen.
- * PARAMETERS
- * p [?] [?]
- * t(?) [IN] Struct variable that stores date and time information from PS(?)
- * RETURNS
- * void
- *****************************************************************************/
- void DateTimerIndication(void *p)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- #ifdef __MTK_TARGET__
- mmi_eq_clock_tick_ind_struct *local_data = (mmi_eq_clock_tick_ind_struct*) p;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- gclockData.rtc_wday = local_data->rtc_time.rtc_wday;
- gclockData.rtc_year = local_data->rtc_time.rtc_year;
- gclockData.rtc_mon = local_data->rtc_time.rtc_mon;
- gclockData.rtc_day = local_data->rtc_time.rtc_day;
- gclockData.rtc_hour = local_data->rtc_time.rtc_hour;
- gclockData.rtc_min = local_data->rtc_time.rtc_min;
- gclockData.rtc_sec = local_data->rtc_time.rtc_sec;
- if (gclockData.rtc_year > MMI_DT_YEAR_BOUNDARY)
- {
- gclockData.rtc_year = 0; /* reset to 2000 */
- DTResetTime();
- }
- #ifdef __DAILY_WALLPAPER__
- if ((mmi_bootup_is_searching_or_idle_reached() == MMI_TRUE) && (GetWallpaperRotateStatus() == MMI_TRUE))
- {
- if (gWallpaperChangeDate.rtc_year == 0xFF
- || gWallpaperChangeDate.rtc_mon == 0xFF || gWallpaperChangeDate.rtc_day == 0xFF)
- {
- gWallpaperChangeDate.rtc_wday = gclockData.rtc_wday;
- gWallpaperChangeDate.rtc_year = gclockData.rtc_year;
- gWallpaperChangeDate.rtc_mon = gclockData.rtc_mon;
- gWallpaperChangeDate.rtc_day = gclockData.rtc_day;
- gWallpaperChangeDate.rtc_hour = gclockData.rtc_hour;
- gWallpaperChangeDate.rtc_min = gclockData.rtc_min;
- gWallpaperChangeDate.rtc_sec = gclockData.rtc_sec;
- }
- else if (gWallpaperChangeDate.rtc_year != gclockData.rtc_year
- || gWallpaperChangeDate.rtc_mon != gclockData.rtc_mon
- || gWallpaperChangeDate.rtc_day != gclockData.rtc_day)
- {
- /* S16 error; */
- WallPaperDailyChange();
- gWallpaperChangeDate.rtc_wday = gclockData.rtc_wday;
- gWallpaperChangeDate.rtc_year = gclockData.rtc_year;
- gWallpaperChangeDate.rtc_mon = gclockData.rtc_mon;
- gWallpaperChangeDate.rtc_day = gclockData.rtc_day;
- gWallpaperChangeDate.rtc_hour = gclockData.rtc_hour;
- gWallpaperChangeDate.rtc_min = gclockData.rtc_min;
- gWallpaperChangeDate.rtc_sec = gclockData.rtc_sec;
- /* WriteRecord(NVRAM_MMI_EF_WALLPAPER_MODTIME_LID,1,(void *)&gWallpaperChangeDate, sizeof(gWallpaperChangeDate), &error); */
- }
- }
- #endif /* __DAILY_WALLPAPER__ */
- #ifdef __MMI_LCD_PARTIAL_ON__
- if ((mmi_bootup_is_searching_or_idle_reached() == MMI_TRUE) || mmi_bootup_is_sim_removed() == MMI_TRUE)
- {
- RedrawPartialOnScreenSaverIfOk();
- }
- #endif /* __MMI_LCD_PARTIAL_ON__ */
- /* Lisen0522 */
- #if !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__)
- if (gIsInSleepMode == KAL_FALSE)
- {
- update_mainlcd_dt_display();
- }
- #else /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */
- update_mainlcd_dt_display();
- #endif /* !defined(__MMI_GPIO_DISABLE_SLEEP_MODE__) */
- update_sublcd_dt_display();
- #else /* __MTK_TARGET__ */
- DateTimerProc();
- #endif /* __MTK_TARGET__ */
- }
- /*****************************************************************************
- * FUNCTION
- * mmi_dt_check_rtc_time
- * DESCRIPTION
- * Check if rtc time is valid
- * PARAMETERS
- * p [?] [?]
- * t(?) [IN] Struct variable that stores date and time information from PS(?)
- * RETURNS
- * void
- *****************************************************************************/
- void mmi_dt_check_rtc_time(void)
- {
- if (gclockData.rtc_year > MMI_DT_YEAR_BOUNDARY)
- {
- gclockData.rtc_year = 0; /* reset to 2000 */
- DTResetTime();
- }
- }
- #endif /* MMI_ON_WIN32 */
- #endif /* _MMI_DATETIME_C */ // #ifndef _MMI_DATETIME_C