int phDal4Nfc_uart_write(uint8_t * pBuffer, int nNbBytesToWrite)
{
    int ret;
    int numWrote = 0;

    DAL_ASSERT_STR(gComPortContext.nOpened == 1, "write called but not opened!");
    DAL_DEBUG("_uart_write() called to write %d bytes\n", nNbBytesToWrite);

/* Samsung modify for TIZEN */
#if 0
    while (numWrote < nNbBytesToWrite) {
        ret = write(gComPortContext.nHandle, pBuffer + numWrote, nNbBytesToWrite - numWrote);
        if (ret > 0) {
            DAL_DEBUG("wrote %d bytes", ret);
            numWrote += ret;
        } else if (ret == 0) {
            DAL_PRINT("_uart_write() EOF");
            return -1;
        } else {
            DAL_DEBUG("_uart_write() errno=%d", errno);
            if (errno == EINTR || errno == EAGAIN) {
                continue;
            }
            return -1;
        }
    }
#endif
    return numWrote;
}
Ejemplo n.º 2
0
NFCSTATUS phDal4Nfc_ConfigRelease(void *pHwRef)
{

   NFCSTATUS result = NFCSTATUS_SUCCESS;
   void * pThreadReturn;
   
   DAL_PRINT("phDal4Nfc_ConfigRelease ");

   if (gDalContext.hw_valid == TRUE)
   {
       /* Signal the read and write threads to exit.  NOTE: there
          actually is no write thread!  :)  */
       DAL_PRINT("Stop Reader Thread");
       gReadWriteContext.nReadThreadAlive = 0;
       gReadWriteContext.nWriteThreadAlive = 0;

       /* Wake up the read thread so it can exit */
       DAL_PRINT("Release Read Semaphore");
       sem_post(&nfc_read_sem);

       DAL_DEBUG("phDal4Nfc_ConfigRelease - doing pthread_join(%d)",
                 gReadWriteContext.nReadThread);
       if (pthread_join(gReadWriteContext.nReadThread,  &pThreadReturn) != 0)
       {
           result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED);
           DAL_PRINT("phDal4Nfc_ConfigRelease  KO");
       }

      /* Close the message queue */
#ifdef USE_MQ_MESSAGE_QUEUE
       mq_close(nDeferedCallMessageQueueId);
#endif

       /* Shutdown NFC Chip */
       phDal4Nfc_Reset(0);

      /* Close the link */
      gLinkFunc.close();

      if (gDalContext.pDev != NULL) {
          nfc_pn544_close(gDalContext.pDev);
      }
      /* Reset the Read Writer context to NULL */
      memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext));
      /* Reset the DAL context values to NULL */
      memset((void *)&gDalContext,0,sizeof(gDalContext));
   }

   gDalContext.hw_valid = FALSE;
   
   DAL_DEBUG("phDal4Nfc_ConfigRelease(): %04x\n", result);


   return result;
}
Ejemplo n.º 3
0
NFCSTATUS phDal4Nfc_Read( void *pContext, void *pHwRef,uint8_t *pBuffer, uint16_t length)
{
    NFCSTATUS result = NFCSTATUS_SUCCESS;

    if ((NULL != pContext) && (NULL != pHwRef)&&
            (NULL != pBuffer) && (0 != length))
    {
        if ( gDalContext.hw_valid== TRUE)
        {
            if((!gReadWriteContext.nReadBusy)&&
                    (!gReadWriteContext.nWaitingOnRead))
            {
                DAL_DEBUG("*****DAl Read called  length : %d\n", length);

                /* Make a copy of the passed arguments */
                gReadWriteContext.pReadBuffer = pBuffer;
                gReadWriteContext.nNbOfBytesToRead  = length;
                /* Change the Read state so that thread can take over the read */
                gReadWriteContext.nReadBusy = TRUE;
                /* Just set variable here. This is the trigger for the Reader thread */
                gReadWriteContext.nWaitingOnRead = TRUE;
                /* Update the return state */
                result = NFCSTATUS_PENDING;
                /* unlock reader thread */
                sem_post(&nfc_read_sem);
            }
            else
            {
                /* Driver is BUSY with prev Read */
                DAL_PRINT("DAL BUSY\n");
                /* Make a copy of the passed arguments */
                gReadWriteContext.pReadBuffer = pBuffer;
                gReadWriteContext.nNbOfBytesToRead  = length;
                result = NFCSTATUS_PENDING;
            }
        }
        else
        {
            /* TBD :Additional error code : NOT_INITIALISED */
            result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE);
        }
    }/*end if-Input parametrs valid-check*/
    else
    {
        result = NFCSTATUS_INVALID_PARAMETER;
    }
    DAL_DEBUG("*****DAl Read called  result : %x\n", result);
    return result;
}
Ejemplo n.º 4
0
int DAL_MessageInit(void)
{
	int				iret = 0;
	
	if( g_dal_message_pool.init == 1)
	{
		DAL_ERROR(("MessagePool already init\n"));
		return -1;
	}

	iret = DAL_SemCreate( &g_dal_message_pool.sem, "MessagePool Sem", 1, 0);
	if( iret != 0)
	{
		DAL_ERROR(("DAL_SemCreate failed\n"));
		return -1;
	}
	
	g_dal_message_pool.pool_size = DAL_MESSAGE_POOL_SIZE;
	g_dal_message_pool.p_block_list = DAL_Malloc(sizeof(MessageBlock_t)*g_dal_message_pool.pool_size);
	if( g_dal_message_pool.p_block_list == NULL)
	{
		DAL_ERROR(("DAL_Malloc MessagePool failed\n"));
		DAL_SemDelete(g_dal_message_pool.sem);
		return -1;
	}
	memset( g_dal_message_pool.p_block_list, 0, sizeof(MessageBlock_t)*g_dal_message_pool.pool_size);
	g_dal_message_pool.used_block = 0;

	DAL_DEBUG(("DAL MessagePool size: %u  use mem: %u\n", g_dal_message_pool.pool_size, sizeof(MessageBlock_t)*g_dal_message_pool.pool_size));
	g_dal_message_pool.init = 1;
	return 0;
}
Ejemplo n.º 5
0
NFCSTATUS phDal4Nfc_Write( void *pContext, void *pHwRef,uint8_t *pBuffer, uint16_t length)
{
    NFCSTATUS result = NFCSTATUS_SUCCESS;
    static int       MsgType= PHDAL4NFC_WRITE_MESSAGE;
    int *            pmsgType=&MsgType;
    phDal4Nfc_Message_t      sMsg;
    phOsalNfc_Message_t      OsalMsg;

    if ((NULL != pContext) && (NULL != pHwRef)&&
            (NULL != pBuffer) && (0 != length))
    {
        if( gDalContext.hw_valid== TRUE)
        {
            if((!gReadWriteContext.nWriteBusy)&&
                    (!gReadWriteContext.nWaitingOnWrite))
            {
                DAL_PRINT("phDal4Nfc_Write() : Temporary buffer !! \n");
                gReadWriteContext.pTempWriteBuffer = (uint8_t*)malloc(length * sizeof(uint8_t));
                /* Make a copy of the passed arguments */
                memcpy(gReadWriteContext.pTempWriteBuffer,pBuffer,length);
                DAL_DEBUG("phDal4Nfc_Write(): %d\n", length);
                gReadWriteContext.pWriteBuffer = gReadWriteContext.pTempWriteBuffer;
                gReadWriteContext.nNbOfBytesToWrite  = length;
                /* Change the write state so that thread can take over the write */
                gReadWriteContext.nWriteBusy = TRUE;
                /* Just set variable here. This is the trigger for the Write thread */
                gReadWriteContext.nWaitingOnWrite = TRUE;
                /* Update the error state */
                result = NFCSTATUS_PENDING;
                /* 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);
                memset(&sMsg,0,sizeof(phDal4Nfc_Message_t));
                memset(&OsalMsg,0,sizeof(phOsalNfc_Message_t));
            }
            else
            {
                /* Driver is BUSY with previous Write */
                DAL_PRINT("phDal4Nfc_Write() : Busy \n");
                result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_BUSY) ;
            }
        }
        else
        {
            /* TBD :Additional error code : NOT_INITIALISED */
            result = PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE);
        }

    }/*end if-Input parametrs valid-check*/
    else
    {
        result = NFCSTATUS_INVALID_PARAMETER;
    }
    return result;
}
Ejemplo n.º 6
0
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_Reset

PURPOSE: Reset the PN544, using the VEN pin

-----------------------------------------------------------------------------*/
NFCSTATUS phDal4Nfc_Reset(long level)
{
    NFCSTATUS	retstatus = NFCSTATUS_SUCCESS;

    DAL_DEBUG("phDal4Nfc_Reset: VEN to %d",level);

    retstatus = gLinkFunc.reset(level);

    return retstatus;
}
Ejemplo n.º 7
0
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_Download

PURPOSE: Put the PN544 in download mode, using the GPIO4 pin

-----------------------------------------------------------------------------*/
NFCSTATUS phDal4Nfc_Download()
{
    NFCSTATUS	retstatus = NFCSTATUS_SUCCESS;

    DAL_DEBUG("phDal4Nfc_Download: GPIO4 to %d",1);

    usleep(10000);
    retstatus = phDal4Nfc_Reset(2);

    return retstatus;
}
Ejemplo n.º 8
0
int phDal4Nfc_uart_write(uint8_t * pBuffer, int nNbBytesToWrite)
{
    int ret;
    int numWrote = 0;

    DAL_ASSERT_STR(gComPortContext.nOpened == 1, "write called but not opened!");
    DAL_DEBUG("_uart_write() called to write %d bytes\n", nNbBytesToWrite);

#ifdef SWISSKNIFEVERSION
    if(nNbBytesToWrite > 4) {
        last_ns = pBuffer[1] & 0x07;
        last_nr = (pBuffer[1] & 0x38) >> 3;
    }
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_uart_reset

PURPOSE:  Reset the PN544, using the VEN pin

-----------------------------------------------------------------------------*/
int phDal4Nfc_uart_reset(long level)
{
    static const char NFC_POWER_PATH[] = "/sys/devices/platform/nfc-power/nfc_power";
    int sz;
    int fd = -1;
    int ret = NFCSTATUS_FAILED;
    char buffer[2];

/* Samsung modify for TIZEN */
#if 0
    DAL_DEBUG("phDal4Nfc_uart_reset, VEN level = %ld", level);

    if (snprintf(buffer, sizeof(buffer), "%u", (unsigned int)level) != 1) {
        LOGE("Bad nfc power level (%u)", (unsigned int)level);
        goto out;
    }

    fd = open(NFC_POWER_PATH, O_WRONLY);
    if (fd < 0) {
        LOGE("open(%s) for write failed: %s (%d)", NFC_POWER_PATH,
                strerror(errno), errno);
        goto out;
    }
    sz = write(fd, &buffer, sizeof(buffer) - 1);
    if (sz < 0) {
        LOGE("write(%s) failed: %s (%d)", NFC_POWER_PATH, strerror(errno),
             errno);
        goto out;
    }
    ret = NFCSTATUS_SUCCESS;
    if (level == 2) {
        libnfc_firmware_mode = 1;
    } else {
        libnfc_firmware_mode = 0;
    }

out:
    if (fd >= 0) {
        close(fd);
    }
#endif
    return ret;
}
Ejemplo n.º 10
0
NFCSTATUS phDal4Nfc_uart_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle)
{
    char *       pComPort;
    int          nComStatus;
    NFCSTATUS    nfcret = NFCSTATUS_SUCCESS;
    int          ret;

    DAL_ASSERT_STR(gComPortContext.nOpened==0, "Trying to open but already done!");

    switch(pConfig->nLinkType)
    {
    case ENUM_DAL_LINK_TYPE_COM1:
        pComPort = "/dev/ttyS0";
        break;
    case ENUM_DAL_LINK_TYPE_COM2:
        pComPort = "/dev/ttyS1";
        break;
    case ENUM_DAL_LINK_TYPE_COM3:
        pComPort = "/dev/ttyS2";
        break;
    case ENUM_DAL_LINK_TYPE_COM4:
        pComPort = "/dev/ttyS3";
        break;
    case ENUM_DAL_LINK_TYPE_COM5:
        pComPort = "/dev/ttyS4";
        break;
    case ENUM_DAL_LINK_TYPE_COM6:
        pComPort = "/dev/ttyS5";
        break;
    case ENUM_DAL_LINK_TYPE_COM7:
        pComPort = "/dev/ttyS6";
        break;
    case ENUM_DAL_LINK_TYPE_COM8:
        pComPort = "/dev/ttyS7";
        break;
    case ENUM_DAL_LINK_TYPE_USB:
        pComPort = "/dev/ttyUSB0";
        break;
    default:
        return NFCSTATUS_INVALID_PARAMETER;
    }

    /* open communication port handle */
    gComPortContext.nHandle = open(pComPort, O_RDWR | O_NOCTTY);
    if (gComPortContext.nHandle < 0)
    {
        *pLinkHandle = NULL;
        return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE);
    }

    gComPortContext.nOpened = 1;
    *pLinkHandle = (void*)gComPortContext.nHandle;

    /*
     *  Now configure the com port
     */
    ret = tcgetattr(gComPortContext.nHandle, &gComPortContext.nIoConfigBackup); /* save the old io config */
    if (ret == -1)
    {
        /* tcgetattr failed -- it is likely that the provided port is invalid */
        *pLinkHandle = NULL;
        return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE);
    }
    ret = fcntl(gComPortContext.nHandle, F_SETFL, 0); /* Makes the read blocking (default).  */
    DAL_ASSERT_STR(ret != -1, "fcntl failed");
    /* Configures the io */
    memset((void *)&gComPortContext.nIoConfig, (int)0, (size_t)sizeof(struct termios));
    /*
     BAUDRATE: Set bps rate. You could also use cfsetispeed and cfsetospeed.
     CRTSCTS : output hardware flow control (only used if the cable has
               all necessary lines. See sect. 7 of Serial-HOWTO)
     CS8     : 8n1 (8bit,no parity,1 stopbit)
     CLOCAL  : local connection, no modem contol
     CREAD   : enable receiving characters
    */
    gComPortContext.nIoConfig.c_cflag = DAL_BAUD_RATE | CS8 | CLOCAL | CREAD;  /* Control mode flags */
    gComPortContext.nIoConfig.c_iflag = IGNPAR;                                          /* Input   mode flags : IGNPAR  Ignore parity errors */
    gComPortContext.nIoConfig.c_oflag = 0;                                               /* Output  mode flags */
    gComPortContext.nIoConfig.c_lflag = 0;                                               /* Local   mode flags. Read mode : non canonical, no echo */
    gComPortContext.nIoConfig.c_cc[VTIME] = 0;                                           /* Control characters. No inter-character timer */
    gComPortContext.nIoConfig.c_cc[VMIN]  = 1;                                           /* Control characters. Read is blocking until X characters are read */

    /*
       TCSANOW  Make changes now without waiting for data to complete
       TCSADRAIN   Wait until everything has been transmitted
       TCSAFLUSH   Flush input and output buffers and make the change
    */
    ret = tcsetattr(gComPortContext.nHandle, TCSANOW, &gComPortContext.nIoConfig);
    DAL_ASSERT_STR(ret != -1, "tcsetattr failed");

    /*
       On linux the DTR signal is set by default. That causes a problem for pn544 chip
       because this signal is connected to "reset". So we clear it. (on windows it is cleared by default).
    */
    ret = ioctl(gComPortContext.nHandle, TIOCMGET, &nComStatus);
    DAL_ASSERT_STR(ret != -1, "ioctl TIOCMGET failed");
    nComStatus &= ~TIOCM_DTR;
    ret = ioctl(gComPortContext.nHandle, TIOCMSET, &nComStatus);
    DAL_ASSERT_STR(ret != -1, "ioctl TIOCMSET failed");
    DAL_DEBUG("Com port status=%d\n", nComStatus);
    usleep(10000); /* Mandatory sleep so that the DTR line is ready before continuing */

    return nfcret;
}
Ejemplo n.º 11
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;
    }
}
Ejemplo n.º 12
0
int phDal4Nfc_ReaderThread(void * pArg)
{
    char      retvalue;
    NFCSTATUS result = NFCSTATUS_SUCCESS;
    uint8_t   retry_cnt=0;
    void *    memsetRet;

    static int       MsgType= PHDAL4NFC_READ_MESSAGE;
    int *     pmsgType=&MsgType;

    phDal4Nfc_Message_t      sMsg;
    phOsalNfc_Message_t      OsalMsg ;
    int i;
    int i2c_error_count;

    pthread_setname_np(pthread_self(), "reader");

    /* Create the overlapped event. Must be closed before exiting
    to avoid a handle leak. This event is used READ API and the Reader thread*/

    DAL_PRINT("RX Thread \n");
    DAL_DEBUG("\nRX Thread nReadThreadAlive = %d",gReadWriteContext.nReadThreadAlive);
    DAL_DEBUG("\nRX Thread nWaitingOnRead = %d",gReadWriteContext.nWaitingOnRead);
    while(gReadWriteContext.nReadThreadAlive) /* Thread Loop */
    {
        /* Check for the read request from user */
        DAL_PRINT("RX Thread Sem Lock\n");
        sem_wait(&nfc_read_sem);
        DAL_PRINT("RX Thread Sem UnLock\n");

        if (!gReadWriteContext.nReadThreadAlive)
        {
            /* got the signal that we should exit.  NOTE: we don't
               attempt to read below, since the read may block */
            break;
        }

        /* Issue read operation.*/

        i2c_error_count = 0;
retry:
        gReadWriteContext.nNbOfBytesRead=0;
        DAL_DEBUG("RX Thread *New *** *****Request Length = %d",gReadWriteContext.nNbOfBytesToRead);
        memsetRet=memset(gReadWriteContext.pReadBuffer,0,gReadWriteContext.nNbOfBytesToRead);

        /* Wait for IRQ !!!  */
        gReadWriteContext.nNbOfBytesRead = gLinkFunc.read(gReadWriteContext.pReadBuffer, gReadWriteContext.nNbOfBytesToRead);

        /* TODO: Remove this hack
         * Reading the value 0x57 indicates a HW I2C error at I2C address 0x57
         * (pn544). There should not be false positives because a read of length 1
         * must be a HCI length read, and a length of 0x57 is impossible (max is 33).
         */
        if(gReadWriteContext.nNbOfBytesToRead == 1 && gReadWriteContext.pReadBuffer[0] == 0x57)
        {
            i2c_error_count++;
            DAL_DEBUG("RX Thread Read 0x57 %d times\n", i2c_error_count);
            if (i2c_error_count < 5) {
                usleep(2000);
                goto retry;
            }
            DAL_PRINT("RX Thread NOTHING TO READ, RECOVER");
            phOsalNfc_RaiseException(phOsalNfc_e_UnrecovFirmwareErr,1);
        }
        else
        {
            i2c_error_count = 0;
#ifdef LOW_LEVEL_TRACES
            phOsalNfc_PrintData("Received buffer", (uint16_t)gReadWriteContext.nNbOfBytesRead, gReadWriteContext.pReadBuffer);
#endif
            DAL_DEBUG("RX Thread Read ok. nbToRead=%d\n", gReadWriteContext.nNbOfBytesToRead);
            DAL_DEBUG("RX Thread NbReallyRead=%d\n", gReadWriteContext.nNbOfBytesRead);
            DAL_PRINT("RX Thread ReadBuff[]={ ");
            for (i = 0; i < gReadWriteContext.nNbOfBytesRead; i++)
            {
                DAL_DEBUG("RX Thread 0x%x ", gReadWriteContext.pReadBuffer[i]);
            }
            DAL_PRINT("RX Thread }\n");

            /* read completed immediately */
            sMsg.eMsgType= PHDAL4NFC_READ_MESSAGE;
            /* Update the state */
            phDal4Nfc_FillMsg(&sMsg,&OsalMsg);
            phDal4Nfc_DeferredCall((pphDal4Nfc_DeferFuncPointer_t)phDal4Nfc_DeferredCb,(void *)pmsgType);
            memsetRet=memset(&sMsg,0,sizeof(phDal4Nfc_Message_t));
            memsetRet=memset(&OsalMsg,0,sizeof(phOsalNfc_Message_t));
        }

    } /* End of thread Loop*/

    DAL_PRINT("RX Thread  exiting");

    return TRUE;
}
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_uart_read

