Fix to hwtimer_spin and improve hwtimer_wait

Fix a big problem with hwtimer_spin (which was not correctly detecting timer overflows), and try to avoid interrupts in hwtimer_wait() while the timer is not set to target time.

This should improve reliability of the hwtimer mechanism.