AlarmFramework.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:106k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * AlarmFramework.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  * MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * This file implements alarm scheduler for alarm, to do list, schedule power on/off and theme.
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  *
  171.  * removed!
  172.  * removed!
  173.  * removed!
  174.  *
  175.  * removed!
  176.  * removed!
  177.  * removed!
  178.  *
  179.  * removed!
  180.  * removed!
  181.  * removed!
  182.  *
  183.  * removed!
  184.  * removed!
  185.  * removed!
  186.  *
  187.  * removed!
  188.  * removed!
  189.  * removed!
  190.  *
  191.  * removed!
  192.  * removed!
  193.  * removed!
  194.  *
  195.  * removed!
  196.  * removed!
  197.  * removed!
  198.  *
  199.  * removed!
  200.  * removed!
  201.  * removed!
  202.  *
  203.  * removed!
  204.  * removed!
  205.  * removed!
  206.  *
  207.  * removed!
  208.  * removed!
  209.  * removed!
  210.  *
  211.  * removed!
  212.  * removed!
  213.  * removed!
  214.  *
  215.  * removed!
  216.  * removed!
  217.  * removed!
  218.  *
  219.  * removed!
  220.  * removed!
  221.  * removed!
  222.  *
  223.  * removed!
  224.  * removed!
  225.  * removed!
  226.  * removed!
  227.  *
  228.  * removed!
  229.  * removed!
  230.  * removed!
  231.  *
  232.  * removed!
  233.  * removed!
  234.  * removed!
  235.  *
  236.  * removed!
  237.  * removed!
  238.  * removed!
  239.  *
  240.  * removed!
  241.  * removed!
  242.  * removed!
  243.  *
  244.  * removed!
  245.  * removed!
  246.  * removed!
  247.  *
  248.  * removed!
  249.  * removed!
  250.  * removed!
  251.  *
  252.  * removed!
  253.  * removed!
  254.  * removed!
  255.  *
  256.  * removed!
  257.  * removed!
  258.  * removed!
  259.  * removed!
  260.  *
  261.  * removed!
  262.  * removed!
  263.  * removed!
  264.  *
  265.  * removed!
  266.  * removed!
  267.  * removed!
  268.  *
  269.  * removed!
  270.  * removed!
  271.  * removed!
  272.  *
  273.  * removed!
  274.  * removed!
  275.  * removed!
  276.  *
  277.  * removed!
  278.  * removed!
  279.  * removed!
  280.  *
  281.  * removed!
  282.  * removed!
  283.  * removed!
  284.  *
  285.  * removed!
  286.  * removed!
  287.  * removed!
  288.  *
  289.  * removed!
  290.  * removed!
  291.  * removed!
  292.  *
  293.  * removed!
  294.  * removed!
  295.  * removed!
  296.  *
  297.  * removed!
  298.  * removed!
  299.  * removed!
  300.  *
  301.  * removed!
  302.  * removed!
  303.  * removed!
  304.  *
  305.  * removed!
  306.  * removed!
  307.  * removed!
  308.  *
  309.  * removed!
  310.  * removed!
  311.  * removed!
  312.  *
  313.  * removed!
  314.  * removed!
  315.  * removed!
  316.  *
  317.  * removed!
  318.  * removed!
  319.  * removed!
  320.  *
  321.  * removed!
  322.  * removed!
  323.  * removed!
  324.  *
  325.  * removed!
  326.  * removed!
  327.  * removed!
  328.  *
  329.  * removed!
  330.  * removed!
  331.  * removed!
  332.  *
  333.  * removed!
  334.  * removed!
  335.  * removed!
  336.  *
  337.  * removed!
  338.  * removed!
  339.  * removed!
  340.  *
  341.  * removed!
  342.  * removed!
  343.  * removed!
  344.  *
  345.  * removed!
  346.  * removed!
  347.  * removed!
  348.  *
  349.  * removed!
  350.  * removed!
  351.  * removed!
  352.  *
  353.  * removed!
  354.  * removed!
  355.  * removed!
  356.  *
  357.  * removed!
  358.  * removed!
  359.  * removed!
  360.  *
  361.  * removed!
  362.  * removed!
  363.  * removed!
  364.  *
  365.  * removed!
  366.  * removed!
  367.  * removed!
  368.  *
  369.  * removed!
  370.  * removed!
  371.  * removed!
  372.  *
  373.  *------------------------------------------------------------------------------
  374.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  375.  *============================================================================
  376.  ****************************************************************************/
  377. /**
  378.  * Copyright Notice
  379.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  380.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  381.  *  (It is illegal to remove this copyright notice from this software or any
  382.  *  portion of it)
  383.  */
  384. /**************************************************************
  385.    FILENAME : AlarmFramework.c
  386.    PURPOSE     : Alarm Application
  387.    REMARKS     : nil
  388.    AUTHOR      : Neeraj Sharma
  389.    DATE     : Jun 16,03
  390. **************************************************************/
  391. #ifndef _MMI_ALARMFRAMEWORK_C
  392. #define _MMI_ALARMFRAMEWORK_C
  393. /*  Include: MMI header file */
  394. #include "MMI_features.h"
  395. /* to be put in include path TBDGS */
  396. #include "StdC.h"
  397. #include "l4Dr.h"
  398. #include "L4Dr1.h"
  399. #include "AlarmProt.h"
  400. #include "AlarmGProt.h"
  401. #include "DateTimeGprot.h"
  402. #include "AlarmFrameworkProt.h"
  403. #include "NVRAMEnum.h"
  404. #include "DebugInitDef.h"
  405. #include "NVRAMType.h"
  406. #include "NVRAMProt.h"
  407. #include "SubLCDHistoryGProt.h"
  408. #include "HistoryGprot.h"
  409. #include "ScheduledPowerOnOffGprot.h"
  410. #include "gpioInc.h"
  411. #include "ProfileGprots.h"
  412. #include "QueueGprot.h"
  413. #include "MMIThemes.h"
  414. #include "ProtocolEvents.h"
  415. #include "AllAppGprot.h"
  416. #include "AsyncEventsGprot.h"
  417. #include "EventsGprot.h"
  418. #include "SettingGprots.h"
  419. #include "ComposeRingToneProts.h"
  420. #include "DownloadProtos.h"
  421. #include "PowerOnChargerProt.h"
  422. // #include "PopulateResGprot.h"
  423. #include "ScheduledPowerOnOff.h"
  424. #include "ToDoListDef.h"
  425. #include "WrapperGprot.h"
  426. #include "AudioInc.h"
  427. #include "IdleAppProt.h"
  428. #include <time.h>
  429. #include "GlobalScrEnum.h"
  430. #include "mdi_datatype.h"
  431. #include "mdi_audio.h"
  432. #ifdef MMI_ON_HARDWARE_P
  433. #include "resource_audio.h"
  434. #include "lcd_sw.h"
  435. #include "lcd_sw_inc.h"
  436. #include "sublcd.h"
  437. #endif /* MMI_ON_HARDWARE_P */ 
  438. #include "JavaAgencyDef.h"
  439. /*  Include: PS header file */
  440. //... Add More PS header
  441. //#include "Gdi_include.h"
  442. #include "SimDetectionGexdcl.h"
  443. #include "SimDetectionGprot.h"
  444. #include "Bootup.h"
  445. // #include "MMITaskProt.h"
  446. #include "USBDeviceGprot.h"
  447. #include "USBDeviceDefs.h"      /* __USB_IN_NORMAL_MODE__ */
  448. #include "mmi_trc.h"
  449. #include "CallManagementGprot.h" /*IsWapCallPresent*/
  450. #if defined(__MMI_ALM_AUDIO_OPTIONS__)
  451. #include "FMRadioDef.h"
  452. #include "FMRadioProt.h"
  453. #include "FMRadioType.h"
  454. extern mmi_fmrdo_struct g_fmrdo;
  455. #endif /* defined(__MMI_ALM_AUDIO_OPTIONS__) */ 
  456. #if defined(__MMI_FM_RADIO_SCHEDULE_REC__)
  457. #include "FMScheduleRecProt.h"
  458. #endif 
  459. #ifdef __SYNCML_SUPPORT__
  460. #include "SyncMLGprot.h"
  461. #endif
  462. #include "Fs_func.h"
  463. /* 
  464.  * Typedef 
  465.  */
  466. /* 
  467.  * Define
  468.  */
  469. #define ALM_AFTER_CM_DURATUION 5000
  470. #define ALM_MAX_DELAY_ALLOWANCE  ((NUM_OF_SPOF + NUM_OF_ALM + NUM_OF_TDL) / 2 +1)       /* maximum delay of each alarm */
  471. #define ALM_TOLERANCE_TIME       10000
  472. #define ALM_POWER_OFF_TOLERANCE  (POWER_OFF_TIMER_STAGE_1 + POWER_OFF_TIMER_STAGE_2 + ALM_TOLERANCE_TIME)
  473. /* 
  474.  * Local Variable
  475.  */
  476. /* 
  477.  * Local Function
  478.  */
  479. /* 
  480.  * Global Variable
  481.  */
  482. AlarmCallback gAlmCBHandler[ALM_TYPE_TOTAL_NUM];
  483. alm_queue_node_struct gAlmQueue[ALM_NUM_OF_ALAMRS];
  484. alm_framework_context_struct g_alm_frm_cntx;
  485. #ifdef __MMI_FACTORY_MODE__
  486. extern U8 gFactoryAlarm;
  487. #endif 
  488. #ifdef MMI_ON_HARDWARE_P
  489. extern kal_uint16 *MainLCD_ShadowBuf_p;
  490. extern kal_uint16 *SubLCD_ShadowBuf_p;
  491. extern U8 gFScheckdiskflag;
  492. extern rtc_format_struct gclockData;
  493. #endif /* MMI_ON_HARDWARE_P */ 
  494. const U8 gAlmDayOfWeek[] = 
  495. {
  496.     0x01,   /* DAY_SUN */
  497.     0x02,   /* DAY_MON */
  498.     0x04,   /* DAY_TUE */
  499.     0x08,   /* DAY_WED */
  500.     0x10,   /* DAY_THU */
  501.     0x20,   /* DAY_FRI */
  502.     0x40    /* DAY_SAT */
  503. };
  504. /* 
  505.  * Global Function
  506.  */
  507. extern void QuitSystemOperation(void);
  508. extern void InitUnicodeSupport(void);
  509. extern void ResetLanguageSettingFlag(void);
  510. extern pBOOL isInCall(void);
  511. extern void MMICheckDiskDisplay(void);
  512. extern void ShutDownSystemOperation2(void);
  513. extern void PmgInitExtMelodyStruct(void);
  514. extern void InitFramework(void);
  515. extern void gdi_init(void);
  516. extern void ShutdownSystemOperation(void);
  517. extern void InitSoundEffect(void);
  518. extern void InitDownloadNVRAM(void);
  519. #ifdef __J2ME__
  520. extern void jvm_pause_dummy_screen(void);
  521. extern void jvm_resume_dummy_screen(void);
  522. #endif /* __J2ME__ */ 
  523. #ifdef MMI_ON_HARDWARE_P
  524. #ifdef __EM_MODE__
  525. extern void custom_em_pwn_cycle(kal_bool is_on);
  526. #endif 
  527. #endif /* MMI_ON_HARDWARE_P */ 
  528. extern void PhnsetReadGPIOSetting(void);
  529. /*****************************************************************************
  530.  * FUNCTION
  531.  *  InitAlarmHandler
  532.  * DESCRIPTION
  533.  *  Initialize Alarm handler
  534.  * PARAMETERS
  535.  *  void
  536.  * RETURNS
  537.  *  void
  538.  *****************************************************************************/
  539. void InitAlarmHandler(void)
  540. {
  541.     /*----------------------------------------------------------------*/
  542.     /* Local Variables                                                */
  543.     /*----------------------------------------------------------------*/
  544.     /*----------------------------------------------------------------*/
  545.     /* Code Body                                                      */
  546.     /*----------------------------------------------------------------*/
  547. #ifdef MMI_ON_HARDWARE_P
  548.     SetProtocolEventHandler(AlmExpiryHandler, MSG_ID_MMI_EQ_ALARM_IND);
  549. #endif 
  550. }
  551. /*****************************************************************************
  552.  * FUNCTION
  553.  *  InitAlarmFrameWork
  554.  * DESCRIPTION
  555.  *  Initialize global context and retrieve all kinds of alarm from NVRAM.
  556.  * PARAMETERS
  557.  *  void
  558.  * RETURNS
  559.  *  void
  560.  *****************************************************************************/
  561. void InitAlarmFrameWork(void)
  562. {
  563.     /*----------------------------------------------------------------*/
  564.     /* Local Variables                                                */
  565.     /*----------------------------------------------------------------*/
  566.     S32 i;
  567.     /*----------------------------------------------------------------*/
  568.     /* Code Body                                                      */
  569.     /*----------------------------------------------------------------*/
  570.     /* 
  571.      * init callback function
  572.      */
  573.     AlmFCBInit();
  574. #if defined(__MMI_TODOLIST__)
  575.     TDLFCBInit();
  576. #endif 
  577. #ifdef __MMI_THEMES_APPLICATION__
  578.     ThemesFCBInit();
  579. #endif 
  580.     SPOFFCBInit();
  581. #if defined(__MMI_FM_RADIO_SCHEDULE_REC__)
  582.     mmi_fmsr_int_cb_function();
  583. #endif 
  584. #ifdef __SYNCML_SUPPORT__
  585.     mmi_syncml_init_alarm();
  586. #endif
  587.     /*
  588.      * init alarm NVRAM
  589.      */
  590.     for (i = 0; i < ALM_TYPE_TOTAL_NUM; i++)
  591.     {
  592.         if (gAlmCBHandler[i].initAlarmNvramCBPtr)
  593.         {
  594.             gAlmCBHandler[i].initAlarmNvramCBPtr();
  595.         }
  596.     }
  597. #if (!defined(MMI_ON_WIN32) && defined(__MMI_ENGINEER_MODE__))
  598.     /*  init Factory RTC and Reset */
  599.     mmi_alm_set_start_index(ALM_TYPE_FACTORY, ALM_FACTORY);
  600.     gAlmCBHandler[ALM_TYPE_FACTORY].expiryTimeCBPtr = FactoryExpiryTimeCB;
  601.     gAlmCBHandler[ALM_TYPE_FACTORY].expiryHandlerCBPtr = FactoryExpiryHandler;
  602. #endif /* (!defined(MMI_ON_WIN32) && defined(__MMI_ENGINEER_MODE__)) */ 
  603.     mmi_alm_set_start_index(ALM_TYPE_PWR_RESET, ALM_PWR_RESET);
  604.     gAlmCBHandler[ALM_TYPE_PWR_RESET].expiryTimeCBPtr = ResetExpiryTimeCB;
  605.     gAlmCBHandler[ALM_TYPE_PWR_RESET].expiryHandlerCBPtr = ResetExpiryHandler;
  606.     InitAlarmHandler();
  607.     AlmInitQueue();
  608.     memset(&g_alm_frm_cntx, 0, sizeof(alm_framework_context_struct));
  609.     g_alm_frm_cntx.CurrAlmIndex = 0xff;
  610.     g_alm_frm_cntx.IsAppExecuting = MMI_FALSE;
  611.     for (i = 0; i < ALM_NUM_OF_ALAMRS && gAlmQueue[i].Index < ALM_INDEX_TOTAL; i++);
  612.     g_alm_frm_cntx.EnabledAlarms = (U8) i;
  613.     if (i && g_pwr_context.PowerOnMode != POWER_ON_ALARM)
  614.     {
  615.         AlmCheckAlarmState();
  616.     }
  617. }
  618. /*****************************************************************************
  619.  * FUNCTION
  620.  *  AlmCancelAlarmRsp
  621.  * DESCRIPTION
  622.  *  Protocol Handler for Message Alarm Del Response
  623.  *  Enabled Expiry Handler
  624.  * PARAMETERS
  625.  *  msg     [?]     
  626.  * RETURNS
  627.  *  void
  628.  *****************************************************************************/
  629. void AlmCancelAlarmRsp(void *msg)
  630. {
  631.     /*----------------------------------------------------------------*/
  632.     /* Local Variables                                                */
  633.     /*----------------------------------------------------------------*/
  634.     /*----------------------------------------------------------------*/
  635.     /* Code Body                                                      */
  636.     /*----------------------------------------------------------------*/
  637. #ifdef MMI_ON_HARDWARE_P
  638.     SetProtocolEventHandler(AlmExpiryHandler, MSG_ID_MMI_EQ_ALARM_IND);
  639. #endif 
  640. }
  641. /*****************************************************************************
  642.  * FUNCTION
  643.  *  AlmSetAlarmRSP
  644.  * DESCRIPTION
  645.  *  Protocol Handler for Message Alarm Set Response
  646.  * PARAMETERS
  647.  *  msg     [?]     
  648.  * RETURNS
  649.  *  void
  650.  *****************************************************************************/
  651. void AlmSetAlarmRSP(void *msg)
  652. {
  653. #ifdef MMI_ON_HARDWARE_P
  654.     /*----------------------------------------------------------------*/
  655.     /* Local Variables                                                */
  656.     /*----------------------------------------------------------------*/
  657.     mmi_eq_set_rtc_time_rsp_struct *alarmRes;
  658.     /*----------------------------------------------------------------*/
  659.     /* Code Body                                                      */
  660.     /*----------------------------------------------------------------*/
  661.     alarmRes = (mmi_eq_set_rtc_time_rsp_struct*) msg;
  662. #ifdef MMI_ON_HARDWARE_P
  663.     SetProtocolEventHandler(AlmExpiryHandler, MSG_ID_MMI_EQ_ALARM_IND);
  664. #endif 
  665.     if (alarmRes->result == MMI_TRUE)
  666.     {
  667.     #ifdef MMI_ON_HARDWARE_P
  668.     #ifdef __MMI_FACTORY_MODE__
  669.         if (gFactoryAlarm == 1)
  670.         {
  671.             gFactoryAlarm = 0;
  672.             if (g_alm_frm_cntx.IsATPwrOffAnimation)
  673.             {
  674.                 ShutdownSystemOperation();
  675.             }
  676.             else
  677.             {
  678.             #ifdef __MTK_TARGET__
  679.                 CloseBacklight();
  680.                 FS_ClearDiskFlag();
  681.                 custom_em_pwn_cycle(KAL_FALSE);
  682.             #else /* __MTK_TARGET__ */ 
  683.                 exit(0);
  684.             #endif /* __MTK_TARGET__ */ 
  685.             }
  686.             return;
  687.         }
  688.     #endif /* __MMI_FACTORY_MODE__ */ 
  689.     #endif /* MMI_ON_HARDWARE_P */ 
  690.         if (g_alm_frm_cntx.IsWaitForPwroff /* == ALM_STATE_POWER_OFF */ )
  691.         {
  692.             g_alm_frm_cntx.IsWaitForPwroff = 0;
  693.             /* if charger connected or power on confirmation screen present */
  694.             if (g_alm_frm_cntx.IsAppExecuting == 0)
  695.             {
  696.                 AlmSendPowerOff();
  697.             }
  698.         }
  699.     }
  700. #endif /* MMI_ON_HARDWARE_P */ 
  701. }
  702. /*****************************************************************************
  703.  * FUNCTION
  704.  *  PendingAlarmReminder
  705.  * DESCRIPTION
  706.  *  Execute pending after a certain period after call or first time entry idle screen.
  707.  * PARAMETERS
  708.  *  void
  709.  * RETURNS
  710.  *  void
  711.  *****************************************************************************/
  712. void PendingAlarmReminder(void)
  713. {
  714.     /*----------------------------------------------------------------*/
  715.     /* Local Variables                                                */
  716.     /*----------------------------------------------------------------*/
  717.     /*----------------------------------------------------------------*/
  718.     /* Code Body                                                      */
  719.     /*----------------------------------------------------------------*/
  720.     if (g_alm_frm_cntx.IsPendingAlm && g_alm_frm_cntx.IsAlmTonePlaying == FALSE)
  721.     {
  722.         StartTimer(ALARM_TIMER_WAIT_FOR_CALL, ALM_AFTER_CM_DURATUION, AlmHandlePendingTimeout);
  723.     }
  724.     else if (g_alm_frm_cntx.IsAlmTonePlaying)
  725.     {
  726.         StartTimer(ALARM_ALERT_NOTIFYDURATION_TIMER, ALM_EXPIRE_DURATION, AlmHandleAlarmTimeout);
  727.     }
  728. }
  729. /*****************************************************************************
  730.  * FUNCTION
  731.  *  PendingAlarmInPwronPeriod
  732.  * DESCRIPTION
  733.  *  Execute pending alarm in security check screen.
  734.  * PARAMETERS
  735.  *  void
  736.  * RETURNS
  737.  *  void
  738.  *****************************************************************************/
  739. void PendingAlarmInPwronPeriod(void)
  740. {
  741.     /*----------------------------------------------------------------*/
  742.     /* Local Variables                                                */
  743.     /*----------------------------------------------------------------*/
  744.     /*----------------------------------------------------------------*/
  745.     /* Code Body                                                      */
  746.     /*----------------------------------------------------------------*/
  747.     if (g_alm_frm_cntx.IsPendingAlm)
  748.     {
  749.         AlmHandlePendingTimeout();
  750.     }
  751. }
  752. /*****************************************************************************
  753.  * FUNCTION
  754.  *  AlmActualTime
  755.  * DESCRIPTION
  756.  *  Calculates the time when alarm will expire as per the frequency and weekdays.
  757.  * PARAMETERS
  758.  *  t               [IN]        Time of the alarm.
  759.  *  frequency       [IN]        Repeat of the alarm.
  760.  *  weekDays        [IN]        
  761.  *  is_tdl(?)       [IN]        If the alarm is to do list.
  762.  *  weekdays(?)     [IN]        Weekdays of the alarm. Each bit is set for every day. Bit 0 for sunday and so on
  763.  * RETURNS
  764.  *  Next expired time of the alarm.
  765.  *****************************************************************************/
  766. MYTIME AlmActualTime(MYTIME t, FREQ_ALARM frequency, U8 weekDays)
  767. {
  768.     /*----------------------------------------------------------------*/
  769.     /* Local Variables                                                */
  770.     /*----------------------------------------------------------------*/
  771.     MYTIME currTime, incTime;
  772.     TIME_EQUALITY diffStatus, diffStatus2;
  773.     U8 hasDate, j;
  774.     /*----------------------------------------------------------------*/
  775.     /* Code Body                                                      */
  776.     /*----------------------------------------------------------------*/
  777.     DTGetRTCTime(&currTime);
  778.     memset(&incTime, 0, sizeof(incTime));
  779.     hasDate = (t.nMonth != 0 && t.nDay != 0);
  780.     /* If frequency is days, alarm time should be calculated even it is greater than current time */
  781.     if (CompareTime(t, currTime, NULL) != TIME_GREATER || frequency == ALM_FREQ_DAYS) 
  782.     {
  783.         switch (frequency)
  784.         {
  785.             case ALM_FREQ_ONCE:
  786.             case ALM_FREQ_HOURLY:
  787.             case ALM_FREQ_EVERYDAY:            
  788.             case ALM_FREQ_WEEKLY:
  789.                 t.nYear = currTime.nYear;
  790.                 t.nMonth = currTime.nMonth;
  791.                 t.nDay = currTime.nDay;
  792.                 if (frequency == ALM_FREQ_ONCE || frequency == ALM_FREQ_EVERYDAY || frequency == ALM_FREQ_HOURLY)
  793.                 {
  794.                     if (frequency == ALM_FREQ_HOURLY)
  795.                     {
  796.                         t.nHour = currTime.nHour;
  797.                         incTime.nHour = 1;
  798.                     }
  799.                     else
  800.                     {
  801.                         incTime.nDay = 1;
  802.                     }
  803.                     diffStatus = CompareTime(t, currTime, NULL);
  804.                     if (diffStatus == TIME_LESS || diffStatus == TIME_EQUAL)
  805.                     {
  806.                         IncrementTime(t, incTime, &t);
  807.                     }
  808.                 }                
  809.                 else    /* frequency == ALM_FREQ_WEEKLY */
  810.                 {
  811.                     if (t.DayIndex == currTime.DayIndex)
  812.                     {
  813.                         diffStatus = CompareTime(t, currTime, NULL);
  814.                         if (diffStatus == TIME_LESS || diffStatus == TIME_EQUAL)
  815.                         {
  816.                             incTime.nDay = 7;
  817.                              IncrementTime(t, incTime, &t);
  818.                         }
  819.                     }
  820.                     else
  821.                     {
  822.                         incTime.nDay = (7 + t.DayIndex - currTime.DayIndex) % 7;
  823.                         IncrementTime(t, incTime, &t);
  824.                     }
  825.                 }
  826.                 break;
  827.                 
  828. case ALM_FREQ_DAYS:
  829.              diffStatus = CompareTime(t, currTime, NULL);
  830.              /* alarm time is larger than current time, calculate next alarm since alarm time. */
  831.              if (diffStatus == TIME_GREATER)           
  832.              {     
  833.              memcpy (&currTime, &t, sizeof(MYTIME));
  834.              }                   
  835.                 for (j = 0; j < 7; j++)
  836.                 {
  837.                     if (gAlmDayOfWeek[(currTime.DayIndex + j) % 7] & weekDays)
  838.                     {
  839.                         break;
  840.                     }
  841.                 }
  842.                 if (!j) /* if it's the same day */
  843.                 {
  844. /* compare HH:MM:SS */
  845. t.nYear = currTime.nYear;
  846. t.nMonth = currTime.nMonth;
  847. t.nDay = currTime.nDay;
  848. diffStatus2 = CompareTime(t, currTime, NULL);
  849. /* alarm time is less than current time and the HH/MM/SS is less than current time*/
  850.                     if (diffStatus != TIME_GREATER && diffStatus2 != TIME_GREATER)//(diffStatus2 == TIME_LESS || diffStatus2 == TIME_EQUAL) )
  851.                     {
  852.                         /* Find Next Day When then the alarm is scheduled */
  853.                         for (j = 1; j < 7; j++)
  854.                         {
  855.                             if (gAlmDayOfWeek[(currTime.DayIndex + j) % 7] & weekDays)
  856.                             {
  857.                                 break;
  858.                              }
  859.                         }
  860.                     }
  861.                     else
  862.                     {
  863.                         break;
  864.                     }
  865.                 }
  866. if (diffStatus == TIME_LESS || diffStatus == TIME_EQUAL)
  867. {
  868. currTime.nHour = t.nHour;
  869. currTime.nMin= t.nMin;
  870. currTime.nSec= t.nSec;
  871. }
  872.                 incTime.nDay = j;
  873.                 IncrementTime(currTime, incTime, &t);
  874.                 break;
  875.             default:
  876.                 break;
  877.         }
  878.     }
  879.     /* for yearly, monthly, seasonally, whether alarm time is before or afeter current time, next expiry time should be re-calculated. */
  880.     switch (frequency)
  881.     {
  882.         case ALM_FREQ_MONTHLY:
  883.                 if (!hasDate)
  884.                 {
  885.                     t.nDay = 1;
  886. t.nYear = currTime.nYear;
  887. t.nMonth = currTime.nMonth;
  888.                 }
  889. else if(CompareTime(t, currTime, NULL) != TIME_GREATER)
  890. {
  891. t.nYear = currTime.nYear;
  892. t.nMonth = currTime.nMonth;
  893. }
  894.             diffStatus = CompareTime(t, currTime, NULL);
  895.             if (diffStatus == TIME_LESS || diffStatus == TIME_EQUAL)    /* || (LastDayOfMonth(t.nMonth, t.nYear) < t.nDay)) */
  896.             {
  897.                 if (currTime.nMonth == 12)
  898.                 {
  899. t.nMonth = 1;
  900.                     t.nYear++;
  901.                 }
  902.                 else
  903.                 {
  904. t.nMonth++;
  905.                 }
  906.             }
  907. j = t.nMonth;                
  908.             for (; j <= 12; j++)
  909.             {
  910.                 if (LastDayOfMonth(t.nMonth, t.nYear) >= t.nDay)
  911.                 {
  912.                     break;
  913.                 }
  914.             }
  915.             break;
  916.         case ALM_FREQ_YEARLY:
  917.             if (!hasDate)
  918.             {
  919.                 t.nYear = currTime.nYear;
  920.                 t.nMonth = 1;
  921.                 t.nDay = 1;
  922.                 }
  923. else if(CompareTime(t, currTime, NULL) != TIME_GREATER)
  924. {
  925. t.nYear = currTime.nYear;
  926.             }
  927.             diffStatus = CompareTime(t, currTime, NULL);
  928.             if (diffStatus == TIME_LESS || diffStatus == TIME_EQUAL)
  929.             {
  930. if (t.nMonth == 2 && t.nDay == 29)
  931. {
  932. incTime.nYear = 4 - ((t.nYear) % 4);
  933. IncrementTime(t, incTime, &t);
  934. }
  935. else
  936. {
  937. t.nYear++;
  938. }
  939.             }
  940.             
  941.             break;
  942.         case ALM_FREQ_SEASONALLY:
  943.             t.nYear = currTime.nYear;
  944.             if (!hasDate)
  945.             {
  946.                 t.nDay = 1;
  947.             }
  948.             switch (currTime.nMonth)
  949.             {
  950.                 case 1:
  951.                 case 2:
  952.                 case 3:
  953.                     t.nMonth = 4;
  954.                     break;
  955.                 case 4:
  956.                 case 5:
  957.                 case 6:
  958.                     t.nMonth = 7;
  959.                     break;
  960.                 case 7:
  961.                 case 8:
  962.                 case 9:
  963.                     t.nMonth = 10;
  964.                     break;
  965.                 default:    /* case 10: case 11: case 12: */
  966.                     t.nMonth = 1;
  967.                     t.nYear = (currTime.nYear + 1);
  968.                     break;
  969.             }
  970.             break;
  971.         default:
  972.             break;
  973.     }
  974.     return t;
  975. }
  976. /*****************************************************************************
  977.  * FUNCTION
  978.  *  AlmsStopAlarmTone
  979.  * DESCRIPTION
  980.  *  Stops Any Alarm Tone that may be playing
  981.  * PARAMETERS
  982.  *  void
  983.  * RETURNS
  984.  *  void
  985.  *****************************************************************************/
  986. void AlmsStopAlarmTone(void)
  987. {
  988.     /*----------------------------------------------------------------*/
  989.     /* Local Variables                                                */
  990.     /*----------------------------------------------------------------*/
  991.     
  992. #if defined (__MMI_ALM_ALERT_TYPE__) || defined (__MMI_PROFILE_ALERT_TYPE_DOMINANT__)
  993.         U8 alert_type;
  994. #endif 
  995.         U8 alarm_index = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  996.     
  997.     /*----------------------------------------------------------------*/
  998.     /* Code Body                                                      */
  999.     /*----------------------------------------------------------------*/
  1000.     if (g_alm_frm_cntx.IsAlmTonePlaying)
  1001.     {
  1002.         /* stopRequestedTone(ALARM_TONE); */
  1003. #if defined (__MMI_ALM_ALERT_TYPE__)
  1004.         alert_type = g_alm_cntx.AlmList[alarm_index].AlertType;
  1005.         switch (alert_type)
  1006.         {
  1007.             case ALM_ALERT_VIBRATION_AND_RING:
  1008.                 VibratorOff();
  1009.                 mdi_audio_stop_all();
  1010.                 break;
  1011.             case ALM_ALERT_RING:
  1012.                 mdi_audio_stop_all();
  1013.                 break;
  1014.             case ALM_ALERT_VIBRATION:
  1015.                 VibratorOff();
  1016.                 break;
  1017.             default:
  1018.                 break;
  1019.         }
  1020. #else
  1021.         mdi_audio_stop_all();;
  1022.         VibratorOff();
  1023. #endif
  1024.         g_alm_frm_cntx.IsAlmTonePlaying = FALSE;
  1025.     }
  1026. }
  1027. /*****************************************************************************
  1028.  * FUNCTION
  1029.  *  AlmPlayAlarmTone
  1030.  * DESCRIPTION
  1031.  *  Play alarm tone if it's not playing.
  1032.  * PARAMETERS
  1033.  *  void
  1034.  * RETURNS
  1035.  *  void
  1036.  *****************************************************************************/
  1037. void AlmPlayAlarmTone(void)
  1038. {
  1039.     /*----------------------------------------------------------------*/
  1040.     /* Local Variables                                                */
  1041.     /*----------------------------------------------------------------*/
  1042. #if defined (__MMI_ALM_ALERT_TYPE__) || defined (__MMI_PROFILE_ALERT_TYPE_DOMINANT__)
  1043.     U8 alert_type;
  1044. #endif 
  1045.     U8 alarm_index = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  1046.     /*----------------------------------------------------------------*/
  1047.     /* Code Body                                                      */
  1048.     /*----------------------------------------------------------------*/
  1049.     if (g_alm_frm_cntx.IsAlmTonePlaying == FALSE)
  1050.     {
  1051.         g_alm_frm_cntx.IsAlmTonePlaying = TRUE;
  1052.     #if defined (__MMI_ALM_ALERT_TYPE__)
  1053.         alert_type = g_alm_cntx.AlmList[alarm_index].AlertType;
  1054.         switch (alert_type)
  1055.         {
  1056.             case ALM_ALERT_VIBRATION_AND_RING:
  1057.                 VibratorOn();
  1058.                 break;
  1059.             case ALM_ALERT_VIBRATION:
  1060.                 VibratorOn();
  1061.                 return;
  1062.                 break;
  1063.             default:
  1064.                 break;
  1065.         }
  1066.     #elif defined(__MMI_PROFILE_ALERT_TYPE_DOMINANT__)
  1067.         alert_type = GetMtCallAlertTypeEnum();
  1068.         VibratorOn();
  1069.         if (alert_type != MMI_VIBRATION_ONLY && alert_type != MMI_SILENT)
  1070.     #endif 
  1071.         {
  1072.             /* Added support for Alarm Audio Options i.e. FM Radio as alarm tone. */
  1073.         #ifdef __MMI_ALM_AUDIO_OPTIONS__
  1074.             if (g_alm_frm_cntx.CurrAlmIndex >= ALM_ALM_START && g_alm_frm_cntx.CurrAlmIndex < ALM_SPOF_START)
  1075.             {
  1076.                 if (g_alm_cntx.AlmList[alarm_index].AudioOption == ALM_AUDIO_OPTIONS_TONE)
  1077.                 {
  1078.                     playRequestedTone(ALARM_TONE);
  1079.                 }
  1080.                 else
  1081.                 {
  1082.                     mmi_alm_aud_fmrdo_play_alarm(alarm_index, GetRingVolumeLevel());
  1083.                 }
  1084.             }
  1085.             else
  1086.         #endif /* __MMI_ALM_AUDIO_OPTIONS__ */ 
  1087.             {
  1088.                 playRequestedTone(ALARM_TONE);
  1089.             }
  1090.         }
  1091.     }
  1092. }
  1093. /*****************************************************************************
  1094.  * FUNCTION
  1095.  *  AlmInitLCDModule
  1096.  * DESCRIPTION
  1097.  *  Initialize main and sub lcd
  1098.  * PARAMETERS
  1099.  *  void
  1100.  * RETURNS
  1101.  *  void
  1102.  *****************************************************************************/
  1103. void AlmInitLCDModule(void)
  1104. {
  1105.     /*----------------------------------------------------------------*/
  1106.     /* Local Variables                                                */
  1107.     /*----------------------------------------------------------------*/
  1108.     /*----------------------------------------------------------------*/
  1109.     /* Code Body                                                      */
  1110.     /*----------------------------------------------------------------*/
  1111.     gdi_init();
  1112. }
  1113. /*****************************************************************************
  1114.  * FUNCTION
  1115.  *  AlmInitRTCPwron
  1116.  * DESCRIPTION
  1117.  *  Initialize all required data and modules for RTC power on.
  1118.  * PARAMETERS
  1119.  *  void
  1120.  * RETURNS
  1121.  *  void
  1122.  *****************************************************************************/
  1123. void AlmInitRTCPwron(void)
  1124. {
  1125.     /*----------------------------------------------------------------*/
  1126.     /* Local Variables                                                */
  1127.     /*----------------------------------------------------------------*/
  1128.     /*----------------------------------------------------------------*/
  1129.     /* Code Body                                                      */
  1130.     /*----------------------------------------------------------------*/
  1131.     InitUnicodeSupport();
  1132.     PhnsetReadGPIOSetting();
  1133.     mdi_audio_init();
  1134.     InitFramework();            /* Initialize framework */
  1135.     InitHardwareEvents();
  1136.     setup_UI_wrappers();
  1137.     PopulateResData();
  1138.     PowerAndEndKeyHandler();    /* deepali */
  1139.     initialize_UI_demo();
  1140.     InitProfileApp();
  1141.     InitMMI_App();
  1142.     InitChargerPwrOn();
  1143.     InitDownloadNVRAM();
  1144.     initnvramprofapp();
  1145.     InitSettingNVRAM();
  1146. #if defined(__MMI_RING_COMPOSER__) && defined(__MMI_IMELODY_SUPPORT__)
  1147.     InitRingToneComposer();
  1148. #endif 
  1149. #ifdef __MMI_USB_SUPPORT__
  1150.     InitMMIUsbContext();
  1151. #endif 
  1152. #ifdef __MMI_PROFILE_EXTMELODY_SUPPORT__
  1153.     PmgInitExtMelodyStruct();
  1154. #endif 
  1155.     mdi_audio_init_event_hdlrs();
  1156.     InitAlarmFrameWork();
  1157. #ifdef __MMI_THEMES_APPLICATION__
  1158.     InitThemes();
  1159. #endif 
  1160.     InitSoundEffect();
  1161.     g_alm_frm_cntx.IsPwronAlarm = TRUE;
  1162.     AlmExecPwrOffAlarm();
  1163. }
  1164. /*****************************************************************************
  1165.  * FUNCTION
  1166.  *  AlmSendPwronReq
  1167.  * DESCRIPTION
  1168.  *  Send power on request to L4. This function is used for RTC power on.
  1169.  * PARAMETERS
  1170.  *  void
  1171.  * RETURNS
  1172.  *  void
  1173.  *****************************************************************************/
  1174. void AlmSendPwronReq()
  1175. {
  1176. #ifdef MMI_ON_HARDWARE_P
  1177.     /*----------------------------------------------------------------*/
  1178.     /* Local Variables                                                */
  1179.     /*----------------------------------------------------------------*/
  1180.     MYQUEUE Message;
  1181.     mmi_eq_power_on_req_struct *myMsgPtr;
  1182.     /*----------------------------------------------------------------*/
  1183.     /* Code Body                                                      */
  1184.     /*----------------------------------------------------------------*/
  1185.     myMsgPtr = (mmi_eq_power_on_req_struct*) OslConstructDataPtr(sizeof(mmi_eq_power_on_req_struct));
  1186.     myMsgPtr->fun = 2;
  1187.     myMsgPtr->rst = 0;
  1188.     Message.oslSrcId = MOD_MMI;
  1189.     Message.oslDestId = MOD_L4C;
  1190.     Message.oslMsgId = PRT_EQ_POWER_ON_REQ;
  1191.     Message.oslDataPtr = (oslParaType*) myMsgPtr;
  1192.     Message.oslPeerBuffPtr = NULL;
  1193.     OslMsgSendExtQueue(&Message);
  1194. #endif /* MMI_ON_HARDWARE_P */ 
  1195. }
  1196. /*****************************************************************************
  1197.  * FUNCTION
  1198.  *  AlmSetAlarm
  1199.  * DESCRIPTION
  1200.  *  To insert alarm into queue and register the nearest alarm to RTC.
  1201.  *  Update alarm profile of L4C if it's normal alarm.
  1202.  * PARAMETERS
  1203.  *  index       [IN]        Index of alarm
  1204.  * RETURNS
  1205.  *  void
  1206.  *****************************************************************************/
  1207. void AlmSetAlarm(U8 index)
  1208. {
  1209. #ifdef MMI_ON_HARDWARE_P
  1210.     /*----------------------------------------------------------------*/
  1211.     /* Local Variables                                                */
  1212.     /*----------------------------------------------------------------*/
  1213.     /*----------------------------------------------------------------*/
  1214.     /* Code Body                                                      */
  1215.     /*----------------------------------------------------------------*/
  1216.     AlmInsertIntoQueue(index, TRUE);
  1217.     AlmStartAlarmOnHW(gAlmQueue[0].Time);
  1218. #endif /* MMI_ON_HARDWARE_P */ 
  1219. }
  1220. /*****************************************************************************
  1221.  * FUNCTION
  1222.  *  AlmCancelAlarm
  1223.  * DESCRIPTION
  1224.  *  To remove alarm from queue and register the nearest alarm to RTC.
  1225.  *  Update alarm profile of L4C if it's normal alarm.
  1226.  * PARAMETERS
  1227.  *  index       [IN]        Index of alarm
  1228.  * RETURNS
  1229.  *  void
  1230.  *****************************************************************************/
  1231. void AlmCancelAlarm(U8 index)
  1232. {
  1233. #ifdef MMI_ON_HARDWARE_P
  1234.     /*----------------------------------------------------------------*/
  1235.     /* Local Variables                                                */
  1236.     /*----------------------------------------------------------------*/
  1237.     /*----------------------------------------------------------------*/
  1238.     /* Code Body                                                      */
  1239.     /*----------------------------------------------------------------*/
  1240.     AlmRemoveFromQueue(index, TRUE);
  1241.     /* re-schedule alarm of RTC, shall be implemented in another function */
  1242.     if (g_alm_frm_cntx.EnabledAlarms == 0)
  1243.     {
  1244.         AlmStopAlarmOnHW();
  1245.     }
  1246.     else
  1247.     {
  1248.         AlmStartAlarmOnHW(gAlmQueue[0].Time);
  1249.     }
  1250.     /* update L4 state */
  1251.     //      if(AlmGetType(index) == ALM_TYPE_ALARM)
  1252.     //              AlmDelRTCInfoForAT(index - ALM_ALM_START);
  1253. #endif /* MMI_ON_HARDWARE_P */ 
  1254. }
  1255. /*****************************************************************************
  1256.  * FUNCTION
  1257.  *  AlmCancelAlarm
  1258.  * DESCRIPTION
  1259.  *  To remove alarm from queue and register the nearest alarm to RTC.
  1260.  *  Update alarm profile of L4C if it's normal alarm.
  1261.  * PARAMETERS
  1262.  *  index       [IN]        Index of alarm
  1263.  * RETURNS
  1264.  *  void
  1265.  *****************************************************************************/
  1266. void AlmCancelMulltiAlarm(U8* index, U8 amount)
  1267. {
  1268. #ifdef MMI_ON_HARDWARE_P
  1269.     /*----------------------------------------------------------------*/
  1270.     /* Local Variables                                                */
  1271.     /*----------------------------------------------------------------*/
  1272.     U8 i = 0;
  1273.     /*----------------------------------------------------------------*/
  1274.     /* Code Body                                                      */
  1275.     /*----------------------------------------------------------------*/
  1276.     for (; i < amount; i++)
  1277.     {
  1278.         AlmRemoveFromQueue(index[i], FALSE);
  1279.     }
  1280.     AlmWriteQueueToNvram();
  1281.     /* re-schedule alarm of RTC, shall be implemented in another function */
  1282.     if (g_alm_frm_cntx.EnabledAlarms == 0)
  1283.     {
  1284.         AlmStopAlarmOnHW();
  1285.     }
  1286.     else
  1287.     {
  1288.         AlmStartAlarmOnHW(gAlmQueue[0].Time);
  1289.     }
  1290. #endif /* MMI_ON_HARDWARE_P */ 
  1291. }
  1292. /*****************************************************************************
  1293.  * FUNCTION
  1294.  *  AlmGetAlarmTime
  1295.  * DESCRIPTION
  1296.  *  Get the time of specific queue node.
  1297.  * PARAMETERS
  1298.  *  index       [IN]        Index of alarm
  1299.  * RETURNS
  1300.  *  Expired time of the alarm.
  1301.  *****************************************************************************/
  1302. MYTIME AlmGetAlarmTime(U8 index)
  1303. {
  1304.     /*----------------------------------------------------------------*/
  1305.     /* Local Variables                                                */
  1306.     /*----------------------------------------------------------------*/
  1307.     U8 AlmType;
  1308.     U8 AlmIndex;
  1309.     MYTIME alarmTime, preReminder, currTime, incTime;
  1310.     U8 Freq = 0;
  1311.     U8 WeekDays = 0;
  1312.     /*----------------------------------------------------------------*/
  1313.     /* Code Body                                                      */
  1314.     /*----------------------------------------------------------------*/
  1315.     memset(&alarmTime, 0, sizeof(MYTIME));
  1316.     memset(&preReminder, 0, sizeof(MYTIME));
  1317.     memset(&incTime, 0, sizeof(MYTIME));
  1318.     GetDateTime(&currTime);
  1319.     AlmType = AlmGetType(index);
  1320.     AlmIndex = index - gAlmCBHandler[AlmType].alarmStartIndex;
  1321.     if (gAlmCBHandler[AlmType].expiryTimeCBPtr)
  1322.     {
  1323.         gAlmCBHandler[AlmType].expiryTimeCBPtr(AlmIndex, &alarmTime, &Freq, &WeekDays, &preReminder);
  1324.     }
  1325.     alarmTime = AlmActualTime(alarmTime, (FREQ_ALARM) Freq, WeekDays);
  1326.     memcpy(&incTime, &preReminder, sizeof(MYTIME));
  1327.     DecrementTime(alarmTime, incTime, &alarmTime);
  1328.     /* check for preminder */
  1329.     if (CompareTime(alarmTime, currTime, NULL) != TIME_GREATER)
  1330.     {
  1331.         /* get original alarm time */
  1332.         memcpy(&incTime, &preReminder, sizeof(MYTIME));
  1333.         IncrementTime(alarmTime, incTime, &alarmTime);
  1334.         memset(&incTime, 0, sizeof(MYTIME));
  1335.         switch (Freq)
  1336.         {
  1337.             case ALM_FREQ_YEARLY:
  1338.                 incTime.nYear = 1;
  1339.                 break;
  1340.             case ALM_FREQ_MONTHLY:
  1341.                 incTime.nMonth = 1;
  1342.                 break;
  1343.             default:
  1344.                 incTime.nDay = 1;
  1345.                 break;
  1346.         }
  1347.         IncrementTime(alarmTime, incTime, &alarmTime);
  1348.         alarmTime = AlmActualTime(alarmTime, (FREQ_ALARM) Freq, WeekDays);
  1349.         DecrementTime(alarmTime, preReminder, &alarmTime);
  1350.     }
  1351.     return alarmTime;
  1352. }
  1353. /*****************************************************************************
  1354.  * FUNCTION
  1355.  *  AlmInsertIntoQueue
  1356.  * DESCRIPTION
  1357.  *  Insert an alarm node to the queue.
  1358.  * PARAMETERS
  1359.  *  index           [IN]        Index of alarm
  1360.  *  saveflag        [IN]        Flag to determine save directly to NVRAM or not
  1361.  * RETURNS
  1362.  *  The position of alarm in queue.
  1363.  *****************************************************************************/
  1364. U8 AlmInsertIntoQueue(U8 index, U8 saveflag)
  1365. {
  1366.     /*----------------------------------------------------------------*/
  1367.     /* Local Variables                                                */
  1368.     /*----------------------------------------------------------------*/
  1369.     S32 i, j;
  1370.     TIME_EQUALITY equality;
  1371.     MYTIME alarmTime;
  1372.     /*----------------------------------------------------------------*/
  1373.     /* Code Body                                                      */
  1374.     /*----------------------------------------------------------------*/
  1375.     if (index >= ALM_INDEX_TOTAL)   /* exceeds boundary */
  1376.     {
  1377.         return 0;
  1378.     }
  1379.     AlmRemoveFromQueue(index, FALSE);   /* node is in queue, remove it first */
  1380.     alarmTime = AlmGetAlarmTime(index);
  1381.     /* Check expiry time */
  1382.     if (!mmi_dt_is_valid(&alarmTime))
  1383.     {
  1384. AlmWriteQueueToNvram();
  1385.         return 0;
  1386.     }
  1387.     /* insert into proper position */
  1388.     for (i = 0; i < g_alm_frm_cntx.EnabledAlarms; i++)
  1389.     {
  1390.         equality = CompareTime(alarmTime, gAlmQueue[i].Time, NULL);
  1391.         if ((equality == TIME_LESS) || (equality == TIME_EQUAL && index < gAlmQueue[i].Index))  /* insert node here */
  1392.         {
  1393.             /* shift all nodes right */
  1394.             for (j = g_alm_frm_cntx.EnabledAlarms - 1; j >= i; j--)
  1395.             {
  1396.                 memcpy(&gAlmQueue[j + 1], &gAlmQueue[j], sizeof(alm_queue_node_struct));
  1397.             }
  1398.             break;
  1399.         }
  1400.     }
  1401.     gAlmQueue[i].Index = index;
  1402.     gAlmQueue[i].Time = alarmTime;
  1403.     gAlmQueue[i].IsExpired = 0;
  1404.     g_alm_frm_cntx.EnabledAlarms++;
  1405.     /* write alarm queue to NVRAM */
  1406.     if (saveflag)
  1407.     {
  1408.         AlmWriteQueueToNvram();
  1409.     }
  1410.     return (U8) i;
  1411. }
  1412. /*****************************************************************************
  1413.  * FUNCTION
  1414.  *  AlmRemoveFromQueue
  1415.  * DESCRIPTION
  1416.  *  Remove an alarm node from the queue.
  1417.  * PARAMETERS
  1418.  *  index           [IN]        Index of alarm
  1419.  *  saveflag        [IN]        Flag to determine save directly to NVRAM or not
  1420.  * RETURNS
  1421.  *  Number of enabled alarms.
  1422.  *****************************************************************************/
  1423. U8 AlmRemoveFromQueue(U8 index, U8 saveflag)
  1424. {
  1425.     /*----------------------------------------------------------------*/
  1426.     /* Local Variables                                                */
  1427.     /*----------------------------------------------------------------*/
  1428.     S32 i;
  1429.     /*----------------------------------------------------------------*/
  1430.     /* Code Body                                                      */
  1431.     /*----------------------------------------------------------------*/
  1432.     if (gAlmQueue[0].Index > ALM_INDEX_TOTAL)   /* queue is empty */
  1433.     {
  1434.         return 0;
  1435.     }
  1436.     for (i = 0; i < ALM_NUM_OF_ALAMRS; i++)
  1437.         if (gAlmQueue[i].Index == index)
  1438.         {
  1439.             break;
  1440.         }
  1441.     if (i >= ALM_NUM_OF_ALAMRS) /* alarm node not found */
  1442.     {
  1443.         return 0;
  1444.     }
  1445.     /* remove from queue */
  1446.     memcpy(&gAlmQueue[i], &gAlmQueue[i + 1], sizeof(alm_queue_node_struct) * (ALM_NUM_OF_ALAMRS - i - 1));
  1447.     g_alm_frm_cntx.EnabledAlarms--;
  1448.     memset(&gAlmQueue[g_alm_frm_cntx.EnabledAlarms], 0xff, sizeof(alm_queue_node_struct));
  1449.     /* write alarm queue to NVRAM */
  1450.     if (saveflag)
  1451.     {
  1452.         AlmWriteQueueToNvram();
  1453.     }
  1454.     return g_alm_frm_cntx.EnabledAlarms;
  1455. }
  1456. /*****************************************************************************
  1457.  * FUNCTION
  1458.  *  AlmIsExpireAllowed
  1459.  * DESCRIPTION
  1460.  *  
  1461.  * PARAMETERS
  1462.  *  void
  1463.  * RETURNS
  1464.  *  
  1465.  *****************************************************************************/
  1466. U8 AlmIsExpireAllowed(void)
  1467. {
  1468.     /*----------------------------------------------------------------*/
  1469.     /* Local Variables                                                */
  1470.     /*----------------------------------------------------------------*/
  1471.     U8 state;
  1472.     pBOOL PowerOnCheck;
  1473.     U16 call_count = 0;
  1474.     /*----------------------------------------------------------------*/
  1475.     /* Code Body                                                      */
  1476.     /*----------------------------------------------------------------*/
  1477.     if (mmi_bootup_is_before_power_on() == 1)
  1478.     {
  1479.         PowerOnCheck = MMI_FALSE;   /* the case of alarm expiration + power on indication */
  1480.     }
  1481.     else if (mmi_bootup_is_in_power_on_period() == 0)
  1482.     {
  1483.         PowerOnCheck = MMI_TRUE;    /* the case of idle screen reached + alarm expiration */
  1484.     }
  1485.     else if (IsScreenPresent(SCR_OPEN_SCREEN_ID))
  1486.     {
  1487.         PowerOnCheck = MMI_TRUE;    /* the case of power on animation + MT call + IMEI + call end + alarm expiration */
  1488.     }
  1489.     else
  1490.     {
  1491.         PowerOnCheck = MMI_FALSE;   /* the case of power on animation + alarm expiration */
  1492.     }
  1493.     if (isInCall())
  1494.     {
  1495.      if (!IsWapCallPresent())
  1496.      {
  1497.      call_count = isInCall();
  1498.      }
  1499.      else if (GetTotalCallCount() == 1)
  1500.      {
  1501.      g_alm_frm_cntx.IsExpiryDisabled = MMI_FALSE;
  1502.      }    
  1503.     }
  1504.     state = ((call_count == 0) && (PowerOnCheck == MMI_TRUE) && (!g_alm_frm_cntx.IsExpiryDisabled));
  1505.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_EXPIRY_STATE, (S32) call_count, (S32) PowerOnCheck,
  1506.                (S32) g_alm_frm_cntx.IsExpiryDisabled));
  1507.     return state;
  1508. }
  1509. /*****************************************************************************
  1510.  * FUNCTION
  1511.  *  AlmHandleAlarmTimeout
  1512.  * DESCRIPTION
  1513.  *  Timer expiry handler for normal alarm.
  1514.  *  Exit previous alarm screen.
  1515.  * PARAMETERS
  1516.  *  void
  1517.  *  index(?)        [IN]        Index of alarm
  1518.  * RETURNS
  1519.  *  void
  1520.  *****************************************************************************/
  1521. void AlmHandleAlarmTimeout(void)
  1522. {
  1523.     /*----------------------------------------------------------------*/
  1524.     /* Local Variables                                                */
  1525.     /*----------------------------------------------------------------*/
  1526.     U8 almType = 0;
  1527.     /*----------------------------------------------------------------*/
  1528.     /* Code Body                                                      */
  1529.     /*----------------------------------------------------------------*/
  1530.     StopTimer(ALARM_ALERT_NOTIFYDURATION_TIMER);
  1531.     almType = AlmGetType(g_alm_frm_cntx.CurrAlmIndex);
  1532.     if (g_alm_frm_cntx.CurrAlmIndex == ALM_FACTORY)
  1533.     {
  1534.         AlmSendPowerOff();
  1535.     }
  1536.     else if (GetActiveScreenId() == SCR_ID_SPOF_CONFIRM)
  1537.     {
  1538.         ShutdownSystemOperation();
  1539.     }
  1540.     else
  1541.     {
  1542.         if (AlmIsExpireAllowed())
  1543.         {
  1544.             g_alm_frm_cntx.IsExitByTimer = TRUE;
  1545.             AlmExitPreviousAlarm();
  1546.             g_alm_frm_cntx.IsExitByTimer = FALSE;
  1547.             if (g_alm_frm_cntx.IsPwronAlarm)
  1548.             {
  1549.                 AlmExecPwrOffAlarm();
  1550.             }
  1551.             else
  1552.             {
  1553.                 AlmExecPwrOnAlarm();
  1554.             }
  1555.         }
  1556.         else
  1557.         {
  1558.             g_alm_frm_cntx.IsPendingAlm = TRUE;
  1559.         }
  1560.     }
  1561. }
  1562. /*****************************************************************************
  1563.  * FUNCTION
  1564.  *  AlmExitPreviousAlarm
  1565.  * DESCRIPTION
  1566.  *  Execute exit handler of previous alarm to to do list alam.
  1567.  *  Exit previous alarm screen.
  1568.  * PARAMETERS
  1569.  *  void
  1570.  * RETURNS
  1571.  *  void
  1572.  *****************************************************************************/
  1573. void AlmExitPreviousAlarm(void)
  1574. {
  1575.     /*----------------------------------------------------------------*/
  1576.     /* Local Variables                                                */
  1577.     /*----------------------------------------------------------------*/
  1578.     U8 almType;
  1579.     /*----------------------------------------------------------------*/
  1580.     /* Code Body                                                      */
  1581.     /*----------------------------------------------------------------*/
  1582.     /* if some alarm is previous displayed, execute previous exit handler */
  1583.     if (g_alm_frm_cntx.CurrAlmIndex < ALM_INDEX_TOTAL)
  1584.     {
  1585.         /* stop previous alarm */
  1586.         almType = AlmGetType(g_alm_frm_cntx.CurrAlmIndex);
  1587.         if (gAlmCBHandler[almType].stopAlarmCBPtr)
  1588.         {
  1589.             gAlmCBHandler[almType].stopAlarmCBPtr();
  1590.         }
  1591.         else
  1592.         {
  1593.             StopTimer(ALARM_ALERT_NOTIFYDURATION_TIMER);
  1594.             g_alm_frm_cntx.CurrAlmIndex = 0xff;
  1595.         }
  1596.     }
  1597.     g_alm_frm_cntx.CurrAlmIndex = 0xff;
  1598. }
  1599. /*****************************************************************************
  1600.  * FUNCTION
  1601.  *  EntryAlmDummyScr
  1602.  * DESCRIPTION
  1603.  *  Dummy screen to exit previous application (Java)
  1604.  * PARAMETERS
  1605.  *  void
  1606.  * RETURNS
  1607.  *  void
  1608.  *****************************************************************************/
  1609. void EntryAlmDummyScr(void)
  1610. {
  1611.     /*----------------------------------------------------------------*/
  1612.     /* Local Variables                                                */
  1613.     /*----------------------------------------------------------------*/
  1614.     /*----------------------------------------------------------------*/
  1615.     /* Code Body                                                      */
  1616.     /*----------------------------------------------------------------*/
  1617.     EntryNewScreen(GLOBAL_SCR_DUMMY, NULL, NULL, NULL);
  1618. }
  1619. /*****************************************************************************
  1620.  * FUNCTION
  1621.  *  mmi_alm_spof_disable_check
  1622.  * DESCRIPTION
  1623.  *  SPOF disable handler
  1624.  * PARAMETERS
  1625.  *  void
  1626.  * RETURNS
  1627.  *  Expired alarm index in the queue except for SPOF
  1628.  *****************************************************************************/
  1629. U8 mmi_alm_spof_disable_check(void)
  1630. {
  1631.     /*----------------------------------------------------------------*/
  1632.     /* Local Variables                                                */
  1633.     /*----------------------------------------------------------------*/
  1634.     MYTIME currTime;
  1635.     U8 i, almIndex = 0xff;;
  1636.     /*----------------------------------------------------------------*/
  1637.     /* Code Body                                                      */
  1638.     /*----------------------------------------------------------------*/
  1639.     DTGetRTCTime(&currTime);
  1640.     g_alm_frm_cntx.IsPendingAlm = TRUE;
  1641.     /* more alarms in queue and */
  1642.     for (i=1; i<NUM_OF_SPOF && i< g_alm_frm_cntx.EnabledAlarms;i++)
  1643.     {
  1644.         if (CompareTime(gAlmQueue[i].Time, currTime, NULL) == TIME_GREATER)
  1645.         {
  1646.             AlmStartAlarmOnHW(gAlmQueue[i].Time);
  1647.             break;
  1648.         }
  1649.         else if ( AlmGetType(gAlmQueue[i].Index) != ALM_TYPE_SPOF)
  1650.         {
  1651.             almIndex = gAlmQueue[i].Index;
  1652.             break;
  1653.         }
  1654.         
  1655.     }
  1656.     
  1657.     return almIndex;
  1658. }
  1659. /*****************************************************************************
  1660.  * FUNCTION
  1661.  *  AlmExpiryHandler
  1662.  * DESCRIPTION
  1663.  *  To set alarm to RTC
  1664.  * PARAMETERS
  1665.  *  msg             [?]         
  1666.  *  index(?)        [IN]        Index of alarm
  1667.  * RETURNS
  1668.  *  void
  1669.  *****************************************************************************/
  1670. void AlmExpiryHandler(void *msg)
  1671. {
  1672. #ifdef MMI_ON_HARDWARE_P
  1673.     /*----------------------------------------------------------------*/
  1674.     /* Local Variables                                                */
  1675.     /*----------------------------------------------------------------*/
  1676.     mmi_eq_alarm_ind_struct *local_data = (mmi_eq_alarm_ind_struct*) msg;
  1677.     /*----------------------------------------------------------------*/
  1678.     /* Code Body                                                      */
  1679.     /*----------------------------------------------------------------*/
  1680.     /* update global time */
  1681.     StopTimer(ALARM_ALERT_NOTIFYDURATION_TIMER);
  1682.     StopTimer(ALARM_TIMER_WAIT_FOR_CALL);
  1683.     gclockData.rtc_wday = local_data->rtc_time.rtc_wday;
  1684.     gclockData.rtc_year = local_data->rtc_time.rtc_year;
  1685.     gclockData.rtc_mon = local_data->rtc_time.rtc_mon;
  1686.     gclockData.rtc_day = local_data->rtc_time.rtc_day;
  1687.     gclockData.rtc_hour = local_data->rtc_time.rtc_hour;
  1688.     gclockData.rtc_min = local_data->rtc_time.rtc_min;
  1689.     gclockData.rtc_sec = local_data->rtc_time.rtc_sec;
  1690.     mmi_dt_check_rtc_time();
  1691.     /* execute exit handler of previous alarm */
  1692.     g_alm_frm_cntx.IsExitByTimer = TRUE;
  1693.     AlmExitPreviousAlarm();
  1694.     g_alm_frm_cntx.IsExitByTimer = FALSE;
  1695.     if (!AlmIsExpireAllowed())
  1696.     {
  1697.         g_alm_frm_cntx.IsPendingAlm = TRUE;
  1698.         return;
  1699.     }
  1700.     if (AlmIsPowerOffMode())
  1701.     {
  1702.         g_alm_frm_cntx.IsPwronAlarm = TRUE;
  1703.     }
  1704.     /* execute next alarm */
  1705.     if (g_alm_frm_cntx.IsPwronAlarm)
  1706.     {
  1707.         AlmExecPwrOffAlarm();
  1708.     }
  1709.     else
  1710.     {
  1711.         AlmExecPwrOnAlarm();
  1712.     }
  1713. #endif /* MMI_ON_HARDWARE_P */ 
  1714. }
  1715. /*****************************************************************************
  1716.  * FUNCTION
  1717.  *  AlmExecPwrOnAlarm
  1718.  * DESCRIPTION
  1719.  *  Popup one alarm entry from queue and execute corresponding handler.
  1720.  * PARAMETERS
  1721.  *  void
  1722.  * RETURNS
  1723.  *  void
  1724.  *****************************************************************************/
  1725. void AlmExecPwrOnAlarm(void)
  1726. {
  1727. #ifdef MMI_ON_HARDWARE_P
  1728.     /*----------------------------------------------------------------*/
  1729.     /* Local Variables                                                */
  1730.     /*----------------------------------------------------------------*/
  1731.     U8 almType, almIndex;
  1732.     MYTIME currTime, alarmTime, incTime;
  1733.     TIME_EQUALITY equality;
  1734.     U8 NexAlmToShow = FALSE;
  1735.     U8 NextAlmToSet = FALSE;
  1736.     U8 AlmSnoozeTime, tmpIndex;
  1737.     U8 IsSPOFPending = FALSE;
  1738.     U16 period = 0;
  1739. #ifdef __J2ME__
  1740.     U8 IsJavaPlaying = FALSE;
  1741. #endif 
  1742.     /*----------------------------------------------------------------*/
  1743.     /* Code Body                                                      */
  1744.     /*----------------------------------------------------------------*/
  1745.     g_alm_frm_cntx.CurrAlmIndex = 0xff;
  1746.     g_alm_frm_cntx.IsPendingAlm = FALSE;
  1747.     /* no alarm expired, to prevent abnormal case */
  1748.     if (!g_alm_frm_cntx.EnabledAlarms)
  1749.     {
  1750.         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_EMPTY_QUEUE));
  1751.         g_alm_frm_cntx.IsPendingAlm = FALSE;
  1752.         return;
  1753.     }
  1754.     if (!AlmIsExpireAllowed())
  1755.     {
  1756.         g_alm_frm_cntx.IsPendingAlm = TRUE;
  1757.         return;
  1758.     }
  1759.     DTGetRTCTime(&currTime);
  1760.     /* to prevent abnormal case */
  1761.     if (CompareTime(gAlmQueue[0].Time, currTime, NULL) == TIME_GREATER)
  1762.     {
  1763.         AlmStartAlarmOnHW(gAlmQueue[0].Time);
  1764.         g_alm_frm_cntx.IsPendingAlm = FALSE;
  1765.         return;
  1766.     }
  1767.     almIndex = gAlmQueue[0].Index;
  1768.     almType = AlmGetType(almIndex);
  1769.     /* spof is disabled, find out next alarm to execute */
  1770.     if (almType == ALM_TYPE_SPOF && g_alm_frm_cntx.IsSpofDisabled)
  1771.     {
  1772.         almIndex = mmi_alm_spof_disable_check();
  1773.         if (almIndex == 0xff)   /* no other alarm expired */
  1774.         {
  1775.             return;
  1776.         }
  1777.         else
  1778.         {
  1779.             IsSPOFPending = TRUE;
  1780.             almType = AlmGetType(almIndex);
  1781.         }
  1782.     }
  1783.     g_alm_frm_cntx.CurrAlmIndex = almIndex;
  1784. #ifdef __J2ME__
  1785.     if (GetActiveScreenId() == SCR_JAVA_APP)
  1786.     {
  1787.         IsJavaPlaying = TRUE;
  1788.         jvm_pause_dummy_screen();
  1789.     }
  1790. #endif /* __J2ME__ */ 
  1791.     /* re-organizer alarm queue */
  1792.     /* if(!g_alm_frm_cntx.IsPendingAlm) */
  1793.     {
  1794.         /* if it's a pending alarm, no need to re-schedule right now */
  1795.         if (AlmGetRepeat(almIndex) == ALM_FREQ_ONCE)
  1796.         {
  1797.             AlmRemoveFromQueue(almIndex, TRUE);
  1798.         }
  1799.         else if (almType != ALM_TYPE_ALARM) /* alarm shall be inserted into queue after stopped */
  1800.         {
  1801.             AlmInsertIntoQueue(almIndex, TRUE);
  1802.         }
  1803.         else
  1804.         {
  1805.             tmpIndex = almIndex - ALM_ALM_START;
  1806.             AlmSnoozeTime = g_alm_cntx.AlmList[tmpIndex].Snooze;
  1807.             g_alm_cntx.AlmList[tmpIndex].Snooze = 0;
  1808.             AlmInsertIntoQueue(almIndex, TRUE);
  1809.             g_alm_cntx.AlmList[tmpIndex].Snooze = AlmSnoozeTime;
  1810.         }
  1811.     }
  1812. #ifdef __J2ME__
  1813.     if (IsJavaPlaying == TRUE)
  1814.     {
  1815.         jvm_resume_dummy_screen();
  1816.     }
  1817. #endif /* __J2ME__ */ 
  1818.     /* execute corrpesonding handler */
  1819.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_EXPIRY_TYPE, (S32) almType));
  1820.     if (gAlmCBHandler[almType].expiryHandlerCBPtr)
  1821.     {
  1822.         U8 isIndSrc;
  1823.         U8 almAppIndex = g_alm_frm_cntx.CurrAlmIndex - gAlmCBHandler[almType].alarmStartIndex;
  1824.         isIndSrc = gAlmCBHandler[almType].expiryHandlerCBPtr(almAppIndex, &period, MMI_TRUE);
  1825.         if (isIndSrc == ALM_HAS_NO_IND)
  1826.         {
  1827.         }
  1828.     }
  1829.     /* set another RTC if requried */
  1830.     if (g_alm_frm_cntx.EnabledAlarms > 0)   /* second alarm exists */
  1831.     {
  1832.         memset(&incTime, 0, sizeof(MYTIME));
  1833.         incTime.nSec = period;
  1834.         IncrementTime(currTime, incTime, &alarmTime);
  1835.         equality = CompareTime(gAlmQueue[0].Time, alarmTime, NULL);
  1836.         /* if next alarm will expire within 30 seconds */
  1837.         if (equality == TIME_LESS || equality == TIME_EQUAL)    /* alarm expired */
  1838.         {
  1839.             /* increment n seconds and then set another alarm */
  1840.             NexAlmToShow = TRUE;
  1841.             NextAlmToSet = TRUE;
  1842.         }
  1843.         else
  1844.         {
  1845.             NextAlmToSet = TRUE;
  1846.             alarmTime = gAlmQueue[0].Time;
  1847.         }
  1848.         AlmStartAlarmOnHW(alarmTime);
  1849.     }
  1850.     if (period == 0)
  1851.     {
  1852.         if (g_alm_frm_cntx.EnabledAlarms)
  1853.         {
  1854.             AlmExecPwrOnAlarm();
  1855.         }
  1856.     }
  1857.     else if (!NexAlmToShow)
  1858.     {
  1859.         StartTimer(ALARM_ALERT_NOTIFYDURATION_TIMER, (period * 1000), AlmHandleAlarmTimeout);
  1860.     }
  1861. #endif /* MMI_ON_HARDWARE_P */ 
  1862. }
  1863. /*****************************************************************************
  1864.  * FUNCTION
  1865.  *  AlmExecPwrOffAlarm
  1866.  * DESCRIPTION
  1867.  *  RTC power on handler
  1868.  * PARAMETERS
  1869.  *  void
  1870.  * RETURNS
  1871.  *  void
  1872.  *****************************************************************************/
  1873. void AlmExecPwrOffAlarm(void)
  1874. {
  1875.     /*----------------------------------------------------------------*/
  1876.     /* Local Variables                                                */
  1877.     /*----------------------------------------------------------------*/
  1878.     U8 almType, almIndex;
  1879.     MYTIME currTime, alarmTime, incTime;
  1880.     TIME_EQUALITY equality;
  1881.     U8 NexAlmToShow = FALSE;
  1882.     U8 NextAlmToSet = FALSE;
  1883.     U16 period;
  1884.     /*----------------------------------------------------------------*/
  1885.     /* Code Body                                                      */
  1886.     /*----------------------------------------------------------------*/
  1887.     /* no alarm expired, to prevent abnormal case */
  1888.     StopTimer(ALARM_ALERT_NOTIFYDURATION_TIMER);
  1889.     g_alm_frm_cntx.CurrAlmIndex = 0xff;
  1890.     g_alm_frm_cntx.IsPwronAlarm = TRUE;
  1891. #ifdef MMI_ON_WIN32
  1892.     EntryAlmIndicationScreen();
  1893.     return;
  1894. #endif /* MMI_ON_WIN32 */ 
  1895.     if (!g_alm_frm_cntx.EnabledAlarms)
  1896.     {
  1897.         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_EMPTY_QUEUE));
  1898.     #ifdef MMI_ON_HARDWARE_P
  1899.         if (g_alm_frm_cntx.IsAppExecuting == 0)
  1900.         {   
  1901.             AlmSendPowerOff();
  1902.         }
  1903.     #endif 
  1904.         return;
  1905.     }
  1906.     /* compare the time */
  1907.     almIndex = gAlmQueue[0].Index;
  1908.     DTGetRTCTime(&currTime);
  1909.     if (CompareTime(gAlmQueue[0].Time, currTime, NULL) == TIME_GREATER)
  1910.     {
  1911.         g_alm_frm_cntx.IsWaitForPwroff = TRUE;
  1912.         AlmStartAlarmOnHW(gAlmQueue[0].Time);
  1913.         return;
  1914.     }
  1915.     almType = AlmGetType(almIndex);
  1916.     g_alm_frm_cntx.CurrAlmIndex = almIndex;
  1917.     /* spof is disabled, find out next alarm to execute */
  1918.     if (almType == ALM_TYPE_SPOF && g_alm_frm_cntx.IsSpofDisabled)
  1919.     {
  1920.         AlmInsertIntoQueue(almIndex, TRUE);
  1921.         if (CompareTime(gAlmQueue[0].Time, currTime, NULL) == TIME_GREATER)
  1922.         {
  1923.          AlmStartAlarmOnHW(gAlmQueue[0].Time);
  1924.         }
  1925.         else
  1926.         {
  1927.          AlmExecPwrOffAlarm();
  1928.         }
  1929.         return;        
  1930.     }
  1931.     if (AlmGetRepeat(almIndex) == ALM_FREQ_ONCE)
  1932.     {
  1933.         AlmRemoveFromQueue(almIndex, TRUE);
  1934.     }
  1935.     else if (almType != ALM_TYPE_ALARM) /* alarm shall be inserted into queue after stopped */
  1936.     {
  1937.         AlmInsertIntoQueue(almIndex, TRUE);
  1938.     }
  1939.     else
  1940.     {
  1941.         U8 tmpIndex, AlmSnoozeTime;
  1942.         tmpIndex = almIndex - ALM_ALM_START;
  1943.         AlmSnoozeTime = g_alm_cntx.AlmList[tmpIndex].Snooze;
  1944.         g_alm_cntx.AlmList[tmpIndex].Snooze = 0;
  1945.         AlmInsertIntoQueue(almIndex, TRUE);
  1946.         g_alm_cntx.AlmList[tmpIndex].Snooze = AlmSnoozeTime;
  1947.     }
  1948.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_EXPIRY_TYPE, (S32) almType));
  1949.     if (gAlmCBHandler[almType].expiryHandlerCBPtr)
  1950.     {
  1951.         U8 almAppIndex = g_alm_frm_cntx.CurrAlmIndex - gAlmCBHandler[almType].alarmStartIndex;
  1952.         gAlmCBHandler[almType].expiryHandlerCBPtr(almAppIndex, &period, MMI_FALSE);
  1953.     }
  1954.     if (g_alm_frm_cntx.EnabledAlarms > 0)   /* second alarm exists */
  1955.     {
  1956.         /* increment 30 seconds and then set another alarm */
  1957.         memset(&incTime, 0, sizeof(MYTIME));
  1958.         incTime.nSec = period;
  1959.         IncrementTime(currTime, incTime, &alarmTime);
  1960.         equality = CompareTime(gAlmQueue[0].Time, alarmTime, NULL);
  1961.         if (equality == TIME_LESS || equality == TIME_EQUAL)    /* alarm expired */
  1962.         {
  1963.             NexAlmToShow = TRUE;
  1964.             NextAlmToSet = TRUE;
  1965.         }
  1966.         else
  1967.         {
  1968.             alarmTime = gAlmQueue[0].Time;
  1969.             NextAlmToSet = TRUE;
  1970.         }
  1971.         AlmStartAlarmOnHW(alarmTime);
  1972.     }
  1973.     if (period == 0)
  1974.     {
  1975.      /* power on/off need not execute next alarm */
  1976.         if (almType != ALM_TYPE_SPOF && almType != ALM_TYPE_SPON && almType != ALM_TYPE_PWR_RESET)
  1977.         {
  1978.             AlmExecPwrOffAlarm();
  1979.         }
  1980.     }
  1981.     else if (!NexAlmToShow)
  1982.     {
  1983.         StartTimer(ALARM_ALERT_NOTIFYDURATION_TIMER, (period * 1000), AlmHandleAlarmTimeout);
  1984.     }
  1985. }
  1986. /*****************************************************************************
  1987.  * FUNCTION
  1988.  *  AlmWriteQueueToNvram
  1989.  * DESCRIPTION
  1990.  *  Write alarm queue to nvram.
  1991.  * PARAMETERS
  1992.  *  void
  1993.  * RETURNS
  1994.  *  void
  1995.  *****************************************************************************/
  1996. void AlmWriteQueueToNvram(void)
  1997. {
  1998.     /*----------------------------------------------------------------*/
  1999.     /* Local Variables                                                */
  2000.     /*----------------------------------------------------------------*/
  2001.     S16 error;
  2002.     /*----------------------------------------------------------------*/
  2003.     /* Code Body                                                      */
  2004.     /*----------------------------------------------------------------*/
  2005.     WriteRecord(NVRAM_EF_ALM_QUEUE_LID, (U16) 1, (void*)gAlmQueue, NVRAM_ALM_QUEUE_SIZE, &error);
  2006. }
  2007. /*****************************************************************************
  2008.  * FUNCTION
  2009.  *  AlmInitQueue
  2010.  * DESCRIPTION
  2011.  *  Read alarm queue from nvram.
  2012.  *  Reset alarm queue if
  2013.  *  1. index misordered.
  2014.  *  2. the expired time of first alarm is far from current time.
  2015.  * PARAMETERS
  2016.  *  void
  2017.  * RETURNS
  2018.  *  void
  2019.  *****************************************************************************/
  2020. void AlmInitQueue(void)
  2021. {
  2022.     /*----------------------------------------------------------------*/
  2023.     /* Local Variables                                                */
  2024.     /*----------------------------------------------------------------*/
  2025.     S16 error;
  2026.     MYTIME currTime, refTime;
  2027.     /*----------------------------------------------------------------*/
  2028.     /* Code Body                                                      */
  2029.     /*----------------------------------------------------------------*/
  2030.     ReadRecord(NVRAM_EF_ALM_QUEUE_LID, (U16) 1, (void*)gAlmQueue, NVRAM_ALM_QUEUE_SIZE, &error);
  2031.     if (gAlmQueue[0].Index >= ALM_INDEX_TOTAL /* && gAlmQueue[0].Index != 0xff */ )     /* o prevent alarm queue being corrupted */
  2032.     {
  2033.         AlmReInitialize();
  2034.     }
  2035.     else
  2036.     {
  2037.         memset(&refTime, 0, sizeof(MYTIME));
  2038.         refTime.nMin = ALM_MAX_DELAY_ALLOWANCE;
  2039.         IncrementTime(gAlmQueue[0].Time, refTime, &refTime);
  2040.         DTGetRTCTime(&currTime);
  2041.         if (CompareTime(currTime, refTime, NULL) == TIME_GREATER)
  2042.         {
  2043.             AlmReInitialize();
  2044.         }
  2045.     }
  2046. }
  2047. /*****************************************************************************
  2048.  * FUNCTION
  2049.  *  AlmFindNodeInQueue
  2050.  * DESCRIPTION
  2051.  *  To see if the alarm node is currently in alarm queue
  2052.  * PARAMETERS
  2053.  *  index       [IN]        Index of alarm
  2054.  * RETURNS
  2055.  *  0xff is the node is not in queue; otherwise, return the position of the alarm node.
  2056.  *****************************************************************************/
  2057. U8 AlmFindNodeInQueue(U8 index)
  2058. {
  2059.     /*----------------------------------------------------------------*/
  2060.     /* Local Variables                                                */
  2061.     /*----------------------------------------------------------------*/
  2062.     U8 i;
  2063.     /*----------------------------------------------------------------*/
  2064.     /* Code Body                                                      */
  2065.     /*----------------------------------------------------------------*/
  2066.     for (i = 0; i < NUM_OF_ALM; i++)
  2067.     {
  2068.         if (gAlmQueue[i].Index == index)
  2069.         {
  2070.             return i;
  2071.         }
  2072.         if (gAlmQueue[i].Index > ALM_INDEX_TOTAL)
  2073.         {
  2074.             return 0xff;
  2075.         }
  2076.     }
  2077.     return 0;
  2078. }
  2079. /*****************************************************************************
  2080.  * FUNCTION
  2081.  *  AlmGetType
  2082.  * DESCRIPTION
  2083.  *  To get the type of alarm
  2084.  * PARAMETERS
  2085.  *  index       [IN]        Index of alarm
  2086.  * RETURNS
  2087.  *  Enum value of alarm type
  2088.  *****************************************************************************/
  2089. U8 AlmGetType(U8 index)
  2090. {
  2091.     /*----------------------------------------------------------------*/
  2092.     /* Local Variables                                                */
  2093.     /*----------------------------------------------------------------*/
  2094.     U8 i;
  2095.     /*----------------------------------------------------------------*/
  2096.     /* Code Body                                                      */
  2097.     /*----------------------------------------------------------------*/
  2098.     for (i = 1; i < ALM_TYPE_TOTAL_NUM; i++)
  2099.     {
  2100.         if (index < gAlmCBHandler[i].alarmStartIndex)
  2101.         {
  2102.             break;
  2103.         }
  2104.     }
  2105.     return i - 1;
  2106. }
  2107. /*****************************************************************************
  2108.  * FUNCTION
  2109.  *  AlmGetRepeat
  2110.  * DESCRIPTION
  2111.  *  To get the repeat type of an alarm.
  2112.  * PARAMETERS
  2113.  *  index       [IN]        Index of alarm
  2114.  * RETURNS
  2115.  *  Enum value of repeat type
  2116.  *****************************************************************************/
  2117. U8 AlmGetRepeat(U8 index)
  2118. {
  2119.     /*----------------------------------------------------------------*/
  2120.     /* Local Variables                                                */
  2121.     /*----------------------------------------------------------------*/
  2122.     MYTIME alarmTime, preReminder;
  2123.     U8 Freq = 0;
  2124.     U8 WeekDays = 0;
  2125.     U8 AlmType, AlmIndex;
  2126.     /*----------------------------------------------------------------*/
  2127.     /* Code Body                                                      */
  2128.     /*----------------------------------------------------------------*/
  2129.     memset(&preReminder, 0, sizeof(MYTIME));
  2130.     AlmType = AlmGetType(index);
  2131.     AlmIndex = index - gAlmCBHandler[AlmType].alarmStartIndex;
  2132.     if (gAlmCBHandler[AlmType].expiryTimeCBPtr)
  2133.     {
  2134.         gAlmCBHandler[AlmType].expiryTimeCBPtr(AlmIndex, &alarmTime, &Freq, &WeekDays, &preReminder);
  2135.     }
  2136.     return Freq;
  2137. }
  2138. /*****************************************************************************
  2139.  * FUNCTION
  2140.  *  AlmGetStringValue
  2141.  * DESCRIPTION
  2142.  *  Compute the string value of given integer. The string will dispaly exact 2 digits.
  2143.  * PARAMETERS
  2144.  *  StringVal       [IN/OUT]        Pointer to store the result.
  2145.  *  Val             [IN]            Value to be computed
  2146.  * RETURNS
  2147.  *  void
  2148.  *****************************************************************************/
  2149. void AlmGetStringValue(S8 *StringVal, U8 Val)
  2150. {
  2151.     /*----------------------------------------------------------------*/
  2152.     /* Local Variables                                                */
  2153.     /*----------------------------------------------------------------*/
  2154.     S8 StrVal[16];
  2155.     /*----------------------------------------------------------------*/
  2156.     /* Code Body                                                      */
  2157.     /*----------------------------------------------------------------*/
  2158.     sprintf(StrVal, "%02d", Val);
  2159.     AnsiiToUnicodeString(StringVal, StrVal);
  2160. }
  2161. /*****************************************************************************
  2162.  * FUNCTION
  2163.  *  AlmIsRTCPwron
  2164.  * DESCRIPTION
  2165.  *  To see if the it's RTC power on or not.
  2166.  * PARAMETERS
  2167.  *  void
  2168.  * RETURNS
  2169.  *  The state of power on alarm.
  2170.  *****************************************************************************/
  2171. U8 AlmIsRTCPwron(void)
  2172. {
  2173.     /*----------------------------------------------------------------*/
  2174.     /* Local Variables                                                */
  2175.     /*----------------------------------------------------------------*/
  2176.     /*----------------------------------------------------------------*/
  2177.     /* Code Body                                                      */
  2178.     /*----------------------------------------------------------------*/
  2179.     return g_alm_frm_cntx.IsPwronAlarm;
  2180. }
  2181. /*****************************************************************************
  2182.  * FUNCTION
  2183.  *  AlmStartAlarmOnHW
  2184.  * DESCRIPTION
  2185.  *  To register RTC alarm on HW
  2186.  * PARAMETERS
  2187.  *  alarmTime       [IN]        
  2188.  * RETURNS
  2189.  *  void
  2190.  *****************************************************************************/
  2191. void AlmStartAlarmOnHW(MYTIME alarmTime)
  2192. {
  2193. #ifdef MMI_ON_HARDWARE_P
  2194.     /*----------------------------------------------------------------*/
  2195.     /* Local Variables                                                */
  2196.     /*----------------------------------------------------------------*/
  2197.     MYQUEUE Message;
  2198.     mmi_eq_set_rtc_time_req_struct *alarmReq;
  2199.     /*----------------------------------------------------------------*/
  2200.     /* Code Body                                                      */
  2201.     /*----------------------------------------------------------------*/
  2202.     Message.oslSrcId = MOD_MMI;
  2203.     Message.oslDestId = MOD_L4C;
  2204.     Message.oslMsgId = MSG_ID_MMI_EQ_EXE_RTC_TIMER_REQ;
  2205.     alarmReq = (mmi_eq_set_rtc_time_req_struct*) OslConstructDataPtr(sizeof(mmi_eq_set_rtc_time_req_struct));
  2206.     alarmReq->rtc_type = RTC_ALARM_IND;
  2207.     alarmReq->set_type = RTC_SETTING_TYPE_DATETIME;
  2208.     alarmReq->info.alarm_format = DEVICE_AL_EN_ChkYMDHMS;
  2209.     alarmReq->info.alarm_index = RTC_ALARM1_IND;    /* Should be always zeor as only 1 alarm */
  2210.     alarmReq->info.type = RTC_ALARM_SOUND;
  2211.     alarmReq->info.text[0] = '';
  2212.     alarmReq->info.recurr = RTC_ALARM_DAY1;
  2213.     alarmReq->info.data_time.rtc_year = alarmTime.nYear - YEARFORMATE;
  2214.     alarmReq->info.data_time.rtc_wday = alarmTime.DayIndex;
  2215.     alarmReq->info.data_time.rtc_mon = alarmTime.nMonth;
  2216.     alarmReq->info.data_time.rtc_day = alarmTime.nDay;
  2217.     alarmReq->info.data_time.rtc_hour = alarmTime.nHour;
  2218.     alarmReq->info.data_time.rtc_min = alarmTime.nMin;
  2219.     alarmReq->info.data_time.rtc_sec = alarmTime.nSec;
  2220.     Message.oslDataPtr = (oslParaType*) alarmReq;
  2221.     Message.oslPeerBuffPtr = NULL;
  2222.     SetProtocolEventHandler(AlmSetAlarmRSP, MSG_ID_MMI_EQ_EXE_RTC_TIMER_RSP);
  2223.     ClearProtocolEventHandler(MSG_ID_MMI_EQ_ALARM_IND);
  2224.     OslMsgSendExtQueue(&Message);
  2225. #endif /* MMI_ON_HARDWARE_P */ 
  2226. #if 0
  2227. /* under construction !*/
  2228. /* under construction !*/
  2229. /* under construction !*/
  2230. /* under construction !*/
  2231. /* under construction !*/
  2232. /* under construction !*/
  2233. /* under construction !*/
  2234. /* under construction !*/
  2235. /* under construction !*/
  2236. /* under construction !*/
  2237. /* under construction !*/
  2238. /* under construction !*/
  2239. /* under construction !*/
  2240. /* under construction !*/
  2241. /* under construction !*/
  2242. /* under construction !*/
  2243. /* under construction !*/
  2244. /* under construction !*/
  2245. /* under construction !*/
  2246. /* under construction !*/
  2247. /* under construction !*/
  2248. /* under construction !*/
  2249. /* under construction !*/
  2250. /* under construction !*/
  2251. /* under construction !*/
  2252. /* under construction !*/
  2253. /* under construction !*/
  2254. /* under construction !*/
  2255. /* under construction !*/
  2256. #endif /* 0 */ 
  2257. }
  2258. /*****************************************************************************
  2259.  * FUNCTION
  2260.  *  AlmStopAlarmOnHW
  2261.  * DESCRIPTION
  2262.  *  To del RTC from HW.
  2263.  * PARAMETERS
  2264.  *  void
  2265.  * RETURNS
  2266.  *  void
  2267.  *****************************************************************************/
  2268. void AlmStopAlarmOnHW(void)
  2269. {
  2270. #ifdef MMI_ON_HARDWARE_P
  2271.     /*----------------------------------------------------------------*/
  2272.     /* Local Variables                                                */
  2273.     /*----------------------------------------------------------------*/
  2274.     MYQUEUE Message;
  2275.     mmi_eq_del_rtc_timer_req_struct *alarmReq;
  2276.     /*----------------------------------------------------------------*/
  2277.     /* Code Body                                                      */
  2278.     /*----------------------------------------------------------------*/
  2279.     Message.oslSrcId = MOD_MMI;
  2280.     Message.oslDestId = MOD_L4C;
  2281.     Message.oslMsgId = MSG_ID_MMI_EQ_EXE_DEL_RTC_TIMER_REQ;
  2282.     alarmReq = (mmi_eq_del_rtc_timer_req_struct*) OslConstructDataPtr(sizeof(mmi_eq_del_rtc_timer_req_struct));
  2283.     alarmReq->rtc_type = RTC_ALARM_IND;
  2284.     alarmReq->rtc_index = RTC_ALARM1_IND;
  2285.     /* MTK end */
  2286.     Message.oslDataPtr = (oslParaType*) alarmReq;
  2287.     Message.oslPeerBuffPtr = NULL;
  2288.     SetProtocolEventHandler(AlmCancelAlarmRsp, MSG_ID_MMI_EQ_EXE_DEL_RTC_TIMER_RSP);
  2289.     ClearProtocolEventHandler(MSG_ID_MMI_EQ_ALARM_IND);
  2290.     OslMsgSendExtQueue(&Message);
  2291. #else /* MMI_ON_HARDWARE_P */ 
  2292.     StopTimer(ALARM_SIMULATE_ON_WIN32);
  2293. #endif /* MMI_ON_HARDWARE_P */ 
  2294. }
  2295. /*****************************************************************************
  2296.  * FUNCTION
  2297.  *  AlmReInitialize
  2298.  * DESCRIPTION
  2299.  *  Re construct whole alarm queue and realted variables.
  2300.  * PARAMETERS
  2301.  *  void
  2302.  * RETURNS
  2303.  *  The state of power on alarm.(?)
  2304.  *****************************************************************************/
  2305. void AlmReInitialize(void)
  2306. {
  2307.     /*----------------------------------------------------------------*/
  2308.     /* Local Variables                                                */
  2309.     /*----------------------------------------------------------------*/
  2310.     S32 i, almPreviousState;
  2311.     /*----------------------------------------------------------------*/
  2312.     /* Code Body                                                      */
  2313.     /*----------------------------------------------------------------*/
  2314.     almPreviousState = g_alm_frm_cntx.IsExpiryDisabled;
  2315.     
  2316.     AlmDisableExpiryHandler();
  2317.     AlmStopAlarmOnHW();
  2318.     memset(gAlmQueue, 0xff, sizeof(gAlmQueue));
  2319.     g_alm_frm_cntx.EnabledAlarms = 0;
  2320.     for (i = 0; i < ALM_TYPE_TOTAL_NUM; i++)
  2321.     {
  2322.         if (gAlmCBHandler[i].reInitAlarmQueueCBPtr)
  2323.         {
  2324.             gAlmCBHandler[i].reInitAlarmQueueCBPtr();
  2325.         }
  2326.     }
  2327.     AlmWriteQueueToNvram();
  2328.     if (gAlmQueue[0].Index != 0xff)
  2329.     {
  2330.         AlmStartAlarmOnHW(gAlmQueue[0].Time);
  2331.     }
  2332.     if (almPreviousState == MMI_FALSE)
  2333.     {
  2334.         AlmEnableExpiryHandler();
  2335.     }
  2336. }
  2337. /*****************************************************************************
  2338.  * FUNCTION
  2339.  *  AlmSendPowerOn
  2340.  * DESCRIPTION
  2341.  *  Display check disk screen, reset language, then send power on request.
  2342.  * PARAMETERS
  2343.  *  void
  2344.  * RETURNS
  2345.  *  void
  2346.  *****************************************************************************/
  2347. void AlmSendPowerOn(void)
  2348. {
  2349.     /*----------------------------------------------------------------*/
  2350.     /* Local Variables                                                */
  2351.     /*----------------------------------------------------------------*/
  2352.     /*----------------------------------------------------------------*/
  2353.     /* Code Body                                                      */
  2354.     /*----------------------------------------------------------------*/
  2355.     AlmsStopAlarmTone();
  2356.     EntryNewScreen(GLOBAL_SCR_DUMMY, NULL, NULL, NULL);
  2357.     ClearKeyHandler(KEY_END, KEY_EVENT_DOWN);
  2358.     ClearKeyHandler(KEY_END, KEY_LONG_PRESS);
  2359.     ResetLanguageSettingFlag();
  2360. #ifdef __NVRAM_IN_USB_MS__
  2361.     if (g_pwr_context.PowerOnMode == POWER_ON_USB)
  2362.     {
  2363.         /* Temporily disable alarm reset in USB boot mode */
  2364.         /*
  2365.          * mmi_usb_set_reset_type(ALARM_RESET);
  2366.          */
  2367.         UsbPwnOnThenPwnOn();
  2368.     }
  2369.     else
  2370. #endif /* __NVRAM_IN_USB_MS__ */ 
  2371.     {
  2372.         MMICheckDiskDisplay();
  2373.         AlmSendPwronReq();
  2374.     }
  2375.     /* turn on backlight to make logo visible for the user */
  2376.     TurnOnBacklight(TRUE);
  2377. }
  2378. /*****************************************************************************
  2379.  * FUNCTION
  2380.  *  AlmSendPowerOff
  2381.  * DESCRIPTION
  2382.  *  Send power off request.
  2383.  * PARAMETERS
  2384.  *  void
  2385.  * RETURNS
  2386.  *  void
  2387.  *****************************************************************************/
  2388. void AlmSendPowerOff(void)
  2389. {
  2390.     /*----------------------------------------------------------------*/
  2391.     /* Local Variables                                                */
  2392.     /*----------------------------------------------------------------*/
  2393.     /*----------------------------------------------------------------*/
  2394.     /* Code Body                                                      */
  2395.     /*----------------------------------------------------------------*/
  2396.     AlmCommonExitProcedure();
  2397. #ifdef __NVRAM_IN_USB_MS__
  2398.     if (g_pwr_context.PowerOnMode == POWER_ON_USB)
  2399.     {
  2400.         mmi_usb_set_reset_type(CHARGING_RESET);
  2401.         UsbPwnOnThenPwnOn();
  2402.     }
  2403.     else
  2404. #endif /* __NVRAM_IN_USB_MS__ */ 
  2405.         QuitSystemOperation();
  2406. }
  2407. /*****************************************************************************
  2408.  * FUNCTION
  2409.  *  AlmCheckAlarmState
  2410.  * DESCRIPTION
  2411.  *  If first alarm time > currTime, start first alarm on hardware.
  2412.  *  Else, set flag to indicate there is some pending alarm.
  2413.  * PARAMETERS
  2414.  *  void
  2415.  * RETURNS
  2416.  *  void
  2417.  *****************************************************************************/
  2418. void AlmCheckAlarmState(void)
  2419. {
  2420.     /*----------------------------------------------------------------*/
  2421.     /* Local Variables                                                */
  2422.     /*----------------------------------------------------------------*/
  2423.     MYTIME currTime;
  2424.     /*----------------------------------------------------------------*/
  2425.     /* Code Body                                                      */
  2426.     /*----------------------------------------------------------------*/
  2427.     DTGetRTCTime(&currTime);
  2428.     if (CompareTime(gAlmQueue[0].Time, currTime, NULL) == TIME_GREATER)
  2429.     {
  2430.         AlmStartAlarmOnHW(gAlmQueue[0].Time);
  2431.     }
  2432.     else
  2433.     {
  2434.         g_alm_frm_cntx.IsPendingAlm = TRUE;
  2435.     }
  2436. }
  2437. /*****************************************************************************
  2438.  * FUNCTION
  2439.  *  AlmHandlePendingTimeout
  2440.  * DESCRIPTION
  2441.  *  Execute pending alarm
  2442.  * PARAMETERS
  2443.  *  void
  2444.  * RETURNS
  2445.  *  void
  2446.  *****************************************************************************/
  2447. void AlmHandlePendingTimeout(void)
  2448. {
  2449.     /*----------------------------------------------------------------*/
  2450.     /* Local Variables                                                */
  2451.     /*----------------------------------------------------------------*/
  2452.     /*----------------------------------------------------------------*/
  2453.     /* Code Body                                                      */
  2454.     /*----------------------------------------------------------------*/
  2455.     if (!AlmIsExpireAllowed())
  2456.     {
  2457.         g_alm_frm_cntx.IsPendingAlm = TRUE;
  2458.     }
  2459.     else
  2460.     {
  2461.         U8 almType;
  2462.         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_PENDING_TIMEOUT));
  2463.         almType = AlmGetType(g_alm_frm_cntx.CurrAlmIndex);
  2464.         /* stop previous alarm */
  2465.         AlmExitPreviousAlarm();
  2466.         if (almType != ALM_TYPE_ALARM)
  2467.         {
  2468.             /* alarm will be executed in the snooze handler. */
  2469.             if (AlmIsPowerOffMode())
  2470.             {
  2471.                 AlmExecPwrOffAlarm();
  2472.             }
  2473.             else
  2474.             {
  2475.                 AlmExecPwrOnAlarm();
  2476.             }
  2477.         }
  2478.     }
  2479. }
  2480. /*****************************************************************************
  2481.  * FUNCTION
  2482.  *  AlmDisableSPOF
  2483.  * DESCRIPTION
  2484.  *  Disable schedule power off functionality.
  2485.  * PARAMETERS
  2486.  *  void
  2487.  * RETURNS
  2488.  *  void
  2489.  *****************************************************************************/
  2490. void AlmDisableSPOF(void)
  2491. {
  2492.     /*----------------------------------------------------------------*/
  2493.     /* Local Variables                                                */
  2494.     /*----------------------------------------------------------------*/
  2495.     /*----------------------------------------------------------------*/
  2496.     /* Code Body                                                      */
  2497.     /*----------------------------------------------------------------*/
  2498.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_DISABLE_SPOF));
  2499.     g_alm_frm_cntx.IsSpofDisabled = TRUE;
  2500. }
  2501. /*****************************************************************************
  2502.  * FUNCTION
  2503.  *  AlmEnableSPOF
  2504.  * DESCRIPTION
  2505.  *  Enable schedule power off functionality.
  2506.  * PARAMETERS
  2507.  *  void
  2508.  * RETURNS
  2509.  *  void
  2510.  *****************************************************************************/
  2511. void AlmEnableSPOF(void)
  2512. {
  2513.     /*----------------------------------------------------------------*/
  2514.     /* Local Variables                                                */
  2515.     /*----------------------------------------------------------------*/
  2516.     /*----------------------------------------------------------------*/
  2517.     /* Code Body                                                      */
  2518.     /*----------------------------------------------------------------*/
  2519.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_ENABLE_SPOF));
  2520.     if (g_alm_frm_cntx.IsSpofDisabled)
  2521.     {
  2522.         g_alm_frm_cntx.IsSpofDisabled = FALSE;
  2523.         PendingAlarmReminder();
  2524.     }
  2525. }
  2526. /*****************************************************************************
  2527.  * FUNCTION
  2528.  *  AlmDisableExpiryHandler
  2529.  * DESCRIPTION
  2530.  *  Disable alarm epxiry handler.
  2531.  * PARAMETERS
  2532.  *  void
  2533.  * RETURNS
  2534.  *  void
  2535.  *****************************************************************************/
  2536. void AlmDisableExpiryHandler(void)
  2537. {
  2538.     /*----------------------------------------------------------------*/
  2539.     /* Local Variables                                                */
  2540.     /*----------------------------------------------------------------*/
  2541.     /*----------------------------------------------------------------*/
  2542.     /* Code Body                                                      */
  2543.     /*----------------------------------------------------------------*/
  2544.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_DISABLE_ALARM));
  2545.     g_alm_frm_cntx.IsExpiryDisabled = TRUE;
  2546. }
  2547. /*****************************************************************************
  2548.  * FUNCTION
  2549.  *  AlmEnableExpiryHandler
  2550.  * DESCRIPTION
  2551.  *  Enable alarm epxiry handler.
  2552.  * PARAMETERS
  2553.  *  void
  2554.  * RETURNS
  2555.  *  void
  2556.  *****************************************************************************/
  2557. void AlmEnableExpiryHandler(void)
  2558. {
  2559.     /*----------------------------------------------------------------*/
  2560.     /* Local Variables                                                */
  2561.     /*----------------------------------------------------------------*/
  2562.     /*----------------------------------------------------------------*/
  2563.     /* Code Body                                                      */
  2564.     /*----------------------------------------------------------------*/
  2565.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_RTC_ALARM_ENABLE_ALARM));
  2566.     if (g_alm_frm_cntx.IsExpiryDisabled)
  2567.     {
  2568.         g_alm_frm_cntx.IsExpiryDisabled = FALSE;
  2569.         PendingAlarmReminder();
  2570.     }
  2571. }
  2572. /*****************************************************************************
  2573.  * FUNCTION
  2574.  *  AlmDeInit
  2575.  * DESCRIPTION
  2576.  *  Inspec queue status and pre-set next alarm if required.
  2577.  * PARAMETERS
  2578.  *  void
  2579.  * RETURNS
  2580.  *  void
  2581.  *****************************************************************************/
  2582. void AlmDeInit(void)
  2583. {
  2584. #ifdef MMI_ON_HARDWARE_P
  2585.     /*----------------------------------------------------------------*/
  2586.     /* Local Variables                                                */
  2587.     /*----------------------------------------------------------------*/
  2588.     /*----------------------------------------------------------------*/
  2589.     /* Code Body                                                      */
  2590.     /*----------------------------------------------------------------*/
  2591.     /* shutdown when alarm is on indication screen */
  2592.     if (AlmGetType(g_alm_frm_cntx.CurrAlmIndex) == ALM_TYPE_ALARM)
  2593.     {
  2594.         U8 i = g_alm_frm_cntx.CurrAlmIndex - ALM_ALM_START;
  2595.         g_alm_cntx.AlmList[i].Snooze++;
  2596.         if (g_alm_cntx.AlmList[i].Snooze <= MAX_SNOOZE_CHANCES)
  2597.         {
  2598.             AlmWriteToNvram();
  2599.             AlmInsertIntoQueue(g_alm_frm_cntx.CurrAlmIndex, TRUE);
  2600.             AlmStartAlarmOnHW(gAlmQueue[0].Time);
  2601.         }
  2602.     }
  2603.     /* Set next alarm. if alarm will expire during power off period, delay it */
  2604.     if (gAlmQueue[0].Index < ALM_INDEX_TOTAL)
  2605.     {
  2606.         MYTIME currTime, incTime;
  2607.         DTGetRTCTime(&currTime);
  2608.         memset(&incTime, 0, sizeof(MYTIME));
  2609.         incTime.nSec = (ALM_POWER_OFF_TOLERANCE / 1000);
  2610.         IncrementTime(currTime, incTime, &currTime);
  2611.         if (CompareTime(gAlmQueue[0].Time, currTime, NULL) != TIME_GREATER)     /* alarm almost expire */
  2612.         {
  2613.             AlmStartAlarmOnHW(currTime);
  2614.         }
  2615.     }
  2616. #endif /* MMI_ON_HARDWARE_P */ 
  2617. }
  2618. /*****************************************************************************
  2619.  * FUNCTION
  2620.  *  AlmIsTonePlaying
  2621.  * DESCRIPTION
  2622.  *  Query if alarm tone playing.
  2623.  * PARAMETERS
  2624.  *  void
  2625.  * RETURNS
  2626.  *  void
  2627.  *****************************************************************************/
  2628. U8 AlmIsTonePlaying(void)
  2629. {
  2630.     /*----------------------------------------------------------------*/
  2631.     /* Local Variables                                                */
  2632.     /*----------------------------------------------------------------*/
  2633.     /*----------------------------------------------------------------*/
  2634.     /* Code Body                                                      */
  2635.     /*----------------------------------------------------------------*/
  2636.     return g_alm_frm_cntx.IsAlmTonePlaying;
  2637. }
  2638. /*****************************************************************************
  2639.  * FUNCTION
  2640.  *  mmi_alm_is_in_alarm
  2641.  * DESCRIPTION
  2642.  *  Query if alarm tone playing.
  2643.  * PARAMETERS
  2644.  *  void
  2645.  * RETURNS
  2646.  *  void
  2647.  *****************************************************************************/
  2648. MMI_BOOL mmi_alm_is_in_alarm(void)
  2649. {
  2650.     if ( AlmIsTonePlaying()
  2651. #if defined(__MMI_FM_RADIO_SCHEDULE_REC__)    
  2652.      || mmi_fmsr_is_schedule_rec_running()
  2653. #endif     
  2654.      )
  2655.     {
  2656. return MMI_TRUE;
  2657.     }
  2658.     return MMI_FALSE;
  2659. }
  2660. /*****************************************************************************
  2661.  * FUNCTION
  2662.  *  FactorySetAlarm
  2663.  * DESCRIPTION
  2664.  *  Set facrtory mode alarm.
  2665.  * PARAMETERS
  2666.  *  sec     [IN]        
  2667.  * RETURNS
  2668.  *  void
  2669.  *****************************************************************************/
  2670. #if (defined(MMI_ON_HARDWARE_P) && defined(__MMI_FACTORY_MODE__))       /* Robin Add 1001 for MMI Feature */
  2671. void FactorySetAlarm(U8 sec)
  2672. {
  2673.     /*----------------------------------------------------------------*/
  2674.     /* Local Variables                                                */
  2675.     /*----------------------------------------------------------------*/
  2676.     /*----------------------------------------------------------------*/
  2677.     /* Code Body                                                      */
  2678.     /*----------------------------------------------------------------*/
  2679.     AlmSetAlarm(ALM_FACTORY);
  2680. }
  2681. /*****************************************************************************
  2682.  * FUNCTION
  2683.  *  FactoryExpiryTimeCB
  2684.  * DESCRIPTION
  2685.  *  Set facrtory mode alarm.
  2686.  * PARAMETERS
  2687.  *  index           [IN]        
  2688.  *  alarmTime       [?]         
  2689.  *  Freq            [?]         
  2690.  *  WeekDays        [?]         
  2691.  * RETURNS
  2692.  *  void
  2693.  *****************************************************************************/
  2694. void FactoryExpiryTimeCB(U8 index, MYTIME *alarmTime, U8 *Freq, U8 *WeekDays, MYTIME *preReminder)
  2695. {
  2696.     /*----------------------------------------------------------------*/
  2697.     /* Local Variables                                                */
  2698.     /*----------------------------------------------------------------*/
  2699.     MYTIME incTime;
  2700.     /*----------------------------------------------------------------*/
  2701.     /* Code Body                                                      */
  2702.     /*----------------------------------------------------------------*/
  2703.     DTGetRTCTime(alarmTime);
  2704.     memset(&incTime, 0, sizeof(MYTIME));
  2705.     incTime.nSec = ALM_FACTORY_RTC_TIME;
  2706.     IncrementTime(*alarmTime, incTime, alarmTime);
  2707.     *Freq = ALM_FREQ_ONCE;
  2708. }
  2709. /*****************************************************************************
  2710.  * FUNCTION
  2711.  *  FactoryExpiryHandler
  2712.  * DESCRIPTION
  2713.  *  Set facrtory mode alarm.
  2714.  * PARAMETERS
  2715.  *  Index           [IN]        
  2716.  *  period          [?]         
  2717.  *  power_on        [IN]        
  2718.  * RETURNS
  2719.  *  void
  2720.  *****************************************************************************/
  2721. U8 FactoryExpiryHandler(U8 Index, U16 *period, BOOL power_on)
  2722. {
  2723.     /*----------------------------------------------------------------*/
  2724.     /* Local Variables                                                */
  2725.     /*----------------------------------------------------------------*/
  2726.     /*----------------------------------------------------------------*/
  2727.     /* Code Body                                                      */
  2728.     /*----------------------------------------------------------------*/
  2729.     if (!power_on)
  2730.     {
  2731.         *period = ALM_DEFAULT_EXPIRY_PERIOD;
  2732.         AlmInitLCDModule();
  2733.         EntryAlmIndicationScreen();
  2734.         g_pwr_context.PowerOnMMIStatus = MMI_POWER_ON_IDLE; /* 0x80: Alarm idle screen */
  2735.         return ALM_HAS_IND;
  2736.     }
  2737.     *period = ALM_WITHOUD_EXPIRY_PERIOD;
  2738.     return ALM_HAS_NO_IND;
  2739. }
  2740. #endif /* (defined(MMI_ON_HARDWARE_P) && defined(__MMI_FACTORY_MODE__)) */ 
  2741. /*****************************************************************************
  2742.  * FUNCTION
  2743.  *  AlmATPowerReset
  2744.  * DESCRIPTION
  2745.  *  Set an reboot alarm for AT command
  2746.  * PARAMETERS
  2747.  *  power_off       [IN]        
  2748.  *  time            [IN]        
  2749.  * RETURNS
  2750.  *  void
  2751.  *****************************************************************************/
  2752. void AlmATPowerReset(U8 power_off, U8 time)
  2753. {
  2754. #ifdef __MMI_FACTORY_MODE__
  2755.     /*----------------------------------------------------------------*/
  2756.     /* Local Variables                                                */
  2757.     /*----------------------------------------------------------------*/
  2758.     /*----------------------------------------------------------------*/
  2759.     /* Code Body                                                      */
  2760.     /*----------------------------------------------------------------*/
  2761.     /* reuse the flag of factory alarm */
  2762.     gFactoryAlarm = 1;
  2763.     if (power_off)
  2764.     {
  2765.         g_alm_frm_cntx.ATPwrCycle = time;
  2766.     }
  2767.     else
  2768.     {
  2769.         g_alm_frm_cntx.ATPwrCycle = ALM_FACTORY_RTC_TIME;
  2770.     }
  2771.     g_alm_frm_cntx.IsATPwrOffAnimation = power_off;
  2772.     AlmSetAlarm(ALM_PWR_RESET);
  2773. #endif /* __MMI_FACTORY_MODE__ */ 
  2774. }
  2775. /*****************************************************************************
  2776.  * FUNCTION
  2777.  *  ResetExpiryTimeCB
  2778.  * DESCRIPTION
  2779.  *  Set facrtory mode alarm.
  2780.  * PARAMETERS
  2781.  *  index           [IN]        
  2782.  *  alarmTime       [?]         
  2783.  *  Freq            [?]         
  2784.  *  WeekDays        [?]         
  2785.  * RETURNS
  2786.  *  void
  2787.  *****************************************************************************/
  2788. void ResetExpiryTimeCB(U8 index, MYTIME *alarmTime, U8 *Freq, U8 *WeekDays, MYTIME *preReminder)
  2789. {
  2790.     /*----------------------------------------------------------------*/
  2791.     /* Local Variables                                                */
  2792.     /*----------------------------------------------------------------*/
  2793.     MYTIME incTime;
  2794.     /*----------------------------------------------------------------*/
  2795.     /* Code Body                                                      */
  2796.     /*----------------------------------------------------------------*/
  2797.     DTGetRTCTime(alarmTime);
  2798.     memset(&incTime, 0, sizeof(MYTIME));
  2799.     incTime.nSec = (g_alm_frm_cntx.ATPwrCycle % 60);
  2800.     incTime.nMin = (g_alm_frm_cntx.ATPwrCycle / 60);
  2801.     IncrementTime(*alarmTime, incTime, alarmTime);
  2802.     *Freq = ALM_FREQ_ONCE;
  2803. }
  2804. /*****************************************************************************
  2805.  * FUNCTION
  2806.  *  ResetExpiryHandler
  2807.  * DESCRIPTION
  2808.  *  Set facrtory mode alarm.
  2809.  * PARAMETERS
  2810.  *  index           [IN]        
  2811.  *  period          [?]         
  2812.  *  power_on        [IN]        
  2813.  * RETURNS
  2814.  *  void
  2815.  *****************************************************************************/
  2816. U8 ResetExpiryHandler(U8 index, U16 *period, BOOL power_on)
  2817. {
  2818.     /*----------------------------------------------------------------*/
  2819.     /* Local Variables                                                */
  2820.     /*----------------------------------------------------------------*/
  2821.     /*----------------------------------------------------------------*/
  2822.     /* Code Body                                                      */
  2823.     /*----------------------------------------------------------------*/
  2824.     if (!power_on)
  2825.     {
  2826.         AlmSendPowerOn();
  2827.     }
  2828.     *period = ALM_WITHOUD_EXPIRY_PERIOD;
  2829.     return ALM_HAS_NO_IND;
  2830. }
  2831. /*****************************************************************************
  2832.  * FUNCTION
  2833.  *  AlmIsPowerOffMode
  2834.  * DESCRIPTION
  2835.  *  Function to check if it's currently in power off mode
  2836.  * PARAMETERS
  2837.  *  void
  2838.  * RETURNS
  2839.  *  TRUE if alarm shall be executed as power off mode; otherwise, FALSE.
  2840.  *****************************************************************************/
  2841. BOOL AlmIsPowerOffMode(void)
  2842. {
  2843.     /*----------------------------------------------------------------*/
  2844.     /* Local Variables                                                */
  2845.     /*----------------------------------------------------------------*/
  2846.     /*----------------------------------------------------------------*/
  2847.     /* Code Body                                                      */
  2848.     /*----------------------------------------------------------------*/
  2849.     return ((g_pwr_context.PowerOnMode != POWER_ON_KEYPAD) && (g_pwr_context.PowerOnMode != POWER_ON_EXCEPTION));
  2850. }
  2851. /*****************************************************************************
  2852.  * FUNCTION
  2853.  *  AlmSetExpiryTimeCB
  2854.  * DESCRIPTION
  2855.  *  Set callback function of getting alarm expiry time by alarm type.
  2856.  * PARAMETERS
  2857.  *  AlmType                 [IN]        
  2858.  *  funcPtr                 [IN]        
  2859.  *  ExpiryTimeCBPtr(?)      [IN]        Function point
  2860.  *  U8(?)                   [IN]        Alarm type
  2861.  * RETURNS
  2862.  *  void
  2863.  *****************************************************************************/
  2864. void AlmSetExpiryTimeCB(U8 AlmType, ExpiryTimeCBPtr funcPtr)
  2865. {
  2866.     /*----------------------------------------------------------------*/
  2867.     /* Local Variables                                                */
  2868.     /*----------------------------------------------------------------*/
  2869.     /*----------------------------------------------------------------*/
  2870.     /* Code Body                                                      */
  2871.     /*----------------------------------------------------------------*/
  2872.     gAlmCBHandler[AlmType].expiryTimeCBPtr = funcPtr;
  2873. }
  2874. /*****************************************************************************
  2875.  * FUNCTION
  2876.  *  AlmSetExpiryHandlerCB
  2877.  * DESCRIPTION
  2878.  *  Set callback function of alarm expiry handler.
  2879.  * PARAMETERS
  2880.  *  AlmType                     [IN]        
  2881.  *  expiryHandler               [IN]        
  2882.  *  ExpiryHandlerCBPtr(?)       [IN]        Function point
  2883.  *  U8(?)                       [IN]        Alarm type
  2884.  * RETURNS
  2885.  *  void
  2886.  *****************************************************************************/
  2887. void AlmSetExpiryHandlerCB(U8 AlmType, ExpiryHandlerCBPtr expiryHandler)
  2888. {
  2889.     /*----------------------------------------------------------------*/
  2890.     /* Local Variables                                                */
  2891.     /*----------------------------------------------------------------*/
  2892.     /*----------------------------------------------------------------*/
  2893.     /* Code Body                                                      */
  2894.     /*----------------------------------------------------------------*/
  2895.     gAlmCBHandler[AlmType].expiryHandlerCBPtr = expiryHandler;
  2896. }
  2897. /*****************************************************************************
  2898.  * FUNCTION
  2899.  *  AlmSetInitHandlerCB
  2900.  * DESCRIPTION
  2901.  *  Set callback function of initing NVRAM and re-scheduling alarm queue.
  2902.  * PARAMETERS
  2903.  *  AlmType                         [IN]        
  2904.  *  initNvram                       [IN]        
  2905.  *  reInitQueue                     [IN]        
  2906.  *  ReInitAlarmQueueCBPtr(?)        [IN]        Function point
  2907.  *  InitAlarmNvramCBPtr(?)          [IN]        Function point
  2908.  *  U8(?)                           [IN]        Alarm type
  2909.  * RETURNS
  2910.  *  void
  2911.  *****************************************************************************/
  2912. void AlmSetInitHandlerCB(U8 AlmType, InitAlarmNvramCBPtr initNvram, ReInitAlarmQueueCBPtr reInitQueue)
  2913. {
  2914.     /*----------------------------------------------------------------*/
  2915.     /* Local Variables                                                */
  2916.     /*----------------------------------------------------------------*/
  2917.     /*----------------------------------------------------------------*/
  2918.     /* Code Body                                                      */
  2919.     /*----------------------------------------------------------------*/
  2920.     gAlmCBHandler[AlmType].initAlarmNvramCBPtr = initNvram;
  2921.     gAlmCBHandler[AlmType].reInitAlarmQueueCBPtr = reInitQueue;
  2922. }
  2923. /*****************************************************************************
  2924.  * FUNCTION
  2925.  *  AlmSetStopAlarmCB
  2926.  * DESCRIPTION
  2927.  *  Set callback function of stopping alarm when timeout
  2928.  * PARAMETERS
  2929.  *  AlmType                 [IN]        
  2930.  *  stopAlarm               [IN]        
  2931.  *  StopAlarmCBPtr(?)       [IN]        Function point
  2932.  *  U8(?)                   [IN]        Alarm type
  2933.  * RETURNS
  2934.  *  void
  2935.  *****************************************************************************/
  2936. void AlmSetStopAlarmCB(U8 AlmType, StopAlarmCBPtr stopAlarm)
  2937. {
  2938.     /*----------------------------------------------------------------*/
  2939.     /* Local Variables                                                */
  2940.     /*----------------------------------------------------------------*/
  2941.     /*----------------------------------------------------------------*/
  2942.     /* Code Body                                                      */
  2943.     /*----------------------------------------------------------------*/
  2944.     gAlmCBHandler[AlmType].stopAlarmCBPtr = stopAlarm;
  2945. }
  2946. /*****************************************************************************
  2947.  * FUNCTION
  2948.  *  mmi_alm_set_start_index
  2949.  * DESCRIPTION
  2950.  *  Set start index of alarm application
  2951.  * PARAMETERS
  2952.  *  AlmType         [IN]        
  2953.  *  startIndex      [IN]        
  2954.  *  U8(?)           [IN]        Start index
  2955.  * RETURNS
  2956.  *  void
  2957.  *****************************************************************************/
  2958. void mmi_alm_set_start_index(U8 AlmType, U8 startIndex)
  2959. {
  2960.     /*----------------------------------------------------------------*/
  2961.     /* Local Variables                                                */
  2962.     /*----------------------------------------------------------------*/
  2963.     /*----------------------------------------------------------------*/
  2964.     /* Code Body                                                      */
  2965.     /*----------------------------------------------------------------*/
  2966.     gAlmCBHandler[AlmType].alarmStartIndex = startIndex;
  2967. }
  2968. /*****************************************************************************
  2969.  * FUNCTION
  2970.  *  mmi_alm_get_index_from_queue
  2971.  * DESCRIPTION
  2972.  *  get alarm index from queue.
  2973.  * PARAMETERS
  2974.  *  num         [IN]        
  2975.  *  U8(?)       [IN]        Nth item of alarm queue
  2976.  * RETURNS
  2977.  *  U8 OUT   alarm index
  2978.  *****************************************************************************/
  2979. U8 mmi_alm_get_index_from_queue(U8 num)
  2980. {
  2981.     /*----------------------------------------------------------------*/
  2982.     /* Local Variables                                                */
  2983.     /*----------------------------------------------------------------*/
  2984.     /*----------------------------------------------------------------*/
  2985.     /* Code Body                                                      */
  2986.     /*----------------------------------------------------------------*/
  2987.     return gAlmQueue[num].Index;
  2988. }
  2989. /*****************************************************************************
  2990.  * FUNCTION
  2991.  *  mmi_alm_get_freq_order
  2992.  * DESCRIPTION
  2993.  *  Get frequency index of inline selection.
  2994.  * PARAMETERS
  2995.  *  freqNum     [IN]        
  2996.  *  freqSet     [IN]        
  2997.  *  freq        [IN]        
  2998.  * RETURNS
  2999.  *  void
  3000.  *****************************************************************************/
  3001. U8 mmi_alm_get_freq_order(U8 freqNum, const U8 *freqSet, U8 freq)
  3002. {
  3003.     /*----------------------------------------------------------------*/
  3004.     /* Local Variables                                                */
  3005.     /*----------------------------------------------------------------*/
  3006.     U8 i;
  3007.     /*----------------------------------------------------------------*/
  3008.     /* Code Body                                                      */
  3009.     /*----------------------------------------------------------------*/
  3010.     for (i = 0; i < freqNum; i++)
  3011.     {
  3012.         if (freqSet[i] == freq)
  3013.         {
  3014.             return i;
  3015.         }
  3016.     }
  3017. #ifdef MMI_ON_HARDWARE_P
  3018.     MMI_ASSERT(i < freqNum);
  3019. #endif 
  3020.     return (U8) 0;
  3021. }
  3022. /*****************************************************************************
  3023.  * FUNCTION
  3024.  *  mmi_alm_disable_pwroff
  3025.  * DESCRIPTION
  3026.  *  For applications executing during power off mode,
  3027.  *  and not allow alarm framework to shutdown the system when finishing alarm expiry.
  3028.  * PARAMETERS
  3029.  *  void
  3030.  * RETURNS
  3031.  *  void
  3032.  *****************************************************************************/
  3033. void mmi_alm_disable_pwroff(void)
  3034. {
  3035.     /*----------------------------------------------------------------*/
  3036.     /* Local Variables                                                */
  3037.     /*----------------------------------------------------------------*/
  3038.     /*----------------------------------------------------------------*/
  3039.     /* Code Body                                                      */
  3040.     /*----------------------------------------------------------------*/
  3041.     g_alm_frm_cntx.IsAppExecuting++;
  3042. }
  3043. /*****************************************************************************
  3044.  * FUNCTION
  3045.  *  mmi_alm_enable_pwroff
  3046.  * DESCRIPTION
  3047.  *  Reference of mmi_alm_disable_pwroff,
  3048.  *  need to be executed when stopping application.
  3049.  * PARAMETERS
  3050.  *  void
  3051.  * RETURNS
  3052.  *  void
  3053.  *****************************************************************************/
  3054. void mmi_alm_enable_pwroff(void)
  3055. {
  3056.     /*----------------------------------------------------------------*/
  3057.     /* Local Variables                                                */
  3058.     /*----------------------------------------------------------------*/
  3059.     /*----------------------------------------------------------------*/
  3060.     /* Code Body                                                      */
  3061.     /*----------------------------------------------------------------*/
  3062.     if (g_alm_frm_cntx.IsAppExecuting != 0)
  3063.     {
  3064.         g_alm_frm_cntx.IsAppExecuting--;
  3065.     }
  3066. }
  3067. #endif /* _MMI_ALARMFRAMEWORK_C */ // #ifndef _MMI_ALARMFRAMEWORK_C