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

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.  * NVRAMINTERFACE.C
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for nvram read write data interface.
  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.  * removed!
  67.  *
  68.  * removed!
  69.  * removed!
  70.  * removed!
  71.  *
  72.  * removed!
  73.  * removed!
  74.  * removed!
  75.  *
  76.  * removed!
  77.  * removed!
  78.  * removed!
  79.  *
  80.  * removed!
  81.  * removed!
  82.  * removed!
  83.  *
  84.  * removed!
  85.  * removed!
  86.  * removed!
  87.  *
  88.  * removed!
  89.  * removed!
  90.  * removed!
  91.  *
  92.  * removed!
  93.  * removed!
  94.  * removed!
  95.  *
  96.  * removed!
  97.  * removed!
  98.  * removed!
  99.  *
  100.  * removed!
  101.  * removed!
  102.  * removed!
  103.  *
  104.  * removed!
  105.  * removed!
  106.  * removed!
  107.  *
  108.  * removed!
  109.  * removed!
  110.  * removed!
  111.  *
  112.  * removed!
  113.  * removed!
  114.  * removed!
  115.  *
  116.  * removed!
  117.  * removed!
  118.  * removed!
  119.  *
  120.  * removed!
  121.  * removed!
  122.  * removed!
  123.  * removed!
  124.  *
  125.  * removed!
  126.  * removed!
  127.  * removed!
  128.  *
  129.  * removed!
  130.  * removed!
  131.  * removed!
  132.  *
  133.  * removed!
  134.  * removed!
  135.  * removed!
  136.  *
  137.  * removed!
  138.  * removed!
  139.  * removed!
  140.  *
  141.  * removed!
  142.  * removed!
  143.  * removed!
  144.  *
  145.  * removed!
  146.  * removed!
  147.  * removed!
  148.  *
  149.  * removed!
  150.  * removed!
  151.  * removed!
  152.  *
  153.  * removed!
  154.  * removed!
  155.  * removed!
  156.  *
  157.  * removed!
  158.  * removed!
  159.  * removed!
  160.  *
  161.  * removed!
  162.  * removed!
  163.  * removed!
  164.  *
  165.  * removed!
  166.  * removed!
  167.  * removed!
  168.  *
  169.  * removed!
  170.  * removed!
  171.  * removed!
  172.  *
  173.  * removed!
  174.  * removed!
  175.  * removed!
  176.  *
  177.  * removed!
  178.  * removed!
  179.  * removed!
  180.  *
  181.  * removed!
  182.  * removed!
  183.  * removed!
  184.  *
  185.  * removed!
  186.  * removed!
  187.  * removed!
  188.  *
  189.  * removed!
  190.  * removed!
  191.  * removed!
  192.  *
  193.  * removed!
  194.  * removed!
  195.  * removed!
  196.  *
  197.  * removed!
  198.  * removed!
  199.  * removed!
  200.  *
  201.  * removed!
  202.  * removed!
  203.  * removed!
  204.  *
  205.  * removed!
  206.  * removed!
  207.  * removed!
  208.  *
  209.  *------------------------------------------------------------------------------
  210.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  211.  *============================================================================
  212.  ****************************************************************************/
  213. #ifndef MMI_ON_WIN32
  214. #include "kal_release.h"        /* Basic data type */
  215. #include "stack_common.h"
  216. #include "stack_msgs.h"
  217. #include "app_ltlcom.h" /* Task message communiction */
  218. #include "syscomp_config.h"
  219. #include "task_config.h"        /* Task creation */
  220. #include "stacklib.h"   /* Basic type for dll, evshed, stacktimer */
  221. #include "event_shed.h" /* Event scheduler */
  222. #include "stack_timer.h"        /* Stack timer */
  223. #include "l4dr.h"
  224. #include "MMI_trc.h"
  225. #include "lcddr.h"
  226. #include "PixtelDataTypes.h"
  227. #include "OslMemory.h"
  228. #endif /* MMI_ON_WIN32 */ 
  229. #include "nvram_user_defs.h"
  230. #include "StdC.h"
  231. #include "QueueGprot.h"
  232. #include "NVRAMEnum.h"
  233. #include "NVRAMProt.h"
  234. #include "NVRAMHwMapFile.h"
  235. #include "NVRAMType.h"
  236. #include "DebugInitDef.h"
  237. #include "TaskInit.h"   /* For MMITaskProt.h */
  238. #include "MMITaskProt.h"        /* For ProtocolEventHandler() prototype */
  239. #include "keyBrd.h"
  240. #ifdef MMI_ON_WIN32
  241. #include "windows.h"
  242. #include "Fat_fs.h"
  243. #endif /* MMI_ON_WIN32 */ 
  244. #include "ucs2prot.h"
  245. #include "TimerEvents.h"
  246. #include "SimDetectionGexdcl.h" /* for g_pwr_context */
  247. #include "SimDetectionGprot.h"
  248. #define __ONLY_FOR_AUTO_RESGEN__
  249. #include "PhoneSetup.h"
  250. #undef __ONLY_FOR_AUTO_RESGEN__
  251. extern void EvshedMMITimerHandler(void *dataPtr);
  252. extern void KeyHandleBeforePWRON(void *paraBuff);
  253. extern oslMsgqid mmi_ext_qid;
  254. #ifndef MMI_ON_WIN32
  255. #include "Stack_timer.h"
  256. extern MMI_BOOL g_keypad_flag;
  257. extern drv_get_key_func keypad_ptr;
  258. #endif /* MMI_ON_WIN32 */ 
  259. static U8 in_nvram_procedure = 0;
  260. static oslMsgqid nvramQID;
  261. static U8 byte_data[NVRAM_CACHE_SIZE];
  262. static U8 uint_data[NVRAM_CACHE_SIZE];
  263. static U8 double_data[NVRAM_CACHE_SIZE];
  264. static U8 byteDataReadFlag = 0;
  265. static U8 uintDataReadFlag = 0;
  266. static U8 doubleDataReadFlag = 0;
  267. static U8 byteDataWriteFlashFlag = 0;
  268. static U8 uintDataWriteFlashFlag = 0;
  269. static U8 doubleDataWriteFlashFlag = 0;
  270. #if defined(__NEW_NVRAMINTERFACE__) && !defined(MMI_ON_WIN32)
  271. /* only for internal read/write value */
  272. #define WriteRecordInt(nFileId,nRecordId,pBuffer,nBufferSize,pError, fileName,lineNumber)
  273.    AccessRecordInt(nFileId,nRecordId,pBuffer,nBufferSize, 1, pError, MMI_TRUE, MMI_TRUE, fileName,lineNumber)
  274. /* only for internal read/write value */
  275. #define ReadRecordInt(nFileId,nRecordId,pBuffer,nBufferSize,pError,fileName,lineNumber)
  276.    AccessRecordInt(nFileId,nRecordId,pBuffer,nBufferSize, 1, pError, MMI_FALSE, MMI_TRUE, fileName,lineNumber)
  277. #endif /* defined(__NEW_NVRAMINTERFACE__) && !defined(MMI_ON_WIN32) */
  278. /*****************************************************************************
  279.  * FUNCTION
  280.  *  SendNVRAMReadReq
  281.  * DESCRIPTION
  282.  *  Send Read NVRAM request to L4
  283.  * PARAMETERS
  284.  *  nFileId             [IN]        File LID
  285.  *  nRecordId           [IN]        Record Index
  286.  *  nRecordAmount       [IN]        
  287.  * RETURNS
  288.  *  void
  289.  *****************************************************************************/
  290. static void SendNVRAMReadReq(U16 nFileId, U16 nRecordId, U16 nRecordAmount)
  291. {
  292.     /*----------------------------------------------------------------*/
  293.     /* Local Variables                                                */
  294.     /*----------------------------------------------------------------*/
  295. #ifndef MMI_ON_WIN32
  296.     MYQUEUE Message;
  297.     mmi_eq_nvram_read_req_struct *local_data;
  298.     /*----------------------------------------------------------------*/
  299.     /* Code Body                                                      */
  300.     /*----------------------------------------------------------------*/
  301.     Message.oslSrcId = MOD_MMI;
  302.     Message.oslDestId = MOD_L4C;
  303.     Message.oslMsgId = MSG_ID_MMI_EQ_NVRAM_READ_REQ;
  304.     local_data = (mmi_eq_nvram_read_req_struct*) OslConstructDataPtr(sizeof(mmi_eq_nvram_read_req_struct));
  305.     /* since we truncate U16 to U8, make sure the value is in U8 range here */
  306.     MMI_ASSERT(nFileId <= 0xFF);
  307.     
  308.     local_data->file_idx = (U8) nFileId;
  309.     local_data->para = nRecordId;
  310.     local_data->rec_amount = nRecordAmount;
  311.     if (local_data->rec_amount == 0)
  312.     {
  313.         local_data->rec_amount = 1;
  314.     }
  315.     Message.oslDataPtr = (oslParaType*) local_data;
  316.     Message.oslPeerBuffPtr = NULL;
  317.     OslMsgSendExtQueue(&Message);
  318. #endif /* MMI_ON_WIN32 */ 
  319. }
  320. /*****************************************************************************
  321.  * FUNCTION
  322.  *  SendNVRAMWriteReq
  323.  * DESCRIPTION
  324.  *  Send Write NVRAM request to L4
  325.  *  
  326.  *  Size should be an even number
  327.  * PARAMETERS
  328.  *  nFileId         [IN]        File ID
  329.  *  nRecordId       [IN]        Record Index
  330.  *  pBuffer         [IN]        Data to be writen
  331.  *  nBufferSize     [IN]        Size of data to be writen
  332.  * RETURNS
  333.  *  void
  334.  *****************************************************************************/
  335. static void SendNVRAMWriteReq(U16 nFileId, U16 nRecordId, void *pBuffer, U16 nBufferSize)
  336. {
  337.     /*----------------------------------------------------------------*/
  338.     /* Local Variables                                                */
  339.     /*----------------------------------------------------------------*/
  340. #ifndef MMI_ON_WIN32
  341.     MYQUEUE Message;
  342.     mmi_eq_nvram_write_req_struct *local_data;
  343.     /*----------------------------------------------------------------*/
  344.     /* Code Body                                                      */
  345.     /*----------------------------------------------------------------*/
  346.     Message.oslSrcId = MOD_MMI;
  347.     Message.oslDestId = MOD_L4C;
  348.     Message.oslMsgId = MSG_ID_MMI_EQ_NVRAM_WRITE_REQ;
  349.     local_data = (mmi_eq_nvram_write_req_struct*) OslConstructDataPtr(sizeof(mmi_eq_nvram_write_req_struct) + nBufferSize);
  350.     /* since we truncate U16 to U8, make sure the value is in U8 range here */
  351.     MMI_ASSERT(nFileId <= 0xFF);
  352.     local_data->file_idx = (U8) nFileId;
  353.     local_data->length = nBufferSize;
  354.     memcpy(local_data->data, pBuffer, nBufferSize);
  355.     local_data->para = nRecordId;
  356.     Message.oslDataPtr = (oslParaType*) local_data;
  357.     Message.oslPeerBuffPtr = NULL;
  358.     OslMsgSendExtQueue(&Message);
  359.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_HDLR));
  360. #endif /* MMI_ON_WIN32 */ 
  361. }
  362. #ifndef MMI_ON_WIN32
  363. #ifdef __NEW_NVRAMINTERFACE__
  364. #define CIRCQ_NODE_SIZE sizeof(MYQUEUE)
  365. #define CIRCQ_NO_OF_NODES 65
  366. typedef enum
  367. {
  368.     circularQ_check_never_check,
  369.     circularQ_check_not_found,
  370.     circularQ_check_found
  371. } circularQ_check_enum;
  372. #ifdef __MMI_TEST_NEW_NVRAMINTERFACE__
  373. /*****************************************************************************
  374.  * FUNCTION
  375.  *  NVRAMDummyTestRW
  376.  * DESCRIPTION
  377.  *  
  378.  * PARAMETERS
  379.  *  void
  380.  * RETURNS
  381.  *  void
  382.  *****************************************************************************/
  383. void NVRAMDummyTestRW(void)
  384. {
  385.     /*----------------------------------------------------------------*/
  386.     /* Local Variables                                                */
  387.     /*----------------------------------------------------------------*/
  388.     static pBOOL isRead = MMI_TRUE;
  389.     static kal_uint8 settingBuffer[NVRAM_SETTING_SIZE] = {0};
  390.     S16 error;
  391.     /*----------------------------------------------------------------*/
  392.     /* Code Body                                                      */
  393.     /*----------------------------------------------------------------*/
  394.     StartTimer(AT_TEST_TIMER, 3000, NVRAMDummyTestRW);
  395.     if (isRead)
  396.     {
  397.         ReadRecord(NVRAM_EF_SETTING_LID, 1, settingBuffer, NVRAM_SETTING_SIZE, &error);
  398.         isRead = MMI_FALSE;
  399.     }
  400.     else
  401.     {
  402.         WriteRecord(NVRAM_EF_SETTING_LID, 1, settingBuffer, NVRAM_SETTING_SIZE, &error);
  403.         isRead = MMI_TRUE;
  404.     }
  405. }
  406. #endif /* __MMI_TEST_NEW_NVRAMINTERFACE__ */ 
  407. /*****************************************************************************
  408.  * FUNCTION
  409.  *  NVRAMCheckCircularQ
  410.  * DESCRIPTION
  411.  *  check if there is nvram access response
  412.  *  in the circular queue; if there is,
  413.  *  retrieve it and put a dummy one in the
  414.  *  same position
  415.  * PARAMETERS
  416.  *  msgPtr          [?]         
  417.  *  nFileId         [IN]        The LID currently waiting
  418.  *  memory(?)       [OUT]       For this.
  419.  *  pBuffer(?)      [OUT]       Buffer in which data need to
  420.  *  be(?)           [OUT]       Retrieved,caller will allocate
  421.  * RETURNS
  422.  *  circularQ_check_enum
  423.  *****************************************************************************/
  424. circularQ_check_enum NVRAMCheckCircularQ(void *msgPtr, U16 nFileId)
  425. {
  426.     /*----------------------------------------------------------------*/
  427.     /* Local Variables                                                */
  428.     /*----------------------------------------------------------------*/
  429.     U8 i;
  430.     extern U8 circq_array[];
  431.     MYQUEUE *tempQueueNode;
  432. #ifdef __MMI_TEST_NEW_NVRAMINTERFACE__
  433.     static pBOOL testFlag = MMI_TRUE;
  434.     /*----------------------------------------------------------------*/
  435.     /* Code Body                                                      */
  436.     /*----------------------------------------------------------------*/
  437.     if (testFlag)
  438.     {
  439.         NVRAMDummyTestRW();
  440.         testFlag = MMI_FALSE;
  441.     }
  442. #endif /* __MMI_TEST_NEW_NVRAMINTERFACE__ */ 
  443.     for (i = 0; i < CIRCQ_NO_OF_NODES; i++)
  444.     {
  445.         tempQueueNode = ((MYQUEUE*) (circq_array + i * CIRCQ_NODE_SIZE));
  446.         switch (tempQueueNode->msg_id)
  447.         {
  448.             case MSG_ID_MMI_EQ_NVRAM_READ_RSP:
  449.             case MSG_ID_MMI_EQ_NVRAM_WRITE_RSP:
  450.             {
  451.                 ilm_struct ilm_ptr; /* DUMMY message */
  452.                 if (((mmi_eq_nvram_read_rsp_struct*) (tempQueueNode->local_para_ptr))->file_idx == nFileId
  453.                     || ((mmi_eq_nvram_write_rsp_struct*) (tempQueueNode->local_para_ptr))->file_idx == nFileId)
  454.                 {
  455.                     memcpy(msgPtr, circq_array + (i * CIRCQ_NODE_SIZE), CIRCQ_NODE_SIZE);
  456.                     ilm_ptr.src_mod_id = MOD_NIL;
  457.                     ilm_ptr.dest_mod_id = MOD_NIL;
  458.                     ilm_ptr.msg_id = MSG_ID_MMI_EQ_NVRAM_READY_IND;
  459.                     ilm_ptr.sap_id = INVALID_SAP;
  460.                     ilm_ptr.local_para_ptr = NULL;
  461.                     ilm_ptr.peer_buff_ptr = NULL;
  462.                     memcpy(circq_array + (i * CIRCQ_NODE_SIZE), &ilm_ptr, CIRCQ_NODE_SIZE);
  463.                     return circularQ_check_found;
  464.                 }
  465.             }
  466.             default:
  467.                 break;
  468.         }
  469.     }
  470.     return circularQ_check_not_found;
  471. }
  472. /*****************************************************************************
  473.  * FUNCTION
  474.  *  AccessRecordInt
  475.  * DESCRIPTION
  476.  *  MMI level API to access NVRAM
  477.  * PARAMETERS
  478.  *  nFileId             [IN]        NVRAM data item id
  479.  *  nRecordId           [IN]        Record index in a data item
  480.  *  pBuffer             [OUT]       Buffer in which data need to
  481.  *  nBufferSize         [IN]        Size of record to be read
  482.  *  nRecordAmount       [IN]        
  483.  *  pError              [OUT]       Error returned from PS
  484.  *  isWrite             [IN]        True =write, false=read
  485.  *  isValue             [IN]        True = from read/write Value
  486.  *                                  False = from read/write Record
  487.  *  filename            [IN]         
  488.  *  lineNumber          [IN]        
  489.  * RETURNS
  490.  *  S32
  491.  *****************************************************************************/
  492. S32 AccessRecordInt
  493.     (U16 nFileId,
  494.      U16 nRecordId,
  495.      void *pBuffer, 
  496.      U16 nBufferSize, 
  497.      U16 nRecordAmount, 
  498.      S16 *pError, 
  499.      pBOOL isWrite, 
  500.      pBOOL isValue,
  501.      S8 *filename, 
  502.      S32 lineNumber)
  503. {
  504.     /*----------------------------------------------------------------*/
  505.     /* Local Variables                                                */
  506.     /*----------------------------------------------------------------*/
  507.     MYQUEUE queueNode;
  508.     S32 status = -1;
  509.     U32 my_index;
  510.     circularQ_check_enum circularQ_check_result = circularQ_check_never_check;
  511.     static U8 nvram_req_count = 0;
  512.     MMI_BOOL toPush;
  513.     /*----------------------------------------------------------------*/
  514.     /* Code Body                                                      */
  515.     /*----------------------------------------------------------------*/
  516.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_REC_INT_HDLR, nFileId, nRecordId));
  517.     if (isWrite)
  518.     {
  519.         SendNVRAMWriteReq(nFileId, nRecordId, pBuffer, nBufferSize);
  520.         if (!isValue)   /* call from read/write Record */
  521.         {
  522.             /* reset BYTE/SHORT/DOUBLE cache */
  523.             /*   since others may access these LIDs directly */
  524.             if (nFileId == NVRAM_EF_CACHE_BYTE_LID)
  525.             {
  526.                 byteDataReadFlag = 0;
  527.             }
  528.             else if (nFileId == NVRAM_EF_CACHE_SHORT_LID)
  529.             {
  530.                 uintDataReadFlag = 0;
  531.             }
  532.             else if (nFileId == NVRAM_EF_CACHE_DOUBLE_LID)
  533.             {
  534.                 doubleDataReadFlag = 0;
  535.             }
  536.         }    
  537.     }
  538.     else
  539.     {
  540.         SendNVRAMReadReq(nFileId, nRecordId, nRecordAmount);
  541.     }
  542.     in_nvram_procedure++;
  543.     while (1)
  544.     {
  545.         /* if more than 1 access request exist, go through the circular Q */
  546.         if ((nvram_req_count > 0) && (circularQ_check_result == circularQ_check_never_check))
  547.         {
  548.             circularQ_check_result = NVRAMCheckCircularQ(&queueNode, nFileId);
  549.         }
  550.         if (circularQ_check_result != circularQ_check_found)
  551.         {
  552.             OslReceiveMsgExtQ(mmi_ext_qid, &queueNode);
  553.             OslGetMyTaskIndex(&my_index);
  554.             OslStackSetActiveModuleID(my_index, MOD_MMI);
  555.         }
  556.         toPush = MMI_FALSE;
  557.         switch (queueNode.msg_id)
  558.         {
  559.             case MSG_ID_MMI_EQ_PLAY_AUDIO_RSP:
  560.             case MSG_ID_MMI_EQ_STOP_AUDIO_RSP:
  561.             case MSG_ID_MMI_EQ_EXE_GPIO_LEVEL_RSP:
  562.             case MSG_ID_MMI_EQ_SET_VOLUME_RSP:
  563.                 OslFreeInterTaskMsg(&queueNode);
  564.                 break;
  565.             case MSG_ID_MMI_EQ_KEYPAD_DETECT_IND:
  566.             {
  567.   /* special handling before entering stable stable state.
  568.      But for charger and USB case, need to treat them as stable state */
  569.   if ((mmi_bootup_is_power_on_animation_complete() == MMI_FALSE) &&
  570.   (g_pwr_context.PowerOnMode != POWER_ON_PRECHARGE) &&
  571.       (g_pwr_context.PowerOnMode != POWER_ON_CHARGER_IN) &&
  572.       (g_pwr_context.PowerOnMode != POWER_ON_USB))
  573.                 {
  574.                     KeyHandleBeforePWRON((void*)queueNode.oslDataPtr);
  575.                 }
  576.                 else
  577.                 {
  578.                     mmi_eq_keypad_detect_ind_struct *p;
  579.                     p = (mmi_eq_keypad_detect_ind_struct*) queueNode.local_para_ptr;
  580.                     if (p->func != keypad_ptr)
  581.                     {
  582.                         ClearKeyEvents();
  583.                     }
  584.                     g_keypad_flag = MMI_TRUE;
  585.                     keypad_ptr = p->func;
  586.                 }
  587.                 OslFreeInterTaskMsg(&queueNode);
  588.                 break;
  589.             }
  590.             /* We don't need to handle MSG_ID_MMI_EQ_GET_RTC_TIME_RSP in special condition */
  591.             case MSG_ID_TIMER_EXPIRY:
  592.             {
  593.                 /* only process non-alignment timer during power-up */
  594.                 if ( (mmi_bootup_is_searching_or_idle_reached() == MMI_FALSE) &&
  595.                      !mmi_frm_is_align_base_timer(queueNode.oslDataPtr))
  596.                 {
  597.                     kal_uint16 msg_len;
  598.                     EvshedMMITimerHandler(get_local_para_ptr(queueNode.oslDataPtr, &msg_len));
  599.                     OslFreeInterTaskMsg(&queueNode);
  600.                     break;
  601.                 }
  602.                 else
  603.                 {
  604.                     stack_timer_struct *stack_timer_ptr;
  605.                     stack_timer_ptr = (stack_timer_struct*) queueNode.oslDataPtr;
  606.                     if (!stack_is_time_out_valid(stack_timer_ptr))
  607.                     {
  608.                         PRINT_INFORMATION(("==========Time out is not valid=========="));
  609.                         OslFreeInterTaskMsg(&queueNode);
  610.                         break;
  611.                     }
  612.                 }
  613.                 toPush = MMI_TRUE;
  614.                 break;
  615.             }
  616.             case MSG_ID_MMI_EQ_NVRAM_READ_RSP:
  617.             {
  618.                 mmi_eq_nvram_read_rsp_struct *readMessage;
  619.                 readMessage = (mmi_eq_nvram_read_rsp_struct *)queueNode.oslDataPtr;
  620.                 if (readMessage->file_idx != nFileId)
  621.                 {
  622.                     nvram_req_count++;
  623.                 }
  624.                 else
  625.                 {
  626.                     if (readMessage->result.flag == MMI_OK)
  627.                     {
  628.                         PRINT_INFORMATION((" NVRAM Read Success"));
  629.                         if (readMessage->length > nBufferSize)
  630.                         {
  631.                             memcpy(pBuffer, readMessage->data, nBufferSize);
  632.                             *pError = NVRAM_ERROR_ACTUAL_READ_GREATER_THAN_REQUESTED_READ;
  633.                         }
  634.                         else if (readMessage->length < nBufferSize)
  635.                         {
  636.                             memcpy(pBuffer, readMessage->data, readMessage->length);
  637.                             *pError = NVRAM_ERROR_ACTUAL_READ_LESS_THAN_REQUESTED_READ;
  638.                         }
  639.                         else
  640.                         {
  641.                             memcpy(pBuffer, readMessage->data, readMessage->length);
  642.                             *pError = NVRAM_READ_SUCCESS;
  643.                         }
  644.                         status = readMessage->length;
  645.                     }
  646.                     else
  647.                     {
  648.                         PRINT_INFORMATION((" NVRAM Read Failed. Cause: %d", readMessage->result.cause));
  649.                         ASSERT(readMessage->result.flag == MMI_OK);
  650.                         *pError = NVRAM_READ_FAIL;
  651.                     }
  652.                     OslFreeInterTaskMsg(&queueNode);
  653.                     PRINT_INFORMATION((" Exiting Reading record status = %dn", status));
  654.                     if (nvram_req_count && circularQ_check_result == circularQ_check_found)
  655.                     {
  656.                         nvram_req_count--;
  657.                     }
  658.                     in_nvram_procedure--;
  659.                     return status;
  660.                 }
  661.                 toPush = MMI_TRUE;
  662.                 break;
  663.             }
  664.             case MSG_ID_MMI_EQ_NVRAM_WRITE_RSP:
  665.             {
  666.                 mmi_eq_nvram_write_rsp_struct *writeMessage;
  667.                 writeMessage = (mmi_eq_nvram_write_rsp_struct*) queueNode.oslDataPtr;
  668.                 if (writeMessage->file_idx != nFileId)
  669.                 {
  670.                     nvram_req_count++;
  671.                 }
  672.                 else
  673.                 {
  674.                     if (writeMessage->result.flag == MMI_OK)
  675.                     {
  676.                         PRINT_INFORMATION((" NVRAM Write Success"));
  677.                         *pError = NVRAM_WRITE_SUCCESS;
  678.                         status = nBufferSize;
  679.                     }
  680.                     else
  681.                     {
  682.                         PRINT_INFORMATION((" NVRAM Write Failed. Cause: %d", writeMessage->result.cause));
  683.                         ASSERT(writeMessage->result.flag == MMI_OK);
  684.                         *pError = NVRAM_WRITE_FAIL;
  685.                     }
  686.                     OslFreeInterTaskMsg(&queueNode);
  687.                     PRINT_INFORMATION((" Exiting Wriring record"));
  688.                     if (nvram_req_count && circularQ_check_result == circularQ_check_found)
  689.                     {
  690.                         nvram_req_count--;
  691.                     }
  692.                     in_nvram_procedure--;
  693.                     return status;
  694.                 }
  695.                 toPush = MMI_TRUE;
  696.                 break;
  697.             }
  698.             default:
  699.             {
  700.                 toPush = MMI_TRUE;
  701.                 break;
  702.             }
  703.         }
  704.         if (toPush == MMI_TRUE)
  705.         {
  706.             ilm_struct ilm_ptr;
  707.             U8 flag = 0;
  708.             ilm_ptr.src_mod_id = queueNode.src_mod_id;
  709.             ilm_ptr.dest_mod_id = queueNode.dest_mod_id;
  710.             ilm_ptr.msg_id = queueNode.msg_id;
  711.             ilm_ptr.sap_id = queueNode.sap_id;
  712.             ilm_ptr.local_para_ptr = queueNode.local_para_ptr;
  713.             ilm_ptr.peer_buff_ptr = queueNode.peer_buff_ptr;
  714.             flag = OslWriteCircularQ(&ilm_ptr);
  715.             /* TIMER use special data in the local_para_ptr field. Can NOT treat as general ILM */
  716.             if ((queueNode.src_mod_id != MOD_TIMER) && (flag == 1))
  717.             {
  718.                 hold_local_para(ilm_ptr.local_para_ptr);
  719.                 hold_peer_buff(ilm_ptr.peer_buff_ptr);
  720.             }
  721.             OslFreeInterTaskMsg(&queueNode);
  722.         }
  723.     }
  724. }
  725. #else /* __NEW_NVRAMINTERFACE__ */ 
  726. #if 0
  727. /* under construction !*/
  728. /* under construction !*/
  729. /* under construction !*/
  730. /* under construction !*/
  731. /* under construction !*/
  732. /* under construction !*/
  733. /* under construction !*/
  734. /* under construction !*/
  735. /* under construction !*/
  736. /* under construction !*/
  737. /* under construction !*/
  738. /* under construction !*/
  739. /* under construction !*/
  740. /* under construction !*/
  741. /* under construction !*/
  742. /* under construction !*/
  743. /* under construction !*/
  744. /* under construction !*/
  745. /* under construction !*/
  746. /* under construction !*/
  747. /* under construction !*/
  748. /* under construction !*/
  749. /* under construction !*/
  750. /* under construction !*/
  751. /* under construction !*/
  752. /* under construction !*/
  753. /* under construction !*/
  754. /* under construction !*/
  755. /* under construction !*/
  756. /* under construction !*/
  757. /* under construction !*/
  758. /* under construction !*/
  759. /* under construction !*/
  760. /* under construction !*/
  761. /* under construction !*/
  762. /* under construction !*/
  763. /* under construction !*/
  764. /* under construction !*/
  765. /* under construction !*/
  766. /* under construction !*/
  767. /* under construction !*/
  768. /* under construction !*/
  769. /* under construction !*/
  770. /* under construction !*/
  771. /* under construction !*/
  772. /* under construction !*/
  773. /* under construction !*/
  774. /* under construction !*/
  775. /* under construction !*/
  776. /* under construction !*/
  777. /* under construction !*/
  778. /* under construction !*/
  779. /* under construction !*/
  780. /* under construction !*/
  781. /* under construction !*/
  782. /* under construction !*/
  783. /* under construction !*/
  784. /* under construction !*/
  785. /* under construction !*/
  786. /* under construction !*/
  787. /* under construction !*/
  788. /* under construction !*/
  789. /* under construction !*/
  790. /* under construction !*/
  791. /* under construction !*/
  792. /* under construction !*/
  793. /* under construction !*/
  794. /* under construction !*/
  795. /* under construction !*/
  796. /* under construction !*/
  797. /* under construction !*/
  798. /* under construction !*/
  799. /* under construction !*/
  800. /* under construction !*/
  801. /* under construction !*/
  802. /* under construction !*/
  803. /* under construction !*/
  804. /* under construction !*/
  805. /* under construction !*/
  806. /* under construction !*/
  807. /* under construction !*/
  808. /* under construction !*/
  809. /* under construction !*/
  810.                #ifdef __MTK_TARGET__
  811. /* under construction !*/
  812.                #endif
  813. /* under construction !*/
  814. /* under construction !*/
  815. /* under construction !*/
  816. /* under construction !*/
  817. /* under construction !*/
  818. /* under construction !*/
  819. /* under construction !*/
  820. /* under construction !*/
  821. /* under construction !*/
  822. /* under construction !*/
  823. /* under construction !*/
  824. /* under construction !*/
  825. /* under construction !*/
  826. /* under construction !*/
  827. /* under construction !*/
  828. /* under construction !*/
  829. /* under construction !*/
  830. /* under construction !*/
  831. /* under construction !*/
  832. /* under construction !*/
  833. /* under construction !*/
  834. /* under construction !*/
  835. /* under construction !*/
  836. /* under construction !*/
  837. /* under construction !*/
  838. /* under construction !*/
  839. /* under construction !*/
  840. /* under construction !*/
  841. /* under construction !*/
  842. /* under construction !*/
  843. /* under construction !*/
  844. /* under construction !*/
  845. /* under construction !*/
  846. /* under construction !*/
  847. /* under construction !*/
  848. /* under construction !*/
  849. /* under construction !*/
  850. /* under construction !*/
  851. /* under construction !*/
  852. /* under construction !*/
  853. /* under construction !*/
  854. /* under construction !*/
  855. /* under construction !*/
  856. /* under construction !*/
  857. /* under construction !*/
  858. /* under construction !*/
  859. /* under construction !*/
  860. /* under construction !*/
  861. /* under construction !*/
  862. /* under construction !*/
  863. /* under construction !*/
  864. /* under construction !*/
  865. /* under construction !*/
  866. /* under construction !*/
  867. /* under construction !*/
  868. /* under construction !*/
  869. /* under construction !*/
  870. /* under construction !*/
  871. /* under construction !*/
  872. /* under construction !*/
  873. /* under construction !*/
  874. /* under construction !*/
  875. /* under construction !*/
  876. /* under construction !*/
  877. /* under construction !*/
  878. /* under construction !*/
  879. /* under construction !*/
  880. /* under construction !*/
  881. /* under construction !*/
  882. /* under construction !*/
  883. /* under construction !*/
  884. /* under construction !*/
  885. /* under construction !*/
  886. /* under construction !*/
  887. /* under construction !*/
  888. /* under construction !*/
  889. /* under construction !*/
  890. /* under construction !*/
  891. /* under construction !*/
  892. /* under construction !*/
  893. /* under construction !*/
  894. /* under construction !*/
  895. /* under construction !*/
  896. /* under construction !*/
  897. /* under construction !*/
  898. /* under construction !*/
  899. /* under construction !*/
  900. /* under construction !*/
  901. /* under construction !*/
  902. /* under construction !*/
  903. /* under construction !*/
  904. /* under construction !*/
  905. /* under construction !*/
  906. /* under construction !*/
  907. /* under construction !*/
  908. /* under construction !*/
  909. /* under construction !*/
  910. /* under construction !*/
  911. /* under construction !*/
  912. /* under construction !*/
  913. /* under construction !*/
  914. /* under construction !*/
  915. /* under construction !*/
  916. /* under construction !*/
  917. /* under construction !*/
  918. /* under construction !*/
  919. /* under construction !*/
  920. /* under construction !*/
  921. /* under construction !*/
  922. /* under construction !*/
  923. /* under construction !*/
  924. /* under construction !*/
  925. /* under construction !*/
  926. /* under construction !*/
  927. /* under construction !*/
  928. /* under construction !*/
  929. /* under construction !*/
  930. /* under construction !*/
  931. /* under construction !*/
  932. /* under construction !*/
  933. /* under construction !*/
  934. /* under construction !*/
  935. /* under construction !*/
  936. /* under construction !*/
  937. /* under construction !*/
  938. /* under construction !*/
  939. /* under construction !*/
  940. /* under construction !*/
  941. /* under construction !*/
  942. /* under construction !*/
  943. /* under construction !*/
  944. /* under construction !*/
  945. /* under construction !*/
  946. /* under construction !*/
  947. /* under construction !*/
  948. /* under construction !*/
  949. /* under construction !*/
  950. /* under construction !*/
  951. /* under construction !*/
  952. /* under construction !*/
  953. /* under construction !*/
  954. /* under construction !*/
  955. /* under construction !*/
  956. /* under construction !*/
  957. /* under construction !*/
  958. /* under construction !*/
  959. /* under construction !*/
  960. /* under construction !*/
  961. /* under construction !*/
  962. /* under construction !*/
  963. /* under construction !*/
  964.          #ifdef __MTK_TARGET__
  965. /* under construction !*/
  966.          #endif
  967. /* under construction !*/
  968. /* under construction !*/
  969. /* under construction !*/
  970. /* under construction !*/
  971. /* under construction !*/
  972. /* under construction !*/
  973. /* under construction !*/
  974. /* under construction !*/
  975. /* under construction !*/
  976. /* under construction !*/
  977. /* under construction !*/
  978. /* under construction !*/
  979. /* under construction !*/
  980. /* under construction !*/
  981. /* under construction !*/
  982. /* under construction !*/
  983. /* under construction !*/
  984. /* under construction !*/
  985. /* under construction !*/
  986. /* under construction !*/
  987. /* under construction !*/
  988. /* under construction !*/
  989. /* under construction !*/
  990. /* under construction !*/
  991. /* under construction !*/
  992. /* under construction !*/
  993. /* under construction !*/
  994. /* under construction !*/
  995. /* under construction !*/
  996. /* under construction !*/
  997. /* under construction !*/
  998. /* under construction !*/
  999. /* under construction !*/
  1000. /* under construction !*/
  1001. /* under construction !*/
  1002. /* under construction !*/
  1003. /* under construction !*/
  1004. /* under construction !*/
  1005. /* under construction !*/
  1006. /* under construction !*/
  1007. /* under construction !*/
  1008. /* under construction !*/
  1009. /* under construction !*/
  1010. /* under construction !*/
  1011. /* under construction !*/
  1012. /* under construction !*/
  1013. /* under construction !*/
  1014. /* under construction !*/
  1015. /* under construction !*/
  1016. /* under construction !*/
  1017. /* under construction !*/
  1018. /* under construction !*/
  1019. /* under construction !*/
  1020. /* under construction !*/
  1021. /* under construction !*/
  1022. /* under construction !*/
  1023. /* under construction !*/
  1024. /* under construction !*/
  1025. /* under construction !*/
  1026. /* under construction !*/
  1027. /* under construction !*/
  1028. /* under construction !*/
  1029. /* under construction !*/
  1030. /* under construction !*/
  1031. /* under construction !*/
  1032. /* under construction !*/
  1033. /* under construction !*/
  1034. /* under construction !*/
  1035. /* under construction !*/
  1036. /* under construction !*/
  1037. /* under construction !*/
  1038. /* under construction !*/
  1039. /* under construction !*/
  1040. /* under construction !*/
  1041. /* under construction !*/
  1042. /* under construction !*/
  1043. /* under construction !*/
  1044. /* under construction !*/
  1045. /* under construction !*/
  1046. /* under construction !*/
  1047. /* under construction !*/
  1048. /* under construction !*/
  1049. /* under construction !*/
  1050. /* under construction !*/
  1051. /* under construction !*/
  1052. /* under construction !*/
  1053. /* under construction !*/
  1054. /* under construction !*/
  1055. #endif /* 0 */ 
  1056. #endif /* __NEW_NVRAMINTERFACE__ */ 
  1057. /*****************************************************************************
  1058.  * FUNCTION
  1059.  *  DeleteRecord
  1060.  * DESCRIPTION
  1061.  *  User level API for Deleting record from the file
  1062.  * PARAMETERS
  1063.  *  nFileId         [IN]        File LID
  1064.  *  nRecordId       [IN]        Record index in file
  1065.  *  pError          [OUT]       Error returned from PS
  1066.  * RETURNS
  1067.  * BOOL
  1068.  *  
  1069.  *****************************************************************************/
  1070. pBOOL DeleteRecord(U16 nFileId, U16 nRecordId, S16 *pError)
  1071. {
  1072.     /*----------------------------------------------------------------*/
  1073.     /* Local Variables                                                */
  1074.     /*----------------------------------------------------------------*/
  1075.     MYQUEUE queueNode;
  1076.     MMIEQNVRAMWRITERSP *writeMessage = NULL;
  1077.     U8 *pBuffer = NULL;
  1078.     S8 status = (S8) - 1;
  1079.     U32 msgSize;
  1080.     U8 noOfFiles = 0;
  1081.     U8 count = 0;
  1082.     /*----------------------------------------------------------------*/
  1083.     /* Code Body                                                      */
  1084.     /*----------------------------------------------------------------*/
  1085.     *pError = -1;
  1086.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_DELETE_REC_INT_HDLR));
  1087.     /* 0 Search for the LID index in logical_data_item_table_cust
  1088.        array of structures  */
  1089.     noOfFiles = NVRAM_EF_LAST_LID_CUST - NVRAM_LID_CUST_BEGIN - 1;
  1090.     for (count = 0; count < noOfFiles; ++count)
  1091.     {
  1092.         if (nFileId == logical_data_item_table_cust[count].LID)
  1093.         {
  1094.             break;
  1095.         }
  1096.     }
  1097.     pBuffer = (U8*) OslMalloc(logical_data_item_table_cust[count].size);
  1098.     memset(pBuffer, '', logical_data_item_table_cust[count].size);
  1099.     /* 1. Send Write Request */
  1100.     SendNVRAMWriteReq(nFileId, nRecordId, pBuffer, logical_data_item_table_cust[count].size);
  1101.     OslMfree(pBuffer);
  1102.     /* 2  Wait for write response on message queue */
  1103.     if (OslReadMsgQ(nvramQID, &queueNode, (U16*) & msgSize, OSL_INFINITE_WAIT) == OSL_SUCCESS)
  1104.     {
  1105.         writeMessage = (MMIEQNVRAMWRITERSP*) queueNode.oslDataPtr;
  1106.         if (writeMessage->result.flag == MMI_OK)
  1107.         {
  1108.             PRINT_INFORMATION((" Inside MMI_OK block"));
  1109.             *pError = NVRAM_WRITE_SUCCESS;
  1110.             status = MMI_TRUE;
  1111.         }
  1112.         else
  1113.         {
  1114.             PRINT_INFORMATION((" Inside MMI_ERROR block"));
  1115.             *pError = ST_FAILURE;
  1116.             status = MMI_FALSE;
  1117.         }
  1118.     }
  1119.     PRINT_INFORMATION((" Exiting Wriring record"));
  1120.     OslMfree(writeMessage);
  1121.     return status;
  1122. }
  1123. #else /* MMI_ON_WIN32 */ 
  1124. /* 
  1125.  * Structure of lookup table entry
  1126.  */
  1127. typedef struct
  1128. {
  1129.     U16 lid;
  1130.     U16 size;
  1131.     const U8 *default_value;
  1132. } pc_ltable_entry_struct;
  1133. /* 
  1134.  * Default Values on PC
  1135.  */
  1136. const U8 NVRAM_EF_ZERO_DEFAULT[] = {0X00};
  1137. const U8 NVRAM_EF_FF_DEFAULT[] = {0XFF};
  1138. pc_ltable_entry_struct pc_logical_data_item_table[] = 
  1139. {
  1140.     {NVRAM_EF_PHONEBOOK_SPEEDDIAL_LID, NVRAM_PHONEBOOK_SPEEDDIAL_RECORD_SIZE, NVRAM_EF_ZERO_DEFAULT},
  1141. #ifdef __MMI_MESSAGES_CHAT__    
  1142.     {NVRAM_EF_CHAT_ROOM_INFO_LID, NVRAM_CHAT_ROOM_INFO_RECORD_SIZE, NVRAM_EF_ZERO_DEFAULT},
  1143. #endif /* __MMI_MESSAGES_CHAT__ */
  1144. #ifdef __MMI_NITZ__    
  1145.         {NVRAM_EF_NITZ_NW_NAME_LID, NVRAM_NITZ_NW_NAME_SIZE, NVRAM_EF_ZERO_DEFAULT},
  1146. #endif /* __MMI_NITZ__ */
  1147.     {0, 0, NVRAM_EF_FF_DEFAULT}
  1148. };
  1149. /*****************************************************************************
  1150.  * FUNCTION
  1151.  *  ReadRecordInt
  1152.  * DESCRIPTION
  1153.  *  User level API for reading record from the file
  1154.  * PARAMETERS
  1155.  *  nFileId         [IN]        File LID
  1156.  *  nRecordId       [IN]        Record index in file
  1157.  *  pBuffer         [OUT]       Buffer in which data need to
  1158.  *  nBufferSize     [IN]        Size of record to be read
  1159.  *  pError          [OUT]       Error returned from PS
  1160.  *  filename        [?]         
  1161.  *  lineNumber      [IN]        
  1162.  *  it(?)           [IN]        Should be same as file
  1163.  *  memory(?)       [OUT]       For this.
  1164.  *  record(?)       [IN]        Size
  1165.  *  be(?)           [OUT]       Retrieved,caller will allocate
  1166.  * RETURNS
  1167.  * BOOL
  1168.  *  
  1169.  *****************************************************************************/
  1170. S32 ReadRecordInt(
  1171.         U16 nFileId,
  1172.         U16 nRecordId,
  1173.         void *pBuffer,
  1174.         U16 nBufferSize,
  1175.         S16 *pError,
  1176.         S8 *filename,
  1177.         S32 lineNumber)
  1178. {
  1179.     /*----------------------------------------------------------------*/
  1180.     /* Local Variables                                                */
  1181.     /*----------------------------------------------------------------*/
  1182.     S8 fileNameA[sizeof(NVRM_FILES_PATH) + 7];  /* 7 : xxx_xxx */
  1183.     S8 fileNameU[(sizeof(NVRM_FILES_PATH) + 7) * 2];
  1184.     U32 iBytesRead;
  1185.     FS_HANDLE handle;
  1186.     S32 retValue = -1;
  1187.     U32 temp = 0;
  1188.     static U8 is_nvram_init = 0;
  1189.     /*----------------------------------------------------------------*/
  1190.     /* Code Body                                                      */
  1191.     /*----------------------------------------------------------------*/
  1192.     if (!is_nvram_init)
  1193.     {
  1194.         S8 pathNameA[sizeof(NVRM_FILES_PATH)];
  1195.         S8 pathNameU[(sizeof(NVRM_FILES_PATH)) * 2];
  1196.         sprintf(pathNameA, "..\..\WIN32FS\DRIVE_C\NVRAM\");
  1197.         AnsiiToUnicodeString(pathNameU, pathNameA);
  1198.         retValue = FS_CreateDir((PU16) pathNameU);
  1199.         if (retValue < FS_NO_ERROR && retValue != FS_FILE_EXISTS)
  1200.         {
  1201.             *pError = NVRAM_READ_FAIL;
  1202.             return retValue;
  1203.         }
  1204.         sprintf(pathNameA, "%s", NVRM_FILES_PATH);
  1205.         AnsiiToUnicodeString(pathNameU, pathNameA);
  1206.         retValue = FS_CreateDir((PU16) pathNameU);
  1207.         if (retValue < FS_NO_ERROR && retValue != FS_FILE_EXISTS)
  1208.         {
  1209.             *pError = NVRAM_READ_FAIL;
  1210.             return retValue;
  1211.         }
  1212.         is_nvram_init = 1;
  1213.     }
  1214.     sprintf(fileNameA, "%s%d_%d", NVRM_FILES_PATH, nFileId, nRecordId);
  1215.     AnsiiToUnicodeString(fileNameU, fileNameA);
  1216.     handle = FS_Open((PU16) fileNameU, FS_READ_ONLY);
  1217.     PRINT_INFORMATION_2( (MMI_TRACE_G1_FRM,"ReadRecordInt open org file: %d",handle));
  1218.     if (handle == FS_FILE_NOT_FOUND)
  1219.     {
  1220.         U32 len = 1;
  1221.         U16 i;
  1222.         pc_ltable_entry_struct *ldi;
  1223.         for (i = 0; i < (sizeof(pc_logical_data_item_table) / sizeof(pc_ltable_entry_struct)); i++)
  1224.         {
  1225.             ldi = &pc_logical_data_item_table[i];
  1226.             if (ldi->lid == nFileId)
  1227.             {
  1228.                 break;
  1229.             }
  1230.         }
  1231.         /* Assign Default */
  1232.         if (ldi->default_value == NVRAM_EF_ZERO_DEFAULT)
  1233.         {
  1234.             memset(pBuffer, 0x00, nBufferSize);
  1235.         }
  1236.         else if (ldi->lid == 0 ||   /* not found */
  1237.                  ldi->default_value == NVRAM_EF_FF_DEFAULT)
  1238.         {
  1239.             memset(pBuffer, 0xFF, nBufferSize);
  1240.         }
  1241.         else
  1242.         {
  1243.             memcpy(pBuffer, &ldi->default_value, ldi->size);
  1244.         }
  1245.         handle = FS_Open((PU16) fileNameU, FS_CREATE_ALWAYS);
  1246.         PRINT_INFORMATION_2( (MMI_TRACE_G1_FRM,"ReadRecordInt create new file: %d",handle));
  1247.         if (handle < FS_NO_ERROR)
  1248.         {
  1249.             *pError = NVRAM_READ_FAIL;
  1250.         }
  1251.         else
  1252.         {
  1253.             retValue = FS_Write(handle, pBuffer, nBufferSize, &iBytesRead);
  1254.             FS_Close(handle);
  1255.         }
  1256.         if (retValue >= FS_NO_ERROR)
  1257.         {
  1258.             *pError = NVRAM_READ_SUCCESS;
  1259.         }
  1260.         else
  1261.         {
  1262.             *pError = NVRAM_READ_FAIL;
  1263.         }
  1264.     }
  1265.     else
  1266.     {
  1267.         retValue = FS_Read(handle, pBuffer, nBufferSize, &iBytesRead);
  1268.         if (retValue >= FS_NO_ERROR)
  1269.         {
  1270.             retValue = iBytesRead;
  1271.             *pError = NVRAM_READ_SUCCESS;
  1272.         }
  1273.         else
  1274.         {
  1275.             *pError = NVRAM_READ_FAIL;
  1276.         }
  1277.         FS_Close(handle);
  1278.     }
  1279.     return retValue;
  1280. }
  1281. /*****************************************************************************
  1282.  * FUNCTION
  1283.  *  WriteRecordInt
  1284.  * DESCRIPTION
  1285.  *  User level API for writing record in the file
  1286.  *  
  1287.  *  The nBufferSize shall be even
  1288.  * PARAMETERS
  1289.  *  nFileId         [IN]        File LID
  1290.  *  nRecordId       [IN]        Record index in file
  1291.  *  pBuffer         [IN]        Buffer in which data need to
  1292.  *  nBufferSize     [IN]        Size of record to be write
  1293.  *  pError          [OUT]       Error returned from PS
  1294.  *  filename        [?]         
  1295.  *  lineNumber      [IN]        
  1296.  *  it(?)           [IN]        Should be same as file
  1297.  *  memory(?)       [IN]        For this.
  1298.  *  record(?)       [IN]        Size
  1299.  *  be(?)           [IN]        Retrieved,caller will allocate
  1300.  * RETURNS
  1301.  * BOOL
  1302.  *  
  1303.  *****************************************************************************/
  1304. S32 WriteRecordInt(
  1305.         U16 nFileId,
  1306.         U16 nRecordId,
  1307.         void *pBuffer,
  1308.         U16 nBufferSize,
  1309.         S16 *pError,
  1310.         S8 *filename,
  1311.         S32 lineNumber)
  1312. {
  1313.     /*----------------------------------------------------------------*/
  1314.     /* Local Variables                                                */
  1315.     /*----------------------------------------------------------------*/
  1316.     S8 fileNameA[sizeof(NVRM_FILES_PATH) + 7];  /* 7 : xxx_xxx */
  1317.     S8 fileNameU[(sizeof(NVRM_FILES_PATH) + 7) * 2];
  1318.     U32 iBytes;
  1319.     FS_HANDLE handle;
  1320.     S32 retValue = -1;
  1321.     /*----------------------------------------------------------------*/
  1322.     /* Code Body                                                      */
  1323.     /*----------------------------------------------------------------*/
  1324.     sprintf(fileNameA, "%s%d_%d", NVRM_FILES_PATH, nFileId, nRecordId);
  1325.     AnsiiToUnicodeString(fileNameU, fileNameA);
  1326.     handle = FS_Open((PU16) fileNameU, FS_CREATE_ALWAYS);
  1327.     PRINT_INFORMATION_2( (MMI_TRACE_G1_FRM,"WriteRecordInt open file: %d",handle));
  1328.     if (handle < FS_NO_ERROR)
  1329.     {
  1330.         *pError = NVRAM_WRITE_FAIL;
  1331.     }
  1332.     else
  1333.     {
  1334.         retValue = FS_Write(handle, pBuffer, nBufferSize, &iBytes);
  1335.         if (retValue >= FS_NO_ERROR)
  1336.         {
  1337.             retValue = iBytes;
  1338.             *pError = NVRAM_WRITE_SUCCESS;
  1339.         }
  1340.         else
  1341.         {
  1342.             *pError = NVRAM_WRITE_FAIL;
  1343.         }
  1344.         FS_Close(handle);
  1345.     }
  1346.     return retValue;
  1347. }
  1348. /*****************************************************************************
  1349.  * FUNCTION
  1350.  *  DeleteRecord
  1351.  * DESCRIPTION
  1352.  *  User level API for Deleting record from the file
  1353.  * PARAMETERS
  1354.  *  nFileId         [IN]        File LID
  1355.  *  nRecordId       [IN]        Record index in file
  1356.  *  pError          [OUT]       Error returned from PS
  1357.  * RETURNS
  1358.  * BOOL
  1359.  *  
  1360.  *****************************************************************************/
  1361. pBOOL DeleteRecord(U16 nFileId, U16 nRecordId, S16 *pError)
  1362. {
  1363.     /*----------------------------------------------------------------*/
  1364.     /* Local Variables                                                */
  1365.     /*----------------------------------------------------------------*/
  1366.     S8 fileName[100];
  1367.     S32 retValue = -1;
  1368.     /*----------------------------------------------------------------*/
  1369.     /* Code Body                                                      */
  1370.     /*----------------------------------------------------------------*/
  1371.     sprintf(fileName, "%s%d_%d", NVRM_FILES_PATH, nFileId, nRecordId);
  1372.     /* Remove file */
  1373.     retValue = remove(fileName);
  1374.     if (retValue == 0)
  1375.     {
  1376.         return MMI_TRUE;
  1377.     }
  1378.     else
  1379.     {
  1380.         return MMI_FALSE;
  1381.     }
  1382. }
  1383. #endif /* MMI_ON_WIN32 */ 
  1384. /*****************************************************************************
  1385.  * FUNCTION
  1386.  *  ReadValueInt
  1387.  * DESCRIPTION
  1388.  *  User level API for 1 byte , 2 byte and 8 byte
  1389.  *  
  1390.  *  The nBufferSize shall be even
  1391.  * PARAMETERS
  1392.  *  nDataItemId     [IN]        Data Item ID
  1393.  *  pBuffer         [IN]        Buffer in which data need to
  1394.  *  nDataType       [IN]        
  1395.  *  pError          [OUT]       Error returned from PS
  1396.  *  fileName        [?]         
  1397.  *  lineNumber      [IN]        
  1398.  *  memory(?)       [IN]        For this.
  1399.  *  be(?)           [IN]        Retrieved,caller will allocate
  1400.  * RETURNS
  1401.  * BOOL
  1402.  *  
  1403.  *****************************************************************************/
  1404. S32 ReadValueInt(U8 nDataItemId, void *pBuffer, U8 nDataType, S16 *pError, S8 *fileName, S32 lineNumber)
  1405. {
  1406.     /*----------------------------------------------------------------*/
  1407.     /* Local Variables                                                */
  1408.     /*----------------------------------------------------------------*/
  1409.     S32 status = -1;
  1410.     S16 error = -1;
  1411.     /*----------------------------------------------------------------*/
  1412.     /* Code Body                                                      */
  1413.     /*----------------------------------------------------------------*/
  1414.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_HDLR, nDataItemId, nDataType));
  1415.     switch (nDataType)
  1416.     {
  1417.         case DS_BYTE:
  1418.         {
  1419.             /* second time reading, it alwasy return one request item */
  1420.             if (byteDataReadFlag)
  1421.             {
  1422.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO_HDLR, nDataType));
  1423.                 /* Data is cached no need to read from NVRAM */
  1424.                 memcpy(pBuffer, &byte_data[nDataItemId * nDataType], nDataType);
  1425.                 status = DS_BYTE;
  1426.                 error = NVRAM_READ_SUCCESS;
  1427.             }
  1428.             /* process first time reading all data and return first request item data */
  1429.             else
  1430.             {
  1431.                 /* Read data from the NVRAM file */
  1432.                 /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files, first time to read all out */
  1433.                 U8 tempBuffer[NVRAM_CACHE_SIZE];
  1434.                 status = ReadRecordInt(
  1435.                             NVRAM_EF_CACHE_BYTE_LID,
  1436.                             1,
  1437.                             tempBuffer,
  1438.                             sizeof(tempBuffer),
  1439.                             &error,
  1440.                             fileName,
  1441.                             lineNumber);
  1442.                 if (status == -1)
  1443.                 {
  1444.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_READ_VAL_INT_HDLR));
  1445.                     *pError = -1;
  1446.                     return status;
  1447.                 }
  1448.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO2_HDLR, nDataType));
  1449.                 /* copy out all total reading data */
  1450.                 memcpy(byte_data, tempBuffer, sizeof(tempBuffer));
  1451.                 byteDataReadFlag = 1;
  1452.                 /* return first request item data */
  1453.                 memcpy(pBuffer, &byte_data[nDataItemId * nDataType], nDataType);
  1454.                 status = DS_BYTE;
  1455.                 error = NVRAM_READ_SUCCESS;
  1456.             }
  1457.             break;
  1458.         }   /* End of case DS_BYTE */
  1459.         case DS_SHORT:
  1460.         {
  1461.             if (uintDataReadFlag)
  1462.             {
  1463.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO_HDLR, nDataType));
  1464.                 /* Data is cached no need to read from NVRAM */
  1465.                 memcpy(pBuffer, &uint_data[nDataItemId * nDataType], nDataType);
  1466.                 status = DS_SHORT;
  1467.                 error = NVRAM_READ_SUCCESS;
  1468.             }
  1469.             else
  1470.             {
  1471.                 /* Read data from the NVRAM file */
  1472.                 /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files */
  1473.                 U8 tempBuffer[NVRAM_CACHE_SIZE];
  1474.                 status = ReadRecordInt(
  1475.                             NVRAM_EF_CACHE_SHORT_LID,
  1476.                             1,
  1477.                             tempBuffer,
  1478.                             sizeof(tempBuffer),
  1479.                             &error,
  1480.                             fileName,
  1481.                             lineNumber);
  1482.                 if (status == -1)
  1483.                 {
  1484.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_READ_VAL_INT_HDLR));
  1485.                     *pError = -1;
  1486.                     return status;
  1487.                 }
  1488.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO2_HDLR, nDataType));
  1489.                 memcpy(uint_data, tempBuffer, NVRAM_CACHE_SIZE);
  1490.                 uintDataReadFlag = 1;
  1491.                 memcpy(pBuffer, &uint_data[nDataItemId * nDataType], nDataType);
  1492.                 status = DS_SHORT;
  1493.                 error = NVRAM_READ_SUCCESS;
  1494.             }
  1495.             break;
  1496.         }   /* End of case DS_SHORT */
  1497.         case DS_DOUBLE:
  1498.         {
  1499.             if (doubleDataReadFlag)
  1500.             {
  1501.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO_HDLR, nDataType));
  1502.                 /* Data is cached no need to read from NVRAM */
  1503.                 memcpy(pBuffer, &double_data[nDataItemId * nDataType], nDataType);
  1504.                 status = DS_DOUBLE;
  1505.                 error = NVRAM_READ_SUCCESS;
  1506.             }
  1507.             else
  1508.             {
  1509.                 /* Read data from the NVRAM file */
  1510.                 /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files */
  1511.                 U8 tempBuffer[NVRAM_CACHE_SIZE];
  1512.                 status = ReadRecordInt(
  1513.                             NVRAM_EF_CACHE_DOUBLE_LID,
  1514.                             1,
  1515.                             tempBuffer,
  1516.                             NVRAM_CACHE_SIZE,
  1517.                             &error,
  1518.                             fileName,
  1519.                             lineNumber);
  1520.                 if (status == -1)
  1521.                 {
  1522.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_READ_VAL_INT_HDLR));
  1523.                     *pError = -1;
  1524.                     return status;
  1525.                 }
  1526.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_VAL_INT_INFO2_HDLR, nDataType));
  1527.                 memcpy(double_data, tempBuffer, NVRAM_CACHE_SIZE);
  1528.                 doubleDataReadFlag = 1;
  1529.                 memcpy(pBuffer, &double_data[nDataItemId * nDataType], nDataType);
  1530.                 status = DS_DOUBLE;
  1531.                 error = NVRAM_READ_SUCCESS;
  1532.             }
  1533.             break;
  1534.         }   /* End of case DS_DOUBLE */
  1535.     }
  1536.     *pError = error;
  1537.     return status;
  1538. }
  1539. /*****************************************************************************
  1540.  * FUNCTION
  1541.  *  WriteValueInt
  1542.  * DESCRIPTION
  1543.  *  User level API to write 1 byte , 2 byte and 8 byte
  1544.  *  
  1545.  *  The nBufferSize shall be even
  1546.  * PARAMETERS
  1547.  *  nDataItemId     [IN]        Data Item ID
  1548.  *  pBuffer         [IN]        Buffer in which data need to
  1549.  *  nDataType       [IN]        
  1550.  *  pError          [OUT]       Error returned from PS
  1551.  *  fileName        [?]         
  1552.  *  lineNumber      [IN]        
  1553.  *  memory(?)       [IN]        For this.
  1554.  *  be(?)           [IN]        Retrieved,caller will allocate
  1555.  * RETURNS
  1556.  * BOOL
  1557.  *  
  1558.  *****************************************************************************/
  1559. S32 WriteValueInt(U8 nDataItemId, void *pBuffer, U8 nDataType, S16 *pError, S8 *fileName, S32 lineNumber)
  1560. {
  1561.     /*----------------------------------------------------------------*/
  1562.     /* Local Variables                                                */
  1563.     /*----------------------------------------------------------------*/
  1564.     S16 error = -1;
  1565.     S32 status = -1;
  1566.     /*----------------------------------------------------------------*/
  1567.     /* Code Body                                                      */
  1568.     /*----------------------------------------------------------------*/
  1569.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_HDLR, nDataItemId, nDataType));
  1570.     switch (nDataType)
  1571.     {
  1572.         case DS_BYTE:
  1573.         {
  1574.             /* second time access, it always sets the request item */
  1575.             if (byteDataReadFlag)
  1576.             {
  1577.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_INFO_HDLR, nDataType));
  1578.                 /* Data is cached no need to read from NVRAM */
  1579.                 memcpy(&byte_data[nDataItemId * nDataType], pBuffer, nDataType);
  1580.                 /* write into NVRAM module, if not wait for falshing directly */
  1581.                 if (!byteDataWriteFlashFlag)
  1582.                 {
  1583.                     status = WriteRecordInt(
  1584.                                 NVRAM_EF_CACHE_BYTE_LID,
  1585.                                 1,
  1586.                                 byte_data,
  1587.                                 NVRAM_CACHE_SIZE,
  1588.                                 &error,
  1589.                                 fileName,
  1590.                                 lineNumber);
  1591.                     if (status == -1)
  1592.                     {
  1593.                         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1594.                         *pError = -1;
  1595.                         return status;
  1596.                     }
  1597.                 }
  1598.                 status = DS_BYTE;
  1599.                 error = NVRAM_WRITE_SUCCESS;
  1600.             }
  1601.             /* process first time access all data and return first write item data */
  1602.             else
  1603.             {
  1604.                 /* Read all data from the NVRAM file */
  1605.                 /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files */
  1606.                 status = ReadRecordInt(
  1607.                             NVRAM_EF_CACHE_BYTE_LID,
  1608.                             1,
  1609.                             byte_data,
  1610.                             NVRAM_CACHE_SIZE,
  1611.                             &error,
  1612.                             fileName,
  1613.                             lineNumber);
  1614.                 if (status == -1)
  1615.                 {
  1616.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_READ_VAL_INT_HDLR));
  1617.                     *pError = -1;
  1618.                     return status;
  1619.                 }
  1620.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_INFO2_HDLR, nDataType));
  1621.                 memcpy(&byte_data[nDataItemId * nDataType], pBuffer, nDataType);
  1622.                 /* write into NVRAM module, if not wait for falshing directly */
  1623.                 if (!byteDataWriteFlashFlag)
  1624.                 {
  1625.                     status = WriteRecordInt(
  1626.                                 NVRAM_EF_CACHE_BYTE_LID,
  1627.                                 1,
  1628.                                 byte_data,
  1629.                                 NVRAM_CACHE_SIZE,
  1630.                                 &error,
  1631.                                 fileName,
  1632.                                 lineNumber);
  1633.                 }
  1634.                 byteDataReadFlag = 1;
  1635.                 status = DS_BYTE;
  1636.                 error = NVRAM_WRITE_SUCCESS;
  1637.             }
  1638.             break;
  1639.         }   /* End of case DS_BYTE */
  1640.         case DS_SHORT:
  1641.         {
  1642.             if (uintDataReadFlag)
  1643.             {
  1644.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_INFO_HDLR, nDataType));
  1645.                 /* Data is cached no need to read from NVRAM */
  1646.                 memcpy(&uint_data[nDataItemId * nDataType], pBuffer, nDataType);
  1647.                 /* write into NVRAM module, if not wait for falshing directly */
  1648.                 if (!uintDataWriteFlashFlag)
  1649.                 {
  1650.                     status = WriteRecordInt(
  1651.                                 NVRAM_EF_CACHE_SHORT_LID,
  1652.                                 1,
  1653.                                 uint_data,
  1654.                                 NVRAM_CACHE_SIZE,
  1655.                                 &error,
  1656.                                 fileName,
  1657.                                 lineNumber);
  1658.                     if (status == -1)
  1659.                     {
  1660.                         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1661.                         *pError = -1;
  1662.                         return status;
  1663.                     }
  1664.                 }
  1665.                 status = DS_SHORT;
  1666.                 error = NVRAM_WRITE_SUCCESS;
  1667.             }
  1668.             else
  1669.             {
  1670.                 /* Read data from the NVRAM file */
  1671.                 /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files */
  1672.                 status = ReadRecordInt(
  1673.                             NVRAM_EF_CACHE_SHORT_LID,
  1674.                             1,
  1675.                             uint_data,
  1676.                             NVRAM_CACHE_SIZE,
  1677.                             &error,
  1678.                             fileName,
  1679.                             lineNumber);
  1680.                 if (status == -1)
  1681.                 {
  1682.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_READ_VAL_INT_HDLR));
  1683.                     *pError = -1;
  1684.                     return status;
  1685.                 }
  1686.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_INFO2_HDLR, nDataType));
  1687.                 memcpy(&uint_data[nDataItemId * nDataType], pBuffer, nDataType);
  1688.                 /* write into NVRAM module, if not wait for falshing directly */
  1689.                 if (!uintDataWriteFlashFlag)
  1690.                 {
  1691.                     WriteRecordInt(
  1692.                         NVRAM_EF_CACHE_SHORT_LID,
  1693.                         1,
  1694.                         uint_data,
  1695.                         NVRAM_CACHE_SIZE,
  1696.                         &error,
  1697.                         fileName,
  1698.                         lineNumber);
  1699.                 }
  1700.                 uintDataReadFlag = 1;
  1701.                 status = DS_SHORT;
  1702.                 error = NVRAM_WRITE_SUCCESS;
  1703.             }
  1704.             break;
  1705.         }   /* End of case DS_SHORT */
  1706.         case DS_DOUBLE:
  1707.         {
  1708.             if (doubleDataReadFlag)
  1709.             {
  1710.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_INFO_HDLR, nDataType));
  1711.                 /* Data is cached no need to read from NVRAM */
  1712.                 memcpy(&double_data[nDataItemId * nDataType], pBuffer, nDataType);
  1713.                 /* write into NVRAM module, if not wait for falshing directly */
  1714.                 if (!doubleDataWriteFlashFlag)
  1715.                 {
  1716.                     status = WriteRecordInt(
  1717.                                 NVRAM_EF_CACHE_DOUBLE_LID,
  1718.                                 1,
  1719.                                 double_data,
  1720.                                 NVRAM_CACHE_SIZE,
  1721.                                 &error,
  1722.                                 fileName,
  1723.                                 lineNumber);
  1724.                     if (status == -1)
  1725.                     {
  1726.                         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1727.                         *pError = -1;
  1728.                         return status;
  1729.                     }
  1730.                 }
  1731.                 status = DS_DOUBLE;
  1732.                 error = NVRAM_WRITE_SUCCESS;
  1733.             }
  1734.             else
  1735.             {
  1736.                 MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_VAL_INT_INFO_HDLR, nDataType));
  1737.                 /* Read data from the NVRAM file */
  1738.                 /* NVRAM_CACHED_FILE_LID is defined in Pluto NVRAM files */
  1739.                 status = ReadRecordInt(
  1740.                             NVRAM_EF_CACHE_DOUBLE_LID,
  1741.                             1,
  1742.                             double_data,
  1743.                             NVRAM_CACHE_SIZE,
  1744.                             &error,
  1745.                             fileName,
  1746.                             lineNumber);
  1747.                 if (status == -1)
  1748.                 {
  1749.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_READ_VAL_INT_HDLR));
  1750.                     *pError = -1;
  1751.                     return status;
  1752.                 }
  1753.                 memcpy(&double_data[nDataItemId * nDataType], pBuffer, nDataType);
  1754.                 /* write into NVRAM module, if not wait for falshing directly */
  1755.                 if (!doubleDataWriteFlashFlag)
  1756.                 {
  1757.                     status = WriteRecordInt(
  1758.                                 NVRAM_EF_CACHE_DOUBLE_LID,
  1759.                                 1,
  1760.                                 double_data,
  1761.                                 NVRAM_CACHE_SIZE,
  1762.                                 &error,
  1763.                                 fileName,
  1764.                                 lineNumber);
  1765.                     if (status == -1)
  1766.                     {
  1767.                         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1768.                         *pError = -1;
  1769.                         return status;
  1770.                     }
  1771.                 }
  1772.                 status = DS_DOUBLE;
  1773.                 error = NVRAM_WRITE_SUCCESS;
  1774.                 doubleDataReadFlag = 1;
  1775.             }
  1776.             break;
  1777.         }   /* End of case DS_DOUBLE */
  1778.     }   /* End of switch */
  1779.     *pError = error;
  1780.     return status;
  1781. }
  1782. /*****************************************************************************
  1783.  * FUNCTION
  1784.  *  SetFlashNVRAMCatchData
  1785.  * DESCRIPTION
  1786.  *  This function is to set the flag if want to flash the BYTE, SHORT, or DOUBLE of catch datas into NVRAM.
  1787.  * PARAMETERS
  1788.  *  nDataType                   [IN]        
  1789.  *  l_DataWriteFlashFlag        [IN]        
  1790.  *  a(?)                        [IN]        Is to enable to flash into NVRAM or not, TRUE is to flash into NVRAM, otherwise is false.
  1791.  * RETURNS
  1792.  *  Data set success or not.
  1793.  *****************************************************************************/
  1794. U8 SetFlashNVRAMCatchData(U8 nDataType, U8 l_DataWriteFlashFlag)
  1795. {
  1796.     /*----------------------------------------------------------------*/
  1797.     /* Local Variables                                                */
  1798.     /*----------------------------------------------------------------*/
  1799.     /*----------------------------------------------------------------*/
  1800.     /* Code Body                                                      */
  1801.     /*----------------------------------------------------------------*/
  1802.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_FLASH_CATCH_DATA_HDLR, nDataType, l_DataWriteFlashFlag));
  1803.     switch (nDataType)
  1804.     {
  1805.         case DS_BYTE:
  1806.             byteDataWriteFlashFlag = l_DataWriteFlashFlag;
  1807.             break;
  1808.         case DS_SHORT:
  1809.             uintDataWriteFlashFlag = l_DataWriteFlashFlag;
  1810.             break;
  1811.         case DS_DOUBLE:
  1812.             doubleDataWriteFlashFlag = l_DataWriteFlashFlag;
  1813.             break;
  1814.         default:
  1815.             MMI_ASSERT(0);
  1816.             break;
  1817.     }
  1818.     return MMI_TRUE;
  1819. }
  1820. /*****************************************************************************
  1821.  * FUNCTION
  1822.  *  SetFlashAllNVRAMCatchData
  1823.  * DESCRIPTION
  1824.  *  This function is to set the flag if want to flash all the BYTE, SHORT, and DOUBLE of catch datas into NVRAM.
  1825.  * PARAMETERS
  1826.  *  l_DataWriteFlashFlag        [IN]        
  1827.  *  a(?)                        [IN]        Is to enable to flash into NVRAM or not, TRUE is to flash into NVRAM, otherwise is false.
  1828.  * RETURNS
  1829.  *  Data set success or not.
  1830.  *****************************************************************************/
  1831. U8 SetFlashAllNVRAMCatchData(U8 l_DataWriteFlashFlag)
  1832. {
  1833.     /*----------------------------------------------------------------*/
  1834.     /* Local Variables                                                */
  1835.     /*----------------------------------------------------------------*/
  1836.     /*----------------------------------------------------------------*/
  1837.     /* Code Body                                                      */
  1838.     /*----------------------------------------------------------------*/
  1839.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_FLASH_CATCH_ALL_DATA_HDLR, l_DataWriteFlashFlag));
  1840.     byteDataWriteFlashFlag = l_DataWriteFlashFlag;
  1841.     uintDataWriteFlashFlag = l_DataWriteFlashFlag;
  1842.     doubleDataWriteFlashFlag = l_DataWriteFlashFlag;
  1843.     return MMI_TRUE;
  1844. }
  1845. /*****************************************************************************
  1846.  * FUNCTION
  1847.  *  WriteFlashNVRAMCatchData
  1848.  * DESCRIPTION
  1849.  *  This function is to write the BYTE, SHORT, DOUBLE of catch datas into NVRAM.
  1850.  * PARAMETERS
  1851.  *  nDataType       [IN]        
  1852.  *  a(?)            [IN]        Is BYTE, SHORT, DOUBLE data type.
  1853.  * RETURNS
  1854.  *  Data write success or not.
  1855.  *****************************************************************************/
  1856. S32 WriteFlashNVRAMCatchData(U8 nDataType)
  1857. {
  1858.     /*----------------------------------------------------------------*/
  1859.     /* Local Variables                                                */
  1860.     /*----------------------------------------------------------------*/
  1861.     S32 status = -1;
  1862.     S16 error = -1;
  1863.     /*----------------------------------------------------------------*/
  1864.     /* Code Body                                                      */
  1865.     /*----------------------------------------------------------------*/
  1866.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_WRITE_NVM_CATCH_DATA_HDLR, nDataType));
  1867.     switch (nDataType)
  1868.     {
  1869.         case DS_BYTE:
  1870.             if (byteDataWriteFlashFlag)
  1871.             {
  1872.                 byteDataWriteFlashFlag = MMI_FALSE;
  1873.                 status = WriteRecordInt(
  1874.                             NVRAM_EF_CACHE_BYTE_LID,
  1875.                             1,
  1876.                             byte_data,
  1877.                             sizeof(byte_data),
  1878.                             &error,
  1879.                             __FILE__,
  1880.                             __LINE__);
  1881.                 if (status == -1)
  1882.                 {
  1883.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1884.                     MMI_ASSERT(0);
  1885.                     return status;
  1886.                 }
  1887.             }
  1888.             break;
  1889.         case DS_SHORT:
  1890.             if (uintDataWriteFlashFlag)
  1891.             {
  1892.                 uintDataWriteFlashFlag = MMI_FALSE;
  1893.                 status = WriteRecordInt(
  1894.                             NVRAM_EF_CACHE_SHORT_LID,
  1895.                             1,
  1896.                             uint_data,
  1897.                             sizeof(uint_data),
  1898.                             &error,
  1899.                             __FILE__,
  1900.                             __LINE__);
  1901.                 if (status == -1)
  1902.                 {
  1903.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1904.                     MMI_ASSERT(0);
  1905.                     return status;
  1906.                 }
  1907.             }
  1908.             break;
  1909.         case DS_DOUBLE:
  1910.             if (doubleDataWriteFlashFlag)
  1911.             {
  1912.                 doubleDataWriteFlashFlag = MMI_FALSE;
  1913.                 status = WriteRecordInt(
  1914.                             NVRAM_EF_CACHE_DOUBLE_LID,
  1915.                             1,
  1916.                             double_data,
  1917.                             sizeof(double_data),
  1918.                             &error,
  1919.                             __FILE__,
  1920.                             __LINE__);
  1921.                 if (status == -1)
  1922.                 {
  1923.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1924.                     MMI_ASSERT(0);
  1925.                     return status;
  1926.                 }
  1927.             }
  1928.             break;
  1929.         default:
  1930.             MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_WARN_NVM_WRITE_HDLR));
  1931.             MMI_ASSERT(0);
  1932.             break;
  1933.     }
  1934.     return status;
  1935. }
  1936. /*****************************************************************************
  1937.  * FUNCTION
  1938.  *  WriteFlashAllNVRAMCatchData
  1939.  * DESCRIPTION
  1940.  *  This function is to write all catch data into NVRAM.
  1941.  * PARAMETERS
  1942.  *  void
  1943.  * RETURNS
  1944.  *  Data write success or not.
  1945.  *****************************************************************************/
  1946. S32 WriteFlashAllNVRAMCatchData(void)
  1947. {
  1948.     /*----------------------------------------------------------------*/
  1949.     /* Local Variables                                                */
  1950.     /*----------------------------------------------------------------*/
  1951.     S32 status = -1;
  1952.     S16 error = -1;
  1953.     /*----------------------------------------------------------------*/
  1954.     /* Code Body                                                      */
  1955.     /*----------------------------------------------------------------*/
  1956.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_FLASH_ALL_CATCH_DATA_HDLR));
  1957.     if (byteDataWriteFlashFlag)
  1958.     {
  1959.         byteDataWriteFlashFlag = MMI_FALSE;
  1960.         status = WriteRecordInt(NVRAM_EF_CACHE_BYTE_LID, 1, byte_data, NVRAM_CACHE_SIZE, &error, __FILE__, __LINE__);
  1961.         if (status == -1)
  1962.         {
  1963.             MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1964.             MMI_ASSERT(0);
  1965.             return status;
  1966.         }
  1967.     }
  1968.     if (uintDataWriteFlashFlag)
  1969.     {
  1970.         uintDataWriteFlashFlag = MMI_FALSE;
  1971.         status = WriteRecordInt(NVRAM_EF_CACHE_SHORT_LID, 1, uint_data, NVRAM_CACHE_SIZE, &error, __FILE__, __LINE__);
  1972.         if (status == -1)
  1973.         {
  1974.             MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1975.             MMI_ASSERT(0);
  1976.             return status;
  1977.         }
  1978.     }
  1979.     if (doubleDataWriteFlashFlag)
  1980.     {
  1981.         doubleDataWriteFlashFlag = MMI_FALSE;
  1982.         status = WriteRecordInt(NVRAM_EF_CACHE_DOUBLE_LID, 1, double_data, NVRAM_CACHE_SIZE, &error, __FILE__, __LINE__);
  1983.         if (status == -1)
  1984.         {
  1985.             MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_NVM_WRITE_VAL_INT_HDLR));
  1986.             MMI_ASSERT(0);
  1987.             return status;
  1988.         }
  1989.     }
  1990.     return status;
  1991. }
  1992. /*****************************************************************************
  1993.  * FUNCTION
  1994.  *  IsInNVRAMProcedure
  1995.  * DESCRIPTION
  1996.  *  This function is to check if in NVRAM procedure while loop
  1997.  * PARAMETERS
  1998.  *  void
  1999.  * RETURNS
  2000.  *  MMI_TRUE - in NVRAM procedure
  2001.  *  MMI_FALSE - not in NVRAM procedure
  2002.  *****************************************************************************/
  2003. U8 IsInNVRAMProcedure(void)
  2004. {
  2005.     /*----------------------------------------------------------------*/
  2006.     /* Local Variables                                                */
  2007.     /*----------------------------------------------------------------*/
  2008.     /*----------------------------------------------------------------*/
  2009.     /* Code Body                                                      */
  2010.     /*----------------------------------------------------------------*/
  2011.     PRINT_INFORMATION((" IsInNVRAMProcedure(%d)", in_nvram_procedure));
  2012.     return (in_nvram_procedure > 0) ? (U8) MMI_TRUE : (U8) MMI_FALSE;
  2013. }