⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nvraminterface.c

📁 MTK手机平台的MMI部分的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:

}

#ifndef MMI_ON_WIN32

#ifdef __NEW_NVRAMINTERFACE__
#define CIRCQ_NODE_SIZE sizeof(MYQUEUE)
#define CIRCQ_NO_OF_NODES 65

typedef enum
{
    circularQ_check_never_check,
    circularQ_check_not_found,
    circularQ_check_found
} circularQ_check_enum;

#ifdef __MMI_TEST_NEW_NVRAMINTERFACE__


/*****************************************************************************
 * FUNCTION
 *  NVRAMDummyTestRW
 * DESCRIPTION
 *  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void NVRAMDummyTestRW(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    static pBOOL isRead = MMI_TRUE;
    static kal_uint8 settingBuffer[NVRAM_SETTING_SIZE] = {0};
    S16 error;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    StartTimer(AT_TEST_TIMER, 3000, NVRAMDummyTestRW);

    if (isRead)
    {
        ReadRecord(NVRAM_EF_SETTING_LID, 1, settingBuffer, NVRAM_SETTING_SIZE, &error);
        isRead = MMI_FALSE;
    }
    else
    {
        WriteRecord(NVRAM_EF_SETTING_LID, 1, settingBuffer, NVRAM_SETTING_SIZE, &error);
        isRead = MMI_TRUE;
    }

}
#endif /* __MMI_TEST_NEW_NVRAMINTERFACE__ */ 


/*****************************************************************************
 * FUNCTION
 *  NVRAMCheckCircularQ
 * DESCRIPTION
 *  check if there is nvram access response
 *  in the circular queue; if there is,
 *  retrieve it and put a dummy one in the
 *  same position
 * PARAMETERS
 *  msgPtr          [?]         
 *  nFileId         [IN]        The LID currently waiting
 *  memory(?)       [OUT]       For this.
 *  pBuffer(?)      [OUT]       Buffer in which data need to
 *  be(?)           [OUT]       Retrieved,caller will allocate
 * RETURNS
 *  circularQ_check_enum
 *****************************************************************************/
circularQ_check_enum NVRAMCheckCircularQ(void *msgPtr, U16 nFileId)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 i;
    extern U8 circq_array[];
    MYQUEUE *tempQueueNode;

#ifdef __MMI_TEST_NEW_NVRAMINTERFACE__
    static pBOOL testFlag = MMI_TRUE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (testFlag)
    {
        NVRAMDummyTestRW();
        testFlag = MMI_FALSE;
    }
#endif /* __MMI_TEST_NEW_NVRAMINTERFACE__ */ 

    for (i = 0; i < CIRCQ_NO_OF_NODES; i++)
    {
        tempQueueNode = ((MYQUEUE*) (circq_array + i * CIRCQ_NODE_SIZE));

        switch (tempQueueNode->msg_id)
        {
            case MSG_ID_MMI_EQ_NVRAM_READ_RSP:
            case MSG_ID_MMI_EQ_NVRAM_WRITE_RSP:
            {
                ilm_struct ilm_ptr; /* DUMMY message */

                if (((mmi_eq_nvram_read_rsp_struct*) (tempQueueNode->local_para_ptr))->file_idx == nFileId
                    || ((mmi_eq_nvram_write_rsp_struct*) (tempQueueNode->local_para_ptr))->file_idx == nFileId)
                {
                    memcpy(msgPtr, circq_array + (i * CIRCQ_NODE_SIZE), CIRCQ_NODE_SIZE);

                    ilm_ptr.src_mod_id = MOD_NIL;
                    ilm_ptr.dest_mod_id = MOD_NIL;
                    ilm_ptr.msg_id = MSG_ID_MMI_EQ_NVRAM_READY_IND;
                    ilm_ptr.sap_id = INVALID_SAP;
                    ilm_ptr.local_para_ptr = NULL;
                    ilm_ptr.peer_buff_ptr = NULL;
                    memcpy(circq_array + (i * CIRCQ_NODE_SIZE), &ilm_ptr, CIRCQ_NODE_SIZE);
                    return circularQ_check_found;
                }

            }
            default:
                break;
        }
    }
    return circularQ_check_not_found;
}


