CHG: start remaking the used timers in "Hf legic write"
     int next_bit_at = 0;
 
        // ACK 3.6ms = 3600us * 1.5 = 5400ticks.
     int next_bit_at = 0;
 
        // ACK 3.6ms = 3600us * 1.5 = 5400ticks.
+       WaitTicks(5300);
+       ResetTicks();
+       
     for( t = 0; t < 80; ++t) {
         edges = 0;
                next_bit_at += TAG_BIT_PERIOD;
     for( t = 0; t < 80; ++t) {
         edges = 0;
                next_bit_at += TAG_BIT_PERIOD;
-        while(timer->TC_CV < next_bit_at) {
+        while ( GET_TICKS < next_bit_at) {
             volatile uint32_t level = (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_DIN);
             if(level != old_level)
                 edges++;
 
             old_level = level;
         }
             volatile uint32_t level = (AT91C_BASE_PIOA->PIO_PDSR & GPIO_SSC_DIN);
             if(level != old_level)
                 edges++;
 
             old_level = level;
         }
                /* expected are 42 edges (ONE) */
         if(edges > 20 ) {
                /* expected are 42 edges (ONE) */
         if(edges > 20 ) {
-                       int t = timer->TC_CV;
-                       int c = t / TAG_BIT_PERIOD;
-                       
-                       ResetTimer(timer);
+       
+                       uint32_t c = (GET_TICKS / TAG_BIT_PERIOD);
                        legic_prng_forward(c);
                return 0;
         }
                        legic_prng_forward(c);
                return 0;
         }
-       switch_off_tag_rwd();
-
        if (len + offset >= card.cardsize)
                len = card.cardsize - offset;
 
        if (len + offset >= card.cardsize)
                len = card.cardsize - offset;
 
-       setup_phase_reader(iv);
-               
        LED_B_ON();
        while (i < len) {
                int r = legic_read_byte(offset + i, card.cmdsize);
        LED_B_ON();
        while (i < len) {
                int r = legic_read_byte(offset + i, card.cmdsize);
 void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) {
 
        #define LOWERLIMIT 4
 void LegicRfWriter(uint16_t offset, uint16_t len, uint8_t iv, uint8_t *data) {
 
        #define LOWERLIMIT 4
        uint8_t isOK = 1;
        legic_card_select_t card;
        
        uint8_t isOK = 1;
        legic_card_select_t card;
        
-       switch_off_tag_rwd();
-       
        if ( len + offset + LOWERLIMIT >= card.cardsize) {
                isOK = 0;
                goto OUT;
        }
        if ( len + offset + LOWERLIMIT >= card.cardsize) {
                isOK = 0;
                goto OUT;
        }
-       
-       setup_phase_reader(iv);
 
     LED_B_ON();        
        while( len > 0 ) {
 
     LED_B_ON();        
        while( len > 0 ) {