NFC part of calling flow

phLibNfc_Mgt_IoCtl
    phLibNfc_Ioctl_Cntx.CliRspCb    =>    nfc_jni_ioctl_callback

phHal4Nfc_Ioctl
    Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb   =>   phLibNfc_Ioctl_Mgmt_CB   

phDnldNfc_Upgrade    
    psDnldContext->p_upper_notify  =>  phHal4Nfc_DownloadComplete
    
    status = phDnldNfc_Send_Command( psDnldContext, pHwRef, PHDNLD_CMD_RESET , NULL , 0 );

phDnldNfc_Send_Command
    status = phDnldNfc_Send( psDnldContext, pHwRef , (uint8_t *)p_dnld_data, tx_length);

phDnldNfc_Send
    phNfc_sLowerIF_t        *plower_if = &(psDnldContext->lower_interface);
    status = plower_if->send((void *)plower_if->pcontext, (void *)pHwRef, pdata, length);
    
phLibNfc_Ioctl_Mgmt_CB
    calling   pIoctlCntx->CliRspCb
    
phHal4Nfc_DownloadComplete
    pUpper_DnldCb = Hal4Ctxt->sUpperLayerInfo.pUpperIoctlCb;
    /*Copy download status*/
    status = (((phNfc_sCompletionInfo_t *)pInfo)->status);
    (*pUpper_DnldCb)(
                pUpper_Context,
                pIoctlOutParam,
                status
                );
    status = (((phNfc_sCompletionInfo_t *)pInfo)->status);
    
phLlcNfc_Interface_Register
        if_cb.receive_complete = (pphNfcIF_Transact_Completion_CB_t)&phLlcNfc_RdResp_Cb;
        if_cb.send_complete = (pphNfcIF_Transact_Completion_CB_t)&phLlcNfc_WrResp_Cb;

        phHal4Nfc.c (externallibnfc-nxpsrc):                    (*pphLayer+i)->layer_registry  = phLlcNfc_Register;

phLlcNfc_Register
        /* Register the LLC functions to the upper layer */
        psReference->plower_if->init = (pphNfcIF_Interface_t)&phLlcNfc_Init;
        psReference->plower_if->release = (pphNfcIF_Interface_t)&phLlcNfc_Release;
        psReference->plower_if->send = (pphNfcIF_Transact_t)&phLlcNfc_Send;
        psReference->plower_if->receive = (pphNfcIF_Transact_t)&phLlcNfc_Receive;
        /* Copy the LLC context to the upper layer */
        psReference->plower_if->pcontext = ps_llc_ctxt;

        /* Register the callback function from the upper layer */
        ps_llc_ctxt->cb_for_if.receive_complete = if_callback.receive_complete;
        ps_llc_ctxt->cb_for_if.send_complete = if_callback.send_complete;
        ps_llc_ctxt->cb_for_if.notify = if_callback.notify;
        /* Get the upper layer context */
        ps_llc_ctxt->cb_for_if.pif_ctxt = if_callback.pif_ctxt;

        result = phLlcNfc_Interface_Register(ps_llc_ctxt, psconfig);
        
       ./external/libnfc-nxp/src/phLlcNfc.c:203:            ps_llc_ctxt->cb_for_if.send_complete = if_callback.send_complete;        

phHal4Nfc_Configure_Layers
                case LAYER_LLC:/*Configure LLC*/
                {
                    (*pphLayer+i)->layer_registry  = phLlcNfc_Register;
                    (*pphLayer+i)->layer_name  = (uint8_t *)"Llc";
                    (*pphLayer+i)->layer_next  =
                                    (((phNfcLayer_sCfg_t *)*pphLayer) + i + 1);
                    break;
                }
                case LAYER_DAL: /*Configure the DAL*/
                {
                    (*pphLayer+i)->layer_registry  = phDal4Nfc_Register;
                    (*pphLayer+i)->layer_name  = (uint8_t *)"Dal";
                    (*pphLayer+i)->layer_next  = NULL ;
                    break;
                }
    
phHciNfc_Initialise
    phNfcIF_sCallBack_t  if_callback = { NULL, NULL, NULL, NULL };
            if_callback.pif_ctxt = psHciContext ;
            if_callback.send_complete = &phHciNfc_Send_Complete;
            if_callback.receive_complete= &phHciNfc_Receive_Complete;
            if_callback.notify = &phHciNfc_Notify_Event;
            plower_if = hciReference.plower_if = &(psHciContext->lower_interface);
            *((phHciNfc_sContext_t **)psHciHandle) = psHciContext;
            psHciContext->init_mode = init_mode;
            psHciContext->p_hci_layer = psHciLayerCfg ;
            lower_index = psHciLayerCfg->layer_index - 1;

            if(NULL != psHciLayerCfg->layer_next->layer_registry)
            {
                status = psHciLayerCfg->layer_next->layer_registry(
                                        &hciReference, if_callback,
                                        (void *)&psHciLayerCfg[lower_index]);
                HCI_DEBUG("HCI Lower Layer Register, Status = %02X ",status);
            }

phLlcNfc_Interface_Register
    phNfcIF_sCallBack_t         if_cb = {0,0,0,0};
        if_cb.notify = NULL;
        if_cb.receive_complete = (pphNfcIF_Transact_Completion_CB_t)&phLlcNfc_RdResp_Cb;
        if_cb.send_complete = (pphNfcIF_Transact_Completion_CB_t)&phLlcNfc_WrResp_Cb;
        if_cb.pif_ctxt = psLlcCtxt;
            result = psIFConfig->layer_next->layer_registry(
                        &sreference,
                        if_cb,
                        (void *)&psIFConfig[(psIFConfig->layer_index - 1)]);


        
