コード例 #1
0
ファイル: sniff.c プロジェクト: chinnyannieb/RFIDler
// watch external clock for PWM messages
// specify minimum gap to look for in us
void sniff_pwm(unsigned int min)
{
    BOOL            toggle;
    BOOL            abort= FALSE;
    unsigned long   i, count, pulsecount= 0L, gaps[DETECT_BUFFER_SIZE], pulses[DETECT_BUFFER_SIZE];
    
    // make sure local clock isn't running & switch to input
    stop_HW_clock();

    COIL_MODE_READER();
    READER_CLOCK_ENABLE_OFF(LOW);
    
    toggle= SNIFFER_COIL;
    
    // wait for 100 ticks to make sure we're settled
    toggle= SNIFFER_COIL;
    while(count < 100)
    {
        while(SNIFFER_COIL == toggle)
            // check for user abort
            if(get_user_abort())
                return;
        ++count;
        toggle= !toggle;
    }
    
    // watch for gaps / pulses
    i= 0;
    GetTimer_us(RESET);
    while(!abort)
    {
        while(SNIFFER_COIL == toggle)
            // check for user abort
            if((abort= get_user_abort()))
                break;
        toggle= !toggle;
        count= GetTimer_us(RESET);
        // check if it was a gap
        if(count > min)
        {
            pulses[i]= pulsecount;
            gaps[i++]= count;
            pulsecount= 0L;
        }
        else
            pulsecount += count;
        if(i == DETECT_BUFFER_SIZE)
        {
            decode_pwm(pulses, gaps, i);
            i= 0;
        }
    }
    
    decode_pwm(pulses, gaps, i);
}
コード例 #2
0
ファイル: ask.c プロジェクト: 10to7/RFIDler
// h/w clock ASK emulator - initialise data pointers for ISR and start timer 2
// args: clock pulsewidth (NOT period!), data as array of 0/1, repeat
void write_ASK_HW_clock(unsigned int pulse, BYTE *data, unsigned int tpb, unsigned int repeat)
{
    // convert to ticks
    pulse= CONVERT_TO_TICKS(pulse);
    // we only need to tick once per bit
    pulse *= (unsigned long) tpb;

    // point globals at data for ISR
    EMU_ThisBit= *data;
    EMU_Data= data + 1;
    EMU_Reset_Data= data;
    EMU_DataBitRate= 1;
    EMU_SubCarrier_T0= 1;

    EMU_Repeat= repeat;

    // if we're manchester or bi-phase encoding, we want to clock twice as fast so we can toggle on half-bit
    if(RFIDlerConfig.Manchester || RFIDlerConfig.BiPhase)
    {
        pulse /= 2;
        EMU_SubCarrier_T0 *= 2;
        EMU_DataBitRate *= 2;
    }

    // make sure no clock is running
    stop_HW_clock();
    
    // set mode
    EmulationMode= MOD_MODE_ASK_OOK;

    // make sure nobody's using our timer
    CloseTimer3();

    // tri-state on, clock low
    READER_CLOCK_ENABLE_ON();
    CLOCK_COIL= LOW;

    // emulator mode
    COIL_MODE_EMULATOR();

    // this is also a semaphore so the rest of the code knows we're running
    mLED_Emulate_On();

    // start timer - ISR will send data
    OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, pulse - 1L);
    mT3SetIntPriority(6);
    mT3ClearIntFlag();
    mT3IntEnable(TRUE);
}
コード例 #3
0
ファイル: q5.c プロジェクト: natashenka/RFIDler
// get raw UID
BOOL q5_get_uid(BYTE *response)
{
    BYTE tmp[17]; // 16 hex digits

    // q5 will be stuck if last command was a read or write, so always hard reset
    stop_HW_clock();

    // delay for sleep period
    Delay_us((RFIDlerConfig.FrameClock * RFIDlerConfig.RWD_Sleep_Period) / 100);

    // delay for startup time
    //Delay_us((RFIDlerConfig.FrameClock * RFIDlerConfig.RWD_Wake_Period) / 100);

    // q5 has fixed em4x02 style data in page 1
    if(q5_send_command(tmp, Q5_GET_TRACE_DATA, strlen(Q5_GET_TRACE_DATA), NO_RESET, SYNC, 64))
    {
        strcpy(response, tmp);
        return TRUE;
    }
    return FALSE;
}
コード例 #4
0
ファイル: t55x7.c プロジェクト: ApertureLabsLtd/RFIDler
// get raw UID
BOOL t55x7_get_uid(BYTE *response)
{
    BYTE tmp[33]; // 16 hex digits

    // t55x7 will be stuck if last command was a read or write, so always hard reset
    stop_HW_clock();

    // delay for sleep period
    Delay_us((RFIDlerConfig.FrameClock * RFIDlerConfig.RWD_Sleep_Period) / 100);

    // delay for startup time
    Delay_us((RFIDlerConfig.FrameClock * RFIDlerConfig.RWD_Wake_Period) / 100);

    // t55x7 has fixed tracebility data - 2 x 32 bit blocks
    if(t55x7_send_command(tmp, T55X7_GET_TRACE_DATA, strlen(T55X7_GET_TRACE_DATA), NO_RESET, SYNC, 64))
    {
        strcpy(response, tmp);
        return TRUE;
    }
    return FALSE;
}
コード例 #5
0
ファイル: psk.c プロジェクト: zhihuawang/RFIDler
// h/w clock PSK emulator - initialise data pointers for ISR and start timer 2
// args: clock period, data as array of 0/1, fc per bit, sub-carrier ticks, repeat
void write_PSK1_HW_clock(unsigned int period, BYTE *data, unsigned int fcpb, unsigned int c0, unsigned int repeat)
{
    // convert to ticks
    period= CONVERT_TO_TICKS(period);
    // for psk we want a full clock cycle, not a tick
    period *= 2;

    // point globals at data for ISR
    EMU_ThisBit= *data;
    EMU_Data= data + 1;
    EMU_Reset_Data= data;
    EMU_DataBitRate= fcpb;
    EMU_SubCarrier_T0= c0;
    EMU_Repeat= repeat;

    // set mode
    EmulationMode= MOD_MODE_PSK1;

    // make sure no clock is running
    stop_HW_clock();

    // make sure nobody's using our timers
    CloseTimer3();

    // tri-state on, clock low
    READER_CLOCK_ENABLE_ON();
    CLOCK_COIL= LOW;

    // emulator mode
    COIL_MODE_EMULATOR();

    // this is also a semaphore so the rest of the code knows we're running
    mLED_Emulate_On();

    // start timer - ISR will send data
    OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, period / 2L - 1L);
    mT3SetIntPriority(6);
    mT3ClearIntFlag();
    mT3IntEnable(TRUE);
}
コード例 #6
0
ファイル: fsk.c プロジェクト: 10to7/RFIDler
// h/w clock FSK emulator - initialise data pointers for ISR and start timer 2
// args: clock pulsewidth (NOT period!), data as array of 0/1, T0 sub-carrier ticks, T1 sub-carrier ticks, repeat
void write_FSK_HW_clock(unsigned long pulse, BYTE *data, unsigned int tpb, unsigned int t0, unsigned int t1, unsigned int repeat)
{
    // convert to ticks
    pulse= CONVERT_TO_TICKS(pulse);

    // point globals at data for ISR
    EMU_ThisBit= *data;
    EMU_Data= data + 1;
    EMU_Reset_Data= data;
    EMU_Repeat= repeat;
    EMU_DataBitRate= tpb;
    EMU_SubCarrier_T0= t0;
    EMU_SubCarrier_T1= t1;

    // set mode
    EmulationMode= MOD_MODE_FSK;

    // make sure no clock is running
    stop_HW_clock();

    // make sure nobody's using our timer
    CloseTimer3();

    // emulator mode
    COIL_MODE_EMULATOR();

    // tri-state on, clock low
    READER_CLOCK_ENABLE_ON();
    CLOCK_COIL= LOW;

    // this is also a semaphore so the rest of the code knows we're running
    mLED_Emulate_On();

    // start timer - ISR will send data
    OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, pulse - 1L);
    mT3SetIntPriority(6);
    mT3ClearIntFlag();
    mT3IntEnable(TRUE);
}
コード例 #7
0
ファイル: tags.c プロジェクト: nsdown/RFIDler
BOOL tag_set(BYTE tag)
{
    // reset everything, then set what needs to be changed
    // most timings are in FCs unless otherwise specified
    // FrameClock itself is in us/100 (i.e. 800 is 8us == 125KHz)
    // Timeout is in us
    RFIDlerConfig.FrameClock= 0;
    RFIDlerConfig.BiPhase= FALSE;
    RFIDlerConfig.Manchester= FALSE;
    RFIDlerConfig.Invert= FALSE;
    RFIDlerConfig.Modulation= MOD_MODE_NONE;
    RFIDlerConfig.PotLow= 0;
    RFIDlerConfig.PotHigh= 0;
    RFIDlerConfig.DataRate= 0;
    RFIDlerConfig.DataRateSub0= 0;
    RFIDlerConfig.DataRateSub1= 0;
    RFIDlerConfig.DataBits= 0;
    RFIDlerConfig.TagType= tag;
    RFIDlerConfig.Repeat= 0;
    RFIDlerConfig.Timeout= 0L;
    RFIDlerConfig.Sync[0]= 0x00;
    RFIDlerConfig.Sync[1]= 0x00;
    RFIDlerConfig.Sync[2]= 0x00;
    RFIDlerConfig.Sync[3]= 0x00;
    RFIDlerConfig.SyncBits= 0;
    RFIDlerConfig.RWD_Gap_Period= 0;
    RFIDlerConfig.RWD_Sleep_Period= 0;
    RFIDlerConfig.RWD_Wake_Period= 0;
    RFIDlerConfig.RWD_Zero_Period= 0;
    RFIDlerConfig.RWD_One_Period= 0;
    RFIDlerConfig.RWD_Wait_Switch_RX_TX= 0;
    RFIDlerConfig.RWD_Wait_Switch_TX_RX= 0;

    switch(tag)
    {
        case TAG_TYPE_NONE:
            break;

        case TAG_TYPE_ASK_RAW:
            RFIDlerConfig.FrameClock= 800; // 125 KHz
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 100;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataBits= RAW_TAGS_DATABITS;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

      case TAG_TYPE_AWID_26:
            //RFIDlerConfig.FrameClock= 765; // 130.7 KHz (134KHz breaks emulation)
            RFIDlerConfig.FrameClock= 800; // 125 KHz
            RFIDlerConfig.Modulation= MOD_MODE_FSK2;
            RFIDlerConfig.PotHigh=  110;
            RFIDlerConfig.DataRate= 50;
            RFIDlerConfig.DataRateSub0= 8;
            RFIDlerConfig.DataRateSub1= 10;
            RFIDlerConfig.DataBits= 96;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.Sync[0]= 0x01;
            RFIDlerConfig.Sync[1]= 0x1D;
            RFIDlerConfig.Sync[2]= 0x80;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 18;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;
              
        case TAG_TYPE_EM4X02:
        case TAG_TYPE_UNIQUE:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Manchester= TRUE;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 150;
            RFIDlerConfig.DataRate= 64;
            RFIDlerConfig.DataBits= 64;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.Sync[0]= 0xFF;
            RFIDlerConfig.Sync[1]= 0xFF;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 9;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

        // DEBUG: work in progress!
        case TAG_TYPE_EM4X05:
            RFIDlerConfig.FrameClock= 800; // 125 KHz
            RFIDlerConfig.Manchester= TRUE;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 130;
            RFIDlerConfig.DataRate= 64;
            RFIDlerConfig.DataBits= 53; // 45 bit OTA format + 8 bit preamble
            RFIDlerConfig.DataBlocks= EM4X05_DATABLOCKS;
            RFIDlerConfig.BlockSize= EM4X05_BLOCKSIZE;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Wake_Period= 1000; // docco says max 3 ms, but round up a bit
            RFIDlerConfig.RWD_Gap_Period= 55; // First Field Stop
            RFIDlerConfig.RWD_Sleep_Period= 2000;
            RFIDlerConfig.RWD_Zero_Period= 16; // note that em4x05 uses it's own PWM scheme
            RFIDlerConfig.RWD_One_Period= 32; // see em.c for details
            RFIDlerConfig.RWD_Wait_Switch_TX_RX= 60; // doc says 544us, (9.34 + 1.38 ms when eeprom write), but tests are much shorter!
            RFIDlerConfig.RWD_Wait_Switch_RX_TX= 80; // docs say 544, so about 68 fcs
            break;

       case TAG_TYPE_FDXB:
            RFIDlerConfig.FrameClock= 745; // 134.2 KHz
            RFIDlerConfig.BiPhase= TRUE;
            RFIDlerConfig.Invert= TRUE;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 130;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataBits= 128;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.Sync[0]= 0x00;
            RFIDlerConfig.Sync[1]= 0x20;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 11;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

       case TAG_TYPE_FSK1_RAW:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Modulation= MOD_MODE_FSK1;
            RFIDlerConfig.PotHigh= POTHIGH_DEFAULT;
            RFIDlerConfig.DataRate= 50;
            RFIDlerConfig.DataRateSub0= 8;
            RFIDlerConfig.DataRateSub1= 5;
            RFIDlerConfig.DataBits= RAW_TAGS_DATABITS;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

       case TAG_TYPE_FSK2_RAW:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Modulation= MOD_MODE_FSK2;
            RFIDlerConfig.PotHigh= 90;
            RFIDlerConfig.DataRate= 50;
            RFIDlerConfig.DataRateSub0= 8;
            RFIDlerConfig.DataRateSub1= 10;
            RFIDlerConfig.DataBits= RAW_TAGS_DATABITS;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;
                  
        case TAG_TYPE_HID_26:
            //RFIDlerConfig.FrameClock= 765; // 130.7 KHz (134KHz breaks emulation)
            RFIDlerConfig.FrameClock= 800; // 125 KHz
            RFIDlerConfig.Modulation= MOD_MODE_FSK2;
            RFIDlerConfig.PotHigh=  110;
            RFIDlerConfig.DataRate= 50;
            RFIDlerConfig.DataRateSub0= 8;
            RFIDlerConfig.DataRateSub1= 10;
            RFIDlerConfig.DataBits= 96;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.Sync[0]= 0x1D;
            RFIDlerConfig.Sync[1]= 0x55;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 16;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

        case TAG_TYPE_HITAG1:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Manchester= TRUE;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 170;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataBits= 33; //
            RFIDlerConfig.DataBlocks= HITAG1_DATABLOCKS;
            RFIDlerConfig.BlockSize= HITAG1_BLOCKSIZE;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Gap_Period= 4; // 4 - 10
            RFIDlerConfig.RWD_Sleep_Period= 2000;
            RFIDlerConfig.RWD_Wake_Period= 500; // documentations says ~3ms, so round up a bit
            RFIDlerConfig.RWD_Zero_Period= 18; // 18 - 22
            RFIDlerConfig.RWD_One_Period= 26; // 26 - 32
            RFIDlerConfig.RWD_Wait_Switch_TX_RX= 180; // docs say 204, so stop a little earlier so we catch leading edge
            RFIDlerConfig.RWD_Wait_Switch_RX_TX= 120; // docs say 96, so give it a bit longer t0 be safe!
            RFIDlerConfig.SyncBits= 0;
            RFIDlerConfig.Sync[0]= 0x00;
            RFIDlerConfig.Sync[0]= 0x00;
            RFIDlerConfig.Sync[0]= 0x00;
            RFIDlerConfig.Sync[0]= 0x00;
            break;

        case TAG_TYPE_HITAG2:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Manchester= TRUE;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 160;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataBits= 37; // 5 bits leadin + 32 bits ID
            RFIDlerConfig.DataBlocks= HITAG2_DATABLOCKS;
            RFIDlerConfig.BlockSize= HITAG2_BLOCKSIZE;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Gap_Period= 3; // 4 - 10 (we use 3 to allow for sloppiness in RWD timings)
            RFIDlerConfig.RWD_Sleep_Period= 2000;  // 2000;
            RFIDlerConfig.RWD_Wake_Period= 525; // (was 450) must be > 312.5 but less than 544 to allow reset of user modes
            RFIDlerConfig.RWD_Zero_Period= 18; // 18 - 22
            RFIDlerConfig.RWD_One_Period= 26; // 26 - 32
            RFIDlerConfig.RWD_Wait_Switch_TX_RX= 150; // docs say 199 - 206 but in practice it can be less
            RFIDlerConfig.RWD_Wait_Switch_RX_TX= 90;
            RFIDlerConfig.Sync[0]= 0xF8;
            RFIDlerConfig.Sync[1]= 0x00;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 5;
            break;

        case TAG_TYPE_INDALA_64:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Modulation= MOD_MODE_PSK1;
            RFIDlerConfig.PotLow= POTLOW_DEFAULT;
            RFIDlerConfig.PotHigh= 170;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataRateSub0= 2;
            RFIDlerConfig.DataBits= 64;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.PSK_Quality= 4L;
            RFIDlerConfig.Sync[0]= 0x00;
            RFIDlerConfig.Sync[1]= 0x00;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 24;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

        case TAG_TYPE_INDALA_224:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Modulation= MOD_MODE_PSK1;
            RFIDlerConfig.PotLow= POTLOW_DEFAULT;
            RFIDlerConfig.PotHigh= 170;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataRateSub0= 2;
            RFIDlerConfig.DataBits= 224;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.PSK_Quality= 4L;
            RFIDlerConfig.Sync[0]= 0x00;
            RFIDlerConfig.Sync[1]= 0x00;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 24;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

        case TAG_TYPE_PSK1_RAW:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Modulation= MOD_MODE_PSK1;
            RFIDlerConfig.PotLow= POTLOW_DEFAULT;
            RFIDlerConfig.PotHigh= POTHIGH_DEFAULT;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataRateSub0= 2;
            RFIDlerConfig.DataBits= RAW_TAGS_DATABITS;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.PSK_Quality= 4L;
            RFIDlerConfig.RWD_Wake_Period= 1000;
            break;

        case TAG_TYPE_Q5:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Manchester= TRUE;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= 160;
            RFIDlerConfig.DataRate= 64;
            RFIDlerConfig.DataBits= 64;
            RFIDlerConfig.DataBlocks= Q5_DATABLOCKS;
            RFIDlerConfig.BlockSize= Q5_BLOCKSIZE;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.Sync[0]= 0xFF;
            RFIDlerConfig.Sync[1]= 0xFF;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 9;
            RFIDlerConfig.RWD_Sleep_Period= 13000;
            RFIDlerConfig.RWD_Wake_Period= 4000; // must be more than 3ms, but play it safe
            RFIDlerConfig.RWD_Gap_Period= 50; // 14 nominal, 8 - 50 normal, 8 - 25 fast write mode
            RFIDlerConfig.RWD_Zero_Period= 16; //24; // 24 nominal, 16 - 31 normal, 8 - 15 fast write mode
            RFIDlerConfig.RWD_One_Period= 48; //54; // 54 nominal, 48 - 63 normal, 24 - 31 fast write mode
            RFIDlerConfig.RWD_Wait_Switch_TX_RX= 48; //64; // q5 will exit downlink mode after 64 but may not yet be damped!
            RFIDlerConfig.RWD_Wait_Switch_RX_TX= 192; // the longer the better!
            PWD_Mode= FALSE;
            break;

        case TAG_TYPE_T55X7:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.Modulation= MOD_MODE_ASK_OOK;
            RFIDlerConfig.PotHigh= POTHIGH_DEFAULT;
            RFIDlerConfig.Manchester= TRUE;
            RFIDlerConfig.DataRate= 32;
            RFIDlerConfig.DataBits= 64;
            RFIDlerConfig.Sync[0]= 0xE0;
            RFIDlerConfig.Sync[1]= 0x15;
            RFIDlerConfig.Sync[2]= 0x00;
            RFIDlerConfig.Sync[3]= 0x00;
            RFIDlerConfig.SyncBits= 16;
            RFIDlerConfig.DataBlocks= T55X7_DATABLOCKS;
            RFIDlerConfig.BlockSize= T55X7_BLOCKSIZE;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Sleep_Period= 13000; // small tags such as keyfobs need a long sleep to reset
            RFIDlerConfig.RWD_Wake_Period= 4000;
            RFIDlerConfig.RWD_Gap_Period= 23; // 14; // 14 nominal, 8 - 30 normal, 8 - 25 fast write mode
            RFIDlerConfig.RWD_Zero_Period= 16; // 24; // 24 nominal, 16 - 31 normal, 8 - 15 fast write mode
            RFIDlerConfig.RWD_One_Period= 48; // 54; // 54 nominal, 48 - 63 normal, 24 - 31 fast write mode
            RFIDlerConfig.RWD_Wait_Switch_TX_RX= 64; // t55x7 will exit downlink mode after 64 but we mustn't read until t55x7 switches damping on
            RFIDlerConfig.RWD_Wait_Switch_RX_TX= 192;
            break;
            
        // special case - TAMAGOTCHI do not do anything but PWM, so most settings are irrelevant
        case TAG_TYPE_TAMAGOTCHI:
            RFIDlerConfig.FrameClock= 800;
            RFIDlerConfig.TagType= tag;
            RFIDlerConfig.Repeat= 20;
            RFIDlerConfig.Timeout= 13000; // timeout in uS (note with prescaler of 16 max is 13107)
            RFIDlerConfig.RWD_Sleep_Period= 13000; // small tags such as keyfobs need a long sleep to reset
            RFIDlerConfig.RWD_Wake_Period= 4000;
            RFIDlerConfig.RWD_Gap_Period= 23; // 14; // 14 nominal, 8 - 30 normal, 8 - 25 fast write mode
            RFIDlerConfig.RWD_Zero_Period= 16; // 24; // 24 nominal, 16 - 31 normal, 8 - 15 fast write mode
            RFIDlerConfig.RWD_One_Period= 48; // 54; // 54 nominal, 48 - 63 normal, 24 - 31 fast write mode
            RFIDlerConfig.RWD_Wait_Switch_TX_RX= 64; // t55x7 will exit downlink mode after 64 but we mustn't read until t55x7 switches damping on
            RFIDlerConfig.RWD_Wait_Switch_RX_TX= 192;
            break;

        default:
            return FALSE;
    }

    // stop clocks
    stop_HW_clock();

    // configure potentiometers
    set_mcp414_wiper(WIPER_HIGH, VOLATILE, RFIDlerConfig.PotHigh, TmpBuff);
    set_mcp414_wiper(WIPER_LOW, VOLATILE, RFIDlerConfig.PotLow, TmpBuff);

    // delay to allow things to settle
    Delay_us(500000);

    // reset globals
    PWD_Mode= FALSE;
    memset(Password, '\0', sizeof(Password));
    
    return TRUE;
}