I need to deal with a counter that gives me ticks for my application. The counter is 32bits so what i need to know is how to deal with it when it wraps. for example:
I h
Cast the result of unsigned subtraction to signed and compare to zero. Should handle overflow when you check it often enough (and your timeout is less than half the range of your timer).
uint32_t timer( void); // Returns the current time value
uint32_t timeout;
timeout = timer() + offset;
// wait until timer() reaches or exceeds timeout value
while ((int32_t)(timeout - timer()) > 0);