aboutsummaryrefslogtreecommitdiff
path: root/common/8b10b.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/8b10b.c')
-rw-r--r--common/8b10b.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/common/8b10b.c b/common/8b10b.c
index a32b7f2..fd89e6f 100644
--- a/common/8b10b.c
+++ b/common/8b10b.c
@@ -139,20 +139,24 @@ static const int8_t map_4b3b[16] = {
};
static const uint16_t k_sym_map[K_CODES_LAST] = {
- [K28_0] = 0b0011110100,
- [K28_1] = 0b0011111001,
- [K28_2] = 0b0011110101,
- [K28_3] = 0b0011110011,
- [K28_4] = 0b0011110010,
- [K28_5] = 0b0011111010,
- [K28_6] = 0b0011110110,
- [K28_7] = 0b0011111000,
- [K23_7] = 0b1110101000,
- [K27_7] = 0b1101101000,
- [K29_7] = 0b1011101000,
- [K30_7] = 0b0111101000
+ [K28_0] = 0b0011110100, /* rd = 0 */
+ [K28_1] = 0b0011111001, /* rd = +2 */
+ [K28_2] = 0b0011110101, /* rd = +2 */
+ [K28_3] = 0b0011110011, /* rd = +2 */
+ [K28_4] = 0b0011110010, /* rd = 0 */
+ [K28_5] = 0b0011111010, /* rd = +2 */
+ [K28_6] = 0b0011110110, /* rd = +2 */
+ [K28_7] = 0b0011111000, /* rd = 0 */
+ [K23_7] = 0b1110101000, /* rd = 0 */
+ [K27_7] = 0b1101101000, /* rd = 0 */
+ [K29_7] = 0b1011101000, /* rd = 0 */
+ [K30_7] = 0b0111101000 /* rd = 0 */
};
+static const uint16_t k_sym_rd =
+ (1<<K28_1) | (1<<K28_2) | (1<<K28_3) | (1<<K28_5) | (1<<K28_6);
+
+
void xfr_8b10b_reset(struct state_8b10b_dec *st) {
st->rx = 0;
st->bit_ctr = 0; /* unsynchronized */
@@ -199,11 +203,19 @@ void xfr_8b10b_encode_reset(struct state_8b10b_enc *st) {
}
int xfr_8b10b_encode(struct state_8b10b_enc *st, int data) {
+ if (st->rd != -1 && st->rd != 1)
+ return -EINVAL;
+
if (data < 0) {
if (-data >= sizeof(k_sym_map)/sizeof(k_sym_map[0]))
return -EINVAL;
- return k_sym_map[-data];
+ int sym = k_sym_map[-data];
+ if (st->rd > 0)
+ sym = (~sym) & 0x3ff;
+ if ((k_sym_rd >> (-data)) & 0x1)
+ st->rd = -st->rd;
+ return sym;
}
if (data > 255)
@@ -215,7 +227,6 @@ int xfr_8b10b_encode(struct state_8b10b_enc *st, int data) {
int x5b = (st->rd == -1) ? map_5b6b[p5b].rd_neg : map_5b6b[p5b].rd_pos;
st->rd -= map_5b6b[p5b].disp * st->rd;
//fprintf(stderr, "\nnow: rd %d data %x p5b %d p3b %d\n", st->rd, data, p5b, p3b);
- //assert(st->rd == -1 || st->rd == 1);
int x3b = (st->rd == -1) ? map_3b4b_d[p3b].rd_neg : map_3b4b_d[p3b].rd_pos;
if (p3b == 7) {