PURPOSE:  Reads nNbBytesToRead bytes and writes them in pBuffer.
          Returns the number of bytes really read or -1 in case of error.

-----------------------------------------------------------------------------*/
int phDal4Nfc_uart_read(uint8_t * pBuffer, int nNbBytesToRead)
{
    int ret;
    int numRead = 0;
    struct timeval tv;
    struct timeval *ptv;
    struct timespec timeout;
    fd_set rfds;

    DAL_ASSERT_STR(gComPortContext.nOpened == 1, "read called but not opened!");
    DAL_DEBUG("_uart_read() called to read %d bytes", nNbBytesToRead);

/* Samsung modify for TIZEN */
#if 0
//    read_property();

    // Read timeout:
    // FW mode: 10s timeout
    // 1 byte read: steady-state LLC length read, allowed to block forever
    // >1 byte read: LLC payload, 100ms timeout (before pn544 re-transmit)
    if (nNbBytesToRead > 1 && !libnfc_firmware_mode) {
        clock_gettime(CLOCK_MONOTONIC, &timeout);
        timeout.tv_nsec += 100000000;
        if (timeout.tv_nsec > 1000000000) {
            timeout.tv_sec++;
            timeout.tv_nsec -= 1000000000;
        }
        ptv = &tv;
    } else if (libnfc_firmware_mode) {
        clock_gettime(CLOCK_MONOTONIC, &timeout);
        timeout.tv_sec += 10;
        ptv = &tv;
    } else {
        ptv = NULL;
    }

    while (numRead < nNbBytesToRead) {
       FD_ZERO(&rfds);
       FD_SET(gComPortContext.nHandle, &rfds);

       if (ptv) {
          tv = timeval_remaining(timeout);
          ptv = &tv;
       }

       ret = select(gComPortContext.nHandle + 1, &rfds, NULL, NULL, ptv);
       if (ret < 0) {
           DAL_DEBUG("select() errno=%d", errno);
           if (errno == EINTR || errno == EAGAIN) {
               continue;
           }
           return -1;
       } else if (ret == 0) {
           LOGW("timeout!");
           break;  // return partial response
       }
       ret = read(gComPortContext.nHandle, pBuffer + numRead, nNbBytesToRead - numRead);
       if (ret > 0) {
           ret = apply_errors(pBuffer + numRead, ret);

           DAL_DEBUG("read %d bytes", ret);
           numRead += ret;
       } else if (ret == 0) {
           DAL_PRINT("_uart_read() EOF");
           return 0;
       } else {
           DAL_DEBUG("_uart_read() errno=%d", errno);
           if (errno == EINTR || errno == EAGAIN) {
               continue;
           }
           return -1;
       }
    }
#endif

    return numRead;
}
Ejemplo n.º 14
0
/*-----------------------------------------------------*/
DAL_ERROR_t DAL_hw_play_start( DAL_Player_Input_t* input, DAL_Player_Output_t* output)
{
#ifdef USE_ST_PLAYREC
	DRV_Still_ErrorCode_t	err_code = STILL_NO_ERROR;
	ST_ErrorCode_t			error = ST_NO_ERROR;
#else
	S32 error = 0;
#endif
	int						iret = 0;
	dal_evt_param_t				dal_evt_param;

	if( input == NULL || output == NULL)
	{
		return DAL_ERROR_BAD_PARAMETER;
	}

#if defined(DRV_Still_Stop)
	if(input->SourceType != SourceType_TUNER  
		&& input->SourceType != SourceType_MMS
		&& input->SourceType != SourceType_FILE)
	{
		DAL_DEBUG(("Not type SourceType_TUNER or SourceType_MMS or SourceType_FILE, Stop still before play start\n"));
		err_code = DRV_Still_Stop();
		if( err_code != 0)
		{
			DAL_DEBUG(("DRV_Still_Stop failed with %d\n", err_code));
		}
	}
#endif

	if( input->SourceType == SourceType_TUNER)
	{
		error = SetDemuxDVB();
		if( error != 0)
		{
			return iret;
		}

#ifdef USE_ST_PLAYREC		
		iret = playrec_start_src_demux(input,output);
#else
		//?hisi
#endif
		if( iret != 0)
		{
			return iret;
		}
		DAL_DVB_CheckFristFrame();	 /*利用dal_core task 去检测第一帧*/	
	}
	else if( input->SourceType == SourceType_HTTP ) /* http play*/
	{
#ifdef USE_ST_PLAYREC	
	//	PLAYREC_SET_STSTREAM_FAVO_DEMUX(playrec_demux_ffmpeg);
		iret = playrec_start_src_file(input,output);
#else
	//hisi?
#endif
		if( iret != 0)
		{
	//		PLAYREC_SET_STSTREAM_FAVO_DEMUX(playrec_demux_none);
			return iret;
		}
	//	PLAYREC_SET_STSTREAM_FAVO_DEMUX(playrec_demux_none);
	}
	else if(input->SourceType == SourceType_FILE)
	{
#ifdef FLV	
		PLAYREC_SET_PLAY_FLVLIST(0);
#endif
#ifdef MMS
		PLAYREC_SET_PLAY_MMS(0);
#endif
#ifdef USE_ST_PLAYREC
		iret = playrec_start_src_file(input,output);
#else
		//hisi?
#endif
		if( iret != 0)
		{
			return iret;
		}
	}
	else if((input->SourceType == SourceType_P2S)
		||(input->SourceType == SourceType_P2V))
	{
		error = SetDemuxP2S();
		if( error != 0)
		{
			DebugMessage("[DAL]SetDemuxP2S failed %d ",error);
			return iret;
		}
		DebugMessage("[DAL]SetDemuxP2S success ");
		
		DAL_P2S_PlayStart( input, output);
	#if 0	
		pbiinfo("\n[%s %d]===== ====start av================== \n\n",DEBUG_LOG);
		hisi_start_audio(0,0);
		hisi_start_video(0,0);
		pbiinfo("\n[%s %d]===== ====================== \n\n",DEBUG_LOG);
	#endif	
	}
#ifdef FLV	
	else if( input->SourceType == SourceType_FLV_LIST)
	{
		DAL_FlvList_PlayStart( input, output);
	}
#endif
	//{{{{add by LYN,for UDP Multicast,2011-08-22
#if defined(USE_DAL_MULTICAST)
	else if(SourceType_UDP == input->SourceType)
	{
	    //change the demux configuration same with P2S stram
	    error = SetDemuxP2S();
		if( error != 0)
		{
			return iret;
		}

        //start Multicast
        DAL_Multicast_PlayStart(input,output);
		
	}
	//}}}}
#endif	
#ifdef MMS	
	else if( input->SourceType == SourceType_MMS)
	{
		DAL_MMS_PlayStart( input, output);
	}
#endif	
	else if(input->SourceType == SourceType_BUFFER)
	{
		DAL_DEBUG(("SourceType_BUFFER DAL_ERROR_NOT_SUPPORT\n"));
		return DAL_ERROR_NOT_SUPPORT;
	}
	else if(input->SourceType == SourceType_HLS)
	{
		error = SetDemuxP2S();
		if( error != 0)
		{
			DebugMessage("[DAL]SetDemuxP2S failed %x ",error);
			dal_core_event_notify(DAL_CORE_EVENT_M3U8_START_BAD_STATUS,&dal_evt_param);
			return iret;
		}
		DebugMessage("[DAL]SetDemuxP2S success,%d ",input->SourceType);

		DAL_hls_PlayStart(input, output);
	}
	else if(input->SourceType == SourceType_TIMESHIFT)
	{
		error = SetDemuxP2S();
		if( error != 0)
		{
			DebugMessage("[DAL]timeshift SetDemuxP2S failed %x ",error);
			dal_core_event_notify(DAL_CORE_EVENT_TIMESHIFT_START_BAD_STATUS,&dal_evt_param);
			return iret;
		}
		DebugMessage("[DAL]timeshift SetDemuxP2S success,%d ",input->SourceType);

		DAL_Timeshift_PlayStart(input, output);
	}
	else
	{
		DAL_DEBUG(("Unknow type DAL_ERROR_NOT_SUPPORT\n"));
		return DAL_ERROR_NOT_SUPPORT;
	}
	return DAL_NO_ERROR;
}
Ejemplo n.º 15
0
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_uart_read

