diff options
| -rw-r--r-- | src/core/ao.h | 7 | ||||
| -rw-r--r-- | src/core/ao_fec.h | 2 | ||||
| -rw-r--r-- | src/core/ao_fec_rx.c | 26 | ||||
| -rw-r--r-- | src/drivers/ao_cc1120.c | 7 | ||||
| -rw-r--r-- | src/drivers/ao_packet.c | 4 | ||||
| -rw-r--r-- | src/test/ao_fec_test.c | 21 | 
6 files changed, 36 insertions, 31 deletions
diff --git a/src/core/ao.h b/src/core/ao.h index 62eb488e..861a0fd4 100644 --- a/src/core/ao.h +++ b/src/core/ao.h @@ -511,6 +511,13 @@ extern __xdata uint8_t ao_radio_dma_done;  extern __xdata uint8_t ao_radio_done;  extern __xdata uint8_t ao_radio_mutex; +#ifdef PKT_APPEND_STATUS_1_CRC_OK +#define AO_RADIO_STATUS_CRC_OK	PKT_APPEND_STATUS_1_CRC_OK +#else +#include <ao_fec.h> +#define AO_RADIO_STATUS_CRC_OK	AO_FEC_DECODE_CRC_OK +#endif +  void  ao_radio_general_isr(void) ao_arch_interrupt(16); diff --git a/src/core/ao_fec.h b/src/core/ao_fec.h index f1192b62..771732bd 100644 --- a/src/core/ao_fec.h +++ b/src/core/ao_fec.h @@ -70,6 +70,8 @@ ao_fec_encode(const uint8_t *in, uint8_t len, uint8_t *out);  #define AO_FEC_DECODE_BLOCK	(32)	/* callback must return multiples of this many bits */ +#define AO_FEC_DECODE_CRC_OK	0x80	/* stored in out[out_len-1] */ +  uint8_t  ao_fec_decode(const uint8_t *in, uint16_t in_len, uint8_t *out, uint8_t out_len, uint16_t (*callback)()); diff --git a/src/core/ao_fec_rx.c b/src/core/ao_fec_rx.c index 0d400bb0..d4c98475 100644 --- a/src/core/ao_fec_rx.c +++ b/src/core/ao_fec_rx.c @@ -211,6 +211,7 @@ ao_fec_decode(const uint8_t *in, uint16_t len, uint8_t *out, uint8_t out_len, ui  			int8_t		dist = b - (o + 8);	/* distance to last ready-for-writing bit */  			uint32_t	min_cost;		/* lowest cost */  			uint8_t		min_state;		/* lowest cost state */ +			uint8_t		byte;  			/* Find the best fit at the current point  			 * of the decode. @@ -238,24 +239,27 @@ ao_fec_decode(const uint8_t *in, uint16_t len, uint8_t *out, uint8_t out_len, ui  			printf ("\tbit %3d min_cost %5d old bit %3d old_state %x bits %02x whiten %0x\n",  				i/2, min_cost, o + 8, min_state, (bits[p][min_state] >> dist) & 0xff, *whiten);  #endif -			if (out_len) { -				uint8_t	byte = (bits[p][min_state] >> dist) ^ *whiten++; +			byte = (bits[p][min_state] >> dist) ^ *whiten++; +			*out++ = byte; +			if (out_len > 2) +				crc = ao_fec_crc_byte(byte, crc); -				if (out_len > 2) { -					crc = ao_fec_crc_byte(byte, crc); -					*out++ = byte; -				} else { -					*out++ = byte ^ (crc >> 8); -					crc <<= 8; -				} -				--out_len; +			if (!--out_len) { +				if ((out[-2] == (uint8_t) (crc >> 8)) && +				    out[-1] == (uint8_t) crc) +					out[-1] = AO_FEC_DECODE_CRC_OK; +				else +					out[-1] = 0; +				out[-2] = 0; +				goto done;  			}  			o += 8;  		}  	} +done:  #if AO_PROFILE  	ao_fec_decode_start = start_tick;  	ao_fec_decode_end = ao_profile_tick();  #endif -	return len/16; +	return 1;  } diff --git a/src/drivers/ao_cc1120.c b/src/drivers/ao_cc1120.c index c974613e..30663042 100644 --- a/src/drivers/ao_cc1120.c +++ b/src/drivers/ao_cc1120.c @@ -690,12 +690,7 @@ ao_radio_recv(__xdata void *d, uint8_t size)  	ao_radio_put(); -	/* Construct final packet */ - -	if (ret && ((uint8_t *) d)[size] == 0 && ((uint8_t *)d)[size+1] == 0) -		((uint8_t *) d)[size + 1] = 0x80; -	else -		((uint8_t *) d)[size + 1] = 0x00; +	/* Store the received RSSI value; the crc-OK byte is already done */  	((uint8_t *) d)[size] = (uint8_t) rssi; diff --git a/src/drivers/ao_packet.c b/src/drivers/ao_packet.c index 19fe0558..28a0c415 100644 --- a/src/drivers/ao_packet.c +++ b/src/drivers/ao_packet.c @@ -65,10 +65,8 @@ ao_packet_recv(void)  	/* Check to see if we got a valid packet */  	if (!dma_done)  		return 0; -#ifdef PKT_APPEND_STATUS_1_CRC_OK -	if (!(ao_rx_packet.status & PKT_APPEND_STATUS_1_CRC_OK)) +	if (!(ao_rx_packet.status & AO_RADIO_STATUS_CRC_OK))  		return 0; -#endif  	/* Accept packets with matching call signs, or any packet if  	 * our callsign hasn't been configured diff --git a/src/test/ao_fec_test.c b/src/test/ao_fec_test.c index 8ce532c8..671fcafc 100644 --- a/src/test/ao_fec_test.c +++ b/src/test/ao_fec_test.c @@ -268,18 +268,17 @@ int  ao_real_packet(void)  {  	uint8_t	decode[64]; -	uint8_t	decode_len; -	int ok = 0; +	int	ok; -	decode_len = ao_fec_decode(real_packet, 576, decode, 34, NULL); +	ok = ao_fec_decode(real_packet, 576, decode, 34, NULL); -	if (decode[32] == 0 && decode[33] == 0) { +	if (ok && decode[33] == AO_FEC_DECODE_CRC_OK) {  		printf ("match\n"); -		ao_fec_dump_bytes(decode, decode_len, "Decode"); -		ok = 1; +		ao_fec_dump_bytes(decode, 34, "Decode");  	} else {  		printf ("actual packet crc error\n"); +		ok = 0;  	}  	return ok;  } @@ -302,7 +301,7 @@ main(int argc, char **argv)  	int		receive_len, receive_errors;  	uint8_t		decode[DECODE_LEN(sizeof(original))]; -	int		decode_len; +	int		decode_ok;  	int		errors = 0;  	int		error; @@ -327,17 +326,17 @@ main(int argc, char **argv)  		receive_len = transmit_len;  		/* Decode it */ -		decode_len = ao_fec_decode(receive, receive_len, decode, original_len + 2, NULL); +		decode_ok = ao_fec_decode(receive, receive_len, decode, original_len + 2, NULL);  		/* Check to see if we received the right data */  		error = 0; -		if (decode_len < original_len + 2) { -			printf ("len mis-match\n"); +		if (!decode_ok) { +			printf ("decode failed\n");  			error++;  		} -		if (decode[original_len] != 0 || decode[original_len+1] != 0) { +		if (decode[original_len +1] != AO_FEC_DECODE_CRC_OK) {  			printf ("crc mis-match\n");  			error++;  		}  | 