phDal4Nfc_Register
        /* Register the LLC functions to the upper layer */
        psRefer->plower_if->init           = phDal4Nfc_Init;
        psRefer->plower_if->release        = phDal4Nfc_Shutdown;
        psRefer->plower_if->send           = phDal4Nfc_Write;
        psRefer->plower_if->receive        = phDal4Nfc_Read;
        psRefer->plower_if->receive_wait   = phDal4Nfc_ReadWait;
        psRefer->plower_if->transact_abort = phDal4Nfc_ReadWaitCancel;
        psRefer->plower_if->unregister     = phDal4Nfc_Unregister;


        if (NULL != pgDalContext)
        {
            /* Copy the DAL context to the upper layer */
            psRefer->plower_if->pcontext = pgDalContext;
            /* Register the callback function from the upper layer */
            pgDalContext->cb_if.receive_complete = if_cb.receive_complete;
            pgDalContext->cb_if.send_complete = if_cb.send_complete;
            pgDalContext->cb_if.notify = if_cb.notify;
            /* Get the upper layer context */
            pgDalContext->cb_if.pif_ctxt = if_cb.pif_ctxt;
            /* Update the error state */
            result = NFCSTATUS_SUCCESS;
        }

    
phLlcNfc_Send
        result = phLlcNfc_Interface_Write (ps_llc_ctxt,
                                (uint8_t *)&(s_packet_info.s_llcbuf),
                                (uint32_t)s_packet_info.llcbuf_len);
phLlcNfc_Interface_Write
            result = psLlcCtxt->lower_if.send(psLlcCtxt->lower_if.pcontext,
                                                psLlcCtxt->phwinfo,
                                                (uint8_t *)&(psLlcCtxt->s_frameinfo.s_llcpacket.s_llcbuf),
                                                (uint16_t)llcBufferLength);
                                                
phDal4Nfc_Write
        /* Send Message and perform physical write in the DefferedCallback */
        /* read completed immediately */
        sMsg.eMsgType= PHDAL4NFC_WRITE_MESSAGE;
        /* Update the state */
        phDal4Nfc_FillMsg(&sMsg,&OsalMsg);
        phDal4Nfc_DeferredCall((pphDal4Nfc_DeferFuncPointer_t)phDal4Nfc_DeferredCb,(void *)pmsgType);

phDal4Nfc_DeferredCb        
        case PHDAL4NFC_WRITE_MESSAGE:
            /* DAL_DEBUG("dalMsg->transactInfo.length : %d ", dalMsg->transactInfo.length); */
            /* Make a Physical WRITE */
            /* NOTE: need to usleep(3000) here if the write is for SWP */
            usleep(500);  /* NXP advise 500us sleep required between I2C writes */
            gReadWriteContext.nNbOfBytesWritten = gLinkFunc.write(gReadWriteContext.pWriteBuffer, gReadWriteContext.nNbOfBytesToWrite);

            if (gReadWriteContext.nNbOfBytesWritten != gReadWriteContext.nNbOfBytesToWrite)
            {
                /* Report write failure or timeout */
                DAL_PRINT(" Physical Write Error !!! ");
                TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesWritten;
                TransactionInfo.status = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_BOARD_COMMUNICATION_ERROR);
            }
            else
            {
                DAL_PRINT(" Physical Write Success ");
                TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesWritten;
                TransactionInfo.status=NFCSTATUS_SUCCESS;
/*              DAL_PRINT("WriteBuff[]={ ");
                for (i = 0; i < gReadWriteContext.nNbOfBytesWritten; i++)
                {
                  DAL_DEBUG("0x%x ", gReadWriteContext.pWriteBuffer[i]);
                }
                DAL_PRINT("} "); */

                // Free TempWriteBuffer
                if(gReadWriteContext.pTempWriteBuffer != NULL)
                {
                    free(gReadWriteContext.pTempWriteBuffer);
                }
            }
            /* Reset Write context */
            gReadWriteContext.nWriteBusy = FALSE;
            gReadWriteContext.nWaitingOnWrite = FALSE;
            
            /* call LLC callback */
            if ((NULL != pgDalContext) && (NULL != pgDalContext->cb_if.send_complete))
            {
                pgDalContext->cb_if.send_complete(pgDalContext->cb_if.pif_ctxt,
                                                    pgDalHwContext,&TransactionInfo);
            }
            break;
            
            
            
phDal4Nfc_Config
      case PN544_LINK_TYPE_I2C:
      {
     DAL_PRINT("I2C link Config");
         /* i2c link interface */
         gLinkFunc.init               = phDal4Nfc_i2c_initialize;
         gLinkFunc.open_from_handle   = phDal4Nfc_i2c_set_open_from_handle;
         gLinkFunc.is_opened          = phDal4Nfc_i2c_is_opened;
         gLinkFunc.flush              = phDal4Nfc_i2c_flush;
         gLinkFunc.close              = phDal4Nfc_i2c_close;
         gLinkFunc.open_and_configure = phDal4Nfc_i2c_open_and_configure;
         gLinkFunc.read               = phDal4Nfc_i2c_read;
         gLinkFunc.write              = phDal4Nfc_i2c_write;
         gLinkFunc.reset              = phDal4Nfc_i2c_reset;
         break;
      }

原文地址:https://www.cnblogs.com/lake-of-embedded-system/p/4174014.html