Code: Select all
cfg = *(&pio->cfg[0] + index);
cfg &= ~(0xf << offset);
cfg |= val << offset;
*(&pio->cfg[0] + index) = cfgCode: Select all
cfg = *(&pio->cfg[0] + index);
cfg &= ~(0xf << offset);
cfg |= val << offset;
*(&pio->cfg[0] + index) = cfg
The first line gets the content of a configuration registerlilzz wrote:anyone see the logic of this?Code: Select all
cfg = *(&pio->cfg[0] + index); cfg &= ~(0xf << offset); cfg |= val << offset; *(&pio->cfg[0] + index) = cfg

Normal?!Fairly normal way of modifying a memory mapped configuration register.
Code: Select all
cfg = pio->cfg[index];
Heater wrote:mikronauts,Normal?!Fairly normal way of modifying a memory mapped configuration register.
Why not just write:Which compiles to the same code as shown above but is a lot clearer.Code: Select all
cfg = pio->cfg[index];
The code as given is only normal in that it is how some C programmers obfuscate their code for job security
Looks like a psychiatrist's test for ill programmers to mePiGraham wrote:It looks like a test. Is it homework on pointers and bitwise logic?
Heater wrote:Mickronauts,
Indeed, ZOG would not approve.
How long does it take Parallax to swap a server? I'm getting twitchy here.
PiGraham wrote:It looks like a test. Is it homework on pointers and bitwise logic?
Ravenous wrote:Looks like a psychiatrist's test for ill programmers to mePiGraham wrote:It looks like a test. Is it homework on pointers and bitwise logic?
Like a Rorschach ink blot test for programmers
Could be. It's not a good programming style example!Ravenous wrote:Like a Rorschach ink blot test for programmers
Code: Select all
// cfg = readl(&pio->cfg[0] + index);
cfg = *(&pio->cfg[0] + index);
cfg &= ~(0xf << offset);
cfg |= val << offset;
// writel(cfg, &pio->cfg[0] + index);
*(&pio->cfg[0] + index) = cfg;