Esempio n. 1
0
/**
 * \ingroup grp_nfc_dal
 *
 * \brief DAL deferred callback function
 * Generic handler function called by a client thread when reading a message from the queue.
 * Will function will directly call the client function (same context). See phDal4Nfc_DeferredCall
 *
  * \param[in]       params    Parameter that will be passed to the client function.
 *
 */
void phDal4Nfc_DeferredCb (void  *params)
{
    int*    pParam=NULL;
    int     i;
    phNfc_sTransactionInfo_t TransactionInfo;

    pParam=(int*)params;

    switch(*pParam)
    {
    case PHDAL4NFC_READ_MESSAGE:
        DAL_PRINT(" Dal deferred read called \n");
        TransactionInfo.buffer=gReadWriteContext.pReadBuffer;
        TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesRead;
        TransactionInfo.status=NFCSTATUS_SUCCESS;
        gReadWriteContext.nReadBusy = FALSE;


        /*  Reset flag so that another opertion can be issued.*/
        gReadWriteContext.nWaitingOnRead = FALSE;
        if ((NULL != pgDalContext) && (NULL != pgDalContext->cb_if.receive_complete))
        {
            pgDalContext->cb_if.receive_complete(pgDalContext->cb_if.pif_ctxt,
                                                 pgDalHwContext,&TransactionInfo);
        }

        break;
    case PHDAL4NFC_WRITE_MESSAGE:
        DAL_PRINT(" Dal deferred write called \n");

#ifdef LOW_LEVEL_TRACES
        phOsalNfc_PrintData("Send buffer", (uint16_t)gReadWriteContext.nNbOfBytesToWrite, gReadWriteContext.pWriteBuffer);
#endif

        /* DAL_DEBUG("dalMsg->transactInfo.length : %d\n", 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)
        {
            /* controller may be in standby. do it again! */
            usleep(10000); /* wait 10 ms */
            gReadWriteContext.nNbOfBytesWritten = gLinkFunc.write(gReadWriteContext.pWriteBuffer, gReadWriteContext.nNbOfBytesToWrite);
        }
        if (gReadWriteContext.nNbOfBytesWritten != gReadWriteContext.nNbOfBytesToWrite)
        {
            /* Report write failure or timeout */
            DAL_PRINT(" Physical Write Error !!! \n");
            TransactionInfo.length=(uint16_t)gReadWriteContext.nNbOfBytesWritten;
            TransactionInfo.status = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_BOARD_COMMUNICATION_ERROR);
        }
        else
        {
            DAL_PRINT(" Physical Write Success \n");
            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("}\n");

            // 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;
    default:
        break;
    }
}