pokeIO Function (Macro)

peekpoke.h

#define pokeIO(port,val) (void)(*((volatile unsigned char*)(long)(port)) = (val))

Sends a byte to an I/O port.

poke is not reliable when sending data to memory-mapped I/O ports. Suppose that you have a device mapped to the address port, and that this device requests sending a sequence ot bytes 127,0,255,0 to this address to be reset. If you simply try to do

poke (port, 127);
poke (port, 0);
poke (port, 255);
poke (port, 0);
the compiler will (incorrectly) conclude that sending a sequence of bytes to the same address is nonsense, because new values will overwrite previous ones (assuming that the address points to the memory), so the optimizer will ignore all stores but the last one. Such behavior is correct if port is a normal memory address, but it may be fatal if port is an address of a memory-mapped I/O port. To prevent such behaviour, use pokeIO instead of poke, i.e. write
pokeIO (port, 127);
pokeIO (port, 0);
pokeIO (port, 255);
pokeIO (port, 0);
Basically, pokeIO works exactly like poke, but prevents any unwanted optimizations generated by the compiler. It may be used even for storing bytes in memory, but poke will generate better code when working with memory.