📄 level3.c
字号:
if ( ( data_buffer[ 1 ] == ( crc & 0xFF ) ) && ( data_buffer[ 2 ] == ( crc >> 8 ) ) )
{
i = ta_uid.sak[ cascade ] = data_buffer[ 0 ];
// em4094_data_valid = 0x55 ;
}
else
{
em4094_data_valid = 0x00 ;
// SendByte( 0xE0 + cascade );
return;
}
}
else
{
em4094_data_valid = 0x00 ;
return;
}
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
i = i & 0x04;
cascade++;
}
//return result (AppSw has to check the sak bytes!)
//FormatResponse_Data( uart_command, 0, sizeof(ta_uid), (uint8_t*)&ta_uid );
}
// ==================================================================
// Scale Once - minimum scale is RF/32
// fixed parameters - maxCaptureTimeScale
uint16_t ScaleOnce( uint16_t period )
{
if ( period > 255 )
{
period /= 2;
if ( maxCaptureTimeScale <= 5 )
{
maxCaptureTimeScale++;
}
else if ( maxCaptureTimeScale == 6 )
{
period /= 2;
maxCaptureTimeScale++;
}
else if ( period > 255 )
{
period = 255;
}
}
return period;
}
// ==================================================================
uint8_t ScaleTime( uint16_t period )
{
uint8_t i;
maxCaptureTimeScale = 3;
for( i = 0 ; i < 4 ; i++ )
{
period = ScaleOnce( period );
}
return period;
}
// ==================================================================
// ==================================================================
// INTERRUPT ROUTINES
// ==================================================================
SIGNAL ( SIG_OVERFLOW2 )
{
/*
wdt_reset( );
#ifdef WDT
WatchDog_Feed( );
#endif
*/
TIMSK = 0; //finished, disable all
}
// ==================================================================
// R E C E I V E R C O D E
// ==================================================================
// ---------------------------------------------------------------
// store bit into capture buffer bytes
void store_bit( uint8_t b , uint8_t v )
{
captured_byte = ( captured_byte * 2 ) + b;
captured_valid = ( captured_valid * 2 ) + v;
if ( captured_bit_count == 7 )
{
captured_bit_count = 0;
if ( capture_cnt < CAPTURE_SIZE )
{
capture.decoded_data.capture_data[ capture_cnt ] = captured_byte;
capture.decoded_data.capture_valid[ capture_cnt++ ] = captured_valid;
}
else
{
TIMSK = 0; //finished, disable all
}
}
else
{
captured_bit_count++;
}
}
// ---------------------------------------------------------------
// debug routine stores the captured pulse lengths
// - note: too much data variables is probably detected by $(OBJTOOL)
// - warning only
void store_pulse( uint8_t b )
{
if ( raw_cnt == SHORT_RAW_SIZE ) //reserve for message header
TIMSK = 0; //disable all
else
capture.raw_data[ raw_cnt++ ] = b;
}
// ==================================================================
void type_A_polling( void )
{
//do not use local register variables
uint8_t z = 0;
uint16_t capt , last_capture;
uint16_t icr;
uint8_t x , j;
uint8_t *sptr = &capture.raw_data[ RAW_DATA_A_OFFSET ];
uint16_t prev_capture , pulses = 0;
j = 0;
raw_cnt = RAW_DATA_A_OFFSET;
last_capture = TCNT1;
ICR1 = last_capture;
prev_capture = last_capture;
//WARNING! This code is very sensitive to latency
while ( bit_is_set( TIMSK , TOIE2 ) ) //wait until done
{
icr = ICR1;
capt = icr - last_capture;
x = 255;
if ( capt < x )
x = capt;
if ( x > 0x30 )
{
*sptr++ = x;
raw_cnt++;
if ( raw_cnt >= SHORT_RAW_SIZE )
{
break;
}
j = 1;
pulses = last_capture - prev_capture;
prev_capture = icr;
icr = ICR1;
}
else if ( j != 0 )
{
j = 0;
x = 255;
if ( pulses < x )
x = pulses;
*sptr++ = x;
raw_cnt++;
if ( raw_cnt >= SHORT_RAW_SIZE )
{
break;
}
prev_capture = last_capture;
icr = ICR1;
}
last_capture = icr;
}
TCCR2 = 0;
TCCR1B = 0;
TCCR0 = 0;
//flush last pulses
store_pulse( 255 );
pulses = last_capture - prev_capture;
x = 255;
if ( pulses < x )
x = pulses;
store_pulse( x );
if ( debug_mode != 1 ) // capture mode
{
#define ATRESHOLD 0x58
//analyse the message
j = raw_cnt - RAW_DATA_A_OFFSET;
sptr = &capture.raw_data[ RAW_DATA_A_OFFSET ];
captured_bit_count = 0; //reset some values
capture_cnt = 0;
bit_pos = 1;
if ( j > 1 )
{
j /= 2;
while ( j-- != 0 )
{
x = *sptr++;
z = *sptr++;
if ( z == 0 )
{ //kludge because of noise
store_bit( 0 , 1 );
}
else if ( sof != 1 )
{
store_bit( 0 , 1 );
if ( sof == 0 )
{
sof = 1;
bit_pos = 1;
store_bit( 1 , 0 );
if ( x >= 0x80 )
bit_pos ^= 1;
}
}
else
{
if ( z >= ATRESHOLD )
{
if ( bit_pos == 0 )
{
store_bit( 0 , 0 );
store_bit( 1 , 0 );
if ( x <= 0x80 )
bit_pos = 1;
}
else
{
//!!!!! if this occurs, the latency of this code is too high!!
store_bit( 1 , 1 );
}
}
else
{
store_bit( bit_pos , 0 );
if ( x >= 0x80 )
bit_pos ^= 1;
}
}
}
}
#undef ATRESHOLD
}
//data validity check is left on CRC
sof = 2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -