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);
#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)());
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.
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;
}
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;
/* 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
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;
}
int receive_len, receive_errors;
uint8_t decode[DECODE_LEN(sizeof(original))];
- int decode_len;
+ int decode_ok;
int errors = 0;
int error;
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++;
}