NFCSTATUS phNxpNciHal_DownloadPinTest(void) { NFCSTATUS status = NFCSTATUS_FAILED; int len = 0; int cnt = 0; NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - start\n"); len = (sizeof(download_pin_test_data1)/sizeof(download_pin_test_data1[0])); for(cnt = 0; cnt < len; cnt++) { status = phNxpNciHal_performTest(&(download_pin_test_data1[cnt])); if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED) { break; } } if (status != NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - FAILED\n"); return status; } status = NFCSTATUS_FAILED; status = phTmlNfc_IoCtl(phTmlNfc_e_EnableDownloadMode); if (NFCSTATUS_SUCCESS != status) { NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - FAILED\n"); return status; } status = NFCSTATUS_FAILED; len = (sizeof(download_pin_test_data2)/sizeof(download_pin_test_data2[0])); for(cnt = 0; cnt < len; cnt++) { status = phNxpNciHal_performTest(&(download_pin_test_data2[cnt])); if(status == NFCSTATUS_RESPONSE_TIMEOUT || status == NFCSTATUS_FAILED) { break; } } if( status == NFCSTATUS_SUCCESS) { NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - SUCCESSS\n"); } else { NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - FAILED\n"); } NXPLOG_NCIHAL_D("phNxpNciHal_DownloadPinTest - end\n"); return status; }
/******************************************************************************* ** ** Function phDnldNfc_ReadComplete ** ** Description Read complete ** ** Parameters pContext - caller layer context ** status - status of the transaction ** pInfo - transaction info ** ** Returns None ** *******************************************************************************/ static void phDnldNfc_ReadComplete(void* pContext,NFCSTATUS status,void* pInfo) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; UNUSED(pContext); /* Call Tml Ioctl to enable/restore normal mode */ wStatus = phTmlNfc_IoCtl(phTmlNfc_e_EnableNormalMode); if(NFCSTATUS_SUCCESS == wStatus) { NXPLOG_FWDNLD_D("Read Done!!"); } UserCb(&UserCtxt,status,pInfo); return; }
NFCSTATUS phNxpNciHal_PrbsTestStop () { NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - Start\n"); NFCSTATUS status = NFCSTATUS_SUCCESS; status = phTmlNfc_IoCtl(phTmlNfc_e_EnableNormalMode); if(NFCSTATUS_SUCCESS == status) { NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - SUCCESS\n"); } else { NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - FAILED\n"); } NXPLOG_NCIHAL_D("phNxpNciHal_PrbsTestStop - end\n"); return status; }
/******************************************************************************* ** ** Function phTmlNfc_Init ** ** Description Provides initialization of TML layer and hardware interface ** Configures given hardware interface and sends handle to the caller ** ** Parameters pConfig - TML configuration details as provided by the upper layer ** ** Returns NFC status: ** NFCSTATUS_SUCCESS - initialization successful ** NFCSTATUS_INVALID_PARAMETER - at least one parameter is invalid ** NFCSTATUS_FAILED - initialization failed ** (for example, unable to open hardware interface) ** NFCSTATUS_INVALID_DEVICE - device has not been opened or has been disconnected ** *******************************************************************************/ NFCSTATUS phTmlNfc_Init(pphTmlNfc_Config_t pConfig) { NFCSTATUS wInitStatus = NFCSTATUS_SUCCESS; NFCSTATUS setPidStatus = NFCSTATUS_SUCCESS; /* Check if TML layer is already Initialized */ if (NULL != gpphTmlNfc_Context) { /* TML initialization is already completed */ wInitStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_ALREADY_INITIALISED); } /* Validate Input parameters */ else if ((NULL == pConfig) || (PH_TMLNFC_RESET_VALUE == pConfig->dwGetMsgThreadId)) { /*Parameters passed to TML init are wrong */ wInitStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_INVALID_PARAMETER); } else { /* Allocate memory for TML context */ gpphTmlNfc_Context = malloc(sizeof(phTmlNfc_Context_t)); if (NULL == gpphTmlNfc_Context) { wInitStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_FAILED); } else { /* Initialise all the internal TML variables */ memset(gpphTmlNfc_Context, PH_TMLNFC_RESET_VALUE, sizeof(phTmlNfc_Context_t)); /* Make sure that the thread runs once it is created */ gpphTmlNfc_Context->bThreadDone = 1; /* Open the device file to which data is read/written */ wInitStatus = phTmlNfc_i2c_open_and_configure(pConfig, &(gpphTmlNfc_Context->pDevHandle)); if (NFCSTATUS_SUCCESS != wInitStatus) { wInitStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_INVALID_DEVICE); gpphTmlNfc_Context->pDevHandle = (void *) NFCSTATUS_INVALID_DEVICE; } else { gpphTmlNfc_Context->tReadInfo.bEnable = 0; gpphTmlNfc_Context->tWriteInfo.bEnable = 0; gpphTmlNfc_Context->tReadInfo.bThreadBusy = FALSE; gpphTmlNfc_Context->tWriteInfo.bThreadBusy = FALSE; if(0 != sem_init(&gpphTmlNfc_Context->rxSemaphore, 0, 0)) { wInitStatus = NFCSTATUS_FAILED; } else if(0 != sem_init(&gpphTmlNfc_Context->txSemaphore, 0, 0)) { wInitStatus = NFCSTATUS_FAILED; } else if(0 != sem_init(&gpphTmlNfc_Context->postMsgSemaphore, 0, 0)) { wInitStatus = NFCSTATUS_FAILED; } else { sem_post(&gpphTmlNfc_Context->postMsgSemaphore); /* Start TML thread (to handle write and read operations) */ if (NFCSTATUS_SUCCESS != phTmlNfc_StartThread()) { wInitStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_FAILED); } else { /* Create Timer used for Retransmission of NCI packets */ gpphTmlNfc_Context->dwTimerId = phOsalNfc_Timer_Create(); if (PH_OSALNFC_TIMER_ID_INVALID != gpphTmlNfc_Context->dwTimerId) { /* Store the Thread Identifier to which Message is to be posted */ gpphTmlNfc_Context->dwCallbackThreadId = pConfig->dwGetMsgThreadId; /* Enable retransmission of Nci packet & set retry count to default */ gpphTmlNfc_Context->eConfig = phTmlNfc_e_DisableRetrans; /** Retry Count = Standby Recovery time of NFCC / Retransmission time + 1 */ gpphTmlNfc_Context->bRetryCount = (2000 / PHTMLNFC_MAXTIME_RETRANSMIT) + 1; gpphTmlNfc_Context->bWriteCbInvoked = FALSE; } else { wInitStatus = PHNFCSTVAL(CID_NFC_TML, NFCSTATUS_FAILED); } } } } } } /* Clean up all the TML resources if any error */ if (NFCSTATUS_SUCCESS != wInitStatus) { /* Clear all handles and memory locations initialized during init */ phTmlNfc_CleanUp(); } #if(NFC_NXP_ESE == TRUE) else { nfc_service_pid = getpid(); setPidStatus = phTmlNfc_IoCtl(phTmlNfc_e_SetNfcServicePid); if(setPidStatus == NFCSTATUS_SUCCESS) { NXPLOG_TML_D("nfc service set pid done"); } else { NXPLOG_TML_D("nfc service set pid failed"); } } #endif return wInitStatus; }
/******************************************************************************* ** ** Function phDnldNfc_ReadMem ** ** Description Dumps the contents of EEPROM. The handle is required for subsequent operations ** ** Parameters pHwRef - pointer to the hardware device ** pNotify - notify caller after getting response ** pContext - caller context ** ** Returns NFC status: ** NFCSTATUS_SUCCESS - request to NFCC is successful ** NFCSTATUS_FAILED - request failed due to internal error ** NFCSTATUS_NOT_ALLOWED - command not allowed ** Other command specific errors - ** *******************************************************************************/ NFCSTATUS phDnldNfc_ReadMem(void *pHwRef, pphDnldNfc_RspCb_t pNotify, void *pContext) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; uint32_t wAddr = 0x2011C0; /* eeprom platform specific area start address */ uint32_t wRdAddr = 0; uint8_t *pAddr; static uint8_t bRdData[3519]; /* buffer to hold the read data */ static phDnldNfc_Buff_t Data; if((NULL == pNotify) || (NULL == pContext)) { NXPLOG_FWDNLD_E("Invalid Input Parameters!!"); wStatus = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER); } else { /* Call Tml Ioctl to enable download mode */ wStatus = phTmlNfc_IoCtl(phTmlNfc_e_EnableDownloadMode); if(NFCSTATUS_SUCCESS == wStatus) { /* Set the obtained device handle to download module */ phDnldNfc_SetHwDevHandle(); } else { wStatus = NFCSTATUS_FAILED; } if(NFCSTATUS_SUCCESS == wStatus) { pAddr = (uint8_t *)&wAddr; wRdAddr = (pAddr[3]); wRdAddr <<= 8; wRdAddr |= (pAddr[2]); wRdAddr <<= 8; wRdAddr |= (pAddr[1]); wRdAddr <<= 8; wRdAddr |= (pAddr[0]); Data.pBuff = bRdData; Data.wLen = sizeof(bRdData); UserCb = pNotify; UserCtxt = pContext; wStatus = phDnldNfc_Read(&Data, wRdAddr,(pphDnldNfc_RspCb_t)phDnldNfc_ReadComplete,gpphDnldContext); } else { Data.pBuff = NULL; Data.wLen = 0; wStatus = NFCSTATUS_FAILED; } if(NFCSTATUS_PENDING == wStatus) { NXPLOG_FWDNLD_D("Read Request submitted successfully.."); } else { NXPLOG_FWDNLD_E("Read Request submission failed!!"); } } return wStatus; }