X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fasix-sigma%2Fprotocol.c;fp=src%2Fhardware%2Fasix-sigma%2Fprotocol.c;h=e87795e8e6e82ee6067797bd6738b485953c9935;hb=ea57157d0d2e17e418463cf8e4f25453e5b903d7;hp=e913e258887cb559d567eaf21aef68cb31001151;hpb=3f5f5484100ba39dafa4d90b84d25cd3d871d2f2;p=libsigrok.git diff --git a/src/hardware/asix-sigma/protocol.c b/src/hardware/asix-sigma/protocol.c index e913e258..e87795e8 100644 --- a/src/hardware/asix-sigma/protocol.c +++ b/src/hardware/asix-sigma/protocol.c @@ -1839,12 +1839,17 @@ static void build_lut_entry(uint16_t *lut_entry, static void add_trigger_function(enum triggerop oper, enum triggerfunc func, size_t index, gboolean neg, uint16_t *mask) { - size_t i, j; - int x[2][2], tmp, a, b, aset, bset, rset; + int x[2][2], a, b, aset, bset, rset; + size_t bitidx; - memset(x, 0, sizeof(x)); + /* + * Beware! The x, a, b, aset, bset, rset variables strictly + * require the limited 0..1 range. They are not interpreted + * as logically true, instead bit arith is done on them. + */ - /* Trigger detect condition. */ + /* Construct a pattern which detects the condition. */ + memset(x, 0, sizeof(x)); switch (oper) { case OP_LEVEL: x[0][1] = 1; @@ -1880,8 +1885,11 @@ static void add_trigger_function(enum triggerop oper, enum triggerfunc func, break; } - /* Transpose if neg is set. */ + /* Transpose the pattern if the condition is negated. */ if (neg) { + size_t i, j; + int tmp; + for (i = 0; i < 2; i++) { for (j = 0; j < 2; j++) { tmp = x[i][j]; @@ -1891,29 +1899,30 @@ static void add_trigger_function(enum triggerop oper, enum triggerfunc func, } } - /* Update mask with function. */ - for (i = 0; i < 16; i++) { - a = (i >> (2 * index + 0)) & 1; - b = (i >> (2 * index + 1)) & 1; + /* Update the LUT mask with the function's condition. */ + for (bitidx = 0; bitidx < 16; bitidx++) { + a = (bitidx & BIT(2 * index + 0)) ? 1 : 0; + b = (bitidx & BIT(2 * index + 1)) ? 1 : 0; - aset = (*mask >> i) & 1; + aset = (*mask & BIT(bitidx)) ? 1 : 0; bset = x[b][a]; - rset = 0; if (func == FUNC_AND || func == FUNC_NAND) rset = aset & bset; else if (func == FUNC_OR || func == FUNC_NOR) rset = aset | bset; else if (func == FUNC_XOR || func == FUNC_NXOR) rset = aset ^ bset; + else + rset = 0; if (func == FUNC_NAND || func == FUNC_NOR || func == FUNC_NXOR) - rset = !rset; - - *mask &= ~BIT(i); + rset = 1 - rset; if (rset) - *mask |= BIT(i); + *mask |= BIT(bitidx); + else + *mask &= ~BIT(bitidx); } }