/*****************************************************************************
 * FUNCTION
 *  AccessRecordInt
 * DESCRIPTION
 *  MMI level API to access NVRAM
 * PARAMETERS
 *  nFileId             [IN]        NVRAM data item id
 *  nRecordId           [IN]        Record index in a data item
 *  pBuffer             [OUT]       Buffer in which data need to
 *  nBufferSize         [IN]        Size of record to be read
 *  nRecordAmount       [IN]        
 *  pError              [OUT]       Error returned from PS
 *  isWrite             [IN]        True =write, false=read
 *  isValue             [IN]        True = from read/write Value
 *                                  False = from read/write Record
 *  filename            [IN]         
 *  lineNumber          [IN]        
 * RETURNS
 *  S32
 *****************************************************************************/
S32 AccessRecordInt
    (U16 nFileId,
     U16 nRecordId,
     void *pBuffer, 
     U16 nBufferSize, 
     U16 nRecordAmount, 
     S16 *pError, 
     pBOOL isWrite, 
     pBOOL isValue,
     S8 *filename, 
     S32 lineNumber)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    MYQUEUE queueNode;
    S32 status = -1;
    U32 my_index;
    circularQ_check_enum circularQ_check_result = circularQ_check_never_check;
    static U8 nvram_req_count = 0;
    MMI_BOOL toPush;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_NVM_READ_REC_INT_HDLR, nFileId, nRecordId));

    if (isWrite)
    {
        SendNVRAMWriteReq(nFileId, nRecordId, pBuffer, nBufferSize);

        if (!isValue)   /* call from read/write Record */
        {
            /* reset BYTE/SHORT/DOUBLE cache */
            /*   since others may access these LIDs directly */
            if (nFileId == NVRAM_EF_CACHE_BYTE_LID)
            {
                byteDataReadFlag = 0;
            }
            else if (nFileId == NVRAM_EF_CACHE_SHORT_LID)
            {
                uintDataReadFlag = 0;
            }
            else if (nFileId == NVRAM_EF_CACHE_DOUBLE_LID)
            {
                doubleDataReadFlag = 0;
            }
        }    
    }
    else
    {
        SendNVRAMReadReq(nFileId, nRecordId, nRecordAmount);
    }

    in_nvram_procedure++;
    while (1)
    {
        /* if more than 1 access request exist, go through the circular Q */
        if ((nvram_req_count > 0) && (circularQ_check_result == circularQ_check_never_check))
        {
            circularQ_check_result = NVRAMCheckCircularQ(&queueNode, nFileId);
        }

        if (circularQ_check_result != circularQ_check_found)
        {
            OslReceiveMsgExtQ(mmi_ext_qid, &queueNode);
            OslGetMyTaskIndex(&my_index);
            OslStackSetActiveModuleID(my_index, MOD_MMI);
        }

        toPush = MMI_FALSE;
        switch (queueNode.msg_id)
        {
            case MSG_ID_MMI_EQ_PLAY_AUDIO_RSP:
            case MSG_ID_MMI_EQ_STOP_AUDIO_RSP:
            case MSG_ID_MMI_EQ_EXE_GPIO_LEVEL_RSP:
            case MSG_ID_MMI_EQ_SET_VOLUME_RSP:
                OslFreeInterTaskMsg(&queueNode);
                break;
            case MSG_ID_MMI_EQ_KEYPAD_DETECT_IND:
            {
			 	/* special handling before entering stable stable state.
			 	   But for charger and USB case, need to treat them as stable state */
			 	if ((mmi_bootup_is_power_on_animation_complete() == MMI_FALSE) &&
			 		(g_pwr_context.PowerOnMode != POWER_ON_PRECHARGE) &&
			 	    (g_pwr_context.PowerOnMode != POWER_ON_CHARGER_IN) &&
			 	    (g_pwr_context.PowerOnMode != POWER_ON_USB))
                {
                    KeyHandleBeforePWRON((void*)queueNode.oslDataPtr);
                }
                else
                {
                    mmi_eq_keypad_detect_ind_struct *p;

                    p = (mmi_eq_keypad_detect_ind_struct*) queueNode.local_para_ptr;
                    if (p->func != keypad_ptr)
                    {
                        ClearKeyEvents();
                    }
                    g_keypad_flag = MMI_TRUE;
                    keypad_ptr = p->func;
                }
                OslFreeInterTaskMsg(&queueNode);
                break;
            }
            /* We don't need to handle MSG_ID_MMI_EQ_GET_RTC_TIME_RSP in special condition */
            case MSG_ID_TIMER_EXPIRY:
            {
                /* only process non-alignment timer during power-up */
                if ( (mmi_bootup_is_searching_or_idle_reached() == MMI_FALSE) &&
                     !mmi_frm_is_align_base_timer(queueNode.oslDataPtr))
                {
                    kal_uint16 msg_len;

                    EvshedMMITimerHandler(get_local_para_ptr(queueNode.oslDataPtr, &msg_len));
                    OslFreeInterTaskMsg(&queueNode);
                    break;
                }
                else
                {
                    stack_timer_struct *stack_timer_ptr;

                    stack_timer_ptr = (stack_timer_struct*) queueNode.oslDataPtr;
                    if (!stack_is_time_out_valid(stack_timer_ptr))
                    {
                        PRINT_INFORMATION(("==========Time out is not valid=========="));
                        OslFreeInterTaskMsg(&queueNode);
                        break;
                    }
                }
                toPush = MMI_TRUE;
                break;
            }
            case MSG_ID_MMI_EQ_NVRAM_READ_RSP:
            {
                mmi_eq_nvram_read_rsp_struct *readMessage;

                readMessage = (mmi_eq_nvram_read_rsp_struct *)queueNode.oslDataPtr;

                if (readMessage->file_idx != nFileId)
                {
                    nvram_req_count++;
                }
                else
                {
                    if (readMessage->result.flag == MMI_OK)
                    {
                        PRINT_INFORMATION((" NVRAM Read Success"));
                        if (readMessage->length > nBufferSize)
                        {
                            memcpy(pBuffer, readMessage->data, nBufferSize);
                            *pError = NVRAM_ERROR_ACTUAL_READ_GREATER_THAN_REQUESTED_READ;
                        }
                        else if (readMessage->length < nBufferSize)
                        {
                            memcpy(pBuffer, readMessage->data, readMessage->length);
                            *pError = NVRAM_ERROR_ACTUAL_READ_LESS_THAN_REQUESTED_READ;
                        }
                        else
                        {
                            memcpy(pBuffer, readMessage->data, readMessage->length);
                            *pError = NVRAM_READ_SUCCESS;
                        }

                        status = readMessage->length;
                    }
                    else
                    {
                        PRINT_INFORMATION((" NVRAM Read Failed. Cause: %d", readMessage->result.cause));
                        ASSERT(readMessage->result.flag == MMI_OK);
                        *pError = NVRAM_READ_FAIL;
                    }

                    OslFreeInterTaskMsg(&queueNode);
                    PRINT_INFORMATION((" Exiting Reading record status = %d\n", status));
                    if (nvram_req_count && circularQ_check_result == circularQ_check_found)
                    {
                        nvram_req_count--;
                    }

                    in_nvram_procedure--;
                    return status;
                }
                toPush = MMI_TRUE;
                break;
            }
            case MSG_ID_MMI_EQ_NVRAM_WRITE_RSP:
            {

                mmi_eq_nvram_write_rsp_struct *writeMessage;

                writeMessage = (mmi_eq_nvram_write_rsp_struct*) queueNode.oslDataPtr;

                if (writeMessage->file_idx != nFileId)
                {
                    nvram_req_count++;
                }
                else
                {
                    if (writeMessage->result.flag == MMI_OK)
                    {
                        PRINT_INFORMATION((" NVRAM Write Success"));
                        *pError = NVRAM_WRITE_SUCCESS;
                        status = nBufferSize;
                    }
                    else
                    {
                        PRINT_INFORMATION((" NVRAM Write Failed. Cause: %d", writeMessage->result.cause));
                        ASSERT(writeMessage->result.flag == MMI_OK);
                        *pError = NVRAM_WRITE_FAIL;
                    }

                    OslFreeInterTaskMsg(&queueNode);
                    PRINT_INFORMATION((" Exiting Wriring record"));
                    if (nvram_req_count && circularQ_check_result == circularQ_check_found)
                    {
                        nvram_req_count--;
                    }

                    in_nvram_procedure--;
                    return status;
                }
                toPush = MMI_TRUE;
                break;
            }

            default:
            {
                toPush = MMI_TRUE;
                break;
            }
        }

        if (toPush == MMI_TRUE)
        {
            ilm_struct ilm_ptr;
            U8 flag = 0;

            ilm_ptr.src_mod_id = queueNode.src_mod_id;
            ilm_ptr.dest_mod_id = queueNode.dest_mod_id;
            ilm_ptr.msg_id = queueNode.msg_id;
            ilm_ptr.sap_id = queueNode.sap_id;
            ilm_ptr.local_para_ptr = queueNode.local_para_ptr;
            ilm_ptr.peer_buff_ptr = queueNode.peer_buff_ptr;
            flag = OslWriteCircularQ(&ilm_ptr);
            /* TIMER use special data in the local_para_ptr field. Can NOT treat as general ILM */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -