altos: decode cc1120 received packets
[fw/altos] / src / core / ao_viterbi.c
index bb93bc83b798540782e928a8c5ac4e0bf448c0fb..7768155669847c62ebb77ad87968f904bc3dd917 100644 (file)
@@ -55,16 +55,19 @@ struct ao_soft_sym {
 #define NUM_HIST       8
 #define MOD_HIST(b)    ((b) & 7)
 
+#define V_0            0xc0
+#define V_1            0x40
+
 static const struct ao_soft_sym ao_fec_decode_table[NUM_STATE][2] = {
 /* next        0              1                 state */
-       { { 0x00, 0x00 }, { 0xff, 0xff } } ,    /* 000 */
-       { { 0x00, 0xff }, { 0xff, 0x00 } },     /* 001 */
-       { { 0xff, 0xff }, { 0x00, 0x00 } },     /* 010 */
-       { { 0xff, 0x00 }, { 0x00, 0xff } },     /* 011 */
-       { { 0xff, 0xff }, { 0x00, 0x00 } },     /* 100 */
-       { { 0xff, 0x00 }, { 0x00, 0xff } },     /* 101 */
-       { { 0x00, 0x00 }, { 0xff, 0xff } },     /* 110 */
-       { { 0x00, 0xff }, { 0xff, 0x00 } }      /* 111 */
+       { { V_0, V_0 }, { V_1, V_1 } } ,        /* 000 */
+       { { V_0, V_1 }, { V_1, V_0 } }, /* 001 */
+       { { V_1, V_1 }, { V_0, V_0 } }, /* 010 */
+       { { V_1, V_0 }, { V_0, V_1 } }, /* 011 */
+       { { V_1, V_1 }, { V_0, V_0 } }, /* 100 */
+       { { V_1, V_0 }, { V_0, V_1 } }, /* 101 */
+       { { V_0, V_0 }, { V_1, V_1 } }, /* 110 */
+       { { V_0, V_1 }, { V_1, V_0 } }  /* 111 */
 };
 
 static inline uint8_t
@@ -88,7 +91,7 @@ ao_cost(struct ao_soft_sym a, struct ao_soft_sym b)
  */
 
 uint8_t
-ao_fec_decode(uint8_t *in, uint16_t len, uint8_t *out)
+ao_fec_decode(uint8_t *in, uint16_t len, uint8_t *out, uint8_t out_len)
 {
        static uint16_t cost[2][NUM_STATE];             /* path cost */
        static uint16_t bits[2][NUM_STATE];             /* save bits to quickly output them */
@@ -200,7 +203,10 @@ ao_fec_decode(uint8_t *in, uint16_t len, uint8_t *out)
                        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
-                       *out++ = (bits[p][min_state] >> dist) ^ *whiten++;
+                       if (out_len) {
+                               *out++ = (bits[p][min_state] >> dist) ^ *whiten++;
+                               --out_len;
+                       }
                        o += 8;
                }
        }