/* * Copyright (c), NXP Semiconductors Caen / France * * (C)NXP Semiconductors * All rights are reserved. Reproduction in whole or in part is * prohibited without the written consent of the copyright owner. * NXP reserves the right to make changes without notice at any time. * NXP makes no warranty, expressed, implied or statutory, including but * not limited to any implied warranty of merchantability or fitness for any *particular purpose, or that the use will not infringe any third party patent, * copyright or trademark. NXP must not be liable for any loss or damage * arising from its use. */ #include #include #include #define print_buf(x,y,z) {int loop; printf(x); for(loop=0;loop 0x8F) && (j < 0xFE)) continue; get_rf[4] = j; tml_transceive(handle, get_rf, sizeof(get_rf), Answer, sizeof(Answer)); if ((Answer[0] != 0x4F) || (Answer[1] != 0x14) || (Answer[3] != 0x00)) continue; printf(" transition 0x%02X, register 0x%02X = ", i, j); for(l=0; l ", i); for(l=1; l ", i); for(l=1; l20 mA / 01h->60 mA / 02h->120 mA / 03h->160 mA)= %.2X ", Answer[5]); printf("\n"); } } } static void SetNciParam (int handle) { char set[255] = {0x20, 0x02, 0x00, 0x01, 0x00, 0x00}; char Answer[255]; unsigned int temp; int loop; printf("Set NCI parameter value menu (enter ff during tag ID selection step to leave):\n"); while (1) { printf("\n"); printf("- enter NCI parameter tag ID in (hexadecimal): "); scanf("%x", &temp); if(temp == 0xff) break; set[4] = (char) temp; printf("- enter length: "); scanf("%x", &temp); if (temp == 0) { printf("Wrong length\n"); continue; } set[5] = temp; set[2] = 3 + temp; printf("- enter value (in hexadecimal) LSB first: "); for(loop=0; loop20 mA / 01h->60 mA / 02h->120 mA / 03h->160 mA)= %.2Xh", Answer[5]); printf("\n"); } } } static void AGC (int handle) { char get[] = {0x2F, 0x3D, 0x04, 0x02, 0xC8, 0x60, 0x03}; char Answer[255]; printf("Get AGC value (enter 'ff' during tag ID selection step to leave):\n"); while (1) { printf("\n"); tml_transceive(handle, get, sizeof(get), Answer, sizeof(Answer)); if ((Answer[0] != 0x4F) || (Answer[1] != 0x3D) || (Answer[3] != 0x00)) { printf("Error, cannot get parameter value\n"); } else { printf("\n"); printf("Measured AGC Value (LSB)= %.2Xh" , Answer[4]); printf("\n"); printf("Measured AGC Value (MSB)= %.2Xh", Answer[5]); printf("\n"); } } } static void AGC_NFCLD (int handle) { char get[] = {0x2F, 0x3D, 0x04, 0x04, 0x20, 0x3F, 0x08}; char Answer[255]; printf("Get AGC_NFCLD value (enter 'ff' during tag ID selection step to leave):\n"); while (1) { printf("\n"); tml_transceive(handle, get, sizeof(get), Answer, sizeof(Answer)); if ((Answer[0] != 0x4F) || (Answer[1] != 0x3D) || (Answer[3] != 0x00)) { printf("Error, cannot get parameter value\n"); } else { printf("\n"); printf("Measured AGC Value (LSB)= %.2Xh" , Answer[4]); printf("\n"); printf("Measured AGC Value (MSB)= %.2Xh", Answer[5]); printf("\n"); } } } static void DPC (int handle) { char get[] = {0x2F, 0x3F, 0x03, 0x03, 0x00, 0x00}; char Answer[255]; unsigned int temp; printf("DPC Check (enter 'ff' during tag ID selection step to leave):\n"); while (1) { printf("\n"); printf("- Enter 00 for DPC Check (hexadecimal): "); scanf("%x", &temp); if(temp == 0xff) break; get[5] = (char) temp; tml_transceive(handle, get, sizeof(get), Answer, sizeof(Answer)); if ((Answer[0] != 0x4F) || (Answer[1] != 0x3F) || (Answer[3] != 0x00)) { printf("Error, cannot get parameter value NXP VER\n"); printf("byte0 %.2Xh" , Answer[0]); printf("\n"); printf("byte1 %.2Xh" , Answer[1]); printf("\n"); printf("Lenght %.2Xh" , Answer[2]); printf("\n"); printf("Status(00h OK) %.2Xh" , Answer[3]); } else { printf("DPC check parameters="); printf("\n"); printf("byte0 %.2Xh" , Answer[0]); printf("\n"); printf("byte1 %.2Xh" , Answer[1]); printf("\n"); printf("Lenght %.2Xh" , Answer[2]); printf("\n"); printf("Status(00h OK) %.2Xh" , Answer[3]); printf("\n"); printf("B1 %.2Xh" , Answer[4]); printf("\n"); printf("B2 %.2Xh" , Answer[5]); printf("\n"); printf("B3 %.2Xh" , Answer[6]); printf("\n"); printf("B4 %.2Xh" , Answer[7]); printf("\n"); printf("B5 %.2Xh" , Answer[8]); printf("\n"); printf("B6 %.2Xh" , Answer[9]); printf("\n"); printf("B7 %.2Xh" , Answer[10]); printf("\n"); printf("B8 %.2Xh" , Answer[11]); printf("\n"); printf("..."); printf("\n"); } } } static void Prbs (int handle) { char NCIPrbsPN7120[] = {0x2F, 0x30, 0x04, 0x00, 0x00, 0x01, 0x01}; char NCIPrbsPN71X0[] = {0x2F, 0x30, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFF}; /* On PN7160, the only allowed value for "PRBS series length" (last two bytes) is 0x01FF when Firmware generated PRBS is selected*/ char Answer[256]; int tech, bitrate; printf("PRBS test:\n"); printf(" Select technology (A=0, B=1, F=2): "); scanf("%d", &tech); printf(" Select bitrate (106=0, 212=1, 424=2, 848=3): "); scanf("%d", &bitrate); if (gNfcController_generation == 1) { NCIPrbsPN7120[3] = tech; NCIPrbsPN7120[4] = bitrate; tml_transceive(handle, NCIPrbsPN7120, sizeof(NCIPrbsPN7120), Answer, sizeof(Answer)); } else { NCIPrbsPN71X0[5] = tech; NCIPrbsPN71X0[6] = bitrate; tml_transceive(handle, NCIPrbsPN71X0, sizeof(NCIPrbsPN71X0), Answer, sizeof(Answer)); } fgets(Answer, sizeof(Answer), stdin); printf("NFC Controller is now in PRBS mode - Press enter to stop\n"); fgets(Answer, sizeof(Answer), stdin); } static void Standby (int handle) { char NCIEnableStandby[] = {0x2F, 0x00, 0x01, 0x01}; char Answer[256]; tml_transceive(handle, NCIEnableStandby, sizeof(NCIEnableStandby), Answer, sizeof(Answer)); if((Answer[0] != 0x4F) || (Answer[1] != 0x00) || (Answer[3] != 0x00)) { printf("Cannot set the NFC Controller in standby mode\n"); return; } /* Wait to allow PN71xx entering the standby mode */ usleep(500 * 1000); fgets(Answer, sizeof(Answer), stdin); printf("NFC Controller is now in standby mode - Press enter to stop\n"); fgets(Answer, sizeof(Answer), stdin); } static int reset_controller(int handle) { char NCICoreReset[] = {0x20, 0x00, 0x01, 0x01}; char NCICoreInit1_0[] = {0x20, 0x01, 0x00}; char NCICoreInit2_0[] = {0x20, 0x01, 0x02, 0x00, 0x00}; char Answer[256]; int NbBytes = 0; tml_reset(handle); tml_transceive(handle, NCICoreReset, sizeof(NCICoreReset), Answer, sizeof(Answer)); /* Catch potential notification */ usleep(100*1000); NbBytes = tml_receive(handle, Answer, sizeof(Answer)); tml_transceive(handle, NCICoreReset, sizeof(NCICoreReset), Answer, sizeof(Answer)); /* Catch potential notification */ usleep(100*1000); NbBytes = tml_receive(handle, Answer, sizeof(Answer)); if((NbBytes == 12) && (Answer[0] == 0x60) && (Answer[1] == 0x00) && (Answer[3] == 0x02)) { NbBytes = tml_transceive(handle, NCICoreInit2_0, sizeof(NCICoreInit2_0), Answer, sizeof(Answer)); if((NbBytes < 19) || (Answer[0] != 0x40) || (Answer[1] != 0x01) || (Answer[3] != 0x00)) { printf("Error communicating with NFC Controller\n"); return -1; } gNfcController_generation = 3; } else { NbBytes = tml_transceive(handle, NCICoreInit1_0, sizeof(NCICoreInit1_0), Answer, sizeof(Answer)); if((NbBytes < 19) || (Answer[0] != 0x40) || (Answer[1] != 0x01) || (Answer[3] != 0x00)) { printf("Error communicating with PN71xx NFC Controller\n"); return -1; } /* Retrieve NXP-NCI NFC Controller generation */ if (Answer[17+Answer[8]] == 0x08) { gNfcController_generation = 1; } else if (Answer[17+Answer[8]] == 0x10) { gNfcController_generation = 2; } else { return -1; } } return 0; } int main() { int nHandle; char NCIDisableStandby[] = {0x2F, 0x00, 0x01, 0x00}; char Answer[256]; int choice = 0; printf("\n----------------------------\n"); printf("NFC Factory Test Application\n"); printf("----------------------------\n"); if(tml_open(&nHandle) != 0) { printf("Cannot connect to NFC controller\n"); return -1; } if(reset_controller(nHandle) != 0) { printf("Error communicating with the NFC Controller\n"); return -1; } switch(gNfcController_generation) { case 1: printf("PN7120 NFC controller detected\n"); break; case 2: printf("PN7150 NFC controller detected\n"); break; case 3: printf("PN7160 NFC controller detected\n"); break; default: printf("Wrong NFC controller detected\n"); break; } /* Disable standby mode */ tml_transceive(nHandle, NCIDisableStandby, sizeof(NCIDisableStandby), Answer, sizeof(Answer)); do { printf("Select the test to run:\n"); printf("\t 1. Continuous RF ON mode\n"); printf("\t 2. Functional mode\n"); printf("\t 3. PRBS mode\n"); printf("\t 4. Standby mode\n"); printf("\t 5. Dump RF settings\n"); printf("\t 6. Set RF setting\n"); printf("\t 7. Get NCI parameter value\n"); printf("\t 8. Set NCI parameter value\n"); printf("\t 9. Get proprietary parameter value\n"); printf("\t10. Set proprietary parameter value\n"); printf("\t11. Get current value\n"); printf("\t12. DPC Check\n"); printf("\t13. Get AGC value\n"); printf("\t14. Get AGC_NFCLD value\n"); printf("\t15. Dump EEPROM settings\n"); printf("enter 0 to leave the application\n"); printf("Your choice: "); scanf("%d", &choice); switch(choice) { case 0: break; case 1: RfOn(nHandle); reset_controller(nHandle); break; case 2: Functional(nHandle); break; case 3: Prbs(nHandle); reset_controller(nHandle); break; case 4: Standby(nHandle); reset_controller(nHandle); tml_transceive(nHandle, NCIDisableStandby, sizeof(NCIDisableStandby), Answer, sizeof(Answer)); break; case 5: Dump(nHandle); break; case 6: SetRF(nHandle); break; case 7: GetNciParam(nHandle); break; case 8: SetNciParam(nHandle); break; case 9: GetPropParam(nHandle); break; case 10: SetPropParam(nHandle); break; case 11: current(nHandle); break; case 12: DPC(nHandle); break; case 13: AGC(nHandle); break; case 14: AGC_NFCLD(nHandle); break; case 15: DumpEEPROM(nHandle); break; default: printf("Wrong choice\n"); break; } } while(choice != 0); tml_reset(nHandle); tml_close(nHandle); return 0; }