@@ -52,6 +52,7 @@ static volatile uint8_t ReaderByteCount;
52
52
static volatile uint8_t CardByteCount ;
53
53
static volatile uint16_t SampleDataCount ;
54
54
static volatile uint8_t bBrokenFrame ;
55
+ static bool bAutoThreshold = true;
55
56
56
57
/////////////////////////////////////////////////
57
58
// VCD->VICC
@@ -272,6 +273,20 @@ INLINE void SNIFF_ISO15693_READER_EOC_VCD(void) {
272
273
// VICC->VCD
273
274
/////////////////////////////////////////////////
274
275
276
+
277
+ /* Inline function to set the threshold, if bAutoThreshold is enabled*/
278
+ INLINE void SetDacCh0Data (uint16_t ch0data ){
279
+ /* TODO: Check if either of the branches can be avoided */
280
+ /* to optimize the performance */
281
+ if (bAutoThreshold ){
282
+ if (ch0data < 0xFFF )
283
+ DACB .CH0DATA = ch0data ;
284
+ else
285
+ DACB .CH0DATA = 0xFFF ;
286
+ }
287
+ return ;
288
+ }
289
+
275
290
/* Initialize card sniffing options
276
291
Note: Currently implemented only single subcarrier SOC detection
277
292
*/
@@ -394,8 +409,8 @@ INLINE void CardSniffInit(void) {
394
409
ADCA .EVCTRL = ADC_SWEEP_01_gc ;
395
410
396
411
/* Write threshold to the DAC channel 0 (connected to Analog Comparator positive input) */
397
- DACB . CH0DATA = DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 3 ); /* Slightly increase DAC output to ease triggering */
398
- DACB . CH0DATA |= - ( ( DACB . CH0DATA & 0xFFF ) < DemodFloorNoiseLevel ); /* Branchfree saturating addition */
412
+ SetDacCh0Data ( DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 3 ) ); /* Slightly increase DAC output to ease triggering */
413
+
399
414
400
415
/**
401
416
* Finally, now that we have the DAC set up, configure analog comparator A (the only one in this MCU)
@@ -449,8 +464,8 @@ ISR_SHARED isr_SNIFF_ISO15693_ACA_AC0_VECT(void) {
449
464
450
465
ACA .AC0CTRL = AC_ENABLE_bm | AC_HSMODE_bm | AC_HYSMODE_LARGE_gc | AC_INTMODE_RISING_gc | AC_INTLVL_OFF_gc ; /* Disable this interrupt */
451
466
452
- DACB . CH0DATA = DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 2 ); /* Blindly increase threshold after 1 pulse */
453
- DACB . CH0DATA |= - ( ( DACB . CH0DATA & 0xFFF ) < DemodFloorNoiseLevel ); /* Branchfree saturating addition */
467
+ SetDacCh0Data ( DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 2 ) ); /* Blindly increase threshold after 1 pulse */
468
+
454
469
/* Note: by the time the DAC has changed its output, we're already after the 2nd pulse */
455
470
}
456
471
@@ -460,9 +475,8 @@ ISR_SHARED isr_SNIFF_ISO15693_ACA_AC0_VECT(void) {
460
475
ISR_SHARED isr_SNIFF_ISO15693_CODEC_TIMER_TIMESTAMPS_CCA_VECT (void ) {
461
476
462
477
uint16_t TempRead = ADCA .CH1RES ; /* Can't possibly be greater than 0xFFF since the dac has 12 bit res */
463
- DACB .CH0DATA = TempRead - ANTENNA_LEVEL_OFFSET ; /* Further increase DAC output after 3 pulses with value from PORTA Pin 2 (DEMOD-READER/2.3) */
464
- DACB .CH0DATA &= - (DACB .CH0DATA <= TempRead ); /* Branchfree saturating subtraction */
465
478
479
+ SetDacCh0Data (TempRead - ANTENNA_LEVEL_OFFSET ); /* Further increase DAC output after 3 pulses with value from PORTA Pin 2 (DEMOD-READER/2.3) */
466
480
CODEC_TIMER_TIMESTAMPS .INTCTRLB = TC_CCAINTLVL_OFF_gc ; /* Disable this interrupt */
467
481
}
468
482
@@ -480,8 +494,8 @@ ISR_SHARED isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_CCA_VECT(void) {
480
494
481
495
CODEC_TIMER_LOADMOD .INTCTRLB = TC_CCAINTLVL_OFF_gc ; /* Disable all compare interrupts, including this one */
482
496
483
- DACB . CH0DATA = DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 3 ); /* Restore DAC output (AC negative comparation threshold) to pre-AC0 interrupt update value */
484
- DACB . CH0DATA |= - ( ( DACB . CH0DATA & 0xFFF ) < DemodFloorNoiseLevel ); /* Branchfree saturating addition */
497
+ SetDacCh0Data ( DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 3 ) ); /* Restore DAC output (AC negative comparation threshold) to pre-AC0 interrupt update value */
498
+
485
499
ACA .AC0CTRL |= AC_INTLVL_HI_gc ; /* Re-enable analog comparator interrupt to search for another pulse */
486
500
487
501
CODEC_TIMER_TIMESTAMPS .INTCTRLB = TC_CCAINTLVL_HI_gc ; /* Re enable CCA interrupt in case it was triggered and then is now disabled */
@@ -564,8 +578,8 @@ ISR_SHARED isr_SNIFF_ISO15693_CODEC_TIMER_LOADMOD_OVF_VECT(void) {
564
578
/* No SOC. The train of pulses was actually garbage. */
565
579
566
580
/* Restore DAC output to intial value */
567
- DACB . CH0DATA = DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 3 );
568
- DACB . CH0DATA |= - ( ( DACB . CH0DATA & 0xFFF ) < DemodFloorNoiseLevel ); /* Branchfree saturating addition */
581
+ SetDacCh0Data ( DemodFloorNoiseLevel + (DemodFloorNoiseLevel >> 3 ) );
582
+
569
583
570
584
/* Re enable AC interrupt */
571
585
ACA .AC0CTRL = AC_ENABLE_bm | AC_HSMODE_bm | AC_HYSMODE_LARGE_gc | AC_INTMODE_RISING_gc | AC_INTLVL_HI_gc ;
@@ -692,6 +706,34 @@ void SniffISO15693CodecInit(void) {
692
706
ReaderSniffInit ();
693
707
}
694
708
709
+ /************************************************************
710
+ Function used by the Terminal command to display (GET)
711
+ the state of the Autothreshold Feature.
712
+ ************************************************************/
713
+ bool SniffISO15693GetAutoThreshold (void ){
714
+ return bAutoThreshold ;
715
+ }
716
+
717
+ /************************************************************
718
+ Function used by the Application level to disable the
719
+ Autothreshold Feature.
720
+ If it is disabled: The threshold will be taken from
721
+ GlobalSettings.ActiveSettingPtr->ReaderThreshold
722
+ ************************************************************/
723
+ void SniffISO15693CtrlAutoThreshold (bool enable ){
724
+ bAutoThreshold = enable ;
725
+ return ;
726
+ }
727
+
728
+ /************************************************************
729
+ Function used by the Application level to get the FloorNoise
730
+ FloorNoise can be used to define the scanning range for the
731
+ Autocalibration.
732
+ ************************************************************/
733
+ uint16_t SniffISO15693GetFloorNoise (void ){
734
+ return DemodFloorNoiseLevel ;
735
+ }
736
+
695
737
void SniffISO15693CodecDeInit (void ) {
696
738
/* Gracefully shutdown codec */
697
739
CODEC_DEMOD_IN_PORT .INT0MASK = 0 ;
0 commit comments