Implement a Save "wait" function

Hello,

I'm using a IC calles CLRC663, its a NFC reader.

When perfoming a time-consuming operation inside the IC, it can't do other things. This is indicated by a "idle register" which reads "0xFF" if busy. When not being 0xFF, the IC can accept new commands.

A quick fix would be

 while (read_reg(idle) == 0xFF){ //nothing}

But what if if the register not becomes idle. Then the micrcontroller would be frozen until a hardware reset. Which is bad.

this function is called nearly in every reader action, and its encapsulated in the reader library.

Is there a better solution to this problem? One that would "quit waiting" after a interval of X

Best option: Just NOT place it in a while() and just poll it. This way you can even do other stuff on the micro while waiting.

Little bit better, make a time out:

const unsigned long StartReadTime = millis();
while ((read_reg(idle) == 0xFF) && (millis() - StartReadMillis < ReadTimeout));

septillion:
Best option: Just NOT place it in a while() and just poll it. This way you can even do other stuff on the micro while waiting.

Little bit better, make a time out:

const unsigned long StartReadTime = millis();

while ((read_reg(idle) == 0xFF) && (millis() - StartReadMillis < ReadTimeout));

How can i make the "millis()" available inside a library? when i use millis() i get a compiler error, since the file does not know that millis exist. I had this problem in the past, for different functions not relying on actual millis, but more a time unit, and i had to pass the value by the function call like "someFunction(uint32_t millis)". Eclipse seems not to like millis() inside libraries, since it does not know that it is.

How can i make the "millis()" available inside a library?

#include "Arduino.h"