Description
Due to a few bugs in the write handler for the mimic registers, the peripheral ports DIO outputs do not work as targets for the mimic registers (111-119). This is the last bug report I was planning to file this round, I swear 😄
Causes
The 3 bugs can all be found in the helper function update_DIO_to_mimic() which is used by the write handler for all the mimic registers. This function is meant to switch DIO pins to output pins:
|
/************************************************************************/ |
|
/* REG_MIMIC_PORT0_IR */ |
|
/************************************************************************/ |
|
void update_DIO_to_mimic (unsigned char reg) |
|
{ |
|
if (reg & GM_MIMIC_OUTPUT_DIO0) |
|
io_pin2out(&PORTD, 4, OUT_IO_DIGITAL, IN_EN_IO_EN); // DIO0 to output |
|
if (reg & GM_MIMIC_OUTPUT_DIO0) |
|
io_pin2out(&PORTE, 4, OUT_IO_DIGITAL, IN_EN_IO_EN); // DIO1 to output |
|
if (reg & GM_MIMIC_OUTPUT_DIO0) |
|
io_pin2out(&PORTF, 4, OUT_IO_DIGITAL, IN_EN_IO_EN); // DIO2 to output |
|
} |
|
|
|
void app_read_REG_MIMIC_PORT0_IR(void) {} |
|
bool app_write_REG_MIMIC_PORT0_IR(void *a) |
|
{ |
|
uint8_t reg = *((uint8_t*)a); |
|
update_DIO_to_mimic(reg); |
|
app_regs.REG_MIMIC_PORT0_IR = reg; |
|
return true; |
|
} |
- Bug 1 is a bitmask test on a value enum when it should be an equality comparison:
if (reg & GM_MIMIC_OUTPUT_DIO0) -> if (reg == GM_MIMIC_OUTPUT_DIO0)
|
#define GM_MIMIC_OUTPUT_NONE 0x00 // |
|
#define GM_MIMIC_OUTPUT_DIO0 0x01 // Is reflected on DIO0 |
|
#define GM_MIMIC_OUTPUT_DIO1 0x02 // Is reflected on DIO1 |
|
#define GM_MIMIC_OUTPUT_DIO2 0x03 // Is reflected on DIO2 |
The result of this bug is that update_DIO_to_mimic() matches odd number pins in the MimicOutput group mask (DIO0, DIO2, DO1, and DO3) rather than just the intended DIO pin to update.
- Bug 2 is the repeated condition testing on the same pin,
reg & GM_MIMIC_OUTPUT_DIO0, when it should be changed to the different DIO pins.
if (reg == GM_MIMIC_OUTPUT_DIO0) -> if (reg == GM_MIMIC_OUTPUT_DIO0)
if (reg == GM_MIMIC_OUTPUT_DIO0) -> if (reg == GM_MIMIC_OUTPUT_DIO1)
The result of this bug is that it would keep matching only DIO0.
- Bug 3 is the wrong target pin for
io_pin2out, pin 4 is the IR pin when it should be pin 5 for the DIO pin.
io_pin2out(&PORTD, 4, OUT_IO_DIGITAL, IN_EN_IO_EN) -> io_pin2out(&PORTD, 5, OUT_IO_DIGITAL, IN_EN_IO_EN)
|
io_pin2in(&PORTD, 4, PULL_IO_UP, SENSE_IO_EDGES_BOTH); // POKE0_IR |
|
io_pin2in(&PORTD, 5, PULL_IO_UP, SENSE_IO_EDGES_BOTH); // POKE0_IO |
|
io_pin2in(&PORTE, 4, PULL_IO_UP, SENSE_IO_EDGES_BOTH); // POKE1_IR |
|
io_pin2in(&PORTE, 5, PULL_IO_UP, SENSE_IO_EDGES_BOTH); // POKE1_IO |
Besides failing to convert the DIO pins to outputs, supposedly, this bug should disable all the peripheral port IR poke inputs. I have tested this out and for some reason the poke IR inputs still detect pokes 😄 Although this should still be fixed.
Testing
Supposedly only mimic targets DO0 and DO2 should work cleanly, and the rest of the targets fail. In practice, all the DO targets work, while the DIO targets fail to respond. Tested with behavior board 2.1 and fw 3.3.
Additional Context
This issue is separate from #43, the code that actually runs to change the mimic pins is here and seems to be fine
|
void mimic_ir_or_valve (uint8_t reg, uint8_t what_to_do) |
|
{ |
|
if (reg & MSK_MIMIC_OUTPUT) |
|
{ |
|
switch (reg) |
|
{ |
|
case GM_MIMIC_OUTPUT_DO0: if (what_to_do == _SET_IO_) set_DO0; if (what_to_do == _CLR_IO_) clr_DO0; if (what_to_do == _TGL_IO_) tgl_DO0; break; |
Description
Due to a few bugs in the write handler for the mimic registers, the peripheral ports DIO outputs do not work as targets for the mimic registers (111-119). This is the last bug report I was planning to file this round, I swear 😄
Causes
The 3 bugs can all be found in the helper function update_DIO_to_mimic() which is used by the write handler for all the mimic registers. This function is meant to switch DIO pins to output pins:
device.behavior/Firmware/Behavior/app_funcs.c
Lines 1847 to 1867 in 704d2a9
if (reg & GM_MIMIC_OUTPUT_DIO0)->if (reg == GM_MIMIC_OUTPUT_DIO0)device.behavior/Firmware/Behavior/app_ios_and_regs.h
Lines 375 to 378 in 704d2a9
The result of this bug is that update_DIO_to_mimic() matches odd number pins in the
MimicOutputgroup mask (DIO0, DIO2, DO1, and DO3) rather than just the intended DIO pin to update.reg & GM_MIMIC_OUTPUT_DIO0, when it should be changed to the different DIO pins.if (reg == GM_MIMIC_OUTPUT_DIO0)->if (reg == GM_MIMIC_OUTPUT_DIO0)if (reg == GM_MIMIC_OUTPUT_DIO0)->if (reg == GM_MIMIC_OUTPUT_DIO1)The result of this bug is that it would keep matching only DIO0.
io_pin2out, pin 4 is the IR pin when it should be pin 5 for the DIO pin.io_pin2out(&PORTD, 4, OUT_IO_DIGITAL, IN_EN_IO_EN)->io_pin2out(&PORTD, 5, OUT_IO_DIGITAL, IN_EN_IO_EN)device.behavior/Firmware/Behavior/app_ios_and_regs.c
Lines 31 to 34 in 704d2a9
Besides failing to convert the DIO pins to outputs, supposedly, this bug should disable all the peripheral port IR poke inputs. I have tested this out and for some reason the poke IR inputs still detect pokes 😄 Although this should still be fixed.
Testing
Supposedly only mimic targets
DO0andDO2should work cleanly, and the rest of the targets fail. In practice, all theDOtargets work, while theDIOtargets fail to respond. Tested with behavior board 2.1 and fw 3.3.Additional Context
This issue is separate from #43, the code that actually runs to change the mimic pins is here and seems to be fine
device.behavior/Firmware/Behavior/app_ios_and_regs.c
Lines 7 to 13 in 704d2a9