PURPOSE:  Reads nNbBytesToRead bytes and writes them in pBuffer.
          Returns the number of bytes really read or -1 in case of error.

-----------------------------------------------------------------------------*/
int phDal4Nfc_uart_read(uint8_t * pBuffer, int nNbBytesToRead)
{
    int ret;
    int numRead = 0;
    struct timeval tv;
    struct timeval *ptv;
    struct timespec timeout;
    fd_set rfds;
#ifdef SWISSKNIFEVERSION
    struct timespec time,time2;
    clock_gettime(CLOCK_MONOTONIC, &time);
#endif

    DAL_ASSERT_STR(gComPortContext.nOpened == 1, "read called but not opened!");
    DAL_DEBUG("_uart_read() called to read %d bytes", nNbBytesToRead);

    read_property();

    // Read timeout:
    // FW mode: 10s timeout
    // 1 byte read: steady-state LLC length read, allowed to block forever
    // >1 byte read: LLC payload, 100ms timeout (before pn544 re-transmit)
    if (nNbBytesToRead > 1 && !libnfc_firmware_mode) {
        clock_gettime(CLOCK_MONOTONIC, &timeout);
        timeout.tv_nsec += 100000000;
        if (timeout.tv_nsec > 1000000000) {
            timeout.tv_sec++;
            timeout.tv_nsec -= 1000000000;
        }
        ptv = &tv;
    } else if (libnfc_firmware_mode) {
        clock_gettime(CLOCK_MONOTONIC, &timeout);
        timeout.tv_sec += 10;
        ptv = &tv;
    } else {
        ptv = NULL;
    }

    while (numRead < nNbBytesToRead) {
        FD_ZERO(&rfds);
        FD_SET(gComPortContext.nHandle, &rfds);

        if (ptv) {
            tv = timeval_remaining(timeout);
            ptv = &tv;
        }

        ret = select(gComPortContext.nHandle + 1, &rfds, NULL, NULL, ptv);

        if (ret < 0) {
            DAL_DEBUG("select() errno=%d", errno);
            if (errno == EINTR || errno == EAGAIN) {
                continue;
            }
            return -1;
        } else if (ret == 0) {
            ALOGW("timeout!");
            break;  // return partial response
        }
        ret = read(gComPortContext.nHandle, pBuffer + numRead, nNbBytesToRead - numRead);
        if (ret > 0) {
//           ret = apply_errors(pBuffer + numRead, ret);

            DAL_DEBUG("read %d bytes", ret);
            numRead += ret;
        } else if (ret == 0) {
            DAL_PRINT("_uart_read() EOF");
            return 0;
        } else {
            DAL_DEBUG("_uart_read() errno=%d", errno);
            if (errno == EINTR || errno == EAGAIN) {
                continue;
            }
            return -1;
        }
    }

#ifdef SWISSKNIFEVERSION
    clock_gettime(CLOCK_MONOTONIC, &time2);

#ifdef LOGSWISSKNIFE
    SwissKnife_Log(pBuffer,nNbBytesToRead,"Receiving message:");
#endif

    if(rapidBitExchange && receivedMessages < 32) {
        if(nNbBytesToRead == 1) {
            if(pBuffer[0] == 0x03) {
                msg3[receivedMessages] = (time2.tv_sec*1000000000)+time2.tv_nsec;
            }
            else if (pBuffer[0] == 0x07) {
                msgsize[receivedMessages] = (time2.tv_sec*1000000000)+time2.tv_nsec;
            }
        } else if(nNbBytesToRead == 7) {
            data[receivedMessages] = (time2.tv_sec*1000000000)+time2.tv_nsec;
        }
    }
#endif

    return numRead;
}