Max7310: confused about the method of reading output port register
Dear All:
Firstly,I'm writing to express my thanks to Zaborowski for the source code of Max7310 which have helped me so much.
But I'm still confused about the method of reading output port register.
code:
Quoted 3 lines
case 0x01: /* Output port */
return s->level & ~s->direction;
break;I found some instruction of output port register in the datasheet.
Quoted 3 lines
" Reads from the output port register reflect the value that is in the flip-flop controlling the output selection, not the actual I/O value, which may differ if the out-put is overloaded."
So,in my opinion,in the defination of MAX7310State,whether the property of outputport_reg should be added? And does the method of reading/writing output port should be modified as follows.
[reading]
case 0x01: /* Output port */
return s->outputport_reg;
break;
[writing]
case 0x01: /* Output port */Quoted 7 lines
for (diff = (data ^ s->level) & ~s->direction; diff;
diff &= ~(1 << line)) {
line = ffs(diff) - 1;
if (s->handler[line])
qemu_set_irq(s->handler[line], (data >> line) & 1);
}
s->level = (s->level & s->direction) | (data & ~s->direction); s->outputport_reg = data;
break; Hi Yang,
Quoted 42 lines · Yang Ning
Dear All:
Firstly,I'm writing to express my thanks to Zaborowski for the source code of Max7310 which have helped me so much.
But I'm still confused about the method of reading output port register.
code:Quoted 4 lines
case 0x01: /* Output port */ return s->level & ~s->direction; break;I found some instruction of output port register in the datasheet.
Quoted 6 lines
" Reads from the output port register reflect the value that is in the flip-flop
controlling the output selection, not the actual I/O value, which may differ if
the out-put is overloaded."So,in my opinion,in the defination of MAX7310State,whether the property of
outputport_regshould be added?
And does the method of reading/writing output port should be modified as follows.[reading]
case 0x01: /* Output port */ return s->outputport_reg; break; [writing] case 0x01: /* Output port */Quoted 8 lines
for (diff = (data ^ s->level) & ~s->direction; diff; diff &= ~(1 << line)) { line = ffs(diff) - 1; if (s->handler[line]) qemu_set_irq(s->handler[line], (data >> line) & 1); } s->level = (s->level & s->direction) | (data & ~s->direction);
Quoted 2 lines
s->outputport_reg = data;
break;Yes, if by "overload" they mean change direction to "input", then yes, I think you are correct.
Personally I'd call it s->output. I'm wondering if we may need to update the output levels when the Configuration (0x03) is written and on reset. This would be best done by adding a short function max7310_update() that does the "for (diff = ...)" loop and calls qemu_set_irq.
Best regards