1) Make sure you compile everything with -O3
2) Get rid of superfluous boolean variables, use break and return.
3) Use do { ... } while (...); to remove the test from the loop top
4) Don't use 'const int' - it is still likely to be a variable.
I would code the bottom of the loop as:
// wait done
nWaitCnt = nMaxWait;
for (;;) {
Data16 = IORD(READ_ADC_BASE,0); //Data16 = Wert des Kanals
if (Data16 & DONE_FLAG)
break;
if (--nWaitCnt == 0)
// All gone horribly wrong....
return 0;
}
DigitalValue = Data16 & 0xFFF // 12 bits
// stop
IOWR(READ_ADC_BASE, 0, 0); //Kanal löschen
return DigitalValue; //DigitalValue zurückgeben
You may also want to use gcc's __builtin_expect() to force which code paths are inlined.