Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8_t RC663_ISO14443A_UID(uint8_t *uid)
- {
- uint8_t result=0;
- quiet = 1;
- // Disable power down and pause ten milisecond before scanning.
- ioport_ext_set_pin_level(TCA6416_H_F_PDOWN, false);
- atomTimerDelay(1);
- phhalSR( 0x0F, 0x98); // (Status: 0x0000)
- phhalSR( 0x14, 0x92); // (Status: 0x0000)
- phhalSR( 0x19, 0x20); // (Status: 0x0000)
- phhalSR( 0x1A, 0x03); // (Status: 0x0000)
- phhalSR( 0x1B, 0xFF); // (Status: 0x0000)
- phhalSR( 0x1E, 0x00); // (Status: 0x0000)
- _DEBUG("//< Configure FIFO Size=255 and Water-level");
- phhalGR( 0x02); // data == A0 // (Status: 0x0000)
- _DEBUG("//< Befor setting SR2 with 90");
- _DEBUG("//Value = 0xA0");
- _DEBUG("//< Configure FIFO Size=255 and Water-level");
- phhalSR( 0x02, 0x90); // (Status: 0x0000)
- phhalGR( 0x02); // data == A0 // (Status: 0x0000)
- _DEBUG("//< After setting SR2 with 90");
- _DEBUG("//Value = 0xA0");
- phhalSR( 0x03, 0xFE); // (Status: 0x0000)
- phhalSR( 0x0C, 0x80); // (Status: 0x0000)
- phhalGR( 0x28); // data == 89 // (Status: 0x0000)
- phhalSR( 0x28, 0x80); // (Status: 0x0000)
- phhalSR( 0x29, 0x00); // (Status: 0x0000)
- phhalSR( 0x2A, 0x01); // (Status: 0x0000)
- phhalSR( 0x2B, 0x05); // (Status: 0x0000)
- phhalSR( 0x34, 0x00); // (Status: 0x0000)
- phhalSR( 0x38, 0x12); // (Status: 0x0000)
- _DEBUG("//< =============================================");
- _DEBUG("//< 2. LoadProtocol( bTxProtocol=0, bRxProtocol=0)");
- _DEBUG("//< =============================================");
- _DEBUG("//< Terminate any running command. Flush_FiFo");
- phhalSR( 0x00, 0x00); // (Status: 0x0000)
- phhalSR( 0x02, 0xB0); // (Status: 0x0000)
- phhalSR( 0x06, 0x7F); // (Status: 0x0000)
- phhalSR( 0x07, 0x7F); // (Status: 0x0000)
- _DEBUG("//< Write in Fifo: Tx and Rx protocol numbers(0,0)");
- phhalGR( 0x04); // data == 00 // (Status: 0x0000)
- phhalSR( 0x05, 0x00); // (Status: 0x0000)
- phhalSR( 0x05, 0x00); // (Status: 0x0000)
- phhalGR( 0x08); // data == 00 // (Status: 0x0000)
- phhalSR( 0x08, 0x10); // (Status: 0x0000)
- phhalGR( 0x09); // data == 00 // (Status: 0x0000)
- phhalSR( 0x09, 0x40); // (Status: 0x0000)
- // The complete RFID scan takes longer than the time needed for led animation rates.
- // Call the led animation step routine halfway through to smooth things out. (should be safe but introduces a new hardware usage state so beware)
- // Block moved around experimentally to find this spot as the right balance to achieve resonsive RFID and smooth led animation.
- ui_LED_thread_step();
- _DEBUG("//< Start RC663 command Load Protocol=0x0d");
- phhalSR( 0x00, 0x0D); // (Status: 0x0000)
- phhalGR( 0x07); // data == 60 // (Status: 0x0000)
- phhalSR( 0x08, 0x00); // (Status: 0x0000)
- phhalSR( 0x09, 0x00); // (Status: 0x0000)
- _DEBUG("//< Flush Fifo. Read Error Reg");
- phhalSR( 0x02, 0xB0); // (Status: 0x0000)
- phhalGR( 0x0A); // data == 00 // (Status: 0x0000)
- _DEBUG("//< Configure CRC-16 calculation, preset value(0x6363) for Tx&Rx");
- phhalSR( 0x2C, 0x18); // (Status: 0x0000)
- phhalSR( 0x2D, 0x18); // (Status: 0x0000)
- phhalSR( 0x2E, 0x08); // (Status: 0x0000)
- phhalSR( 0x2F, 0x20); // (Status: 0x0000)
- phhalSR( 0x30, 0x00); // (Status: 0x0000)
- phhalSR( 0x33, 0xCF); // (Status: 0x0000)
- phhalSR( 0x35, 0x04); // (Status: 0x0000)
- phhalSR( 0x37, 0x32); // (Status: 0x0000)
- phhalSR( 0x39, 0x00); // (Status: 0x0000)
- phhalSR( 0x36, 0x90); // (Status: 0x0000)
- phhalSR( 0x31, 0xC0); // (Status: 0x0000)
- phhalSR( 0x32, 0x0B); // (Status: 0x0000)
- phhalSR( 0x10, 0x08); // (Status: 0x0000)
- phhalSR( 0x11, 0xD8); // (Status: 0x0000)
- phhalSR( 0x15, 0x00); // (Status: 0x0000)
- phhalSR( 0x16, 0x00); // (Status: 0x0000)
- phhalSR( 0x28, 0x81); // (Status: 0x0000) // Tx2Inv, output pulled low
- _DEBUG("//< MIFARE Crypto1 state is further disabled.");
- phhalSR( 0x0B, 0x00); // (Status: 0x0000) // Disable crypto
- // The complete RFID scan takes longer than the time needed for perfect led animation.
- // Call the led animation step routine halfway through to smooth things out. (should be safe but introduces a new hardware usage state so beware)
- // Move this block around to find the right balance to achieve resonsive RFID and smooth led animation.
- ui_LED_thread_step();
- // Experimental - Set the gain in the RxAna register
- phhalSR( 0x39, rfid_gain_setting); // (Status: 0x0000)
- _DEBUG("//< FieldOn");
- phhalSR( 0x28, 0x89); // (Status: 0x0000) // Tx2Inv, start transmitter,output pulled low
- _DEBUG("//< =============================================");
- _DEBUG("//< I14443p3a_Sw_RequestA");
- _DEBUG("//< =============================================");
- phhalSR( 0x31, 0xC0); // (Status: 0x0000) // TxWaitTime started at end of receive data, TxWait time is TxWait e 0.5 / DBFreq
- phhalSR( 0x32, 0x0B); // (Status: 0x0000) // minimum time between receive and send or between two send data streams
- _DEBUG("//< Set timeout for this command cmd. Init reload values for timers-0,1");
- // Set the timer values to 0xffff. This changed the 0x63 to 0x61
- phhalSR( 0x10, 0xff); // (Status: 0x0000)
- phhalSR( 0x11, 0xff); // (Status: 0x0000)
- phhalSR( 0x15, 0xff); // (Status: 0x0000)
- phhalSR( 0x16, 0xff); // (Status: 0x0000)
- phhalSR( 0x06, 0x08); // (Status: 0x0000) // enable TX IRQ
- phhalSR( 0x36, 0x90); // (Status: 0x0000) // Put 90 in rcvr wait register
- phhalSR( 0x2E, 0x0F); // (Status: 0x0000) // Put 0xf in TxDataNum reg
- _DEBUG("//< ---------------------");
- _DEBUG("//< Send the ReqA command");
- _DEBUG("//< ---------------------");
- _DEBUG("//< Terminate any running command. FlushFifo");
- phhalSR( 0x00, 0x00); // (Status: 0x0000)
- phhalSR( 0x02, 0xB0); // (Status: 0x0000) // Set fifo size to 255 and clear input fifo. Is actually setting bit 5 which is reserved ???
- phhalSR( 0x06, 0x7F); // (Status: 0x0000) // Enables all IRQ (does not include lowpower(
- phhalSR( 0x07, 0x7F); // (Status: 0x0000) // Clear all IRQs
- _DEBUG("//< Write ReqA=26 into FIFO");
- phhalSR( 0x05, 0x26); // (Status: 0x0000)
- _DEBUG("//< Start RC663 command Transcieve=0x07. Activate Rx after Tx finishes.");
- phhalSR( 0x00, 0x07); // (Status: 0x0000) // Issue a trasceive command. Transmit and then switch to recieve
- _DEBUG("//< Wait until the command is finished. Enable IRQ sources.");
- phhalSR( 0x08, 0x18); // (Status: 0x0000) // Enable Idle and TX IRQ
- phhalSR( 0x09, 0x42); // (Status: 0x0000) // Enable global IRQ and Timer1 IRQ
- phhalGR( 0x07); // data == 60 // (Status: 0x0000) // Reads back 0x61 or 0x63
- phhalSR( 0x08, 0x00); // (Status: 0x0000) // Clear SR1 and SR2
- phhalSR( 0x09, 0x00); // (Status: 0x0000)
- // _DEBUG("//< Wait until reception");
- phhalSR( 0x08, 0x54); // (Status: 0x0000) // Enable LowAlert, Idle RX IRQ
- phhalSR( 0x09, 0x42); // (Status: 0x0000) // Enable Global IRQ and Timer1 IRQ
- phhalGR( 0x07); // data == 60 // (Status: 0x0000)
- phhalSR( 0x08, 0x00); // (Status: 0x0000)
- phhalSR( 0x09, 0x00); // (Status: 0x0000)
- _DEBUG("//< Read FIFO, expected: AtqA");
- phhalGR( 0x04); // data == 02 // (Status: 0x0000) // 0
- phhalGR( 0x05); // data == 44 // (Status: 0x0000) // 26
- phhalGR( 0x05); // data == 00 // (Status: 0x0000) // 26
- phhalGR( 0x0A); // data == 00 // (Status: 0x0000) // 0
- phhalSR( 0x2E, 0x08); // (Status: 0x0000)
- static uint8_t this_reading[6];
- bool r=GET_UID_CL(1, this_reading, uid);
- if (r && this_reading[1] != 0x88)
- result = 4;
- else if(r && SELECT_CL(1, &this_reading[1]))
- {
- r=GET_UID_CL(2, this_reading, uid);
- if (r)
- result = 7;
- if(r && SELECT_CL(2, &this_reading[1]))
- {
- r = 0; //clear result flag
- result = 0;
- #if 0 //only if our uid array can support 10 bytes
- r=GET_UID_CL(3, this_reading, uid);
- if (r)
- result = 11;
- SELECT_CL(3, &this_reading[1]);
- #endif
- }
- }
- _DEBUG("//< =============================================");
- _DEBUG("//< Send HaltA cmd");
- _DEBUG("//< =============================================");
- phhalSR( 0x2E, 0x08); // (Status: 0x0000)
- _DEBUG("//< HaltA command needs CRC-16 appended to the data stream.");
- phhalSR( 0x2C, 0x19); // (Status: 0x0000)
- phhalSR( 0x2D, 0x19); // (Status: 0x0000)
- phhalSR( 0x0C, 0x00); // (Status: 0x0000)
- phhalSR( 0x08, 0x00); // (Status: 0x0000)
- phhalSR( 0x09, 0x00); // (Status: 0x0000)
- phhalSR( 0x10, 0x3E); // (Status: 0x0000)
- phhalSR( 0x11, 0x58); // (Status: 0x0000)
- phhalSR( 0x15, 0x00); // (Status: 0x0000)
- phhalSR( 0x16, 0x00); // (Status: 0x0000)
- phhalSR( 0x00, 0x00); // (Status: 0x0000)
- phhalSR( 0x02, 0xB0); // (Status: 0x0000)
- phhalSR( 0x06, 0x7F); // (Status: 0x0000)
- phhalSR( 0x07, 0x7F); // (Status: 0x0000)
- _DEBUG("//< Write command data into FIFO");
- phhalSR( 0x05, 0x50); // (Status: 0x0000)
- phhalSR( 0x05, 0x00); // (Status: 0x0000)
- _DEBUG("//< Start the command (Transcieve)");
- phhalSR( 0x00, 0x07); // (Status: 0x0000)
- phhalSR( 0x08, 0x18); // (Status: 0x0000)
- phhalSR( 0x09, 0x42); // (Status: 0x0000)
- phhalGR( 0x07); // data == 63 // (Status: 0x0000)
- phhalSR( 0x08, 0x00); // (Status: 0x0000)
- phhalSR( 0x09, 0x00); // (Status: 0x0000)
- _DEBUG("//< Wait until reception. Enable IRQ0 interrupt sources");
- phhalSR( 0x06, 0x40); // (Status: 0x0000)
- phhalSR( 0x08, 0x54); // (Status: 0x0000)
- phhalSR( 0x09, 0x42); // (Status: 0x0000)
- phhalGR( 0x07); // data == 63 // (Status: 0x0000)
- phhalSR( 0x08, 0x00); // (Status: 0x0000)
- phhalSR( 0x09, 0x00); // (Status: 0x0000)
- phhalSR( 0x00, 0x00); // (Status: 0x0000)
- phhalSR( 0x02, 0xB0); // (Status: 0x0000)
- phhalSR( 0x0E, 0x03); // (Status: 0x0000)
- phhalSR( 0x2E, 0x08); // (Status: 0x0000)
- _DEBUG("//< End of the script.");
- _DEBUG("//< .............................................");
- // Shut the power back down
- ioport_ext_set_pin_level(TCA6416_H_F_PDOWN, true);
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement