Пример #1
0
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_Config

PURPOSE: Configure the serial port.

-----------------------------------------------------------------------------*/
NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
{
    NFCSTATUS                       retstatus = NFCSTATUS_SUCCESS;

    DAL_PRINT("phDal4Nfc_Config");

    if ((config == NULL) || (phwref == NULL) || (config->nClientId == -1))
        return NFCSTATUS_INVALID_PARAMETER;

    /* Register the link callbacks */
    memset(&gLinkFunc, 0, sizeof(phDal4Nfc_link_cbk_interface_t));
    switch(config->nLinkType)
    {
    case ENUM_DAL_LINK_TYPE_COM1:
    case ENUM_DAL_LINK_TYPE_COM2:
    case ENUM_DAL_LINK_TYPE_COM3:
    case ENUM_DAL_LINK_TYPE_COM4:
    case ENUM_DAL_LINK_TYPE_COM5:
    case ENUM_DAL_LINK_TYPE_USB:
    {
        DAL_PRINT("UART link Config");
        /* Uart link interface */
        gLinkFunc.init               = phDal4Nfc_uart_initialize;
        gLinkFunc.open_from_handle   = phDal4Nfc_uart_set_open_from_handle;
        gLinkFunc.is_opened          = phDal4Nfc_uart_is_opened;
        gLinkFunc.flush              = phDal4Nfc_uart_flush;
        gLinkFunc.close              = phDal4Nfc_uart_close;
        gLinkFunc.open_and_configure = phDal4Nfc_uart_open_and_configure;
        gLinkFunc.read               = phDal4Nfc_uart_read;
        gLinkFunc.write              = phDal4Nfc_uart_write;
        gLinkFunc.download           = phDal4Nfc_uart_download;
        gLinkFunc.reset              = phDal4Nfc_uart_reset;
    }
    break;

    case ENUM_DAL_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;
    }

    default:
    {
        /* Shound not happen : Bad parameter */
        return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_PARAMETER);
    }
    }

    gLinkFunc.init(); /* So that link interface can initialize its internal state */
    retstatus = gLinkFunc.open_and_configure(config, phwref);
    if (retstatus != NFCSTATUS_SUCCESS)
        return retstatus;

    /* Iniatilize the DAL context */
    (void)memset(&gDalContext,0,sizeof(phDal4Nfc_SContext_t));
    pgDalContext = &gDalContext;

    /* Reset the Reader Thread values to NULL */
    memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext));
    gReadWriteContext.nReadThreadAlive     = TRUE;
    gReadWriteContext.nWriteBusy = FALSE;
    gReadWriteContext.nWaitingOnWrite = FALSE;

    /* Prepare the message queue for the defered calls */
#ifdef USE_MQ_MESSAGE_QUEUE
    nDeferedCallMessageQueueId = mq_open(MQ_NAME_IDENTIFIER, O_CREAT|O_RDWR, 0666, &MQ_QUEUE_ATTRIBUTES);
#else
    nDeferedCallMessageQueueId = config->nClientId;
#endif
    /* Start Read and Write Threads */
    if(NFCSTATUS_SUCCESS != phDal4Nfc_StartThreads())
    {
        return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED);
    }

    gDalContext.hw_valid = TRUE;

    phDal4Nfc_Reset(1);
    phDal4Nfc_Reset(0);
    phDal4Nfc_Reset(1);

    return NFCSTATUS_SUCCESS;
}
Пример #2
0
/*-----------------------------------------------------------------------------

FUNCTION: phDal4Nfc_Config

PURPOSE: Configure the serial port.

-----------------------------------------------------------------------------*/
NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
{
   NFCSTATUS                       retstatus = NFCSTATUS_SUCCESS;
   const hw_module_t* hw_module;
   nfc_pn544_device_t* pn544_dev;
   uint8_t num_eeprom_settings;
   uint8_t* eeprom_settings;
   int ret;

   /* Retrieve the hw module from the Android NFC HAL */
   ret = hw_get_module(NFC_HARDWARE_MODULE_ID, &hw_module);
   if (ret) {
       ALOGE("hw_get_module() failed");
       return NFCSTATUS_FAILED;
   }
   ret = nfc_pn544_open(hw_module, &pn544_dev);
   if (ret) {
       ALOGE("Could not open pn544 hw_module");
       return NFCSTATUS_FAILED;
   }
   config->deviceNode = pn544_dev->device_node;
   if (config->deviceNode == NULL) {
       ALOGE("deviceNode NULL");
       return NFCSTATUS_FAILED;
   }

   DAL_PRINT("phDal4Nfc_Config");

   if ((config == NULL) || (phwref == NULL))
      return NFCSTATUS_INVALID_PARAMETER;

   /* Register the link callbacks */
   memset(&gLinkFunc, 0, sizeof(phDal4Nfc_link_cbk_interface_t));
   switch(pn544_dev->linktype)
   {
      case PN544_LINK_TYPE_UART:
      case PN544_LINK_TYPE_USB:
      {
	 DAL_PRINT("UART link Config");
         /* Uart link interface */
         gLinkFunc.init               = phDal4Nfc_uart_initialize;
         gLinkFunc.open_from_handle   = phDal4Nfc_uart_set_open_from_handle;
         gLinkFunc.is_opened          = phDal4Nfc_uart_is_opened;
         gLinkFunc.flush              = phDal4Nfc_uart_flush;
         gLinkFunc.close              = phDal4Nfc_uart_close;
         gLinkFunc.open_and_configure = phDal4Nfc_uart_open_and_configure;
         gLinkFunc.read               = phDal4Nfc_uart_read;
         gLinkFunc.write              = phDal4Nfc_uart_write;
         gLinkFunc.reset              = phDal4Nfc_uart_reset;
      }
      break;

      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;
      }

      default:
      {
         /* Shound not happen : Bad parameter */
         return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_PARAMETER);
      }
   }

   gLinkFunc.init(); /* So that link interface can initialize its internal state */
   retstatus = gLinkFunc.open_and_configure(config, phwref);
   if (retstatus != NFCSTATUS_SUCCESS)
      return retstatus;

   /* Iniatilize the DAL context */
   (void)memset(&gDalContext,0,sizeof(phDal4Nfc_SContext_t));
   pgDalContext = &gDalContext;
   
   /* Reset the Reader Thread values to NULL */
   memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext));
   gReadWriteContext.nReadThreadAlive     = TRUE;
   gReadWriteContext.nWriteBusy = FALSE;
   gReadWriteContext.nWaitingOnWrite = FALSE;
   
   /* Prepare the message queue for the defered calls */
#ifdef USE_MQ_MESSAGE_QUEUE
   nDeferedCallMessageQueueId = mq_open(MQ_NAME_IDENTIFIER, O_CREAT|O_RDWR, 0666, &MQ_QUEUE_ATTRIBUTES);
#else
   nDeferedCallMessageQueueId = config->nClientId;
#endif

   gDalContext.pDev = pn544_dev;

   /* Start Read and Write Threads */
   if(NFCSTATUS_SUCCESS != phDal4Nfc_StartThreads())
   {
      return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_FAILED);
   }

   gDalContext.hw_valid = TRUE;
   phDal4Nfc_Reset(1);
   phDal4Nfc_Reset(0);
   phDal4Nfc_Reset(1);

   return NFCSTATUS_SUCCESS;
}