phStatus_t initLayers() { /* Initialize the Reader BAL (Bus Abstraction Layer) component */ PH_CHECK_SUCCESS_FCT(status, phbalReg_R_Pi_spi_Init(&bal, sizeof(phbalReg_R_Pi_spi_DataParams_t))); PH_CHECK_SUCCESS_FCT(status, phbalReg_OpenPort((void *)&bal)); /* we have a board with PN512, * but on the software point of view, * it's compatible to the RC523 */ PH_CHECK_SUCCESS_FCT(status, phhalHw_Rc523_Init(&hal, sizeof(phhalHw_Rc523_DataParams_t), (void *)&bal, 0, bHalBufferReader, sizeof(bHalBufferReader), bHalBufferReader, sizeof(bHalBufferReader))); /* Set the HAL configuration to SPI */ PH_CHECK_SUCCESS_FCT(status, phhalHw_SetConfig(&hal, PHHAL_HW_CONFIG_BAL_CONNECTION, PHHAL_HW_BAL_CONNECTION_SPI)); PH_CHECK_SUCCESS_FCT(status, phpalI14443p3a_Sw_Init(&palI14443p3a, sizeof(phpalI14443p3a_Sw_DataParams_t), &hal)); PH_CHECK_SUCCESS_FCT(status, phpalI14443p4_Sw_Init(&palI14443p4, sizeof(phpalI14443p4_Sw_DataParams_t), &hal)); PH_CHECK_SUCCESS_FCT(status, phpalMifare_Sw_Init(&palMifare, sizeof(phpalMifare_Sw_DataParams_t), &hal, &palI14443p4)); PH_CHECK_SUCCESS_FCT(status, phalMfc_Sw_Init(&alMfc, sizeof(phalMfc_Sw_DataParams_t), &palMifare, NULL)); return PH_ERR_SUCCESS; }
phStatus_t NfcRdLibInit(void) { phStatus_t status; /* * Initialize the Reader BAL (Bus Abstraction Layer) component */ status = phbalReg_Stub_Init(&sBalReader, sizeof(phbalReg_Stub_DataParams_t)); CHECK_SUCCESS(status); /* * Initialize the OSAL Events. */ status = phOsal_Event_Init(); CHECK_STATUS(status); // Start interrupt thread Set_Interrupt(); /* * Set HAL type in BAL */ #ifdef NXPBUILD__PHHAL_HW_PN5180 status = phbalReg_SetConfig(&sBalReader, PHBAL_REG_CONFIG_HAL_HW_TYPE, PHBAL_REG_HAL_HW_PN5180); #endif #ifdef NXPBUILD__PHHAL_HW_RC523 status = phbalReg_SetConfig(&sBalReader, PHBAL_REG_CONFIG_HAL_HW_TYPE, PHBAL_REG_HAL_HW_RC523); #endif #ifdef NXPBUILD__PHHAL_HW_RC663 status = phbalReg_SetConfig(&sBalReader, PHBAL_REG_CONFIG_HAL_HW_TYPE, PHBAL_REG_HAL_HW_RC663); #endif CHECK_STATUS(status); status = phbalReg_SetPort(&sBalReader, (uint8_t *) SPI_CONFIG); CHECK_STATUS(status); /* * Open BAL */ status = phbalReg_OpenPort(&sBalReader); CHECK_STATUS(status); /* * Initialize the Reader HAL (Hardware Abstraction Layer) component */ status = phhalHw_Nfc_IC_Init(&sHal_Nfc_Ic, sizeof(phhalHw_Nfc_Ic_DataParams_t), &sBalReader, 0, bHalBufferTx, sizeof(bHalBufferTx), bHalBufferRx, sizeof(bHalBufferRx)); CHECK_SUCCESS(status); /* * Set the parameter to use the SPI interface */ sHal_Nfc_Ic.sHal.bBalConnectionType = PHHAL_HW_BAL_CONNECTION_SPI; Configure_Device(&sHal_Nfc_Ic); /* * Set the generic pointer */ pHal = &sHal_Nfc_Ic.sHal; /* * Initializing specific objects for the communication with MIFARE (R) Classic cards. The MIFARE (R) Classic card * is compliant of ISO 14443-3 and ISO 14443-4 */ /* * Initialize the I14443-A PAL layer */ status = phpalI14443p3a_Sw_Init(&spalI14443p3a, sizeof(phpalI14443p3a_Sw_DataParams_t), &sHal_Nfc_Ic.sHal); CHECK_STATUS(status); /* * Initialize the I14443-A PAL component */ status = phpalI14443p4a_Sw_Init(&spalI14443p4a, sizeof(phpalI14443p4a_Sw_DataParams_t), &sHal_Nfc_Ic.sHal); CHECK_STATUS(status); /* * Initialize the I14443-4 PAL component */ status = phpalI14443p4_Sw_Init(&spalI14443p4, sizeof(phpalI14443p4_Sw_DataParams_t), &sHal_Nfc_Ic.sHal); CHECK_STATUS(status); /* * Initialize the I14443-B PAL component */ status = phpalI14443p3b_Sw_Init(&spalI14443p3b, sizeof(phpalI14443p3b_Sw_DataParams_t), &sHal_Nfc_Ic.sHal); CHECK_STATUS(status); /* * Initialize the MIFARE PAL component */ status = phpalMifare_Sw_Init(&spalMifare, sizeof(phpalMifare_Sw_DataParams_t), &sHal_Nfc_Ic.sHal, NULL); CHECK_STATUS(status); /* * Initialize the discover component */ status = phacDiscLoop_Sw_Init(&sDiscLoop, sizeof(phacDiscLoop_Sw_DataParams_t), &sHal_Nfc_Ic.sHal); CHECK_SUCCESS(status); /* * Load profile for Discovery loop */ LoadProfile(); status = phalMfc_Sw_Init(&salMfc, sizeof(phalMfc_Sw_DataParams_t), &spalMifare, NULL); CHECK_STATUS(status); /* * Read the version of the reader IC */ #if defined NXPBUILD__PHHAL_HW_RC523 status = phhalHw_Rc523_ReadRegister(&sHal_Nfc_Ic.sHal, PHHAL_HW_RC523_REG_VERSION, &bDataBuffer[0]); CHECK_SUCCESS(status); #endif #if defined NXPBUILD__PHHAL_HW_RC663 status = phhalHw_Rc663_ReadRegister(&sHal_Nfc_Ic.sHal, PHHAL_HW_RC663_REG_VERSION, &bDataBuffer[0]); CHECK_SUCCESS(status); #endif /* * Return Success */ return PH_ERR_SUCCESS; }